blob: 99a8be6e9e0d61eeb94eeb53802f9ddf82092795 [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,
* Regent L'Archeveque - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.core.environment.surface.ui.composites;
import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage;
import org.eclipse.apogy.common.emf.transaction.ApogyCommonTransactionFacade;
import org.eclipse.apogy.core.environment.surface.ApogySurfaceEnvironmentPackage;
import org.eclipse.apogy.core.environment.surface.MapLayerPresentation;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class MapLayerPresentationOverviewComposite extends Composite {
private MapLayerPresentation mapLayerPresentation;
private DataBindingContext m_bindingContext;
private final Text txtNamevalue;
private final Text txtDescriptionvalue;
private final Label lblVisible;
private final Button btnVisiblevalue;
public MapLayerPresentationOverviewComposite(Composite parent, int style) {
super(parent, SWT.NO_BACKGROUND);
setLayout(new GridLayout(2, false));
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.BORDER);
GridData gd_txtNamevalue = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_txtNamevalue.minimumWidth = 300;
gd_txtNamevalue.widthHint = 300;
this.txtNamevalue.setLayoutData(gd_txtNamevalue);
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.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
GridData gd_txtDescriptionvalue = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
gd_txtDescriptionvalue.widthHint = 300;
gd_txtDescriptionvalue.minimumWidth = 300;
gd_txtDescriptionvalue.minimumHeight = 50;
gd_txtDescriptionvalue.heightHint = 50;
this.txtDescriptionvalue.setLayoutData(gd_txtDescriptionvalue);
this.lblVisible = new Label(this, SWT.NONE);
this.lblVisible.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
this.lblVisible.setAlignment(SWT.RIGHT);
this.lblVisible.setText("Visible:");
this.btnVisiblevalue = new Button(this, SWT.CHECK);
// Dispose
addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (MapLayerPresentationOverviewComposite.this.m_bindingContext != null)
MapLayerPresentationOverviewComposite.this.m_bindingContext.dispose();
}
});
}
public MapLayerPresentation getMapLayerPresentation() {
return this.mapLayerPresentation;
}
public void setMapLayerPresentation(MapLayerPresentation newMapLayerPresentation) {
if (this.m_bindingContext != null)
this.m_bindingContext.dispose();
this.mapLayerPresentation = newMapLayerPresentation;
if (newMapLayerPresentation != null) {
this.m_bindingContext = initDataBindingsCustom();
}
}
@SuppressWarnings("unchecked")
private DataBindingContext initDataBindingsCustom() {
DataBindingContext bindingContext = new DataBindingContext();
/* Name Value. */
IObservableValue<Double> observeName = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getDefaultEditingDomain(),
FeaturePath.fromList(ApogyCommonEMFPackage.Literals.NAMED__NAME))
.observe(getMapLayerPresentation());
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(ApogyCommonEMFPackage.Literals.DESCRIBED__DESCRIPTION))
.observe(getMapLayerPresentation());
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;
}
}));
// Visibility
IObservableValue<Double> observeVisible = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getDefaultEditingDomain(),
FeaturePath.fromList(ApogySurfaceEnvironmentPackage.Literals.MAP_LAYER_PRESENTATION__VISIBLE))
.observe(getMapLayerPresentation());
IObservableValue<String> observeVisibleButton = WidgetProperties.selection().observe(this.btnVisiblevalue);
bindingContext.bindValue(observeVisibleButton, observeVisible,
new UpdateValueStrategy().setConverter(new Converter(Boolean.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
}), new UpdateValueStrategy().setConverter(new Converter(Boolean.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
}));
return bindingContext;
}
}