Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2012-04-12 11:31:33 +0000
committerptessier2012-04-12 11:31:33 +0000
commitd6904025e99da3129b60797c0a70e2b5c86679f3 (patch)
tree8eaff2133aa46866ccce475a9fb7dfbee060a9d9 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase
parent3a99137c2efac5135c379f1467f86db10af94c3e (diff)
downloadorg.eclipse.papyrus-d6904025e99da3129b60797c0a70e2b5c86679f3.tar.gz
org.eclipse.papyrus-d6904025e99da3129b60797c0a70e2b5c86679f3.tar.xz
org.eclipse.papyrus-d6904025e99da3129b60797c0a70e2b5c86679f3.zip
312589: [Use Case diagram] Cannot place packaged element into diagram
https://bugs.eclipse.org/bugs/show_bug.cgi?id=312589
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ChangetoDefaultShapeCommand.java94
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ElementToDefaultNamedElementShape.java74
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/ChangeShapeHandler.java104
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/DefaultNamedElementHandler.java51
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/SubjectHandler.java56
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/plugin.xml44
6 files changed, 422 insertions, 1 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ChangetoDefaultShapeCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ChangetoDefaultShapeCommand.java
new file mode 100644
index 00000000000..c5ff6aea427
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ChangetoDefaultShapeCommand.java
@@ -0,0 +1,94 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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.uml.diagram.usecase.command;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.usecase.part.UMLVisualIDRegistry;
+import org.eclipse.papyrus.uml.diagram.usecase.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.usecase.providers.UMLViewProvider;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * this is the specific command in charge to transform an element editpart into a defaultShape
+ *
+ */
+public class ChangetoDefaultShapeCommand extends AbstractTransactionalCommand {
+
+ protected GraphicalEditPart elementEditPart;
+
+ /**
+ *
+ * Constructor of this command
+ *
+ * @param domain
+ * the transactional editing domain to execute transaction
+ * @param classView
+ * the editpart that will be transformed
+ */
+ public ChangetoDefaultShapeCommand(TransactionalEditingDomain domain, GraphicalEditPart classView) {
+ super(domain, "ChangeToDefaultNamedElement", Collections.EMPTY_LIST);
+ this.elementEditPart = classView;
+ }
+
+ public IElementType getUMLElementType(int elementID) {
+ return UMLElementTypes.getElementType(elementID);
+ }
+
+ public int getNodeVisualID(View containerView, EObject domainElement) {
+ return UMLVisualIDRegistry.getNodeVisualID(containerView, domainElement);
+ }
+
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ //creation of the node
+ Element semanticElement=(Element)elementEditPart.resolveSemanticElement();
+ View containerView=(View)elementEditPart.getNotationView().eContainer();
+ int visualID=UMLVisualIDRegistry.getNodeVisualID(containerView, semanticElement);
+ UMLViewProvider umlViewProvider = new UMLViewProvider();
+ IAdaptable elementAdapter = new EObjectAdapter(semanticElement);
+ String semanticHint=((IHintedType)getUMLElementType(visualID)).getSemanticHint();
+ Node node= umlViewProvider.createNode(elementAdapter, containerView, semanticHint, -1, true, elementEditPart.getDiagramPreferencesHint());
+ node.setLayoutConstraint(((Node)elementEditPart.getNotationView()).getLayoutConstraint());
+
+ //copy of all eannotations
+ Iterator<EAnnotation> iter = elementEditPart.getNotationView().getEAnnotations().iterator();
+ while(iter.hasNext()) {
+ EAnnotation annotation = EcoreUtil.copy(iter.next());
+ node.getEAnnotations().add(annotation);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ElementToDefaultNamedElementShape.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ElementToDefaultNamedElementShape.java
new file mode 100644
index 00000000000..fe865fc0d3a
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/command/ElementToDefaultNamedElementShape.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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.uml.diagram.usecase.command;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.usecase.providers.UMLViewProvider;
+
+/**
+ * this is the specific command in charge to transform an element editpart into a shape_namedElement Editpart
+ *
+ */
+public class ElementToDefaultNamedElementShape extends AbstractTransactionalCommand {
+
+ protected GraphicalEditPart elementEditPart;
+
+ /**
+ *
+ * Constructor of this command
+ *
+ * @param domain
+ * the transactional editing domain to execute transaction
+ * @param classView
+ * the editpart that will be transformed
+ */
+ public ElementToDefaultNamedElementShape(TransactionalEditingDomain domain, GraphicalEditPart classView) {
+ super(domain, "ChangeToDefaultNamedElement", Collections.EMPTY_LIST);
+ this.elementEditPart = classView;
+ }
+
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ //creation of the node
+ UMLViewProvider umlViewProvider = new UMLViewProvider();
+ View container=(View)elementEditPart.getNotationView().eContainer();
+ Node packageview = umlViewProvider.createNamedElement_2022(elementEditPart.resolveSemanticElement(), container, -1, true, elementEditPart.getDiagramPreferencesHint());
+ packageview.setLayoutConstraint(((Node)elementEditPart.getNotationView()).getLayoutConstraint());
+
+ //copy of all eannotations
+ Iterator<EAnnotation> iter = elementEditPart.getNotationView().getEAnnotations().iterator();
+ while(iter.hasNext()) {
+ EAnnotation annotation = EcoreUtil.copy(iter.next());
+ packageview.getEAnnotations().add(annotation);
+
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/ChangeShapeHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/ChangeShapeHandler.java
new file mode 100644
index 00000000000..086ef1be177
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/ChangeShapeHandler.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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.uml.diagram.usecase.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This class is an abstract class in charge to transform a editpart into another editpart
+ *
+ */
+public abstract class ChangeShapeHandler extends AbstractHandler {
+ protected TransactionalEditingDomain transactionalEditingDomain=null;
+ protected org.eclipse.uml2.uml.Element selectedElement=null;
+
+ public ChangeShapeHandler() {
+ super();
+ }
+
+
+ protected abstract AbstractTransactionalCommand getChangeShapeCommand(final GraphicalEditPart editPart);
+
+ /**
+ *
+ * @return null or the selected editPart
+ */
+ protected GraphicalEditPart getSelectedGraphicalEditpart() {
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = selectionService.getSelection();
+
+ if(selection instanceof IStructuredSelection) {
+ Object selectedobject = ((IStructuredSelection)selection).getFirstElement();
+ if(selectedobject instanceof GraphicalEditPart) {
+ return (GraphicalEditPart)selectedobject;
+ }
+ }
+ return null;
+ }
+
+
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final GraphicalEditPart editPart= getSelectedGraphicalEditpart();
+ ServiceUtilsForActionHandlers util = new ServiceUtilsForActionHandlers();
+ try {
+ transactionalEditingDomain =util.getTransactionalEditingDomain();
+ } catch (Exception e) {
+ System.err.println("impossible to get the Transactional Editing Domain "+e);
+ }
+ try {
+ editPart.getEditingDomain().runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ AbstractTransactionalCommand command = getChangeShapeCommand(editPart);
+ Request deleteViewRequest = new GroupRequest(RequestConstants.REQ_DELETE);
+ Command deleteCommand = editPart.getCommand(deleteViewRequest);
+ org.eclipse.emf.common.command.CompoundCommand compoundCommand= new org.eclipse.emf.common.command.CompoundCommand("change Shape");
+ compoundCommand.append(new GMFtoEMFCommandWrapper(command));
+ compoundCommand.append(new GEFtoEMFCommandWrapper(deleteCommand));
+ editPart.getEditingDomain().getCommandStack().execute(compoundCommand);
+
+ }
+ });
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/DefaultNamedElementHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/DefaultNamedElementHandler.java
new file mode 100644
index 00000000000..39d0adc9cff
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/DefaultNamedElementHandler.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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.uml.diagram.usecase.handler;
+
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.uml.diagram.usecase.command.ElementToDefaultNamedElementShape;
+import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.SubjectClassEditPartTN;
+import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.SubjectComponentEditPartTN;
+import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.SubjectInterfaceEditPartTN;
+
+/**
+ * the goal of this class is to transform a change a Subject as a default named Element
+ *
+ */
+public class DefaultNamedElementHandler extends ChangeShapeHandler implements IHandler {
+ protected TransactionalEditingDomain transactionalEditingDomain=null;
+ protected org.eclipse.uml2.uml.Element selectedElement=null;
+
+
+ @Override
+ public boolean isEnabled() {
+ GraphicalEditPart editPart= getSelectedGraphicalEditpart();
+ if((editPart instanceof SubjectClassEditPartTN)|| (editPart instanceof SubjectComponentEditPartTN)||(editPart instanceof SubjectInterfaceEditPartTN)){
+ return true;
+ }
+ return false;
+ }
+
+
+ @Override
+ protected AbstractTransactionalCommand getChangeShapeCommand(GraphicalEditPart editPart) {
+ ElementToDefaultNamedElementShape command = new ElementToDefaultNamedElementShape(editPart.getEditingDomain(), editPart);
+ return command;
+ }
+
+
+} \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/SubjectHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/SubjectHandler.java
new file mode 100644
index 00000000000..d59aa32c09e
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/handler/SubjectHandler.java
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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.uml.diagram.usecase.handler;
+
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.papyrus.uml.diagram.usecase.command.ChangetoDefaultShapeCommand;
+import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.SubjectClassEditPartTN;
+import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.SubjectComponentEditPartTN;
+import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.SubjectInterfaceEditPartTN;
+import org.eclipse.uml2.uml.Interface;
+
+/**
+ * the goal of this class is to transform a default named element as a subject
+ *
+ *
+ */
+public class SubjectHandler extends ChangeShapeHandler implements IHandler {
+
+ @Override
+ public boolean isEnabled() {
+ GraphicalEditPart editPart= getSelectedGraphicalEditpart();
+ if((editPart.resolveSemanticElement() instanceof org.eclipse.uml2.uml.Class)||(editPart.resolveSemanticElement() instanceof Interface)){
+ if((editPart instanceof SubjectClassEditPartTN)|| (editPart instanceof SubjectComponentEditPartTN)||(editPart instanceof SubjectInterfaceEditPartTN)){
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
+ return false;
+ }
+
+/**
+ *
+ * @see org.eclipse.papyrus.uml.diagram.usecase.handler.ChangeShapeHandler#getChangeShapeCommand(org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)
+ *
+ * @param editPart
+ * @return
+ */
+ protected ChangetoDefaultShapeCommand getChangeShapeCommand(final GraphicalEditPart editPart) {
+ ChangetoDefaultShapeCommand command = new ChangetoDefaultShapeCommand(editPart.getEditingDomain(), editPart);
+ return command;
+ }
+} \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/plugin.xml
index 5ef30c6d2f6..2f25fae7055 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/plugin.xml
@@ -1413,6 +1413,48 @@
<instanceof value="org.eclipse.papyrus.uml.diagram.usecase.navigator.UMLAbstractNavigatorItem"/>
</selectionEnablement>
</linkHelper>
- </extension>
+ </extension>
+<extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu?after=filtersMenu">
+ <command
+ commandId="org.eclipse.papyrus.diagram.usecase.displayasdefaultnamedelement.popup"
+ id="displayasdefaultnamedelement.popup"
+ label="Display as default NameElement"
+ style="push"
+ tooltip="Display as default NameElement">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.diagram.usecase.displayassubject.popup"
+ id="displayassubject.popup"
+ label="Display as a subject"
+ style="push"
+ tooltip="Display as a subject">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ </menuContribution>
+</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.uml.diagram.usecase.handler.DefaultNamedElementHandler"
+ id="org.eclipse.papyrus.diagram.usecase.displayasdefaultnamedelement.popup"
+ name="Display as default NamedElement">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.uml.diagram.usecase.handler.SubjectHandler"
+ id="org.eclipse.papyrus.diagram.usecase.displayassubject.popup"
+ name="Display as subject">
+ </command>
+</extension>
</plugin>

Back to the top