Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaged Elaasar2018-05-09 14:21:19 +0000
committerBenoit Maggi2018-06-20 08:50:30 +0000
commitd64f2d709ce5d0eebc1fb520eafae6406b45ace8 (patch)
tree8218e70d79fabb57c958d9af1b27af26a2fd26cc
parenta634e9d9dcf04bd336e70fc588e0492ef04c036a (diff)
downloadorg.eclipse.papyrus-d64f2d709ce5d0eebc1fb520eafae6406b45ace8.tar.gz
org.eclipse.papyrus-d64f2d709ce5d0eebc1fb520eafae6406b45ace8.tar.xz
org.eclipse.papyrus-d64f2d709ce5d0eebc1fb520eafae6406b45ace8.zip
Bug 528441 - [AFViewpoints][Palettes] Setting diagram prototype
programmatically does not refresh palettes of open diagrams - Handle the listener case of no PapyrusDiagramStyle initially found on the diagram Change-Id: I32d93478bbf5a4fd10faad615afb5189e85dfc2b 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/service/palette/PapyrusPaletteService.java74
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/UmlGmfDiagramEditor.java44
2 files changed, 48 insertions, 70 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/PapyrusPaletteService.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/PapyrusPaletteService.java
index 209b55f8b5c..e7a3a0a4a15 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/PapyrusPaletteService.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/PapyrusPaletteService.java
@@ -227,17 +227,7 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
if (!(part instanceof DiagramEditorWithFlyOutPalette)) {
return false;
}
- boolean supports = getProviderConfiguration().supports(o.getEditor(), o.getContent());
-
- if (!supports) {
- return false;
- }
-
- if (isHidden(o)) {
- return false;
- }
-
- return true;
+ return getProviderConfiguration().supports(o.getEditor(), o.getContent()) && !isHidden(o);
}
return false;
@@ -264,23 +254,8 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
return policy.provides(operation);
}
- // FIXME: that statement is always true (let's see the method's
- // parameter).
- // => Remove the test
- if (operation instanceof ContributeToPaletteOperation) {
- ContributeToPaletteOperation o = operation;
- // FIXME returns directly the result
- boolean supports = getProviderConfiguration().supports(o.getEditor(), o.getContent());
-
- if (!supports) {
- return false;
- }
-
- return true;
- }
-
- return false;
+ return getProviderConfiguration().supports(operation.getEditor(), operation.getContent());
}
/**
@@ -466,7 +441,6 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
filePath = filePath.substring(jarPathEndIndex + 2, path.length());
ZipEntry entry = zipFile.getEntry(path);
return zipFile.getInputStream(entry);
- // return new File(filePath);
}
}
} catch (IOException e) {
@@ -502,8 +476,7 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
Activator.log.error("Impossible to read local definition of the file " + stateLocationRootFile, null);
return null;
}
- URI uri = URI.createFileURI(stateLocationRootFile.getAbsolutePath());
- return uri;
+ return URI.createFileURI(stateLocationRootFile.getAbsolutePath());
}
}
@@ -638,29 +611,21 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
if (!isEnable) {
return false;
}
- // FIXME: that statement is always true (let's see the method's
- // parameter).
- // => Remove the test
- if (operation instanceof ContributeToPaletteOperation) {
- ContributeToPaletteOperation o = operation;
- IEditorPart part = o.getEditor();
- if (!(part instanceof DiagramEditorWithFlyOutPalette)) {
- return false;
- }
+ IEditorPart part = operation.getEditor();
+ if (!(part instanceof DiagramEditorWithFlyOutPalette)) {
+ return false;
+ }
- // will never work, ID of the site is the multi diagram
- // editor...
- if (description.getContributionEditorID() != null) {
- if (!description.getContributionEditorID().equals(((DiagramEditorWithFlyOutPalette) part).getContributorId())) {
- return false;
- }
+ // will never work, ID of the site is the multi diagram
+ // editor...
+ if (description.getContributionEditorID() != null) {
+ if (!description.getContributionEditorID().equals(((DiagramEditorWithFlyOutPalette) part).getContributorId())) {
+ return false;
}
-
- return true;
}
- return false;
+ return true;
}
}
@@ -944,9 +909,20 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
configurePaletteVisibility(checker, diagram, drawer);
}
}
+
+ // if the default entry is set but not visible, set it to null instead to avoid a potential NPE
+ if (root.getDefaultEntry() != null && !isVisible(root.getDefaultEntry())) {
+ root.setDefaultEntry(null);
+ }
+
return root;
}
+ private boolean isVisible(PaletteEntry entry) {
+ PaletteContainer parent = entry.getParent();
+ return entry.isVisible() && (parent == null || isVisible(parent));
+ }
+
protected void configurePaletteVisibility(PolicyChecker checker, Diagram diagram, PaletteContainer container) {
boolean isVisible = checker.isInPalette(diagram, container.getId());
container.setVisible(isVisible);
@@ -1047,7 +1023,7 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
// 2. inits the operation used to check if the provider really provides
// to this service
// 3. inits the list of ids of hidden palettes
- List<PapyrusPaletteService.ProviderDescriptor> descriptors = new ArrayList<PapyrusPaletteService.ProviderDescriptor>();
+ List<PapyrusPaletteService.ProviderDescriptor> descriptors = new ArrayList<>();
final ContributeToPaletteOperation o = new ContributeToPaletteOperation(part, part.getEditorInput(), root, new HashMap());
// For each provider, checks it contributes to the palette of this
// editor part
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 ada965339ba..d1cfd0b9756 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
@@ -20,7 +20,6 @@ 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.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.papyrus.infra.core.services.ServiceException;
@@ -29,6 +28,7 @@ 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.gmfdiag.style.StylePackage;
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;
@@ -103,20 +103,31 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
viewerInitialized = false;
// add a listener to the diagram kind id
- PapyrusDiagramStyle style = DiagramUtils.getPapyrusDiagramStyle(diagram);
diagramKindAdapter = new AdapterImpl() {
-
@Override
public void notifyChanged(Notification msg) {
- //reload the editor's two viewers
- getEditDomain().setPaletteRoot(createPaletteRoot(null));
- DiagramEditPart diagramEditPart = (DiagramEditPart) UmlGmfDiagramEditor.this.getAdapter(DiagramEditPart.class);
- if(diagramEditPart!= null) {
- getGraphicalViewer().setContents(diagramEditPart);
+ if (msg.getNewValue() instanceof PapyrusDiagramStyle) {
+ ((PapyrusDiagramStyle)msg.getNewValue()).eAdapters().add(diagramKindAdapter);
+ } else if (msg.getOldValue() instanceof PapyrusDiagramStyle) {
+ ((PapyrusDiagramStyle)msg.getOldValue()).eAdapters().remove(diagramKindAdapter);
+ }
+ if (StylePackage.Literals.PAPYRUS_DIAGRAM_STYLE__DIAGRAM_KIND_ID.equals(msg.getFeature()) ||
+ msg.getNewValue() instanceof PapyrusDiagramStyle ||
+ msg.getOldValue() instanceof PapyrusDiagramStyle ) {
+ //reload the editor's two viewers
+ if (getEditDomain().getPaletteViewer() != null) {
+ getEditDomain().setPaletteRoot(createPaletteRoot(null));
+ }
+ if (getGraphicalViewer() != null) {
+ getGraphicalViewer().setContents(diagram);
+ }
+
}
}
-
};
+
+ diagram.eAdapters().add(diagramKindAdapter);
+ PapyrusDiagramStyle style = DiagramUtils.getPapyrusDiagramStyle(diagram);
if(style!=null) {
style.eAdapters().add(diagramKindAdapter);
}
@@ -148,9 +159,6 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
super.initializeGraphicalViewer();
}
- /**
- * @generated
- */
@Override
protected void initializeGraphicalViewer() {
// do nothing to enable a lazy initialization.
@@ -183,6 +191,7 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
if(style!=null) {
style.eAdapters().remove(diagramKindAdapter);
}
+ getDiagram().eAdapters().remove(diagramKindAdapter);
diagramKindAdapter = null;
}
@@ -226,11 +235,6 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
return super.getAdapter(type);
}
- @Override
- protected void stopListening() {
- super.stopListening();
- }
-
/**
*
* @return the backbone service registry. it cannot return null.
@@ -263,9 +267,7 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
*/
@Override
protected KeyHandler getKeyHandler() {
- // we remove all keybinding provided by GMF
- KeyHandler keyHandler = new KeyHandler();
- return keyHandler;
+ return new KeyHandler();// we remove all keybinding provided by GMF
}
/**
@@ -343,7 +345,7 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor implemen
@Override
public void createPartControl(Composite parent) {
- IContextService contextService = (IContextService) getSite().getService(IContextService.class);
+ IContextService contextService = getSite().getService(IContextService.class);
// FIXME : before Eclipse Juno, this line was not necessary
// see bug 367816 and bug 382218
contextService.activateContext("org.eclipse.gmf.runtime.diagram.ui.diagramContext"); //$NON-NLS-1$

Back to the top