blob: 80b313a47034bd789ddeadf0f521b8f8ec4f8fb5 [file] [log] [blame]
/*******************************************************************************
* 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 - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.topology.bindings.ui.composites;
import org.eclipse.apogy.common.emf.AbstractFeatureNode;
import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade;
import org.eclipse.apogy.common.emf.transaction.ApogyCommonTransactionFacade;
import org.eclipse.apogy.common.topology.bindings.AbstractTopologyBinding;
import org.eclipse.apogy.common.topology.bindings.ApogyCommonTopologyBindingsPackage;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.databinding.FeaturePath;
import org.eclipse.emf.databinding.edit.EMFEditProperties;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
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.Label;
import org.eclipse.swt.widgets.Text;
public class AbstractTopologyBindingOverviewComposite extends Composite {
private AbstractTopologyBinding abstractTopologyBinding;
private DataBindingContext m_bindingContext;
private final Text txtNamevalue;
private final Text txtDescriptionvalue;
private final Text txtAbstractFeatureTreeNode;
public AbstractTopologyBindingOverviewComposite(Composite parent, int style) {
super(parent, SWT.NO_BACKGROUND);
setLayout(new GridLayout(3, false));
// Name
Label lblName = new Label(this, SWT.NONE);
lblName.setAlignment(SWT.RIGHT);
lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblName.setText("Name:");
this.txtNamevalue = new Text(this, SWT.NONE);
GridData gd_txtNamevalue = new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1);
gd_txtNamevalue.minimumWidth = 300;
gd_txtNamevalue.widthHint = 300;
this.txtNamevalue.setLayoutData(gd_txtNamevalue);
// Description
Label lblDescription = new Label(this, SWT.NONE);
lblDescription.setAlignment(SWT.RIGHT);
lblDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblDescription.setText("Description:");
this.txtDescriptionvalue = new Text(this, SWT.NONE | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
GridData gd_txtDescriptionvalue = new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1);
gd_txtDescriptionvalue.minimumWidth = 300;
gd_txtDescriptionvalue.widthHint = 300;
gd_txtDescriptionvalue.minimumHeight = 50;
gd_txtDescriptionvalue.heightHint = 50;
this.txtDescriptionvalue.setLayoutData(gd_txtDescriptionvalue);
// AbstractFeatureTreeNode
Label AbstractFeatureTreeNode = new Label(this, SWT.NONE);
AbstractFeatureTreeNode.setAlignment(SWT.RIGHT);
AbstractFeatureTreeNode.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
AbstractFeatureTreeNode.setText("Feature :");
this.txtAbstractFeatureTreeNode = new Text(this, SWT.NONE);
this.txtAbstractFeatureTreeNode.setEnabled(false);
GridData gd_txtAbstractFeatureTreeNode = new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1);
gd_txtAbstractFeatureTreeNode.minimumWidth = 300;
gd_txtAbstractFeatureTreeNode.widthHint = 300;
this.txtAbstractFeatureTreeNode.setLayoutData(gd_txtAbstractFeatureTreeNode);
// Dispose
addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (AbstractTopologyBindingOverviewComposite.this.m_bindingContext != null)
AbstractTopologyBindingOverviewComposite.this.m_bindingContext.dispose();
}
});
}
public AbstractTopologyBinding getAbstractTopologyBinding() {
return this.abstractTopologyBinding;
}
public void setAbstractTopologyBinding(AbstractTopologyBinding newAbstractTopologyBinding) {
if (this.m_bindingContext != null)
this.m_bindingContext.dispose();
this.abstractTopologyBinding = newAbstractTopologyBinding;
if (newAbstractTopologyBinding != null) {
this.m_bindingContext = initDataBindingsCustom();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private DataBindingContext initDataBindingsCustom() {
DataBindingContext bindingContext = new DataBindingContext();
/* Name Value. */
IObservableValue<Double> observeName = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getDefaultEditingDomain(),
FeaturePath
.fromList(ApogyCommonTopologyBindingsPackage.Literals.ABSTRACT_TOPOLOGY_BINDING__NAME))
.observe(getAbstractTopologyBinding());
IObservableValue<String> observeNameValueText = WidgetProperties.text(SWT.Modify).observe(this.txtNamevalue);
bindingContext.bindValue(observeNameValueText, observeName,
new UpdateValueStrategy().setConverter(new Converter(String.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
}), new UpdateValueStrategy().setConverter(new Converter(String.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
}));
/* Description Value. */
IObservableValue<Double> observeDescription = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getDefaultEditingDomain(),
FeaturePath.fromList(
ApogyCommonTopologyBindingsPackage.Literals.ABSTRACT_TOPOLOGY_BINDING__DESCRIPTION))
.observe(getAbstractTopologyBinding());
IObservableValue<String> observeDescriptionText = WidgetProperties.text(SWT.Modify)
.observe(this.txtDescriptionvalue);
bindingContext.bindValue(observeDescriptionText, observeDescription,
new UpdateValueStrategy().setConverter(new Converter(String.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
}), new UpdateValueStrategy().setConverter(new Converter(String.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
}));
// AbstractFeatureTreeNode
IObservableValue observeAbstractFeatureValue = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getDefaultEditingDomain(),
FeaturePath.fromList(
ApogyCommonTopologyBindingsPackage.Literals.ABSTRACT_TOPOLOGY_BINDING__FEATURE_NODE))
.observe(getAbstractTopologyBinding());
IObservableValue<String> observeAbstractFeatureTreeNodeText = WidgetProperties.text(SWT.Modify)
.observe(this.txtAbstractFeatureTreeNode);
bindingContext.bindValue(observeAbstractFeatureTreeNodeText, observeAbstractFeatureValue,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
new UpdateValueStrategy().setConverter(new Converter(AbstractFeatureNode.class, String.class) {
@Override
public Object convert(Object fromObject) {
if (fromObject instanceof AbstractFeatureNode) {
AbstractFeatureNode abstractFeatureNode = (AbstractFeatureNode) fromObject;
return ApogyCommonEMFFacade.INSTANCE.getAncestriesString(abstractFeatureNode);
} else {
return "";
}
}
}));
return bindingContext;
}
}