| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| * Olivier L. Larouche - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.invocator.ui.composites; |
| |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage; |
| import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFacade; |
| import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorPackage; |
| import org.eclipse.apogy.core.invocator.Context; |
| import org.eclipse.apogy.core.invocator.DataProductsList; |
| import org.eclipse.core.databinding.DataBindingContext; |
| import org.eclipse.core.databinding.observable.list.IObservableList; |
| import org.eclipse.core.databinding.observable.value.IObservableValue; |
| import org.eclipse.core.databinding.observable.value.WritableValue; |
| import org.eclipse.emf.databinding.EMFProperties; |
| import org.eclipse.emf.databinding.FeaturePath; |
| import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; |
| import org.eclipse.jface.databinding.viewers.ViewerProperties; |
| import org.eclipse.jface.databinding.viewers.ViewerSupport; |
| import org.eclipse.jface.viewers.TableViewer; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.ScrolledComposite; |
| import org.eclipse.swt.events.DisposeEvent; |
| import org.eclipse.swt.events.DisposeListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.swt.widgets.Table; |
| import org.eclipse.ui.forms.widgets.FormToolkit; |
| |
| public class DataProductsListsContainerComposite extends Composite { |
| |
| private DataBindingContext m_bindingContext; |
| |
| private WritableValue<Context> contextBinder; |
| |
| private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); |
| |
| private final Table tableDataProductsContainer; |
| private final ObservableListContentProvider listContentProvider; |
| private final TableViewer dataProductsListsContainerViewer; |
| |
| /** |
| * Creates the parentComposite. |
| * |
| * @param parent |
| * @param style |
| */ |
| public DataProductsListsContainerComposite(Composite parent, int style) { |
| super(parent, style); |
| addDisposeListener(new DisposeListener() { |
| @Override |
| public void widgetDisposed(DisposeEvent e) { |
| DataProductsListsContainerComposite.this.toolkit.dispose(); |
| } |
| }); |
| this.toolkit.adapt(this); |
| this.toolkit.paintBordersFor(this); |
| setLayout(new GridLayout(1, true)); |
| |
| ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); |
| scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
| this.toolkit.adapt(scrolledComposite); |
| this.toolkit.paintBordersFor(scrolledComposite); |
| scrolledComposite.setExpandHorizontal(true); |
| scrolledComposite.setExpandVertical(true); |
| |
| Composite compositeCheckboxViewer = new Composite(scrolledComposite, SWT.NONE); |
| this.toolkit.adapt(compositeCheckboxViewer); |
| this.toolkit.paintBordersFor(compositeCheckboxViewer); |
| compositeCheckboxViewer.setLayout(new GridLayout(1, false)); |
| |
| this.dataProductsListsContainerViewer = new TableViewer(compositeCheckboxViewer); |
| this.dataProductsListsContainerViewer.getTable().setLinesVisible(true); |
| |
| this.listContentProvider = new ObservableListContentProvider(); |
| this.dataProductsListsContainerViewer.setContentProvider(this.listContentProvider); |
| |
| this.tableDataProductsContainer = this.dataProductsListsContainerViewer.getTable(); |
| this.tableDataProductsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
| this.tableDataProductsContainer.setSize(83, 83); |
| this.toolkit.paintBordersFor(this.tableDataProductsContainer); |
| scrolledComposite.setContent(compositeCheckboxViewer); |
| scrolledComposite.setMinSize(compositeCheckboxViewer.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
| |
| this.m_bindingContext = initDataBindingsCustom(); |
| |
| // Dispose |
| addDisposeListener(new DisposeListener() { |
| @Override |
| public void widgetDisposed(DisposeEvent e) { |
| if (DataProductsListsContainerComposite.this.m_bindingContext != null) |
| DataProductsListsContainerComposite.this.m_bindingContext.dispose(); |
| } |
| }); |
| } |
| |
| /** |
| * Returns the {@link Context} that is manipulated by this parentComposite. |
| * |
| * @return Reference to the context. |
| */ |
| public Context getContext() { |
| if (this.contextBinder != null && !this.contextBinder.isDisposed()) { |
| return this.contextBinder.getValue(); |
| } |
| return null; |
| } |
| |
| /** |
| * Binds the {@link Context} with the parentComposite. Detail |
| * |
| * @param context Reference to the context. |
| */ |
| public void setContext(Context context) { |
| if (context != null && context.getDataProductsList() == null) { |
| context.setDataProductsList((DataProductsList) this.dataProductsListsContainerViewer.getElementAt(0)); |
| } |
| |
| if (this.contextBinder == null) { |
| this.contextBinder = new WritableValue<Context>(); |
| } |
| this.contextBinder.setValue(context); |
| } |
| |
| /** |
| * Creates and returns the data bindings context that takes care of the Contexts |
| * List Viewer. |
| * |
| * @return Reference to the data bindings context. |
| */ |
| @SuppressWarnings("unchecked") |
| private DataBindingContext initDataBindingsCustom() { |
| this.m_bindingContext = new DataBindingContext(); |
| |
| if (this.contextBinder == null) { |
| this.contextBinder = new WritableValue<Context>(); |
| } |
| |
| /** |
| * Bind data products list. |
| */ |
| IObservableList<?> invocatorFacadeEnvironmentContextsListContextsObserveValue = EMFProperties |
| .list(FeaturePath.fromList( |
| ApogyCoreInvocatorPackage.Literals.INVOCATOR_SESSION__DATA_PRODUCTS_LIST_CONTAINER, |
| ApogyCoreInvocatorPackage.Literals.DATA_PRODUCTS_LISTS_CONTAINER__DATA_PRODUCTS_LIST)) |
| .observe(ApogyCoreInvocatorFacade.INSTANCE.getActiveInvocatorSession()); |
| |
| ViewerSupport.bind(this.dataProductsListsContainerViewer, |
| invocatorFacadeEnvironmentContextsListContextsObserveValue, |
| EMFProperties.value(ApogyCommonEMFPackage.Literals.NAMED__NAME)); |
| |
| /** |
| * Bind the selection to the context's data products list |
| */ |
| IObservableValue<?> observeDataProductsListsContainerViewerSingleSelection = ViewerProperties.singleSelection() |
| .observe(this.dataProductsListsContainerViewer); |
| IObservableValue<?> observeContextDataProductListObserveValue = EMFProperties |
| .value(ApogyCoreInvocatorPackage.Literals.CONTEXT__DATA_PRODUCTS_LIST) |
| .observeDetail(this.contextBinder); |
| |
| this.m_bindingContext.bindValue(observeDataProductsListsContainerViewerSingleSelection, |
| observeContextDataProductListObserveValue); |
| |
| return this.m_bindingContext; |
| } |
| } |