Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2013-10-25 11:17:44 -0400
committerCamille Letavernier2013-10-25 11:17:44 -0400
commit4139b8c672d8ebf94ef86c1242b683fd5d320386 (patch)
tree016192a57b2007db8b6d335358ea8b7fee13b886 /plugins
parent9ecdf45298cb6e4a1b3f2d3280b39c62c3e4833a (diff)
downloadorg.eclipse.papyrus-4139b8c672d8ebf94ef86c1242b683fd5d320386.tar.gz
org.eclipse.papyrus-4139b8c672d8ebf94ef86c1242b683fd5d320386.tar.xz
org.eclipse.papyrus-4139b8c672d8ebf94ef86c1242b683fd5d320386.zip
419965: Display of the name must be optional
https://bugs.eclipse.org/bugs/show_bug.cgi?id=419965
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java85
1 files changed, 68 insertions, 17 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java
index 4ccdeb1d9f2..5aa2c433915 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java
@@ -18,9 +18,13 @@ import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.draw2d.Border;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.OneLineBorder;
+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.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
@@ -30,10 +34,9 @@ import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomBoolean
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
/**
- * this edit policy has in charge to display the border of node NodeNamedElement
- * associated figure has to be a {@link NodeNamedElementFigure}
+ * this edit policy has in charge to toggle the border of its edit part's figure
*/
-public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IChangeListener {
+public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IChangeListener, NotificationListener {
public static final String DISPLAY_BORDER = "displayBorder";
@@ -57,7 +60,30 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC
styleObservable = new CustomBooleanStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), DISPLAY_BORDER);
styleObservable.addChangeListener(this);
- getHost().refresh();
+ // adds a listener on the view and the element controlled by the
+ // editpart
+ getDiagramEventBroker().addNotificationListener(view, this);
+
+ EObject semanticElement = EMFHelper.getEObject(getHost());
+ if(semanticElement != null) {
+ getDiagramEventBroker().addNotificationListener(semanticElement, this);
+ }
+
+ refreshBorderDisplay();
+ }
+
+
+ /**
+ * 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;
}
@@ -84,6 +110,11 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC
}
@Override
+ public void notifyChanged(Notification notification) {
+ refreshBorderDisplay();
+ }
+
+ @Override
public void handleChange(ChangeEvent event) {
getHost().refresh();
}
@@ -121,7 +152,7 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC
return;
}
- BooleanValueStyle displayBorderStyle = (BooleanValueStyle)view.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), BorderDisplayEditPolicy.DISPLAY_BORDER);
+ BooleanValueStyle displayBorderStyle = findDisplayBorderStyle(view);
if(displayBorderStyle != null && !displayBorderStyle.isBooleanValue()) {
if(defaultBorder == null) {
@@ -129,12 +160,13 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC
}
getPrimaryShape().setBorder(null);
- for(Object currentEditPart : getHost().getChildren()) {
- if(currentEditPart instanceof ResizableCompartmentEditPart) {
- ((ResizableCompartmentEditPart)currentEditPart).getFigure().setBorder(null);
- }
-
- }
+ //TODO: This edit policy should be installed on all compartments. We shouldn't need to refresh them from here
+ // for(Object currentEditPart : getHost().getChildren()) {
+ // if(currentEditPart instanceof ResizableCompartmentEditPart) {
+ // ((ResizableCompartmentEditPart)currentEditPart).getFigure().setBorder(null);
+ // }
+ // }
+ //
} else {
@@ -143,14 +175,33 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC
}
defaultBorder = null;
- for(Object currentEditPart : getHost().getChildren()) {
- if(currentEditPart instanceof ResizableCompartmentEditPart) {
- ((ResizableCompartmentEditPart)currentEditPart).getFigure().setBorder(new OneLineBorder());
- }
+ //TODO: This edit policy should be installed on all compartments. We shouldn't need to refresh them from here
+ // for(Object currentEditPart : getHost().getChildren()) {
+ // if(currentEditPart instanceof ResizableCompartmentEditPart) {
+ // ((ResizableCompartmentEditPart)currentEditPart).getFigure().setBorder(new OneLineBorder());
+ // }
+ // }
+ //
+
+ }
+ }
+
+
+ private BooleanValueStyle findDisplayBorderStyle(View view) {
+ View parentView = view;
+ while(parentView.getElement() == view.getElement()) {
+ BooleanValueStyle style = (BooleanValueStyle)parentView.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), DISPLAY_BORDER);
+ if(style != null) {
+ return style;
}
+ if(parentView.eContainer() instanceof View) {
+ parentView = (View)parentView.eContainer();
+ }
}
+
+ return null;
}
}

Back to the top