Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaged Elaasar2018-04-17 11:00:36 +0000
committerPatrick Tessier2018-05-04 09:39:21 +0000
commit4459589b1b8c10ff365482233900b175d792aa78 (patch)
tree816e700006e02f11299871fb9dfc46d450347060
parent7b41679a6519d9f1726426766b3e43f7ecad57e2 (diff)
downloadorg.eclipse.papyrus-4459589b1b8c10ff365482233900b175d792aa78.tar.gz
org.eclipse.papyrus-4459589b1b8c10ff365482233900b175d792aa78.tar.xz
org.eclipse.papyrus-4459589b1b8c10ff365482233900b175d792aa78.zip
Bug 528441 [AFViewpoints][Palettes] Setting diagram prototype
programmatically does not refresh palettes of open diagrams - Added a listener in the diagram editor to the diagram's representationkind changes to refresh the editor. - The DiagramUtils.setPrototype() API now checks that the new prototype applies to the type of diagram, and throws an exception otherwise Change-Id: I9b4d34a7e051aaec77170c061f4ac932a04b14ba Signed-off-by: Maged Elaasar <melaasar@gmail.com>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java17
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/UmlGmfDiagramEditor.java30
2 files changed, 39 insertions, 8 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
index f918e830dbc..8a26c8cdb2d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
@@ -252,13 +252,16 @@ public class DiagramUtils {
* The new diagram's prototype
*/
public static void setPrototype(Diagram diagram, DiagramPrototype prototype) {
- PapyrusDiagramStyle pvs = getPapyrusDiagramStyle(diagram);
- if (pvs != null) {
- pvs.setDiagramKindId(prototype.getRepresentationKind().getId());
- } else {
- pvs = (PapyrusDiagramStyle) diagram.createStyle(StylePackage.Literals.PAPYRUS_DIAGRAM_STYLE);
- pvs.setDiagramKindId(prototype.getRepresentationKind().getId());
- }
+ if (diagram.getType() == null || diagram.getType().equals(prototype.getRepresentationKind().getImplementationID())) {
+ PapyrusDiagramStyle pvs = getPapyrusDiagramStyle(diagram);
+ if (pvs != null) {
+ pvs.setDiagramKindId(prototype.getRepresentationKind().getId());
+ } else {
+ pvs = (PapyrusDiagramStyle) diagram.createStyle(StylePackage.Literals.PAPYRUS_DIAGRAM_STYLE);
+ pvs.setDiagramKindId(prototype.getRepresentationKind().getId());
+ }
+ } else
+ throw new IllegalArgumentException("The diagram's type differs from the prototype's implementation id");
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/UmlGmfDiagramEditor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/UmlGmfDiagramEditor.java
index 0e7f08d6626..44ab3acf8c9 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/UmlGmfDiagramEditor.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/UmlGmfDiagramEditor.java
@@ -18,6 +18,7 @@ import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.gef.KeyHandler;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.NotationPackage;
@@ -25,6 +26,8 @@ import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.gmfdiag.common.SynchronizableGmfDiagramEditor;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.gmfdiag.style.PapyrusDiagramStyle;
import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage;
import org.eclipse.papyrus.infra.internationalization.common.editor.IInternationalizationEditor;
import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization;
@@ -66,6 +69,11 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
* of Papyrus editor.
*/
protected boolean viewerInitialized = false;
+
+ /**
+ * Listener to to the diagram kind
+ */
+ protected Adapter diagramKindAdapter;
/**
* Constructor.
@@ -91,6 +99,19 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
ISaveAndDirtyService saveAndDirtyService = servicesRegistry.getService(ISaveAndDirtyService.class);
saveAndDirtyService.registerIsaveablePart(this);
viewerInitialized = false;
+
+ // add a listener to the diagram kind id
+ PapyrusDiagramStyle style = DiagramUtils.getPapyrusDiagramStyle(diagram);
+ style.eAdapters().add(diagramKindAdapter = new AdapterImpl() {
+
+ @Override
+ public void notifyChanged(Notification msg) {
+ //reload the editor's two viewers
+ getEditDomain().setPaletteRoot(createPaletteRoot(null));
+ getGraphicalViewer().setContents(getDiagram());
+ }
+
+ });
}
/**
@@ -148,6 +169,13 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
*/
@Override
public void dispose() {
+ // remove the listener to the diagram kind id
+ if (diagramKindAdapter != null) {
+ PapyrusDiagramStyle style = DiagramUtils.getPapyrusDiagramStyle(getDiagram());
+ style.eAdapters().remove(diagramKindAdapter);
+ diagramKindAdapter = null;
+ }
+
this.setUndoContext(new IUndoContext() {
@Override
@@ -174,7 +202,7 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
// the service can't be found. Maybe it is already disposed.
// Do nothing
}
-
+
partNameSynchronizer = null;
diagram = null;
servicesRegistry = null;

Back to the top