diff options
author | Benoit Maggi | 2014-01-20 08:51:19 +0000 |
---|---|---|
committer | vlorenzo | 2014-01-31 10:28:25 +0000 |
commit | fff4eee01dc36cbd207eaf92132ab5b0b02c3640 (patch) | |
tree | 733b330d02dea92eb8d7887ed686d98e545708d6 /plugins | |
parent | e232ae82899f533e103388dd475fc33eded27890 (diff) | |
download | org.eclipse.papyrus-fff4eee01dc36cbd207eaf92132ab5b0b02c3640.tar.gz org.eclipse.papyrus-fff4eee01dc36cbd207eaf92132ab5b0b02c3640.tar.xz org.eclipse.papyrus-fff4eee01dc36cbd207eaf92132ab5b0b02c3640.zip |
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>
Diffstat (limited to 'plugins')
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 5fd5cbfb5e3..bd1bff4a63a 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 afc1923c737..7214786414a 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; + } + } + +} |