blob: 51b1581b5cb486b3734192d3f479cdddbec7d8b9 [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
* Regent L'Archeveque,
* Sebastien Gemme
*
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.common.topology.ui.composites;
import org.eclipse.apogy.common.emf.transaction.ApogyCommonTransactionFacade;
import org.eclipse.apogy.common.topology.ApogyCommonTopologyPackage;
import org.eclipse.apogy.common.topology.AttachedViewPoint;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
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;
public class AttachedViewPointComposite extends Composite {
private AttachedViewPoint attachedViewPoint;
private final AbstractViewPointComposite abstractViewPointComposite;
private final Button enableRotationButton;
private final Button enableTranslationButton;
private DataBindingContext m_bindingContext;
public AttachedViewPointComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
this.abstractViewPointComposite = new AbstractViewPointComposite(this, SWT.None, null);
this.abstractViewPointComposite.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
Composite bottom = new Composite(this, SWT.BORDER);
bottom.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
bottom.setLayout(new GridLayout(4, false));
// Rotation Enable.
Label lblEnableRotationLabel = new Label(bottom, SWT.NONE);
lblEnableRotationLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblEnableRotationLabel.setText("Enable Rotation:");
this.enableRotationButton = new Button(bottom, SWT.CHECK);
// Translation Enable.
Label lblEnableTranslationLabel = new Label(bottom, SWT.NONE);
lblEnableTranslationLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblEnableTranslationLabel.setText("Enable Translation:");
this.enableTranslationButton = new Button(bottom, SWT.CHECK);
// Adds dispose cleanup.
this.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (AttachedViewPointComposite.this.m_bindingContext != null)
AttachedViewPointComposite.this.m_bindingContext.dispose();
}
});
}
public AttachedViewPoint getAttachedViewPoint() {
return this.attachedViewPoint;
}
public void setAttachedViewPoint(AttachedViewPoint attachedViewPoint) {
if (this.m_bindingContext != null)
this.m_bindingContext.dispose();
this.attachedViewPoint = attachedViewPoint;
if (attachedViewPoint != null) {
this.m_bindingContext = initDataBindingsCustom();
}
}
@SuppressWarnings("unchecked")
private DataBindingContext initDataBindingsCustom() {
DataBindingContext bindingContext = new DataBindingContext();
/* Enable Rotation. */
IObservableValue<Double> observeAllowRotation = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getTransactionalEditingDomain(this.attachedViewPoint),
FeaturePath.fromList(ApogyCommonTopologyPackage.Literals.ATTACHED_VIEW_POINT__ALLOW_ROTATION))
.observe(this.attachedViewPoint);
IObservableValue<String> observeEnableRotationButton = WidgetProperties.selection()
.observe(this.enableRotationButton);
bindingContext.bindValue(observeEnableRotationButton, observeAllowRotation, new UpdateValueStrategy(),
new UpdateValueStrategy());
/* Enable Translation. */
IObservableValue<Double> observeAllowTranslation = EMFEditProperties
.value(ApogyCommonTransactionFacade.INSTANCE.getTransactionalEditingDomain(this.attachedViewPoint),
FeaturePath
.fromList(ApogyCommonTopologyPackage.Literals.ATTACHED_VIEW_POINT__ALLOW_TRANSLATION))
.observe(this.attachedViewPoint);
IObservableValue<String> observeEnableTranslationButton = WidgetProperties.selection()
.observe(this.enableTranslationButton);
bindingContext.bindValue(observeEnableTranslationButton, observeAllowTranslation, new UpdateValueStrategy(),
new UpdateValueStrategy());
return bindingContext;
}
}