Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java76
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ManageProvidedInterfacesHandler.java92
2 files changed, 70 insertions, 98 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java
index 4db78ba0efe..5548682905d 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java
@@ -13,51 +13,55 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.component.custom.actions;
-import java.util.List;
-
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-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.uml.diagram.common.handlers.GraphicalCommandHandler;
+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.uml.diagram.component.custom.messages.Messages;
import org.eclipse.papyrus.uml.diagram.component.custom.ui.InterfaceManagerDialog;
-import org.eclipse.papyrus.uml.diagram.component.edit.parts.PortEditPart;
+import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Type;
-// TODO: Auto-generated Javadoc
/**
* This handler provides the action to manage the provided and required {@link Interface} for a {@link Port}.
*/
-public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
+public class ManageProvidedInterfacesHandler extends AbstractHandler {
- /**
- * Gets the command.
- *
- * @return the command
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler#getCommand()
- */
- @Override
- protected Command getCommand() {
- List<IGraphicalEditPart> selection = getSelectedElements();
- if(selection.size() != 1) {
- return UnexecutableCommand.INSTANCE;
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if(selection.isEmpty()) {
+ return null;
}
- if(!(selection.get(0) instanceof PortEditPart)) {
- return UnexecutableCommand.INSTANCE;
+
+ 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);
+ }
+ }
}
- ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(selection.get(0));
- return action.getCommand();
+
+ return null;
}
/**
@@ -78,10 +82,8 @@ public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
* @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;
+ public ManageProvidedInterfaceAction(Port port) {
+ this.port = port;
this.type = port.getType();
}
@@ -107,18 +109,4 @@ public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
}
}
- /**
- * Checks if is enabled.
- *
- * @return true, if is enabled
- * @see org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler#isEnabled()
- */
- @Override
- public boolean isEnabled() {
- if(getSelectedElements().size() == 1) {
- Object obj = ((View)getSelectedElements().get(0).getModel()).getElement();
- return obj instanceof Port;
- }
- return false;
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ManageProvidedInterfacesHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ManageProvidedInterfacesHandler.java
index 5f0816a84af..0bec9c5be2a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ManageProvidedInterfacesHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ManageProvidedInterfacesHandler.java
@@ -13,66 +13,66 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.composite.custom.actions;
-import java.util.List;
-
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-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.uml.diagram.common.handlers.GraphicalCommandHandler;
+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.uml.diagram.composite.custom.messages.Messages;
import org.eclipse.papyrus.uml.diagram.composite.custom.ui.InterfaceManagerDialog;
-import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Type;
/**
- * This handler provides the action to manage the provided and required {@link Interface} for a {@link Port}
- *
- *
- *
+ * This handler provides the action to manage the provided and required {@link Interface} for a {@link Port}.
*/
-public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
+public class ManageProvidedInterfacesHandler extends AbstractHandler {
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler#getCommand()
- *
- * @return
- * @throws ExecutionException
- */
- @Override
- protected Command getCommand() {
- List<IGraphicalEditPart> selection = getSelectedElements();
- if(selection.size() != 1) {
- return UnexecutableCommand.INSTANCE;
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if(selection.isEmpty()) {
+ return null;
}
- if(!(selection.get(0) instanceof PortEditPart)) {
- return UnexecutableCommand.INSTANCE;
+
+ 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);
+ }
+ }
}
- ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(selection.get(0));
- return action.getCommand();
+
+ return null;
}
/**
- *
- * This class provides the action to manage the provided and required interfaces
- *
- *
+ * This class provides the action to manage the provided and required interfaces.
*/
public class ManageProvidedInterfaceAction {
- /** the {@link Port} */
+ /** the {@link Port}. */
private Port port;
- /** the {@link Type} of the port */
+ /** the {@link Type} of the port. */
private Type type;
/**
@@ -82,17 +82,15 @@ public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
* @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;
+ public ManageProvidedInterfaceAction(Port port) {
+ this.port = port;
this.type = port.getType();
}
/**
- * Returns the command to add/remove provided/required interfaces
+ * Returns the command to add/remove provided/required interfaces.
*
- * @return
+ * @return the command
* the command to add/remove provided/required interfaces
*/
public Command getCommand() {
@@ -111,18 +109,4 @@ public class ManageProvidedInterfacesHandler extends GraphicalCommandHandler {
}
}
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler#isEnabled()
- *
- * @return
- */
- @Override
- public boolean isEnabled() {
- if(getSelectedElements().size() == 1) {
- Object obj = ((View)getSelectedElements().get(0).getModel()).getElement();
- return obj instanceof Port;
- }
- return false;
- }
}

Back to the top