Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2018-06-14 15:28:19 +0000
committerNicolas FAUVERGUE2018-06-29 08:24:58 +0000
commit66b5376f078ea1b3c4f090d0c747695eacd69fdc (patch)
tree880fe89a3e08f73f4d8ab88cb4422479461004b4 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus
parent5556afe5736a545f64ddb28b6e8593869a6930da (diff)
downloadorg.eclipse.papyrus-66b5376f078ea1b3c4f090d0c747695eacd69fdc.tar.gz
org.eclipse.papyrus-66b5376f078ea1b3c4f090d0c747695eacd69fdc.tar.xz
org.eclipse.papyrus-66b5376f078ea1b3c4f090d0c747695eacd69fdc.zip
Bug 535713: [ActivityDiagram] JoinNode and ForkNode properties view have
2 Appearance tab Manage the appearance tab with the properties framework. Change-Id: Ib31c5947d5237b769bb0bdb88bd0f31174543b07 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElement.java62
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElementFactory.java62
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/observables/SwitchOrientationObservableValue.java232
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/tabbedproperties/appearance/SwitchSegmentDirectionSection.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationEditor.java38
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationWidget.java197
6 files changed, 593 insertions, 0 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElement.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElement.java
new file mode 100644
index 00000000000..579cce91711
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElement.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.activity.modelelement;
+
+import java.util.Collections;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement;
+import org.eclipse.papyrus.uml.diagram.activity.observables.SwitchOrientationObservableValue;
+
+/**
+ * This allows to define the model element for the activity notation.
+ *
+ * @since 3.2
+ */
+public class ActivityNotationModelElement extends AbstractModelElement {
+ TransactionalEditingDomain domain;
+ EditPart editPart;
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * The editing domain.
+ * @param source
+ * The source edit part.
+ */
+ public ActivityNotationModelElement(final TransactionalEditingDomain domain, final EditPart source) {
+ super();
+
+ this.domain = domain;
+ this.editPart = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#doGetObservable(java.lang.String)
+ */
+ @Override
+ protected IObservable doGetObservable(final String propertyPath) {
+ IObservable result = null;
+
+ if (propertyPath.endsWith("switchOrientation")) { //$NON-NLS-1$
+ result = new SwitchOrientationObservableValue(domain, Collections.singleton(editPart));
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElementFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElementFactory.java
new file mode 100644
index 00000000000..b7cf3aab490
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/modelelement/ActivityNotationModelElementFactory.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.activity.modelelement;
+
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElementFactory;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+
+/**
+ * A factory for handling the GMF Notation Activity elements.
+ *
+ * @since 3.2
+ */
+public class ActivityNotationModelElementFactory extends AbstractModelElementFactory<ActivityNotationModelElement> {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElementFactory#doCreateFromSource(java.lang.Object, org.eclipse.papyrus.infra.properties.contexts.DataContextElement)
+ */
+ @Override
+ protected ActivityNotationModelElement doCreateFromSource(final Object sourceElement, final DataContextElement context) {
+ ActivityNotationModelElement result = null;
+ final IGraphicalEditPart editPart = AdapterUtils.adapt(sourceElement, IGraphicalEditPart.class, null);
+
+ if (editPart == null) {
+ Activator.log.warn("The selected element cannot be resolved to a GEF EditPart"); //$NON-NLS-1$
+ } else {
+ result = new ActivityNotationModelElement(editPart.getEditingDomain(), editPart);
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElementFactory#updateModelElement(org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement, java.lang.Object)
+ */
+ @Override
+ protected void updateModelElement(final ActivityNotationModelElement modelElement, final Object newSourceElement) {
+ final IGraphicalEditPart editPart = AdapterUtils.adapt(newSourceElement, IGraphicalEditPart.class, null);
+ if (editPart == null) {
+ throw new IllegalArgumentException("Cannot resolve EditPart selection: " + newSourceElement); //$NON-NLS-1$
+ }
+
+ modelElement.domain = editPart.getEditingDomain();
+ modelElement.editPart = editPart;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/observables/SwitchOrientationObservableValue.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/observables/SwitchOrientationObservableValue.java
new file mode 100644
index 00000000000..a632f2732bf
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/observables/SwitchOrientationObservableValue.java
@@ -0,0 +1,232 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.activity.observables;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ForkNodeEditPart;
+import org.eclipse.papyrus.uml.diagram.activity.edit.parts.JoinNodeEditPart;
+import org.eclipse.papyrus.uml.diagram.activity.part.CustomMessages;
+
+/**
+ * The observable value for the switch observable action.
+ *
+ * @since 3.2
+ */
+public class SwitchOrientationObservableValue extends AbstractObservableValue<Boolean> {
+
+ /**
+ * The transactional editing domain.
+ */
+ private TransactionalEditingDomain editingDomain;
+
+ /**
+ * The activity nodes edit parts to modify.
+ */
+ private List<EditPart> activityNodesEP;
+
+ /**
+ * Constructor.
+ *
+ * @param editingDomain
+ * The transactional editing domain.
+ * @param activityNodesEP
+ * The activity nodes edit parts to modify.
+ */
+ public SwitchOrientationObservableValue(final TransactionalEditingDomain editingDomain, final Collection<EditPart> activityNodesEP) {
+ this.activityNodesEP = new ArrayList<EditPart>(activityNodesEP.size());
+ this.activityNodesEP.addAll(activityNodesEP);
+ this.editingDomain = editingDomain;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType()
+ */
+ @Override
+ public Object getValueType() {
+ return Boolean.class;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue()
+ */
+ @Override
+ protected Boolean doGetValue() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object)
+ */
+ @Override
+ protected void doSetValue(final Boolean value) {
+ CompositeCommand globalCommand = new CompositeCommand(CustomMessages.ForkJoinSegmentSwitchOrientation_actionLabel);
+ for (Object part : this.activityNodesEP) {
+ Object view = null;
+ Figure figure = null;
+ if (part instanceof JoinNodeEditPart) {
+ view = ((JoinNodeEditPart) part).getModel();
+ figure = ((JoinNodeEditPart) part).getPrimaryShape();
+ } else if (part instanceof ForkNodeEditPart) {
+ view = ((ForkNodeEditPart) part).getModel();
+ figure = ((ForkNodeEditPart) part).getPrimaryShape();
+ }
+ // append a command for selected part only if correct configuration
+ if (view instanceof View && figure != null) {
+ SwitchSegmentOrientation switchCom = new SwitchSegmentOrientation(editingDomain, figure, (View) view);
+ globalCommand.add(switchCom);
+ }
+ }
+ // execute the command for all parts
+ if (!globalCommand.isEmpty() && globalCommand.canExecute()) {
+ editingDomain.getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(new ICommandProxy(globalCommand)));
+ }
+ }
+
+ /**
+ * This class is a command which switches the orientation of a figure. The figure's width and height are switched, rotating the figure on its center. (center location kept)
+ */
+ private class SwitchSegmentOrientation extends AbstractTransactionalCommand {
+
+ /** The figure to switch */
+ private Figure selectedFigure = null;
+
+ /** The model view for the figure to switch */
+ private View selectedView = null;
+
+ /**
+ * Construct a switch orientation command.
+ *
+ * @param domain
+ * The transactional editing domain.
+ * @param figure
+ * The figure to rotate.
+ * @param view
+ * The view which is the model of the figure.
+ */
+ SwitchSegmentOrientation(final TransactionalEditingDomain domain, final Figure figure, final View view) {
+ super(domain, CustomMessages.ForkJoinSegmentSwitchOrientation_actionLabel, null);
+ selectedFigure = figure;
+ selectedView = view;
+ }
+
+ /**
+ * Execute the command, rotating the figure.
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * The progress monitor.
+ * @param info
+ * The adapter for information.
+ * @return The result of the command.
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ if (selectedFigure == null || selectedView == null) {
+ return CommandResult.newCancelledCommandResult();
+ }
+ Dimension newSize = selectedFigure.getSize().getTransposed();
+ Point newLocation = selectedFigure.getLocation().getCopy();
+ newLocation.translate((newSize.height - newSize.width) / 2, (newSize.width - newSize.height) / 2);
+ ViewUtil.setStructuralFeatureValue(selectedView, NotationPackage.eINSTANCE.getLocation_X(), newLocation.x);
+ ViewUtil.setStructuralFeatureValue(selectedView, NotationPackage.eINSTANCE.getLocation_Y(), newLocation.y);
+ ViewUtil.setStructuralFeatureValue(selectedView, NotationPackage.eINSTANCE.getSize_Width(), newSize.width);
+ ViewUtil.setStructuralFeatureValue(selectedView, NotationPackage.eINSTANCE.getSize_Height(), newSize.height);
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ * @see org.eclipse.emf.workspace.AbstractEMFOperation#canUndo()
+ * @return true if command can undo.
+ */
+ @Override
+ public boolean canUndo() {
+ return selectedFigure != null && selectedView != null;
+ }
+
+ /**
+ * @see org.eclipse.emf.workspace.AbstractEMFOperation#canRedo()
+ * @return true if command can redo.
+ */
+ @Override
+ public boolean canRedo() {
+ return selectedFigure != null && selectedView != null;
+ }
+
+ /**
+ * Undo the switch (by switching again).
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doUndo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * The progress monitor.
+ * @param info
+ * The adapter for information.
+ * @return The result of the command.
+ * @throws ExecutionException
+ */
+ @Override
+ protected IStatus doUndo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ return doExecute(monitor, info);
+ }
+
+ /**
+ * Redo the switch (by switching again).
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doRedo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * The progress monitor.
+ * @param info
+ * The adapter for information.
+ * @return The result of the command.
+ * @throws ExecutionException
+ */
+ @Override
+ protected IStatus doRedo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ return doExecute(monitor, info);
+ }
+ }
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/tabbedproperties/appearance/SwitchSegmentDirectionSection.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/tabbedproperties/appearance/SwitchSegmentDirectionSection.java
index 58057774e76..0fd679c1923 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/tabbedproperties/appearance/SwitchSegmentDirectionSection.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/tabbedproperties/appearance/SwitchSegmentDirectionSection.java
@@ -55,6 +55,8 @@ import org.eclipse.ui.forms.widgets.ImageHyperlink;
/**
* Section to use in the properties view. This section enables to switch the
* direction of a segment representation (for fork or join).
+ *
+ * @deprecated since 3.2
*/
public class SwitchSegmentDirectionSection extends AbstractNotationPropertiesSection {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationEditor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationEditor.java
new file mode 100644
index 00000000000..a5c36e2a4d6
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationEditor.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.activity.widgets;
+
+import org.eclipse.papyrus.infra.properties.ui.widgets.AbstractPropertyEditor;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * The switch orientation editor.
+ *
+ * @since 3.2
+ */
+public class SwitchOrientationEditor extends AbstractPropertyEditor {
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * The composite in which the widget will be displayed
+ * @param style
+ * The style for the widget
+ */
+ public SwitchOrientationEditor(final Composite parent, final int style) {
+ super(new SwitchOrientationWidget(parent, style));
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationWidget.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationWidget.java
new file mode 100644
index 00000000000..e1afb46d1c0
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/widgets/SwitchOrientationWidget.java
@@ -0,0 +1,197 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.activity.widgets;
+
+import java.io.IOException;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor;
+import org.eclipse.papyrus.uml.diagram.activity.part.CustomMessages;
+import org.eclipse.papyrus.uml.diagram.activity.part.UMLDiagramEditorPlugin;
+import org.eclipse.papyrus.uml.diagram.common.ui.helper.HelpComponentFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+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.Display;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ImageHyperlink;
+
+/**
+ * The switch orientation widget with a simple button and a help button.
+ *
+ * @since 3.2
+ */
+public class SwitchOrientationWidget extends AbstractValueEditor {
+
+ /** The path to the switch icon. */
+ private static final String ICON_PATH = "icons/switchSegmentOrientation.gif";
+
+ /** The switch image. */
+ public static Image switchImage = null;
+
+ /** Load the switch icon once. */
+ static {
+ try {
+ switchImage = new Image(Display.getDefault(), UMLDiagramEditorPlugin.getInstance().getBundle().getResource(ICON_PATH).openStream());
+ } catch (IOException e) {
+ UMLDiagramEditorPlugin.getInstance().logError(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * The button to use.
+ */
+ private Button button;
+
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * The composite in which this editor should be displayed.
+ * @param style
+ * The style for this editor's text box.
+ */
+ public SwitchOrientationWidget(final Composite parent, final int style) {
+ this(parent, style, null); //$NON-NLS-1$
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * The composite in which this editor should be displayed.
+ * @param style
+ * The style for this editor's text box.
+ * @param label
+ * The label to be displayed.
+ */
+ public SwitchOrientationWidget(final Composite parent, final int style, final String label) {
+ super(parent, label);
+
+ final Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, true));
+ composite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, true));
+
+ button = new Button(composite, SWT.PUSH);
+ button.setImage(switchImage);
+ GridData gd = new GridData(SWT.CENTER, SWT.CENTER, true, true);
+ button.setLayoutData(gd);
+
+ button.addSelectionListener(new SelectionListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (null != widgetObservable) {
+ widgetObservable.setValue(true);
+ }
+ }
+ });
+
+ // create help
+ final ImageHyperlink help = HelpComponentFactory.createHelpComponent(composite, new FormToolkit(parent.getDisplay()), CustomMessages.ForkJoinSegmentSwitchOrientation_helpMessage);
+ gd = new GridData(SWT.RIGHT, SWT.CENTER, false, true);
+ help.setLayoutData(gd);
+ help.setBackground(parent.getBackground());
+
+ pack();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#setLabel(java.lang.String)
+ */
+ @Override
+ public void setLabel(final String label) {
+ // Don't display label
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor#setModelObservable(org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ public void setModelObservable(final IObservableValue modelProperty) {
+ IObservableValue newWidgetObservable = modelProperty;
+
+ if (this.widgetObservable != null) {
+ this.widgetObservable.dispose();
+ }
+
+ setWidgetObservable(newWidgetObservable, true);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor#getValue()
+ */
+ @Override
+ public Object getValue() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#getEditableType()
+ */
+ @Override
+ public Object getEditableType() {
+ return Boolean.class;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#setReadOnly(boolean)
+ */
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ button.setEnabled(!readOnly);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#isReadOnly()
+ */
+ @Override
+ public boolean isReadOnly() {
+ return !button.isEnabled();
+ }
+
+}

Back to the top