Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2012-11-16 10:22:00 +0000
committerptessier2012-11-16 10:22:00 +0000
commit6319e43978704b5ee5f7a8cfa9c8d6f9ca7d0eab (patch)
treec4e5002750e3834b369ad1f12be73e39afe4cba9 /plugins
parent511ed26fc545de0788fa0b4947d334211fcbf8b8 (diff)
downloadorg.eclipse.papyrus-6319e43978704b5ee5f7a8cfa9c8d6f9ca7d0eab.tar.gz
org.eclipse.papyrus-6319e43978704b5ee5f7a8cfa9c8d6f9ca7d0eab.tar.xz
org.eclipse.papyrus-6319e43978704b5ee5f7a8cfa9c8d6f9ca7d0eab.zip
269492: [All Diagrams] Display properties of a applied stereotypes as a " comment"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=269492
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateAppliedStereotypeCommentViewCommand.java137
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java229
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java271
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentEditPolicy.java19
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java44
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypePropertiesEditPolicy.java138
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java174
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java8
8 files changed, 840 insertions, 180 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateAppliedStereotypeCommentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateAppliedStereotypeCommentViewCommand.java
new file mode 100644
index 00000000000..336562f9a7b
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateAppliedStereotypeCommentViewCommand.java
@@ -0,0 +1,137 @@
+/*****************************************************************************
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import java.util.ArrayList;
+
+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.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.Connector;
+import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
+import org.eclipse.gmf.runtime.notation.TitleStyle;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
+import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
+import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
+import org.eclipse.papyrus.uml.diagram.common.editparts.AppliedStereotypesCommentEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editparts.AppliedStereotypesCommentLinkEditPart;
+
+/**
+ * the goal of this command is to create a comment in the notation that represent a compartment of stereotypes
+ *
+ */
+public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand {
+
+ protected View owner;
+ protected EObject base_element;
+ protected int x;
+ protected int y;
+ protected TransactionalEditingDomain domain;
+ protected Boolean isBorderedElement;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * @param owner
+ * @param StereotypeApplication
+ * @param displayit
+ */
+ public CreateAppliedStereotypeCommentViewCommand(TransactionalEditingDomain domain,View owner,int x, int y, EObject base_Element, boolean isABordererElement) {
+ super(domain);
+ this.owner = owner;
+ this.base_element=base_Element;
+ this.x=x;
+ this.y=y;
+ this.domain= domain;
+ this.isBorderedElement=isABordererElement;
+
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public void doExecute() {
+
+ //create the node
+ Node node = NotationFactory.eINSTANCE.createShape();
+ node.setVisible(true);
+ Bounds bounds=NotationFactory.eINSTANCE.createBounds();
+ bounds.setX(x);
+ bounds.setY(y);
+ node.setLayoutConstraint(bounds);
+ TitleStyle ts = NotationFactory.eINSTANCE.createTitleStyle();
+ ts.setShowTitle(true);
+ node.getStyles().add(ts);
+ node.setElement(null);
+ node.setType(AppliedStereotypesCommentEditPart.ID);
+ View econtainer=(View)owner.eContainer();
+ if( isBorderedElement){
+ if(econtainer.eContainer()!=null){
+ econtainer=(View)econtainer.eContainer();
+ }
+ }
+ ViewUtil.insertChildView(econtainer, node, ViewUtil.APPEND, true);
+
+
+ EObjectValueStyle eObjectValueStyle=(EObjectValueStyle)node.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
+ eObjectValueStyle.setEObjectValue(base_element);
+ eObjectValueStyle.setName("BASE_ELEMENT");
+
+ //create the link
+ Connector edge = NotationFactory.eINSTANCE.createConnector();
+ edge.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
+ RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints();
+ ArrayList<RelativeBendpoint> points = new ArrayList<RelativeBendpoint>(2);
+ points.add(new RelativeBendpoint());
+ points.add(new RelativeBendpoint());
+ bendpoints.setPoints(points);
+ edge.setBendpoints(bendpoints);
+ ViewUtil.insertChildView((View)owner.getDiagram(), edge, -1, true);
+ edge.setType(AppliedStereotypesCommentLinkEditPart.ID);
+ edge.setElement(base_element);
+ IdentityAnchor anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ edge.setSourceAnchor(anchor);
+ anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ edge.setTargetAnchor(anchor);
+ edge.setSource(owner);
+ edge.setTarget(node);
+ edge.setElement(null);
+ eObjectValueStyle=(EObjectValueStyle)edge.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
+ eObjectValueStyle.setEObjectValue(base_element);
+ eObjectValueStyle.setName("BASE_ELEMENT");
+
+ //copy EAnnotation
+ final EAnnotation stereotypeAnnotation=owner.getEAnnotation(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION);
+ EAnnotation stereotypeAnnotationCopy=EcoreUtil.copy(stereotypeAnnotation);
+ node.getEAnnotations().add(stereotypeAnnotationCopy);
+ RecordingCommand cmd=AppliedStereotypeHelper.getSetAppliedStereotypePropertiesLocalizationCommand(domain, node, UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
+ cmd.execute();
+
+ String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(node);
+ cmd =AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(domain, node, AppliedStereotypeHelper.getStereotypesToDisplay(node), presentationKind);
+ cmd.execute();
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java
index 9e749cd1190..dd800b42d84 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java
@@ -23,8 +23,10 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
+import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
@@ -60,7 +62,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic
super();
}
-
+
/**
* clean stereotype to display in Eannotation this method can be called directly
* at the activation of this class
@@ -175,129 +177,136 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic
protected void removeEAnnotationAboutStereotype(final String stereotypeQN){
- try {
- ((IGraphicalEditPart)getHost()).getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(getView());
- RecordingCommand command = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(((IGraphicalEditPart)getHost()).getEditingDomain(), getView(),stereotypeQN, presentationKind);
- ((IGraphicalEditPart)getHost()).getEditingDomain().getCommandStack().execute(command);
- }
- });
- }
- });
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ try {
+ if( getView()!=null){
+ final TransactionalEditingDomain editingDomain= TransactionUtil.getEditingDomain(getView());
+ if( editingDomain!=null){
+ editingDomain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ if( getView()!=null&& editingDomain!=null){
+ String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(getView());
+ RecordingCommand command = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(editingDomain, getView(),stereotypeQN, presentationKind);
+ editingDomain.getCommandStack().execute(command);
+ }
+ }
+ });
+ }
+ });
+ }
}
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+ }
- /**
- *
- * {@inheritedDoc}
- */
- public void notifyChanged(Notification notification) {
- // change the label of the figure managed by the host edit part (managed
- // by the parent edit
- // part in general...)
- // it must be changed only if:
- // - the annotation corresponding to the display of the stereotype
- // changes
- // - the stereotype application list has changed
- final int eventType = notification.getEventType();
-
- if(eventType == PapyrusStereotypeListener.APPLIED_STEREOTYPE) {
- // a stereotype was applied to the notifier
- // then a new listener should be added to the stereotype application
- getDiagramEventBroker().addNotificationListener((EObject)notification.getNewValue(), this);
- } else if(eventType == PapyrusStereotypeListener.UNAPPLIED_STEREOTYPE) {
- getDiagramEventBroker().removeNotificationListener((EObject)notification.getOldValue(), this);
- cleanStereotypeDisplayInEAnnotation();
-
- }
+ /**
+ *
+ * {@inheritedDoc}
+ */
+ public void notifyChanged(Notification notification) {
+ // change the label of the figure managed by the host edit part (managed
+ // by the parent edit
+ // part in general...)
+ // it must be changed only if:
+ // - the annotation corresponding to the display of the stereotype
+ // changes
+ // - the stereotype application list has changed
+ final int eventType = notification.getEventType();
+
+ if(eventType == PapyrusStereotypeListener.APPLIED_STEREOTYPE) {
+ // a stereotype was applied to the notifier
+ // then a new listener should be added to the stereotype application
+ getDiagramEventBroker().addNotificationListener((EObject)notification.getNewValue(), this);
+ } else if(eventType == PapyrusStereotypeListener.UNAPPLIED_STEREOTYPE) {
+ getDiagramEventBroker().removeNotificationListener((EObject)notification.getOldValue(), this);
+ cleanStereotypeDisplayInEAnnotation();
- // if element that has changed is a stereotype => refresh the label.
- if(notification.getNotifier() instanceof EAnnotation) {
- if(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation)notification.getNotifier()).getSource()) {
- // stereotype annotation has changed => refresh label display
- refreshDisplay();
- }
- }
+ }
- // if element that has changed is a stereotype => refresh the label.
- if((eventType == PapyrusStereotypeListener.MODIFIED_STEREOTYPE)) {
+ // if element that has changed is a stereotype => refresh the label.
+ if(notification.getNotifier() instanceof EAnnotation) {
+ if(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation)notification.getNotifier()).getSource()) {
// stereotype annotation has changed => refresh label display
refreshDisplay();
}
+ }
- // The value of a property of stereotype (dynamic profile) has changed
- // To avoid refresh to be called during stereotype removal (stereotype#base_xxx set to null in particular) a complementary test is
- // added here to ensure the stereotype is still applied (the notifier is a stereotype application of the semantic element).
- if((notification.getNotifier() instanceof DynamicEObjectImpl) && (hostSemanticElement != null) && (hostSemanticElement.getStereotypeApplications().contains(notification.getNotifier()))) {
- refreshDisplay();
- }
+ // if element that has changed is a stereotype => refresh the label.
+ if((eventType == PapyrusStereotypeListener.MODIFIED_STEREOTYPE)) {
+ // stereotype annotation has changed => refresh label display
+ refreshDisplay();
}
- /**
- * Refreshes the display for the element controlled by the edit part with
- * this edit policies
- */
- public abstract void refreshDisplay();
-
- /**
- * Parses the string containing the complete definition of properties to be
- * displayed, and generates a map.
- *
- * @param stereotypesToDisplay
- * the list of stereotypes to display
- * @param stereotypesPropertiesToDisplay
- * the properties of stereotypes to display
- * @return a map. The keys are the name of displayed stereotypes, the
- * corresponding data is a collection of its properties to be
- * displayed
- */
- protected Map<String, List<String>> parseStereotypeProperties(String stereotypesToDisplay, String stereotypesPropertiesToDisplay) {
- Map<String, List<String>> propertiesMap = new HashMap<String, List<String>>();
-
- StringTokenizer stringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, UMLVisualInformationPapyrusConstant.STEREOTYPE_PROPERTIES_LIST_SEPARATOR);
- while(stringTokenizer.hasMoreTokens()) {
- String propertyName = stringTokenizer.nextToken();
- // retrieve the name of the stereotype for this property
- String stereotypeName = propertyName.substring(0, propertyName.lastIndexOf(".")); // stereotypequalifiedName.propertyname
- if(!propertiesMap.containsKey(stereotypeName)) {
- List<String> propertiesForStereotype = new ArrayList<String>();
- propertiesMap.put(stereotypeName, propertiesForStereotype);
- }
- propertiesMap.get(stereotypeName).add(propertyName.substring(propertyName.lastIndexOf(".") + 1, propertyName.length()));
- }
- return propertiesMap;
+ // The value of a property of stereotype (dynamic profile) has changed
+ // To avoid refresh to be called during stereotype removal (stereotype#base_xxx set to null in particular) a complementary test is
+ // added here to ensure the stereotype is still applied (the notifier is a stereotype application of the semantic element).
+ if((notification.getNotifier() instanceof DynamicEObjectImpl) && (hostSemanticElement != null) && (hostSemanticElement.getStereotypeApplications().contains(notification.getNotifier()))) {
+ refreshDisplay();
}
+ }
- /**
- * Returns the image to be displayed for the applied stereotypes.
- *
- * @return the image that represents the first applied stereotype or <code>null</code> if no image has to be displayed
- */
- public Image stereotypeIconToDisplay() {
- String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View)getHost().getModel());
- if(stereotypespresentationKind == null) {
- return null;
- }
- if(stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) || stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.TEXT_ICON_STEREOTYPE_PRESENTATION)) {
-
- // retrieve the first stereotype in the list of displayed stereotype
- String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View)getHost().getModel());
- StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ",");
- if(tokenizer.hasMoreTokens()) {
- String firstStereotypeName = tokenizer.nextToken();
- Stereotype stereotype = getUMLElement().getAppliedStereotype(firstStereotypeName);
- return Activator.getIconElement(getUMLElement(), stereotype, false);
- }
+ /**
+ * Refreshes the display for the element controlled by the edit part with
+ * this edit policies
+ */
+ public abstract void refreshDisplay();
+
+ /**
+ * Parses the string containing the complete definition of properties to be
+ * displayed, and generates a map.
+ *
+ * @param stereotypesToDisplay
+ * the list of stereotypes to display
+ * @param stereotypesPropertiesToDisplay
+ * the properties of stereotypes to display
+ * @return a map. The keys are the name of displayed stereotypes, the
+ * corresponding data is a collection of its properties to be
+ * displayed
+ */
+ protected Map<String, List<String>> parseStereotypeProperties(String stereotypesToDisplay, String stereotypesPropertiesToDisplay) {
+ Map<String, List<String>> propertiesMap = new HashMap<String, List<String>>();
+
+ StringTokenizer stringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, UMLVisualInformationPapyrusConstant.STEREOTYPE_PROPERTIES_LIST_SEPARATOR);
+ while(stringTokenizer.hasMoreTokens()) {
+ String propertyName = stringTokenizer.nextToken();
+ // retrieve the name of the stereotype for this property
+ String stereotypeName = propertyName.substring(0, propertyName.lastIndexOf(".")); // stereotypequalifiedName.propertyname
+ if(!propertiesMap.containsKey(stereotypeName)) {
+ List<String> propertiesForStereotype = new ArrayList<String>();
+ propertiesMap.put(stereotypeName, propertiesForStereotype);
}
+ propertiesMap.get(stereotypeName).add(propertyName.substring(propertyName.lastIndexOf(".") + 1, propertyName.length()));
+ }
+ return propertiesMap;
+ }
+
+ /**
+ * Returns the image to be displayed for the applied stereotypes.
+ *
+ * @return the image that represents the first applied stereotype or <code>null</code> if no image has to be displayed
+ */
+ public Image stereotypeIconToDisplay() {
+ String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View)getHost().getModel());
+ if(stereotypespresentationKind == null) {
return null;
}
+ if(stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) || stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.TEXT_ICON_STEREOTYPE_PRESENTATION)) {
+
+ // retrieve the first stereotype in the list of displayed stereotype
+ String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View)getHost().getModel());
+ StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ",");
+ if(tokenizer.hasMoreTokens()) {
+ String firstStereotypeName = tokenizer.nextToken();
+ Stereotype stereotype = getUMLElement().getAppliedStereotype(firstStereotypeName);
+ return Activator.getIconElement(getUMLElement(), stereotype, false);
+ }
+ }
+ return null;
}
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java
new file mode 100644
index 00000000000..e16a8980b06
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java
@@ -0,0 +1,271 @@
+/*****************************************************************************
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.notify.Notification;
+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.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.LayoutConstraint;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
+import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.commands.CreateAppliedStereotypeCommentViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractBorderEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editparts.AppliedStereotypesCommentLinkEditPart;
+import org.eclipse.papyrus.uml.tools.listeners.PapyrusStereotypeListener;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * This editpolicy has in charge to :
+ * - create or destroy the appliedStereotypesCommentEditpart
+ * - adapt the information about stereotype display into appliedstereotypeCommentEditPart
+ * by using eannotation existing mechanism
+ *
+ */
+public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
+
+
+ /** constant for this edit policy role */
+ public final static String APPLIED_STEREOTYPE_COMMENT = "Applied_Stereotype_Comment";
+
+
+ protected void updateAppliedStereotypeCommentShape(){
+ String stereotypeLocalizationToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization((View)getHost().getModel());
+ String stereotypePropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View)getHost().getModel());
+ //look for the AppliedStereotypesCommentEditPart
+ if(getAppliedStereotypeCommentNode()==null&&(!stereotypePropertiesToDisplay.trim().equals(""))){
+ //test if stereotype has to be display as a comment
+ if (stereotypeLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMMENT_LOCATION)){
+
+ if( getHost() instanceof ConnectionEditPart){
+ executeAppliedStereotypeCommentCreation((ConnectionEditPart) getHost(), ((ConnectionEditPart) getHost()).getEditingDomain(), ((ConnectionEditPart) getHost()).resolveSemanticElement());
+ }
+
+ if( getHost() instanceof GraphicalEditPart){
+ executeAppliedStereotypeCommentCreation((GraphicalEditPart) getHost(), ((GraphicalEditPart) getHost()).getEditingDomain(), ((GraphicalEditPart) getHost()).resolveSemanticElement());
+ }
+ }
+ }
+ if(getAppliedStereotypeCommentNode()!=null){
+ View commentNode=getAppliedStereotypeCommentNode();
+ if (!stereotypeLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMMENT_LOCATION)||getvisisbleAppliedStereotypeCompartment(commentNode, getUMLElement())==0){
+ final TransactionalEditingDomain domain= TransactionUtil.getEditingDomain(commentNode);
+ executeAppliedStereotypeCommentDeletion(domain, commentNode);
+
+ }
+ }
+ }
+
+ protected int getvisisbleAppliedStereotypeCompartment(View view,EObject eobject){
+ int nbVisibleCompartment=0;
+ Iterator<View> iteratorView= view.getChildren().iterator();
+ while(iteratorView.hasNext()) {
+ View subview = (View)iteratorView.next();
+ if( !subview.getElement().equals(eobject)){
+ nbVisibleCompartment++;
+ }
+ }
+ return nbVisibleCompartment;
+ }
+ protected void delegateEAnnotationInCommentShape(){
+ final Node appliedStereotypeComment= getAppliedStereotypeCommentNode();
+
+ if(appliedStereotypeComment!=null){
+ View originView= getView();
+ final EAnnotation stereotypeAnnotation=originView.getEAnnotation(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION);
+
+ final TransactionalEditingDomain domain= TransactionUtil.getEditingDomain(originView);
+ final RecordingCommand cmd=new RecordingCommand(domain) {
+ @Override
+ protected void doExecute() {
+ EAnnotation stereotypeAnnotationCopy=EcoreUtil.copy(stereotypeAnnotation);
+ appliedStereotypeComment.getEAnnotations().clear();
+ appliedStereotypeComment.getEAnnotations().add(stereotypeAnnotationCopy);
+ RecordingCommand cmd=AppliedStereotypeHelper.getSetAppliedStereotypePropertiesLocalizationCommand(domain, appliedStereotypeComment, UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
+ cmd.execute();
+ String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(getView());
+ cmd =AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(domain, appliedStereotypeComment, AppliedStereotypeHelper.getStereotypesToDisplay(appliedStereotypeComment), presentationKind);
+ cmd.execute();
+ }
+ };
+ try {
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(cmd);
+ }
+ });
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+ }
+
+ /**
+ * return the comment nodes that represent stereotype properties
+ * @return may be null if nothing is founded
+ */
+ protected Node getAppliedStereotypeCommentNode(){
+ View SemanticView=(View) getHost().getModel();
+
+ Edge appliedStereotypeLink= null;
+ //look for all links with the id AppliedStereotypesCommentLinkEditPart.ID
+ @SuppressWarnings("unchecked")
+ Iterator<Edge>edgeIterator=SemanticView.getSourceEdges().iterator();
+ while(edgeIterator.hasNext()) {
+ Edge edge = (Edge)edgeIterator.next();
+ if (edge.getType().equals(AppliedStereotypesCommentLinkEditPart.ID)){
+ appliedStereotypeLink=edge;
+ }
+
+ }
+ if(appliedStereotypeLink== null){
+ return null;
+ }
+ return (Node)appliedStereotypeLink.getTarget();
+
+ }
+
+ /**
+ * the goal of this method is to execute the a command to create a notation node for applied stereotype
+ * as "Comment" shape
+ *
+ * @param editPart
+ * the semantic Editpart
+ * @param appliedstereotype
+ * the stereotype application
+ */
+ protected void executeAppliedStereotypeCommentCreation(final EditPart editPart, final TransactionalEditingDomain domain, final EObject semanticElement) {
+ try {
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ int x=200;
+ int y=100;
+ if(editPart.getModel()instanceof Node){
+ LayoutConstraint constraint=((Node)editPart.getModel()).getLayoutConstraint();
+ if( constraint instanceof Bounds){
+ x=x+ ((Bounds) constraint).getX();
+ y= ((Bounds) constraint).getY();
+ }
+
+ }
+ if(editPart.getModel()instanceof Edge&& ((((Edge)editPart.getModel()).getSource()) instanceof Node)){
+
+ LayoutConstraint constraint=((Node)((Edge)editPart.getModel()).getSource()).getLayoutConstraint();
+ if( constraint instanceof Bounds){
+ x=x+ ((Bounds) constraint).getX();
+ y= ((Bounds) constraint).getY()-100;
+ }
+
+ }
+ boolean isBorderElement= false;
+ if(editPart instanceof BorderedBorderItemEditPart ){
+ isBorderElement=true;
+ }
+ if(getAppliedStereotypeCommentNode()==null){
+ CreateAppliedStereotypeCommentViewCommand command = new CreateAppliedStereotypeCommentViewCommand(domain, (View)editPart.getModel(),x,y, semanticElement,isBorderElement);
+ domain.getCommandStack().execute(command);
+ }
+ }
+ });
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+ protected void executeAppliedStereotypeCommentDeletion( final TransactionalEditingDomain domain, final View commentNode) {
+ try {
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ //because it is asynchrone the comment node maybe become s null
+ if( commentNode!= null&& TransactionUtil.getEditingDomain(commentNode)!=null){
+ DeleteCommand command= new DeleteCommand(commentNode);
+ TransactionUtil.getEditingDomain(commentNode).getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ }
+ }
+ });
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ /**
+ *
+ * {@inheritedDoc}
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ // change the label of the figure managed by the host edit part (managed
+ // by the parent edit
+ // part in general...)
+ // it must be changed only if:
+ // - the annotation corresponding to the display of the stereotype
+ // changes
+ // - the stereotype application list has changed
+ final int eventType = notification.getEventType();
+ if(eventType == PapyrusStereotypeListener.APPLIED_STEREOTYPE) {
+ // a stereotype was applied to the notifier
+ // then a new listener should be added to the stereotype application
+ getDiagramEventBroker().addNotificationListener((EObject)notification.getNewValue(), this);
+ //createAppliedStereotypeCompartment((EObject)notification.getNewValue());
+ } else if(eventType == PapyrusStereotypeListener.UNAPPLIED_STEREOTYPE) {
+ getDiagramEventBroker().removeNotificationListener((EObject)notification.getOldValue(), this);
+ cleanStereotypeDisplayInEAnnotation();
+ updateAppliedStereotypeCommentShape();
+
+ }
+ // if element that has changed is a stereotype => refresh the label.
+ if(notification.getNotifier() instanceof View && (notification.getEventType() == Notification.ADD) && (notification.getNewValue() instanceof EAnnotation)) {
+ if(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation)notification.getNewValue()).getSource()) {
+ // stereotype annotation has changed => refresh label display
+ updateAppliedStereotypeCommentShape();
+ delegateEAnnotationInCommentShape();
+ //refreshDisplay();
+ }
+ }
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentEditPolicy.java
index 010a5b4ac02..3fa9740cac4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentEditPolicy.java
@@ -24,9 +24,12 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.common.Activator;
@@ -53,13 +56,14 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
super();
}
+
+
@Override
public void activate() {
super.activate();
// if stereotype has been applied, compartment has to be created
- final GraphicalEditPart editPart = (GraphicalEditPart)getHost();
- Element umlElement = (Element)editPart.resolveSemanticElement();
+ Element umlElement = getUMLElement();
//umlElement may be null if the semantic element has been deleted and the view hasn't been cleaned
if(umlElement != null) {
Iterator<EObject> iterator = umlElement.getStereotypeApplications().iterator();
@@ -73,7 +77,10 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
protected boolean hasToDisplayCompartment(EObject applicationOfStereotype) {
String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View)getHost().getModel());
-
+ String stereotypesLocalizationToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization((View)getHost().getModel());
+ if( !(stereotypesLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION))){
+ return false;
+ }
HashSet<org.eclipse.uml2.uml.Stereotype> stereoSet = new HashSet<org.eclipse.uml2.uml.Stereotype>();
ArrayList<String> stPropList = new ArrayList<String>();
@@ -283,8 +290,10 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
- DeleteCommand command = new DeleteCommand(currentNode);
- editPart.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ if(currentNode!=null&&editPart.getEditingDomain()!=null){
+ DeleteCommand command = new DeleteCommand(editPart.getEditingDomain(),currentNode);
+ editPart.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ }
}
});
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java
new file mode 100644
index 00000000000..00b8a8d227f
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.uml2.uml.Element;
+
+
+/**
+ * • AppliedStereotypeCompartmentForCommentShapeEditPolicy is another editpolicy attached
+ * to StereotypeCommentEdipart. It does the same work as AppliedStereotypeCompartmentEditPolicy.
+ * Because the StereotypeCommentEdipart is not attached to a semantic element by the attribute element of the notation view. It specializes the method getUMLElement to find the semantic element
+ *
+ */
+public class AppliedStereotypeCompartmentForCommentShapeEditPolicy extends AppliedStereotypeCompartmentEditPolicy {
+ /**
+ * Returns the uml element controlled by the host edit part
+ *
+ * @return the uml element controlled by the host edit part
+ */
+ protected Element getUMLElement() {
+ if( (Element)getView().getElement()!=null){
+ return (Element)getView().getElement();
+ }
+ if(getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT")!=null){
+ EObjectValueStyle eObjectValueStyle=(EObjectValueStyle)getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT");
+ return (Element)eObjectValueStyle.getEObjectValue();
+ }
+ return null;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypePropertiesEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypePropertiesEditPolicy.java
index 389c10a5279..f068c85a669 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypePropertiesEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypePropertiesEditPolicy.java
@@ -69,20 +69,52 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
return (View)((EObject)getHost().getModel()).eContainer();
}
-
+
/**
* this method is used to create a notation node for the property of the stereotype
* @param editPart the editpart container
- * @param property the property of the stereotype that we want to edit with the application of the stereotype
+ * @param stereotypesPropertiesToDisplay list of applied stereotype properties to display
+ * @param node the comaprtment node that contains all properties
+ * @param stereotype the stereotype associated to compartment node
*/
- protected void executeAppliedStereotypePropertytCreation(final GraphicalEditPart editPart, final Property property) {
+ protected void executeAppliedStereotypePropertytCreation(final GraphicalEditPart editPart, final String stereotypesPropertiesToDisplay,final View node, final Stereotype stereotype) {
try {
editPart.getEditingDomain().runExclusive(new Runnable() {
public void run() {
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
- CreateAppliedStereotypePropertyViewCommand command= new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), property);
- editPart.getEditingDomain().getCommandStack().execute(command);
+
+ StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ",");
+ while(propStringTokenizer.hasMoreElements()) {
+ // extract property to display
+ String propertyQN = propStringTokenizer.nextToken();
+ //get a property that is interesting for us
+ if( propertyQN.startsWith(stereotype.getQualifiedName())){
+
+ String propertyName= propertyQN.substring(propertyQN.lastIndexOf(".")+1);
+ Property stereotypeProperty=StereotypeUtil.getPropertyByName(stereotype, propertyName);
+
+ Node sterotypePropertyNode= null;
+ int i=0;
+ //we go through all sub nodes to get sub node that is link to this property
+ while(i<node.getChildren().size()&&sterotypePropertyNode==null){
+ if( (node.getChildren().get(i)) instanceof Node){
+ final Node currentNode=(Node)(node.getChildren().get(i));
+ if(currentNode.getType().equals(AppliedStereotypePropertyEditPart.ID)){
+ if( currentNode.getElement().equals(stereotypeProperty)){
+ sterotypePropertyNode= currentNode;
+ }
+ }
+ }
+ i++;
+ }
+ if( sterotypePropertyNode==null){
+ //System.err.println("+ add "+stereotypeProperty );
+ CreateAppliedStereotypePropertyViewCommand command= new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotypeProperty);
+ editPart.getEditingDomain().getCommandStack().execute(command);
+ }
+ }
+ }
}
});
}
@@ -99,7 +131,7 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
public void notifyChanged(Notification notification) {
// refresh obly when the EAnnotation about stereotype is added or remove
// to update only property of stereotype application
-
+
// if element that has changed is a stereotype => refresh the label.
if(notification.getNotifier() instanceof Node && (notification.getEventType()==Notification.ADD) &&(notification.getNewValue() instanceof EAnnotation)) {
@@ -111,9 +143,9 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
}
-/**
- * maybe to remove
- */
+ /**
+ * maybe to remove
+ */
protected void refreshEAnnotation() {
final GraphicalEditPart editPart= (GraphicalEditPart)getHost();
String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View)editPart.getNotationView().eContainer());
@@ -143,67 +175,47 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
* Refreshes the stereotype application property
*/
public void refreshDisplay() {
+ if(((View)getHost().getModel()).eContainer()!=null ){
+ String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View)((View)getHost().getModel()).eContainer());
+ final GraphicalEditPart editPart= (GraphicalEditPart)getHost();
+ final View node=editPart.getNotationView();
- String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View)((View)getHost().getModel()).eContainer());
- final GraphicalEditPart editPart= (GraphicalEditPart)getHost();
- final View node=editPart.getNotationView();
-
- //1. Manage adding of application stereotype properties
- EObject stereotypeApplication=editPart.resolveSemanticElement();
- Stereotype stereotype=UMLUtil.getStereotype(stereotypeApplication);
- //go through each stereotype property
-
- manageAddingStereotypeProperties(stereotypesPropertiesToDisplay, editPart, node, stereotype);
-
- //Manage removing of Stereotype application properties
- manageRemovingPropertiesNodes(stereotypesPropertiesToDisplay, editPart, node, stereotype);
+ //1. Manage adding of application stereotype properties
+ EObject stereotypeApplication=editPart.resolveSemanticElement();
+ Stereotype stereotype=UMLUtil.getStereotype(stereotypeApplication);
+ //if stereotype is null all property of stereotype has to be removed!
+ if( stereotype!=null){
+ //go through each stereotype property
+ executeAppliedStereotypePropertytCreation(editPart, stereotypesPropertiesToDisplay, node, stereotype);
+ //Manage removing of Stereotype application properties
+ manageRemovingPropertiesNodes(stereotypesPropertiesToDisplay, editPart, node, stereotype);
- }
+ }
+ else{
+ try{
+ editPart.getEditingDomain().runExclusive(new Runnable() {
+ public void run() {
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ DeleteCommand command= new DeleteCommand((View)getHost().getModel());
+ editPart.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ }
-
- /**
- * this method is used to add if needed propertyNode by taking in account a list of properties to display
- * @param stereotypesPropertiesToDisplay a list of qualified name of properties
- * @param editPart the graphical editpart that is the container
- * @param node the notation node that is the container
- * @param stereotype the stereotype that is display in this container
- */
- protected void manageAddingStereotypeProperties(String stereotypesPropertiesToDisplay, final GraphicalEditPart editPart, final View node, Stereotype stereotype) {
- // fill our data structure in order to generate the string
- StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ",");
- while(propStringTokenizer.hasMoreElements()) {
- // extract property to display
- String propertyQN = propStringTokenizer.nextToken();
- //get a property that is interesting for us
- if( propertyQN.startsWith(stereotype.getQualifiedName())){
-
- String propertyName= propertyQN.substring(propertyQN.lastIndexOf(".")+1);
- Property stereotypeProperty=StereotypeUtil.getPropertyByName(stereotype, propertyName);
-
- Node sterotypePropertyNode= null;
- int i=0;
- //we go through all sub nodes to get sub node that is link to this property
- while(i<node.getChildren().size()&&sterotypePropertyNode==null){
- if( (node.getChildren().get(i)) instanceof Node){
- final Node currentNode=(Node)(node.getChildren().get(i));
- if(currentNode.getType().equals(AppliedStereotypePropertyEditPart.ID)){
- if( currentNode.getElement().equals(stereotypeProperty)){
- sterotypePropertyNode= currentNode;
- }
+ });
}
- }
- i++;
- }
- if( sterotypePropertyNode==null){
- executeAppliedStereotypePropertytCreation(editPart, stereotypeProperty);
+ });
+ }catch (Exception e) {
+ System.err.println(e);
}
}
}
}
+
+
/**
* this method is used to remove nodes of property that are not in a given list
*@param stereotypesPropertiesToDisplay a list of qualified name of properties
@@ -218,7 +230,7 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
final Node currentNode=(Node)(node.getChildren().get(i));
if(currentNode.getType().equals(AppliedStereotypePropertyEditPart.ID)){
Property property=(Property)currentNode.getElement();
- String propertyQN= stereotype.getQualifiedName()+"."+property.getName();
+ final String propertyQN= stereotype.getQualifiedName()+"."+property.getName();
if(!stereotypesPropertiesToDisplay.contains(propertyQN) ){
try{
//yes, Execution of the Deletion command
@@ -226,8 +238,12 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
public void run() {
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
- DeleteCommand command= new DeleteCommand(currentNode);
- editPart.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ if( currentNode.eContainer()!=null){
+ //System.err.println("- remove "+propertyQN );
+ DeleteCommand command= new DeleteCommand(currentNode);
+ editPart.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ }
+
}
});
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java
new file mode 100644
index 00000000000..335fff0fc07
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * this editpolicy attached to StereotypeCommentEdipart has in charge to prevent the remove form model
+ * and launch command of deletion if it detect that any properties of applied stereotype are displayed
+ *
+ */
+public class CommentShapeForAppliedStereotypeEditPolicy extends GraphicalEditPolicy implements NotificationListener, IPapyrusListener {
+
+ public void notifyChanged(Notification notification) {
+ View commentNode=getView();
+ final TransactionalEditingDomain domain= TransactionUtil.getEditingDomain(commentNode);
+ if(getUMLElement()==null){
+ executeAppliedStereotypeCommentDeletion(domain, commentNode);
+ }
+ final int eventType = notification.getEventType();
+ if(eventType==Notification.SET && notification.getFeature().equals(NotationPackage.eINSTANCE.getView_Visible())){
+
+ if(getView()!=null){
+
+ if (getvisibleAppliedStereotypeCompartment(commentNode, getUMLElement())==0){
+
+ executeAppliedStereotypeCommentDeletion(domain, commentNode);
+
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the uml element controlled by the host edit part
+ *
+ * @return the uml element controlled by the host edit part
+ */
+ protected Element getUMLElement() {
+ if( (Element)getView().getElement()!=null){
+ return (Element)getView().getElement();
+ }
+ if(getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT")!=null){
+ EObjectValueStyle eObjectValueStyle=(EObjectValueStyle)getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT");
+ return (Element)eObjectValueStyle.getEObjectValue();
+ }
+ return null;
+ }
+ @Override
+ public Command getCommand(Request request) {
+ if(request instanceof EditCommandRequestWrapper){
+ if(((EditCommandRequestWrapper)(request)).getEditCommandRequest() instanceof DestroyElementRequest){
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+ return super.getCommand(request);
+ }
+
+
+ protected void executeAppliedStereotypeCommentDeletion( final TransactionalEditingDomain domain, final View commentNode) {
+ try {
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ //because it is asynchrone the comment node maybe become s null
+ if( commentNode!= null&& TransactionUtil.getEditingDomain(commentNode)!=null){
+ DeleteCommand command= new DeleteCommand(commentNode);
+ TransactionUtil.getEditingDomain(commentNode).getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ }
+ }
+ });
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ protected int getvisibleAppliedStereotypeCompartment(View view, EObject eobject){
+ int nbVisibleCompartment=0;
+ Iterator<View> iteratorView= view.getChildren().iterator();
+ while(iteratorView.hasNext()) {
+ View subview = (View)iteratorView.next();
+ if( subview.isVisible()==true){
+ nbVisibleCompartment++;
+ }
+ }
+ return nbVisibleCompartment;
+ }
+
+
+ @Override
+ public void activate() {
+ // retrieve the view and the element managed by the edit part
+ View view = getView();
+ if(view == null) {
+ return;
+ }
+
+ // adds a listener on the view and the element controlled by the
+ // editpart
+ getDiagramEventBroker().addNotificationListener(view, this);
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void deactivate() {
+ // retrieve the view and the element managed by the edit part
+ View view = getView();
+ if(view == null) {
+ return;
+ }
+
+ getDiagramEventBroker().removeNotificationListener(view, this);
+ }
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ protected DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain();
+ if(theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ return null;
+ }
+ /**
+ * Returns the view controlled by the host edit part
+ *
+ * @return the view controlled by the host edit part
+ */
+ protected View getView() {
+ return (View)getHost().getModel();
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java
index 062cd417077..166bd71722c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java
@@ -77,7 +77,7 @@ public class StereotypePropertyParser implements IParser, ISemanticParser {
return result;
}
else{return "";}
-
+
}
return "<UNDEFINED>";
}
@@ -145,9 +145,9 @@ public class StereotypePropertyParser implements IParser, ISemanticParser {
final EObject stereotypeApplication=((View)view.eContainer()).getElement();
final Stereotype stereotype=UMLUtil.getStereotype(stereotypeApplication);
final Element umlElement=UMLUtil.getBaseElement(stereotypeApplication);
-
-
- return StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, "");
+ if(stereotype!=null && property!=null && umlElement!=null){
+ return StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, "");
+ }
}
return "<UNDEFINED>";
}

Back to the top