Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/NameDisplayEditPolicy.java141
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java9
3 files changed, 152 insertions, 0 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java
index 1a8269e0638..34921ccf8fd 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java
@@ -17,6 +17,7 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.BorderDisplayEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.NameDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -115,6 +116,7 @@ public abstract class NamedElementEditPart extends UMLNodeEditPart implements IU
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+ installEditPolicy(NameDisplayEditPolicy.NAME_DISPLAY_EDITPOLICY, new NameDisplayEditPolicy());
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/NameDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/NameDisplayEditPolicy.java
new file mode 100644
index 00000000000..e0491647224
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/NameDisplayEditPolicy.java
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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.draw2d.Border;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+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.editparts.ResizableCompartmentEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.OneLineBorder;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
+import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure;
+
+/**
+ * this edit policy has in charge to display the name of node NodeNamedElement
+ * associated figure has to be a {@link NodeNamedElementFigure}
+ */
+public class NameDisplayEditPolicy extends GraphicalEditPolicy implements NotificationListener, IPapyrusListener {
+
+ public static final String DISPLAY_NAME = "NameDisplay";
+
+ /** key for this edit policy */
+ public final static String NAME_DISPLAY_EDITPOLICY = "NAME_DISPLAY_EDITPOLICY";
+
+
+ private Border defaultBorder;
+
+ /**
+ * Creates a new QualifiedNameDisplayEditPolicy
+ */
+ public NameDisplayEditPolicy() {
+ super();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void activate() {
+ // retrieve the view and the element managed by the edit part
+ View view = (View)getHost().getModel();
+ if(view == null) {
+ return;
+ }
+
+ // adds a listener on the view and the element controlled by the
+ // editpart
+ getDiagramEventBroker().addNotificationListener(view, this);
+
+ if(getHost() instanceof NamedElementEditPart) {
+ NamedElementEditPart namedElementEditPart = (NamedElementEditPart)getHost();
+ defaultBorder=namedElementEditPart.getPrimaryShape().getBorder();
+
+ }
+ refreshBorder();
+ }
+
+ /**
+ * refresh the qualified name
+ */
+ protected void refreshBorder() {
+ if(getHost() instanceof NamedElementEditPart) {
+ NamedElementEditPart namedElementEditPart = (NamedElementEditPart)getHost();
+ BooleanValueStyle nameStyle = getBorderStyle(namedElementEditPart.getNotationView());
+ if(nameStyle != null && nameStyle.isBooleanValue() == false) {
+ ((NodeNamedElementFigure)namedElementEditPart.getPrimaryShape()).removeNameLabel();
+
+ } else {
+ ((NodeNamedElementFigure)namedElementEditPart.getPrimaryShape()).restoreNameLabel();
+ }
+ }
+ }
+
+ /**
+ *
+ * @param currentView
+ * @return the current Style that repersent the boder
+ */
+ protected BooleanValueStyle getBorderStyle(View currentView) {
+ return (BooleanValueStyle)currentView.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), DISPLAY_NAME);
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void deactivate() {
+ // retrieve the view and the element managed by the edit part
+ View view = (View)getHost().getModel();
+ if(view == null) {
+ return;
+ }
+ // remove notification on element and view
+ 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;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void notifyChanged(Notification notification) {
+ refreshBorder();
+ }
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java
index 90b1a6b5991..d8560626afe 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java
@@ -168,6 +168,13 @@ public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyru
getNameLabelContainer().add(nameLabel, getNameLabelConstraint(), -1);
}
+ public void restoreNameLabel() {
+ nameLabel.setOpaque(false);
+ nameLabel.setAlignment(PositionConstants.MIDDLE);
+ getNameLabelContainer().add(nameLabel, getNameLabelConstraint(), getNameLabelPosition());
+ }
+
+
/**
* Create a label that contains the name of the element.
*/
@@ -652,6 +659,8 @@ public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyru
return position;
}
+
+
/**
* Returns the position of the stereotype properties location. this is just

Back to the top