summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-01-20 03:51:19 (EST)
committervlorenzo2014-01-30 10:07:02 (EST)
commita084969bd9a4bcea794bd53b785facc44805d78d (patch)
treea6adb3dfda5a9cac069e5137a68ddad06b76e0ae
parentc850305a4860b009d54142cc76562fd2fde20829 (diff)
downloadorg.eclipse.papyrus-a084969bd9a4bcea794bd53b785facc44805d78d.zip
org.eclipse.papyrus-a084969bd9a4bcea794bd53b785facc44805d78d.tar.gz
org.eclipse.papyrus-a084969bd9a4bcea794bd53b785facc44805d78d.tar.bz2
Bug 421911 - [IBD/BDD] Cannot display context menu for a port in IBD
diagram https://bugs.eclipse.org/bugs/show_bug.cgi?id=421911 Change-Id: I466f6c54640f9fd56268fbd5bfb5652cfbd0bca0 Signed-off-by: B. Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java269
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java263
2 files changed, 240 insertions, 292 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java
index 5fd5cbf..bd1bff4 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java
@@ -1,148 +1,121 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.handler;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.messages.Messages;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.ui.InterfaceManagerDialog;
-import org.eclipse.papyrus.sysml.portandflows.FlowPort;
-import org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.InterfaceRealization;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.Usage;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-/**
- * <pre>
- * This handler provides the handler to manage the provided and required {@link Interface}
- * of a {@link Port} without graphically creating {@link InterfaceRealization} and
- * {@link Usage} relationships.
- * </pre>
- */
-public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Command getCommand() {
- List<IGraphicalEditPart> selection = getSelectedElements();
- if(selection.size() != 1) {
- return UnexecutableCommand.INSTANCE;
- }
- EObject semanticElement = selection.get(0).resolveSemanticElement();
-
- // Selection should be a Port
- if(!(semanticElement instanceof Port)) {
- return UnexecutableCommand.INSTANCE;
- }
-
- // Selection should not be a FlowPort
- FlowPort flowPort = UMLUtil.getStereotypeApplication((Port)semanticElement, FlowPort.class);
- if(flowPort != null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(selection.get(0));
- return action.getCommand();
- }
-
- /**
- *
- * This class provides the action to manage the provided and required interfaces
- *
- *
- */
- public class ManageProvidedInterfaceAction {
-
- /** the {@link Port} */
- private Port port;
-
- /** the {@link Type} of the port */
- private Type type;
-
- /**
- *
- * Constructor.
- *
- * @param editpart
- * the editpart of the port
- */
- public ManageProvidedInterfaceAction(IGraphicalEditPart editpart) {
- Object obj = ((View)editpart.getModel()).getElement();
- Assert.isTrue(obj instanceof Port);
- this.port = (Port)obj;
- this.type = port.getType();
- }
-
- /**
- * Returns the command to add/remove provided/required interfaces
- *
- * @return
- * the command to add/remove provided/required interfaces
- */
- public Command getCommand() {
- if(type != null && !(type instanceof Classifier)) {
- return UnexecutableCommand.INSTANCE;
- } else if(type == null) {
- MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0);
- dialog.open();
- } else {
- InterfaceManagerDialog dialog = new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), this.port);
- if(dialog.open() == Dialog.OK) {
- return dialog.getCommand();
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isEnabled() {
- List<IGraphicalEditPart> selection = getSelectedElements();
- if(selection.size() != 1) {
- return false;
- }
- EObject semanticElement = selection.get(0).resolveSemanticElement();
-
- // Selection should be a Port but should not be a FlowPort
- if(!(semanticElement instanceof Port)) {
- return false;
- }
-
- // Selection should not be a FlowPort
- FlowPort flowPort = UMLUtil.getStereotypeApplication((Port)semanticElement, FlowPort.class);
- if(flowPort != null) {
- return false;
- }
-
- return true;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.blockdefinition.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.sysml.diagram.blockdefinition.messages.Messages;
+import org.eclipse.papyrus.sysml.diagram.blockdefinition.ui.InterfaceManagerDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.InterfaceRealization;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.Usage;
+
+
+/**
+ * <pre>
+ * This handler provides the handler to manage the provided and required {@link Interface}
+ * of a {@link Port} without graphically creating {@link InterfaceRealization} and
+ * {@link Usage} relationships.
+ * </pre>
+ */
+public class ManageProvidedInterfacesHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if(selection.isEmpty()) {
+ return null;
+ }
+
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ EObject selectedElement = EMFHelper.getEObject(structuredSelection.getFirstElement());
+ if(selectedElement instanceof Port) {
+ Port port = (Port)selectedElement;
+ ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(port);
+ try {
+ ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(port).getCommandStack().execute(new GEFtoEMFCommandWrapper(action.getCommand()));
+ } catch (ServiceException ex) {
+ throw new ExecutionException("An unexpected exception occurred", ex);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * This class provides the action to manage the provided and required interfaces
+ *
+ *
+ */
+ public class ManageProvidedInterfaceAction {
+
+ /** the {@link Port} */
+ private Port port;
+
+ /** the {@link Type} of the port */
+ private Type type;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param editpart
+ * the editpart of the port
+ */
+ public ManageProvidedInterfaceAction(Port port) {
+ this.port = port;
+ this.type = port.getType();
+ }
+
+ /**
+ * Returns the command to add/remove provided/required interfaces
+ *
+ * @return
+ * the command to add/remove provided/required interfaces
+ */
+ public Command getCommand() {
+ if(type != null && !(type instanceof Classifier)) {
+ return UnexecutableCommand.INSTANCE;
+ } else if(type == null) {
+ MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0);
+ dialog.open();
+ } else {
+ InterfaceManagerDialog dialog = new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), this.port);
+ if(dialog.open() == Dialog.OK) {
+ return dialog.getCommand();
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java
index afc1923..7214786 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java
@@ -1,144 +1,119 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.handler;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
-import org.eclipse.papyrus.sysml.diagram.internalblock.ui.InterfaceManagerDialog;
-import org.eclipse.papyrus.sysml.portandflows.FlowPort;
-import org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.InterfaceRealization;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.Usage;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-/**
- * <pre>
- * This handler provides the handler to manage the provided and required {@link Interface}
- * of a {@link Port} without graphically creating {@link InterfaceRealization} and
- * {@link Usage} relationships.
- * </pre>
- */
-public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Command getCommand() {
- List<IGraphicalEditPart> selection = getSelectedElements();
- if(selection.size() != 1) {
- return UnexecutableCommand.INSTANCE;
- }
- EObject semanticElement = selection.get(0).resolveSemanticElement();
-
- // Selection should be a Port
- if(!(semanticElement instanceof Port)) {
- return UnexecutableCommand.INSTANCE;
- }
-
- // Selection should not be a FlowPort
- FlowPort flowPort = UMLUtil.getStereotypeApplication((Port)semanticElement, FlowPort.class);
- if(flowPort != null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(selection.get(0));
- return action.getCommand();
- }
-
- /**
- * This class provides the action to manage the provided and required interfaces
- */
- public class ManageProvidedInterfaceAction {
-
- /** the {@link Port} */
- private Port port;
-
- /** the {@link Type} of the port */
- private Type type;
-
- /**
- * Constructor.
- *
- * @param editpart
- * the edit part of the port
- */
- public ManageProvidedInterfaceAction(IGraphicalEditPart editpart) {
- Object obj = ((View)editpart.getModel()).getElement();
- Assert.isTrue(obj instanceof Port);
- this.port = (Port)obj;
- this.type = port.getType();
- }
-
- /**
- * Returns the command to add/remove provided/required interfaces
- *
- * @return
- * the command to add/remove provided/required interfaces
- */
- public Command getCommand() {
- if(type != null && !(type instanceof Classifier)) {
- return UnexecutableCommand.INSTANCE;
- } else if(type == null) {
- MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0);
- dialog.open();
- } else {
- InterfaceManagerDialog dialog = new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), this.port);
- if(dialog.open() == Dialog.OK) {
- return dialog.getCommand();
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isEnabled() {
- List<IGraphicalEditPart> selection = getSelectedElements();
- if(selection.size() != 1) {
- return false;
- }
- EObject semanticElement = selection.get(0).resolveSemanticElement();
-
- // Selection should be a Port but should not be a FlowPort
- if(!(semanticElement instanceof Port)) {
- return false;
- }
-
- // Selection should not be a FlowPort
- FlowPort flowPort = UMLUtil.getStereotypeApplication((Port)semanticElement, FlowPort.class);
- if(flowPort != null) {
- return false;
- }
-
- return true;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.internalblock.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
+import org.eclipse.papyrus.sysml.diagram.internalblock.ui.InterfaceManagerDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.InterfaceRealization;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.Usage;
+
+/**
+ * <pre>
+ * This handler provides the handler to manage the provided and required {@link Interface}
+ * of a {@link Port} without graphically creating {@link InterfaceRealization} and
+ * {@link Usage} relationships.
+ * </pre>
+ */
+public class ManageProvidedInterfacesHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if(selection.isEmpty()) {
+ return null;
+ }
+
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ EObject selectedElement = EMFHelper.getEObject(structuredSelection.getFirstElement());
+ if(selectedElement instanceof Port) {
+ Port port = (Port)selectedElement;
+ ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(port);
+ try {
+ ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(port).getCommandStack().execute(new GEFtoEMFCommandWrapper(action.getCommand()));
+ } catch (ServiceException ex) {
+ throw new ExecutionException("An unexpected exception occurred", ex);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * This class provides the action to manage the provided and required interfaces
+ */
+ public class ManageProvidedInterfaceAction {
+
+ /** the {@link Port} */
+ private Port port;
+
+ /** the {@link Type} of the port */
+ private Type type;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param editpart
+ * the editpart of the port
+ */
+ public ManageProvidedInterfaceAction(Port port) {
+ this.port = port;
+ this.type = port.getType();
+ }
+
+
+ /**
+ * Returns the command to add/remove provided/required interfaces
+ *
+ * @return
+ * the command to add/remove provided/required interfaces
+ */
+ public Command getCommand() {
+ if(type != null && !(type instanceof Classifier)) {
+ return UnexecutableCommand.INSTANCE;
+ } else if(type == null) {
+ MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0);
+ dialog.open();
+ } else {
+ InterfaceManagerDialog dialog = new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), this.port);
+ if(dialog.open() == Dialog.OK) {
+ return dialog.getCommand();
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+
+}