Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe ROLAND2014-03-14 11:16:43 -0400
committerPhilippe ROLAND2014-03-14 11:16:43 -0400
commit6f70c04962bc001ae9a61ccf39665168ba3626cf (patch)
tree6e0ee714eb1298e29bc1382dda2a9b6efd1c7537 /plugins/infra/gmfdiag
parentc05175d4aee887c85fa8c32daa7b991123f274a9 (diff)
parent9f626161fd840f0cdbbd96a0bbba8454f140d8a3 (diff)
downloadorg.eclipse.papyrus-6f70c04962bc001ae9a61ccf39665168ba3626cf.tar.gz
org.eclipse.papyrus-6f70c04962bc001ae9a61ccf39665168ba3626cf.tar.xz
org.eclipse.papyrus-6f70c04962bc001ae9a61ccf39665168ba3626cf.zip
Merge branch 'master' of ssh://git.eclipse.org/gitroot/papyrus/org.eclipse.papyrus
Diffstat (limited to 'plugins/infra/gmfdiag')
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSDiagramImpl.java27
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/ICreationCommand.java74
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml95
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java793
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java3
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/DynamicDiagramsMenuContribution.java101
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramEditHelper.java178
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramPrototype.java120
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java165
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java15
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java482
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationLabelProvider.java34
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java124
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.controlmode/src/org/eclipse/papyrus/infra/gmfdiag/controlmode/ControlDiagramsCommand.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/plugin.xml29
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java3
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramIcon.java5
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java3
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/CreateDiagramWithNavigationHandler.java173
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/notation.ctx110
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java88
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/provider/ModelContentProvider.java78
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/util/LegacyOwnerObservable.java158
29 files changed, 1908 insertions, 967 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
index c8f2154ede7..385a581b8bf 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
@@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
org.eclipse.gmf.runtime.notation.edit;bundle-version="1.7.0",
org.w3c.dom.svg;bundle-version="1.1.0"
Export-Package: org.eclipse.papyrus.infra.gmfdiag.css,
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSDiagramImpl.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSDiagramImpl.java
index 28183752898..62f2a628285 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSDiagramImpl.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSDiagramImpl.java
@@ -28,6 +28,11 @@ import org.eclipse.papyrus.infra.gmfdiag.css.engine.DiagramCSSEngine;
import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
import org.eclipse.papyrus.infra.gmfdiag.css.resource.CSSNotationResource;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
/**
* Default implementation for CSSDiagram
@@ -84,9 +89,31 @@ public class CSSDiagramImpl extends DiagramImpl implements CSSDiagram {
}
}
+ StyleSheet s = getViewpointDefinedStylesheet();
+ if (s != null)
+ result.add(s);
+
return result;
}
+ private StyleSheet getViewpointDefinedStylesheet() {
+ ViewPrototype proto = ViewPrototype.get(this);
+ if (proto == null) {
+ return null;
+ }
+ PapyrusView conf = proto.getConfiguration();
+ if (conf == null || !(conf instanceof PapyrusDiagram)) {
+ return null;
+ }
+ String path = ((PapyrusDiagram) conf).getCustomStyle();
+ if (path == null || path.isEmpty()) {
+ return null;
+ }
+ StyleSheetReference ref = StylesheetsFactory.eINSTANCE.createStyleSheetReference();
+ ref.setPath(path);
+ return ref;
+ }
+
private class DiagramDisposeListener extends AdapterImpl {
@Override
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF
index 8870a72c112..493e7348a61 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF
@@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.ui.workbench,
org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
org.eclipse.core.expressions;bundle-version="3.4.500",
org.eclipse.gmf.runtime.diagram.ui.resources.editor
Bundle-Vendor: %providerName
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/ICreationCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/ICreationCommand.java
index cf4e726d3f5..532f4ebe38b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/ICreationCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/ICreationCommand.java
@@ -12,7 +12,10 @@ package org.eclipse.papyrus.commands;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
/**
* Define a command use to create new diagram. It use to provide Eclipse
@@ -24,33 +27,66 @@ import org.eclipse.papyrus.infra.core.resource.ModelSet;
public interface ICreationCommand {
/**
- * Create a new diagram in diResourceSet with the given name and open it.
+ * Create a diagram.
+ * This method will try to find an adequate view for the passed arguments
*
* @param modelSet
- * the resourceSet containing all diagrams
- * @param container
- * of the diagram, if container is null, the diagram is contained
- * by the top level container
- * @param diagramName
- * the name of the new diagram or null to use a dialog to choose
- * the name
+ * the current model set
+ * @param owner
+ * the diagram's owner and root element
+ * @param name
+ * the diagram's name
+ * @return the created diagram, or <code>null</code> if the creation failed
*/
- public void createDiagram(ModelSet modelSet, EObject container, String diagramName);
+ public Diagram createDiagram(ModelSet modelSet, EObject owner, String name);
/**
- * Get a command to create a new diagram in diResourceSet with the given
- * name.
+ * Create a diagram.
*
* @param modelSet
- * the resourceSet containing all diagrams
- * @param container
- * of the diagram, if container is null, the diagram is contained
- * by the top level container
- * @param diagramName
- * the name of the new diagram or null to use a dialog to choose
- * the name
+ * the current model set
+ * @param owner
+ * the diagram's owner
+ * @param element
+ * the diagram's model element
+ * @param prototype
+ * the diagram's prototype
+ * @param name
+ * the diagram's name
+ * @return the created diagram, or <code>null</code> if the creation failed
*/
- public ICommand getCreateDiagramCommand(final ModelSet modelSet, final EObject container, final String diagramName);
+ public Diagram createDiagram(ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name);
+
+ /**
+ * Gets the GMF command for the diagram creation
+ * This method will try to find an adequate view for the passed arguments
+ *
+ * @param modelSet
+ * the current model set
+ * @param owner
+ * the diagram's owner and root element
+ * @param name
+ * the diagram's name
+ * @return the created diagram, or <code>null</code> if the creation failed
+ */
+ public ICommand getCreateDiagramCommand(ModelSet modelSet, EObject owner, String name);
+
+ /**
+ * Gets the GMF command for the diagram creation
+ *
+ * @param modelSet
+ * the current model set
+ * @param owner
+ * the diagram's owner
+ * @param element
+ * the diagram's model element
+ * @param prototype
+ * the diagram's prototype
+ * @param name
+ * the diagram's name
+ * @return the created diagram, or <code>null</code> if the creation failed
+ */
+ public ICommand getCreateDiagramCommand(ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name);
/**
* Get the type of the diagram to create.
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
index 2df85a9ff59..5d782327186 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
@@ -55,6 +55,8 @@ Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.5.0",
org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="0.4.0",
org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.0",
org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
org.eclipse.papyrus.uml.tools
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
index 2d220dd6389..9ed75968eea 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -7,8 +7,8 @@
<extension-point id="shapeProvider" name="ShapeProvider" schema="schema/shapeProvider.exsd"/>
<extension-point id="notationTypesMapping" name="notationTypesMapping" schema="schema/notationTypesMapping.exsd"/>
<extension-point id="svgPostProcessors" name="svgPostProcessors" schema="schema/svgPostProcessors.exsd"/>
- <extension-point id="pasteCommandProvider" name="pasteCommandProvider" schema="schema/pasteCommandProvider.exsd"/>
-
+ <extension-point id="pasteCommandProvider" name="pasteCommandProvider" schema="schema/pasteCommandProvider.exsd"/>
+
<extension
point="org.eclipse.ui.handlers">
<handler
@@ -148,6 +148,27 @@
</binding>
</extension>
<extension
+ point="org.eclipse.gmf.runtime.emf.type.core.elementTypes">
+ <metamodel
+ nsURI="http://www.eclipse.org/gmf/runtime/1.0.2/notation">
+ <metamodelType
+ eclass="Diagram"
+ edithelper="org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramEditHelper"
+ id="org.eclipse.papyrus.infra.gmfdiag.common.DiagramElementType"
+ name="Diagram">
+ </metamodelType>
+ </metamodel>
+</extension>
+<extension
+ point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings">
+ <binding
+ context="org.eclipse.papyrus.infra.services.edit.TypeContext">
+ <elementType
+ ref="org.eclipse.papyrus.infra.gmfdiag.common.DiagramElementType">
+ </elementType>
+ </binding>
+</extension>
+<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramPropertyTester"
@@ -163,6 +184,76 @@
properties="isGmfDiagramContextActive"
type="java.util.Collection">
</propertyTester>
+</extension>
+<extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.popupmenu.creatediagram">
+ <dynamic
+ class="org.eclipse.papyrus.infra.gmfdiag.common.handler.DynamicDiagramsMenuContribution"
+ id="org.eclipse.papyrus.infra.gmfdiag.common.handler.DynamicDiagramsMenuContribution">
+ </dynamic>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="menu:org.eclipse.papyrus.ui.menu">
+ <menu
+ icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewDiagram.gif"
+ id="org.eclipse.papyrus.uml.diagram.ui.menu.diagrams"
+ label="New Diagram">
+ <dynamic
+ class="org.eclipse.papyrus.infra.gmfdiag.common.handler.DynamicDiagramsMenuContribution"
+ id="org.eclipse.papyrus.infra.gmfdiag.common.handler.DynamicDiagramsMenuContribution">
+ </dynamic>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.eclipse.ui.main.toolbar">
+ <toolbar
+ id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar">
+ <command
+ commandId="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.diagrams.command"
+ icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewDiagram.gif"
+ id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.diagrams"
+ label="Create a new diagram ..."
+ style="pulldown"
+ tooltip="Create a new diagram ...">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ </command>
+ </toolbar>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="menu:org.eclipse.papyrus.infra.viewpoints.policy.toolbar.diagrams">
+ <dynamic
+ class="org.eclipse.papyrus.infra.gmfdiag.common.handler.DynamicDiagramsMenuContribution"
+ id="org.eclipse.papyrus.infra.gmfdiag.common.handler.DynamicDiagramsMenuContribution">
+ </dynamic>
+ </menuContribution>
+</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.infra.viewpoints.policy.commands"
+ defaultHandler="org.eclipse.papyrus.infra.viewpoints.policy.DynamicCommandHandler"
+ id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.diagrams.command"
+ name="Create Dynamic Diagram Command">
+ </command>
+</extension>
+<extension
+ point="org.eclipse.papyrus.infra.viewpoints.policy.viewType">
+ <helper
+ class="org.eclipse.papyrus.infra.gmfdiag.common.helper.GMFDiagramViewTypeHelper">
+ </helper>
</extension>
<extension
point="org.eclipse.papyrus.infra.gmfdiag.common.shapeProvider">
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
index 103b1eb5ee7..6ebafce763c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
@@ -1,382 +1,411 @@
-/*****************************************************************************
- * Copyright (c) 2008, 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- * Christian W. Damus (CEA) - only calculate affected files for workspace resources (CDO)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.commands.ICreationCommand;
-import org.eclipse.papyrus.commands.OpenDiagramCommand;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
-import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
-import org.eclipse.papyrus.uml.tools.model.UmlUtils;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Command creating a new GMF diagram in Papyrus. This command is intended to be used in eclipse
- * extensions.
- *
- * Commands to create a GMF Diagram can subclass this class. There is two kinds of commands: -
- * Eclipse handlers issuing commands (toolbar, menu, ...). This commands can find the active editor
- * by using the Worbench.getActivePArt(). The entry point is {@link #execute(ExecutionEvent)}. -
- * Commands called during editor initializing (like wizard). This commands require the diResourceSet
- * to work. The entry point is {@link #createDiagram(DiResourceSet, EObject, String)}
- *
- * @author cedric dumoulin
- * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
- */
-public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends AbstractHandler implements IHandler, ICreationCommand {
-
- /**
- * Method called when the command is invoked.
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- ServicesRegistry registry;
- try {
- registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
- } catch (ServiceException ex) {
- throw new ExecutionException("Cannot retrieve the ServicesRegistry", ex);
- }
-
- EObject container = null;
- // if editor is open and active
- container = getSelectedElement();
- runAsTransaction(container, registry);
- return null;
- }
-
- /**
- * Create a new class diagram
- *
- * @param sharedObjects
- * @param container
- * The uml element to which the diagram should be attached, if possible.
- * @throws ExecutionException
- */
- protected void runAsTransaction(EObject container, ServicesRegistry registry) throws ExecutionException {
-
- ModelSet modelSet;
- try {
- modelSet = registry.getService(ModelSet.class);
- } catch (ServiceException e) {
- throw new ExecutionException("Can't get ModelSet", e);
- }
-
- runAsTransaction(modelSet, container, null);
- }
-
- /**
- * Create a new gmf diagram
- *
- * @param sharedObjects
- * @param container
- * The eObject to which the diagram should be attached, if possible.
- */
- protected void runAsTransaction(final ModelSet modelSet, final EObject container, String name) {
- TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain();
- CompositeCommand cmd = new CompositeCommand("Create diagram");
- ICommand createCmd = getCreateDiagramCommand(modelSet, container, name);
- cmd.add(createCmd);
- cmd.add(new OpenDiagramCommand(dom, createCmd));
-
- dom.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
- }
-
- /**
- * Get the root element associated with canvas.
- */
- protected EObject getRootElement(Resource modelResource) {
- EObject rootElement = null;
- if(modelResource != null && modelResource.getContents() != null && modelResource.getContents().size() > 0) {
- Object root = modelResource.getContents().get(0);
- if(root instanceof EObject) {
- rootElement = (EObject)root;
- }
- }
-
- return rootElement;
- }
-
- /**
- * Store model element in the resource.
- */
- protected void attachModelToResource(EObject root, Resource resource) {
- resource.getContents().add(root);
- }
-
- /**
- * Get the type of the diagram to create.
- *
- * @return diagram type
- */
- public String getCreatedDiagramType() {
- return getDiagramNotationID();
- }
-
- /**
- * @return
- */
- abstract protected String getDiagramNotationID();
-
- /**
- * @return
- */
- abstract protected PreferencesHint getPreferenceHint();
-
- /**
- * Get the name used for diagram.
- *
- * @return
- */
- abstract protected String getDefaultDiagramName();
-
- /**
- * Get currently selected element.
- *
- * @return The currently selected element, or null if any.
- */
- protected EObject getSelectedElement() {
- EObject eObject = null;
- Object selection = getCurrentSelection();
- if(selection != null) {
- eObject = EMFHelper.getEObject(selection);
- }
- return eObject;
- }
-
- /**
- * Get current selection first element.
- *
- * @return the selected element or null.
- */
- private Object getCurrentSelection() {
- ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- return structuredSelection.getFirstElement();
- }
-
- return null;
- }
-
- /**
- * Create a diagram.
- *
- * @param diagramResource
- * the diagram resource
- * @param owner
- * the diagram container
- * @param name
- * the diagram name
- * @return
- */
- protected Diagram createDiagram(Resource diagramResource, EObject owner, String name) {
- // create diagram
- Diagram diagram = ViewService.createDiagram(owner, getDiagramNotationID(), getPreferenceHint());
- if(diagram != null) {
- diagram.setName(name);
- diagram.setElement(owner);
- initializeDiagram(diagram);
- diagramResource.getContents().add(diagram);
- }
- return diagram;
- }
-
- protected void initializeDiagram(EObject diagram) {
- };
-
- /**
- * Get the current MultiDiagramEditor.
- *
- * @return
- */
- protected IMultiDiagramEditor getMultiDiagramEditor() {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editorPart = page.getActiveEditor();
- return (IMultiDiagramEditor)editorPart;
- }
-
- /**
- * Open popup to enter the new diagram name
- *
- * @param defaultValue
- * the default value
- * @return the entered diagram name
- */
- protected String openDiagramNameDialog(String defaultValue) {
- if(defaultValue == null) {
- defaultValue = "";
- }
-
- InputDialog inputDialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_SelectNewDiagramName, Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_NewDiagramName, defaultValue, null);
- int result = inputDialog.open();
-
- if(result == Window.OK) {
- String name = inputDialog.getValue();
- if(name == null || name.length() == 0) {
- name = defaultValue;
- }
- return name;
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void createDiagram(final ModelSet modelSet, final EObject container, final String diagramName) {
- runAsTransaction(modelSet, container, diagramName);
- }
-
- /**
- * {@inheritDoc}
- */
- public ICommand getCreateDiagramCommand(final ModelSet modelSet, final EObject container, final String diagramName) {
- //Diagram creation should not change the semantic resource
- final Resource modelResource = UmlUtils.getUmlResource(modelSet);
- final Resource notationResource = NotationUtils.getNotationResource(modelSet);
- final Resource diResource = DiModelUtils.getDiResource(modelSet);
-
- ArrayList<IFile> modifiedFiles = new ArrayList<IFile>();
- if (notationResource.getURI().isPlatformResource()) {
- modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(notationResource.getURI().toPlatformString(true))));
- }
- if (diResource.getURI().isPlatformResource()) {
- modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(diResource.getURI().toPlatformString(true))));
- }
-
- return new AbstractTransactionalCommand(modelSet.getTransactionalEditingDomain(), Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_CreateDiagramCommandLabel, modifiedFiles) {
-
- protected Diagram diagram;
-
- protected EObject modelElement;
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- String name = diagramName;
- if(name == null) {
- name = openDiagramNameDialog(getDefaultDiagramName());
- }
- // canceled
- if(name == null) {
- return CommandResult.newCancelledCommandResult();
- }
-
- EObject model = container;
- if(model == null) {
- model = getRootElement(modelResource);
- attachModelToResource(model, modelResource);
- }
-
- diagram = createDiagram(notationResource, model, name);
-
- if(diagram != null) {
- try {
- IPageManager pageManager = ServiceUtilsForResource.getInstance().getIPageManager(diResource);
- pageManager.addPage(diagram);
- return CommandResult.newOKCommandResult(diagram);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return CommandResult.newErrorCommandResult(ex);
- }
- }
- return CommandResult.newErrorCommandResult("Error during diagram creation");
- }
-
- @Override
- protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- // the undo corresponds to a destroy diagram command
- // during diagram creation no adapters are set to the diagram so the setElement is not registered
- // to remove the cross reference using the element reference it is better to use the destroy element command
- // DestroyElementPapyrusCommand depc = (diagram != null) ? new DestroyElementPapyrusCommand(new DestroyElementRequest(diagram, false)) : null;
- IStatus status = super.doUndo(monitor, info);
-
- modelElement = diagram.getElement();
- diagram.setElement(null);
- return status;
- }
-
- @Override
- protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- diagram.setElement(modelElement);
- IStatus status = super.doRedo(monitor, info);
- return status;
- }
- };
- }
-
- /**
- * Get the ISashWindowsContentProvider from the main editor.
- *
- * @return
- */
- protected ISashWindowsContentProvider getISashWindowsContentProvider(ServicesRegistry registry) {
- try {
- return registry.getService(ISashWindowsContentProvider.class);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return null;
- }
- }
-
- /**
- * Check if the creation of this diagram is strongly attached to its parent or if it can be reassigned after creation.
- *
- * @return true if parent can be reassigned
- */
- public boolean isParentReassignable() {
- // yes by default
- return true;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - only calculate affected files for workspace resources (CDO)
+ * Laurent Wouters (CEA) - laurent.wouters@cea.fr - Refactoring for viewpoints
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.commands.ICreationCommand;
+import org.eclipse.papyrus.commands.OpenDiagramCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ui.IModelElementValidator;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ui.ModelElementSelectionDialog;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Command creating a new GMF diagram in Papyrus. This command is intended to be used in eclipse
+ * extensions.
+ *
+ * Commands to create a GMF Diagram can subclass this class. There is two kinds of commands: -
+ * Eclipse handlers issuing commands (toolbar, menu, ...). This commands can find the active editor
+ * by using the Worbench.getActivePArt(). The entry point is {@link #execute(ExecutionEvent)}. -
+ * Commands called during editor initializing (like wizard). This commands require the diResourceSet
+ * to work. The entry point is {@link #createDiagram(Resource, EObject, String)}
+ *
+ * @author cedric dumoulin
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends AbstractHandler implements IHandler, ICreationCommand {
+
+ /**
+ * Inner class for the creation of diagrams
+ *
+ * @author Laurent Wouters
+ *
+ */
+ private class Creator {
+ private ModelSet modelSet;
+ private EObject owner;
+ private EObject element;
+ private ViewPrototype prototype;
+ private String name;
+
+ public Creator(ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) {
+ this.modelSet = modelSet;
+ this.owner = owner;
+ this.element = element;
+ this.prototype = prototype;
+ this.name = name;
+ }
+
+ private Diagram createDiagram() throws ServiceException {
+ Resource modelResource = UmlUtils.getUmlResource(modelSet);
+ Resource notationResource = NotationUtils.getNotationResource(modelSet);
+ Resource diResource = DiModelUtils.getDiResource(modelSet);
+
+ if (owner == null) {
+ owner = getRootElement(modelResource);
+ attachModelToResource(owner, modelResource);
+ }
+
+ if (!PolicyChecker.getCurrent().canOwnNewView(owner, prototype)) {
+ ModelElementSelectionDialog dialog = new ModelElementSelectionDialog(Display.getCurrent().getActiveShell(), getMultiDiagramEditor().getServicesRegistry(), "Select an appropriate owner for the diagram:", getRootElement(modelResource), owner,
+ new IModelElementValidator() {
+ public String isSelectable(EObject element) {
+ if (PolicyChecker.getCurrent().canOwnNewView(owner, prototype))
+ return null;
+ return "This element cannot own the diagram.";
+ }
+ });
+ int result = dialog.open();
+ if (result != Window.OK)
+ return null;
+ owner = dialog.getSelection();
+ }
+
+ element = prototype.getRootFor(owner);
+ if (!PolicyChecker.getCurrent().canHaveNewView(element, owner, prototype)) {
+ StringBuilder builder = new StringBuilder("Select a root element for the diagram. Allowed types: ");
+ if (prototype.getConfiguration() == null) {
+ builder.append("<unknown>");
+ } else if (prototype.getConfiguration().getModelRules().size() == 0) {
+ builder.append("<unknown>");
+ } else {
+ boolean first = true;
+ for (ModelRule rule : prototype.getConfiguration().getModelRules()) {
+ EClass model = rule.getElement();
+ if (model != null) {
+ if (!first) {
+ builder.append(", ");
+ }
+ first = false;
+ builder.append(model.getName());
+ }
+ }
+ }
+ builder.append(".");
+ ModelElementSelectionDialog dialog = new ModelElementSelectionDialog(Display.getCurrent().getActiveShell(), getMultiDiagramEditor().getServicesRegistry(), builder.toString(), getRootElement(modelResource), element,
+ new IModelElementValidator() {
+ public String isSelectable(EObject element) {
+ if (PolicyChecker.getCurrent().canHaveNewView(element, owner, prototype))
+ return null;
+ return "This element cannot be the root element of the diagram.";
+ }
+ });
+ int result = dialog.open();
+ if (result != Window.OK)
+ return null;
+ element = dialog.getSelection();
+ }
+
+ if (name == null) {
+ name = openDiagramNameDialog(prototype.isNatural() ? getDefaultDiagramName() : "New" + prototype.getLabel().replace(" ", ""));
+ }
+ // canceled
+ if (name == null) {
+ return null;
+ }
+
+ Diagram diagram = doCreateDiagram(notationResource, owner, element, prototype, name);
+
+ if (diagram != null) {
+ IPageManager pageManager = ServiceUtilsForResource.getInstance().getIPageManager(diResource);
+ pageManager.addPage(diagram);
+
+ }
+ return diagram;
+ }
+ }
+
+
+ /**
+ * Get the root element associated with canvas.
+ */
+ private EObject getRootElement(Resource modelResource) {
+ EObject rootElement = null;
+ if (modelResource != null && modelResource.getContents() != null && modelResource.getContents().size() > 0) {
+ Object root = modelResource.getContents().get(0);
+ if (root instanceof EObject) {
+ rootElement = (EObject) root;
+ }
+ }
+
+ return rootElement;
+ }
+
+ /**
+ * Store model element in the resource.
+ */
+ private void attachModelToResource(EObject root, Resource resource) {
+ resource.getContents().add(root);
+ }
+
+ /**
+ * Get the current MultiDiagramEditor.
+ */
+ private IMultiDiagramEditor getMultiDiagramEditor() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editorPart = page.getActiveEditor();
+ return (IMultiDiagramEditor) editorPart;
+ }
+
+ /**
+ * Open popup to enter the new diagram name
+ *
+ * @param defaultValue
+ * the default value
+ * @return the entered diagram name
+ */
+ private String openDiagramNameDialog(String defaultValue) {
+ if (defaultValue == null) {
+ defaultValue = "";
+ }
+
+ InputDialog inputDialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_SelectNewDiagramName, Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_NewDiagramName, defaultValue, null);
+ int result = inputDialog.open();
+
+ if (result == Window.OK) {
+ String name = inputDialog.getValue();
+ if (name == null || name.length() == 0) {
+ name = defaultValue;
+ }
+ return name;
+ }
+ return null;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.commands.ICreationCommand#createDiagram(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.EObject, java.lang.String)
+ */
+ public final Diagram createDiagram(ModelSet modelSet, EObject owner, String name) {
+ ViewPrototype proto = ViewPrototype.get(getCreatedDiagramType(), owner, owner);
+ if (proto == null)
+ return null;
+ return createDiagram(modelSet, owner, owner, proto, name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.commands.ICreationCommand#createDiagram(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype, java.lang.String)
+ */
+ public final Diagram createDiagram(ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) {
+ ICommand createCmd = getCreateDiagramCommand(modelSet, owner, element, prototype, name);
+ TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain();
+ CompositeCommand cmd = new CompositeCommand("Create diagram");
+ cmd.add(createCmd);
+ cmd.add(new OpenDiagramCommand(dom, createCmd));
+ dom.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.commands.ICreationCommand#getCreateDiagramCommand(org.eclipse.papyrus.infra.core.resource.ModelSet, org.eclipse.emf.ecore.EObject, java.lang.String)
+ */
+ public final ICommand getCreateDiagramCommand(ModelSet modelSet, EObject owner, String name) {
+ ViewPrototype proto = ViewPrototype.get(getCreatedDiagramType(), owner, owner);
+ if (proto == null)
+ return null;
+ return getCreateDiagramCommand(modelSet, owner, owner, proto, name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.commands.ICreationCommand#getCreateDiagramCommand(org.eclipse.papyrus.infra.core.resource.ModelSet, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype,
+ * java.lang.String)
+ */
+ public final ICommand getCreateDiagramCommand(final ModelSet modelSet, final EObject owner, final EObject element, final ViewPrototype prototype, final String name) {
+ // Diagram creation should not change the semantic resource
+ final Resource notationResource = NotationUtils.getNotationResource(modelSet);
+ final Resource diResource = DiModelUtils.getDiResource(modelSet);
+
+ ArrayList<IFile> modifiedFiles = new ArrayList<IFile>();
+ if (notationResource.getURI().isPlatformResource()) {
+ modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(notationResource.getURI().toPlatformString(true))));
+ }
+ if (diResource.getURI().isPlatformResource()) {
+ modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(diResource.getURI().toPlatformString(true))));
+ }
+
+ return new AbstractTransactionalCommand(modelSet.getTransactionalEditingDomain(), Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_CreateDiagramCommandLabel, modifiedFiles) {
+ private Diagram diagram = null;
+ private EObject diagramElement = null;
+ private EObject diagramOwner = null;
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Creator creator = new Creator(modelSet, owner, element, prototype, name);
+ try {
+ diagram = creator.createDiagram();
+ if (diagram == null)
+ return CommandResult.newCancelledCommandResult();
+ diagramElement = diagram.getElement();
+ diagramOwner = DiagramUtils.getOwner(diagram);
+ return CommandResult.newOKCommandResult(diagram);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return CommandResult.newErrorCommandResult("Error during diagram creation");
+ }
+
+ @Override
+ protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // the undo corresponds to a destroy diagram command
+ // during diagram creation no adapters are set to the diagram so the setElement is not registered
+ // to remove the cross reference using the element reference it is better to use the destroy element command
+ // DestroyElementPapyrusCommand depc = (diagram != null) ? new DestroyElementPapyrusCommand(new DestroyElementRequest(diagram, false)) : null;
+ IStatus status = super.doUndo(monitor, info);
+ diagram.setElement(null);
+ return status;
+ }
+
+ @Override
+ protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ diagram.setElement(diagramElement);
+ DiagramUtils.setOwner(diagram, diagramOwner);
+ IStatus status = super.doRedo(monitor, info);
+ return status;
+ }
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.commands.ICreationCommand#getCreatedDiagramType()
+ */
+ public String getCreatedDiagramType() {
+ return getDiagramNotationID();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.commands.ICreationCommand#isParentReassignable()
+ */
+ public boolean isParentReassignable() {
+ // yes by default
+ return true;
+ }
+
+
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // This method should not be called, use the execute(ExecutionEvent, ViewPrototype, String) method.
+ throw new UnsupportedOperationException();
+ }
+
+
+ protected abstract String getDiagramNotationID();
+
+ protected abstract PreferencesHint getPreferenceHint();
+
+ protected abstract String getDefaultDiagramName();
+
+ /**
+ * Overridable method that effectively create the diagram with the given validated parameters
+ *
+ * @param diagramResource
+ * the diagram resource
+ * @param owner
+ * the diagram's owner
+ * @param element
+ * the diagram's model element
+ * @param prototype
+ * the diagram's prototype
+ * @param name
+ * the diagram's name
+ * @return the created diagram, or <code>null</code> if the creation failed
+ */
+ protected Diagram doCreateDiagram(Resource diagramResource, EObject owner, EObject element, ViewPrototype prototype, String name) {
+ // create diagram
+ Diagram diagram = ViewService.createDiagram(element, getDiagramNotationID(), getPreferenceHint());
+ if (diagram != null) {
+ diagram.setName(name);
+ diagram.setElement(element);
+ DiagramUtils.setOwner(diagram, owner);
+ if (!prototype.isNatural())
+ DiagramUtils.setPrototype(diagram, prototype);
+ initializeDiagram(diagram);
+ diagramResource.getContents().add(diagram);
+ }
+ return diagram;
+ }
+
+ /**
+ * Overridable method for the initialization of create diagrams
+ *
+ * @param diagram
+ * the created diagram
+ */
+ protected void initializeDiagram(EObject diagram) {
+
+ };
+}
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java
index 0ade2777252..5c7b9e57d0e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java
@@ -26,6 +26,7 @@ import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
@@ -201,7 +202,7 @@ public class GmfEditorFactory extends AbstractEditorFactory {
*
*/
public Image getTabIcon() {
- ImageDescriptor imageDescriptor = getEditorDescriptor().getIcon();
+ ImageDescriptor imageDescriptor = DiagramUtils.getPrototype(diagram).getIconDescriptor();
if(imageDescriptor == null)
return null;
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/DynamicDiagramsMenuContribution.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/DynamicDiagramsMenuContribution.java
new file mode 100755
index 00000000000..cd6e89e6823
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/DynamicDiagramsMenuContribution.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.handler;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.policy.DynamicContribution;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+
+/**
+ * Represents the dynamic contribution of a policy to menus
+ * @author Laurent Wouters
+ */
+public class DynamicDiagramsMenuContribution extends DynamicContribution {
+ /**
+ * Constructor.
+ */
+ public DynamicDiagramsMenuContribution() { }
+
+ /**
+ * Constructor.
+ * @param id
+ */
+ public DynamicDiagramsMenuContribution(String id) {
+ super(id);
+ }
+
+ /**
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ final EObject selection = getSelection();
+ if (selection == null)
+ return new IContributionItem[0];
+
+ // build a list of all the available prototypes
+ List<ViewPrototype> data = new ArrayList<ViewPrototype>();
+ for (final ViewPrototype proto : PolicyChecker.getCurrent().getPrototypesFor(selection)) {
+ if (!(proto.getConfiguration() instanceof PapyrusDiagram))
+ continue;
+ data.add(proto);
+ }
+
+ // sort them
+ Collections.sort(data, new ViewPrototype.Comp());
+
+ // build the full labels
+ List<String> labels = new ArrayList<String>(data.size());
+ String last = null;
+ boolean first = true;
+ for (ViewPrototype item : data) {
+ String label = item.getLabel();
+ if (last != null && last.equals(label)) {
+ // name collision
+ if (first) {
+ labels.set(labels.size() - 1, data.get(labels.size() - 1).getFullLabel());
+ first = false;
+ }
+ labels.add(item.getFullLabel());
+ } else {
+ labels.add(label);
+ last = label;
+ first = true;
+ }
+ }
+
+ // build the menu
+ List<IContributionItem> items = new ArrayList<IContributionItem>(data.size());
+ for (int i = 0; i != data.size(); i++) {
+ final ViewPrototype proto = data.get(i);
+ String label = labels.get(i);
+ items.add(new ActionContributionItem(new Action(CREATE_MESSAGE + label, proto.getIconDescriptor()) {
+ @Override
+ public void run() {
+ proto.instantiateOn(selection);
+ }
+ }));
+ }
+ return items.toArray(new IContributionItem[items.size()]);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramEditHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramEditHelper.java
new file mode 100755
index 00000000000..96a332820f5
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramEditHelper.java
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.viewpoints.policy.ModelAddData;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+
+/**
+ * Represents an Edit Helper for GMF Diagrams
+ * @author Laurent Wouters
+ */
+public class DiagramEditHelper implements IEditHelper {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper#canEdit(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ */
+ public boolean canEdit(IEditCommandRequest req) {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper#getEditCommand(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ */
+ public ICommand getEditCommand(final IEditCommandRequest req) {
+ if (req instanceof DestroyElementRequest) {
+ DestroyElementRequest r = (DestroyElementRequest)req;
+ return getDestroyDiagramCommand((Diagram)r.getElementToDestroy());
+ } else if (req instanceof SetRequest) {
+ SetRequest r = (SetRequest)req;
+ return GetSimpleSetCommand(r.getElementToEdit(), r.getFeature(), r.getValue());
+ } else if (req instanceof CreateElementRequest) {
+ CreateElementRequest r = (CreateElementRequest)req;
+ EObject container = r.getContainer();
+ if (container instanceof Diagram)
+ return getCreateCommand((Diagram)container, r.getContainmentFeature(), r.getElementType());
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper#getContainedValues(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EReference)
+ */
+ public List getContainedValues(EObject eContainer, EReference feature) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Gets the command for destroying the given diagram
+ * @param diagram The diagram to destroy
+ * @return The appropriate command
+ */
+ private ICommand getDestroyDiagramCommand(final Diagram diagram) {
+ final Resource resource = diagram.eResource();
+ return new AbstractCommand("Destroy diagram") {
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ resource.getContents().remove(diagram);
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ resource.getContents().remove(diagram);
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ resource.getContents().add(diagram);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ }
+
+ /**
+ * Gets the command for setting a property of a view
+ * @param object The object to modify
+ * @param feature The feature to modify
+ * @param newValue The new value for the feature
+ * @return The appropriate command
+ */
+ private ICommand GetSimpleSetCommand(final EObject object, final EStructuralFeature feature, final Object newValue) {
+ return new AbstractCommand("Edit property") {
+ private Object oldValue;
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ oldValue = object.eGet(feature);
+ object.eSet(feature, newValue);
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ object.eSet(feature, newValue);
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ object.eSet(feature, oldValue);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ }
+
+
+ /**
+ * Gets the command for the creation of an element in a diagram
+ * @param diagram The diagram to change
+ * @param reference The containment feature
+ * @param type The type of the element to be created
+ * @return The appropriate command
+ */
+ private ICommand getCreateCommand(final Diagram diagram, final EReference reference, final IElementType type) {
+ return new AbstractCommand("Create element") {
+ private EObject newElement;
+ private ModelAddData data;
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ data = PolicyChecker.getCurrent().getChildAddData(diagram, diagram.getElement().eClass(), type.getEClass());
+ if (!data.isPermitted())
+ return CommandResult.newErrorCommandResult("The current active viewpoint policy prevents the addition of this element to the view");
+ newElement = type.getEClass().getEPackage().getEFactoryInstance().create(type.getEClass());
+ if (data.isPathDefined()) {
+ if (!data.execute(diagram.getElement(), newElement))
+ return CommandResult.newErrorCommandResult("Failed to follow the path");
+ } else {
+ diagram.getElement().eSet(reference, newElement);
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ data.redoExecute();
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ data.undoExecute();
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramPrototype.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramPrototype.java
new file mode 100755
index 00000000000..e28a4eaf4ec
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramPrototype.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.commands.Activator;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+
+/**
+ * Represents a prototype of GMF diagram for the viewpoints infrastructure
+ * @author Laurent Wouters
+ */
+public class DiagramPrototype extends ViewPrototype {
+ protected final String category;
+ protected final AbstractPapyrusGmfCreateDiagramCommandHandler command;
+
+ public DiagramPrototype(PapyrusView configuration, String category, AbstractPapyrusGmfCreateDiagramCommandHandler command) {
+ super(configuration);
+ this.category = category;
+ this.command = command;
+ }
+
+ @Override
+ public boolean instantiateOn(EObject owner) {
+ return instantiateOn(owner, null);
+ }
+
+ @Override
+ public boolean instantiateOn(EObject owner, String name) {
+ ServicesRegistry registry;
+ try {
+ registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(owner);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return false;
+ }
+ ModelSet modelSet;
+ try {
+ modelSet = registry.getService(ModelSet.class);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return false;
+ }
+ Object result = command.createDiagram(modelSet, owner, owner, this, name);
+ return (result != null);
+ }
+
+ @Override
+ public boolean isOwnerReassignable() {
+ // Users can always move diagrams that are part of their viewpoint
+ return true;
+ }
+
+ @Override
+ public Command getCommandChangeOwner(EObject view, final EObject target) {
+ final Diagram diagram = (Diagram)view;
+ final EObject previous = DiagramUtils.getOwner(diagram);
+ return new AbstractCommand("Change diagram owner") {
+ @Override
+ public void execute() {
+ DiagramUtils.setOwner(diagram, target);
+ }
+ @Override
+ public void redo() {
+ DiagramUtils.setOwner(diagram, previous);
+ }
+ @Override
+ protected boolean prepare() { return true; }
+ };
+ }
+
+ @Override
+ public Command getCommandChangeRoot(EObject view, final EObject target) {
+ final Diagram diagram = (Diagram)view;
+ final EObject previous = diagram.getElement();
+ return new AbstractCommand("Change diagram root element") {
+ @Override
+ public void execute() {
+ diagram.setElement(target);
+ }
+ @Override
+ public void redo() {
+ diagram.setElement(previous);
+ }
+ @Override
+ protected boolean prepare() { return true; }
+ };
+ }
+
+ @Override
+ public EObject getOwnerOf(EObject view) {
+ return DiagramUtils.getOwner((Diagram)view);
+ }
+
+ @Override
+ public EObject getRootOf(EObject view) {
+ return ((Diagram)view).getElement();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java
new file mode 100755
index 00000000000..19544a0c3ea
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java
@@ -0,0 +1,165 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
+import org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+
+/**
+ * Represents the dynamic contribution of a policy to menus
+ * @author Laurent Wouters
+ */
+public class GMFDiagramViewTypeHelper implements IViewTypeHelper {
+ /**
+ * ID of the extension point for Papyrus diagrams
+ */
+ private static final String EXTENSION_PAPYRUS_DIAGRAM = "org.eclipse.papyrus.infra.core.papyrusDiagram";
+
+ private static class NakedViewPrototype extends DiagramPrototype {
+ private final String label;
+ private final String icon;
+ public NakedViewPrototype(PapyrusView configuration, String category, AbstractPapyrusGmfCreateDiagramCommandHandler command, String label, String icon) {
+ super(configuration, category, command);
+ this.label = label;
+ this.icon = icon;
+ }
+ @Override
+ public String getLabel() { return label; }
+ @Override
+ public String getIconURI() { return icon; }
+ }
+
+ private static class Implementation {
+ public final String name;
+ public final String icon;
+ public final String language;
+ public final AbstractPapyrusGmfCreateDiagramCommandHandler command;
+ public Implementation(String name, String icon, String language, AbstractPapyrusGmfCreateDiagramCommandHandler command) {
+ this.name = name;
+ this.icon = icon;
+ this.language = language;
+ this.command = command;
+ }
+ }
+
+
+ /**
+ * The cache of prototypes
+ */
+ private Map<PapyrusView, DiagramPrototype> cache;
+
+ /**
+ * The cache of implementations
+ */
+ private Map<String, Implementation> implementations;
+
+ /**
+ * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#isSupported(org.eclipse.emf.ecore.EClass)
+ */
+ public boolean isSupported(EClass type) {
+ return EcoreUtil.equals(type, ConfigurationPackage.eINSTANCE.getPapyrusDiagram());
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#isSupported(org.eclipse.emf.ecore.EObject)
+ */
+ public boolean isSupported(EObject view) {
+ return (view instanceof Diagram);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#getPrototypeFor(org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView)
+ */
+ public ViewPrototype getPrototypeFor(PapyrusView configuration) {
+ if (!(configuration instanceof PapyrusDiagram))
+ return null;
+ if (implementations == null)
+ buildImplementationCache();
+ if (cache == null)
+ cache = new HashMap<PapyrusView, DiagramPrototype>();
+ if (cache.containsKey(configuration))
+ return cache.get(configuration);
+ if (!implementations.containsKey(configuration.getImplementationID()))
+ return null;
+ Implementation impl = implementations.get(configuration.getImplementationID());
+ if (ViewPrototype.isNatural(configuration)) {
+ NakedViewPrototype proto = new NakedViewPrototype(configuration, impl.language, impl.command, impl.name, impl.icon);
+ cache.put(configuration, proto);
+ return proto;
+ } else {
+ DiagramPrototype proto = new DiagramPrototype(configuration, impl.language, impl.command);
+ cache.put(configuration, proto);
+ return proto;
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#getPrototypeOf(org.eclipse.emf.ecore.EObject)
+ */
+ public ViewPrototype getPrototypeOf(EObject view) {
+ if (!(view instanceof Diagram))
+ return null;
+ return DiagramUtils.getPrototype((Diagram)view);
+ }
+
+ /**
+ * Builds the cache of metadata
+ */
+ private void buildImplementationCache() {
+ implementations = new HashMap<String, Implementation>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint point = registry.getExtensionPoint(EXTENSION_PAPYRUS_DIAGRAM);
+ IExtension[] extensions = point.getExtensions();
+ for (int i=0; i!=extensions.length; i++) {
+ IConfigurationElement[] elements = extensions[i].getConfigurationElements();
+ for (int j=0; j!=elements.length; j++) {
+ if (elements[j].getName().equals("creationCommand")) {
+ try {
+ Object obj = elements[j].createExecutableExtension("creationCommandClass");
+ if (obj instanceof AbstractPapyrusGmfCreateDiagramCommandHandler) {
+ AbstractPapyrusGmfCreateDiagramCommandHandler command = (AbstractPapyrusGmfCreateDiagramCommandHandler)obj;
+ String label = elements[j].getAttribute("label");
+ String icon = elements[j].getAttribute("icon");
+ String language = elements[j].getAttribute("language");
+ String implID = command.getCreatedDiagramType();
+ if (!icon.startsWith("platform:/"))
+ icon = "platform:/plugin/" + extensions[i].getContributor().getName() + "/" + icon;
+ if (!implementations.containsKey(implID))
+ implementations.put(implID, new Implementation(label, icon, language, command));
+ }
+ }
+ catch (CoreException e) { }
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java
index 7d783690bec..5d9b14456b6 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java
@@ -11,7 +11,6 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.helper;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
@@ -34,18 +33,8 @@ public class NotationHelper {
if(source instanceof View) {
return (View)source;
}
- if(source instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable)source;
- Object adapter = adaptable.getAdapter(View.class);
- if(adapter != null) {
- return (View)adapter;
- }
- adapter = EMFHelper.getEObject(adaptable);
- if(adapter instanceof View) {
- return (View)adapter;
- }
- }
- return null;
+ EObject obj = EMFHelper.getEObject(source);
+ return (obj instanceof View) ? (View) obj : null;
}
/**
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
index 9ad8ee049be..606fa01febd 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
@@ -1,272 +1,210 @@
-/*****************************************************************************
- * Copyright (c) 2009 Atos Origin.
- *
- *
- * 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:
- * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.model;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.papyrus.infra.core.resource.IModel;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * Utilities method to manage notation models. Should be moved in a more
- * suitable plugin
- */
-public class NotationUtils {
-
- /**
- * Get the notation Resource.
- *
- * @return
- *
- * @deprecated Usage of the internal Resource is discouraged.
- */
- @Deprecated
- public static Resource getNotationResource() {
- return getNotationModel().getResource();
- }
-
- /**
- * Gets the NotationModel for the currently selected editor. <br>
- * Warning: This method is designed to be call from ui.handlers. It is not
- * designed to be call from Editors. This method can return null if called
- * during the MultiEditor initialization.
- *
- * @see ServiceUtilsForActionHandlers.getInstance().getModelSet()
- *
- * @return The {@link NotationModel} of the current editor, or null if not
- * found.
- */
- public static NotationModel getNotationModel() {
-
- try {
- return (NotationModel)ServiceUtilsForActionHandlers.getInstance().getModelSet().getModel(NotationModel.MODEL_ID);
- } catch (ServiceException e) {
- return null;
- }
- }
-
- /**
- * Gets the NotationModel for the currently selected editor. <br>
- * Warning: This method is designed to be call from ui.handlers. It is not
- * designed to be call from Editors. This method can return null if called
- * during the MultiEditor initialization.
- *
- * @see ServiceUtilsForActionHandlers.getInstance().getModelSet()
- *
- * @return The {@link NotationModel} of the current editor, or null if not
- * found.
- * @throws ServiceException
- * If an error occurs while getting or starting the service.
- */
- public static NotationModel getNotationModelChecked() throws ServiceException {
-
- return (NotationModel)ServiceUtilsForActionHandlers.getInstance().getModelSet().getModel(NotationModel.MODEL_ID);
- }
-
- /**
- * Gets the NotationModel from the {@link ModelSet}. <br>
- *
- * @param modelsManager
- * The modelManager containing the requested model.
- *
- * @return The {@link NotationModel} registered in modelManager, or null if
- * not found.
- */
- public static NotationModel getNotationModel(ModelSet modelsManager) {
-
- return (NotationModel)modelsManager.getModel(NotationModel.MODEL_ID);
- }
-
- /**
- * Gets the direct associated diagram of the specified eObject.
- *
- * @param eObject
- * @param notationResource
- *
- * @return the associated diagram
- */
- public static Diagram getAssociatedDiagram(Resource notationResource, EObject eObject) {
- if(notationResource != null) {
- for(EObject obj : notationResource.getContents()) {
- if(obj instanceof Diagram) {
- Diagram diagram = (Diagram)obj;
- if(eObject != null && eObject.equals(diagram.getElement())) {
- return diagram;
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Gets the direct associated diagram of the specified eObject.
- *
- * @param eObject
- * @param notationResource
- * @param resolve
- * the resource if true
- *
- * @return the associated diagram
- */
- public static Diagram getAssociatedDiagram(Resource notationResource, EObject eObject, boolean resolve) {
- if(notationResource != null && resolve) {
- EcoreUtil.resolveAll(notationResource);
- }
- return getAssociatedDiagram(notationResource, eObject);
- }
-
- /**
- * Gets the all the diagrams contained in the specified ancestor eObject
- *
- * @param notationResource
- * @param eObject
- *
- * @return all the contained diagrams
- *
- */
- public static List<Diagram> getDiagrams(Resource notationResource, EObject eObject) {
- List<Diagram> diagrams = new LinkedList<Diagram>();
- if(notationResource != null) {
- for(EObject obj : notationResource.getContents()) {
- if(obj instanceof Diagram) {
- Diagram diagram = (Diagram)obj;
- if(EcoreUtil.isAncestor(eObject, diagram.getElement())) {
- diagrams.add(diagram);
- }
- }
- }
- }
- return diagrams;
- }
-
- /**
- * Gets the all the diagrams contained in the specified ancestor eObject
- *
- * @param notationResource
- * @param eObject
- * @param resolve
- * the resource if true
- *
- * @return all the contained diagrams
- */
- public static List<Diagram> getDiagrams(Resource notationResource, EObject eObject, boolean resolve) {
- if(notationResource != null && resolve) {
- EcoreUtil.resolveAll(notationResource);
- }
- return getDiagrams(notationResource, eObject);
- }
-
- /**
- * Helper to retrieve the Notation resource associated to a ModelSet. May be null.
- *
- * @param from
- * @return
- */
- public static Resource getNotationResource(ModelSet from) {
- IModel notationModel = from.getModel(NotationModel.MODEL_ID);
- if(notationModel instanceof NotationModel) {
- return ((NotationModel)notationModel).getResource();
- }
- return null;
- }
-
- /**
- * Helper to retrieve the Notation resource associated to a ServicesRegistry. May be null.
- *
- * @param from
- * @return
- */
- public static Resource getNotationResource(ServicesRegistry registry) {
- try {
- ModelSet modelSet = ServiceUtils.getInstance().getModelSet(registry);
- return getNotationResource(modelSet);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return null;
- }
- }
-
- /**
- * Gets the loaded associated diagrams of the specified eObject.
- * This method uses the cross referencer to compute them.
- *
- * @param eObject
- * @param notationResource
- *
- * @return the associated diagram
- */
- public static List<Diagram> getLoadedAssociatedDiagrams(EObject eObject) {
- Predicate<EStructuralFeature.Setting> p = new Predicate<EStructuralFeature.Setting>() {
-
- public boolean apply(EStructuralFeature.Setting setting) {
- return setting.getEObject() instanceof Diagram && NotationPackage.Literals.VIEW__ELEMENT.equals(setting.getEStructuralFeature());
- }
- };
- Function<EStructuralFeature.Setting, Diagram> f = new Function<EStructuralFeature.Setting, Diagram>() {
-
- public Diagram apply(EStructuralFeature.Setting setting) {
- return (Diagram)setting.getEObject();
- }
-
- };
- return Lists.newArrayList(Iterables.transform(Iterables.filter(EMFHelper.getUsages(eObject), p), f));
- }
-
- /**
- * Gets the all the diagrams contained in the specified ancestor eObject and
- * currently stored in the specified notation resource.
- *
- * @param notationResource
- * @param eObject
- *
- * @return all the contained diagrams
- *
- */
- public static List<Diagram> getAllDescendantDiagramsInResource(EObject eObject, Resource notationResource) {
- List<Diagram> diagrams = new ArrayList<Diagram>();
- if(notationResource != null) {
- for(EObject obj : notationResource.getContents()) {
- if(obj instanceof Diagram) {
- Diagram diagram = (Diagram)obj;
- if(EcoreUtil.isAncestor(eObject, diagram.getElement())) {
- diagrams.add(diagram);
- }
- }
- }
- }
- return diagrams;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+
+/**
+ * Utilities method to manage notation models. Should be moved in a more
+ * suitable plugin
+ */
+public class NotationUtils {
+
+ /**
+ * Get the notation Resource.
+ *
+ * @return
+ *
+ * @deprecated Usage of the internal Resource is discouraged.
+ */
+ @Deprecated
+ public static Resource getNotationResource() {
+ return getNotationModel().getResource();
+ }
+
+ /**
+ * Gets the NotationModel for the currently selected editor. <br>
+ * Warning: This method is designed to be call from ui.handlers. It is not
+ * designed to be call from Editors. This method can return null if called
+ * during the MultiEditor initialization.
+ *
+ * @see ServiceUtilsForActionHandlers.getInstance().getModelSet()
+ *
+ * @return The {@link NotationModel} of the current editor, or null if not
+ * found.
+ */
+ public static NotationModel getNotationModel() {
+
+ try {
+ return (NotationModel)ServiceUtilsForActionHandlers.getInstance().getModelSet().getModel(NotationModel.MODEL_ID);
+ } catch (ServiceException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Gets the NotationModel for the currently selected editor. <br>
+ * Warning: This method is designed to be call from ui.handlers. It is not
+ * designed to be call from Editors. This method can return null if called
+ * during the MultiEditor initialization.
+ *
+ * @see ServiceUtilsForActionHandlers.getInstance().getModelSet()
+ *
+ * @return The {@link NotationModel} of the current editor, or null if not
+ * found.
+ * @throws ServiceException
+ * If an error occurs while getting or starting the service.
+ */
+ public static NotationModel getNotationModelChecked() throws ServiceException {
+
+ return (NotationModel)ServiceUtilsForActionHandlers.getInstance().getModelSet().getModel(NotationModel.MODEL_ID);
+ }
+
+ /**
+ * Gets the NotationModel from the {@link ModelSet}. <br>
+ *
+ * @param modelsManager
+ * The modelManager containing the requested model.
+ *
+ * @return The {@link NotationModel} registered in modelManager, or null if
+ * not found.
+ */
+ public static NotationModel getNotationModel(ModelSet modelsManager) {
+
+ return (NotationModel)modelsManager.getModel(NotationModel.MODEL_ID);
+ }
+
+ /**
+ * Gets the direct associated diagram of the specified eObject.
+ *
+ * @param eObject
+ * @param notationResource
+ *
+ * @return the associated diagram
+ */
+ public static Diagram getAssociatedDiagram(Resource notationResource, EObject eObject) {
+ if(notationResource != null) {
+ for(EObject obj : notationResource.getContents()) {
+ if(obj instanceof Diagram) {
+ Diagram diagram = (Diagram)obj;
+ if (DiagramUtils.getOwner(diagram) == eObject)
+ return diagram;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets the direct associated diagram of the specified eObject.
+ *
+ * @param eObject
+ * @param notationResource
+ * @param resolve
+ * the resource if true
+ *
+ * @return the associated diagram
+ */
+ public static Diagram getAssociatedDiagram(Resource notationResource, EObject eObject, boolean resolve) {
+ if(notationResource != null && resolve) {
+ EcoreUtil.resolveAll(notationResource);
+ }
+ return getAssociatedDiagram(notationResource, eObject);
+ }
+
+ /**
+ * Gets the all the diagrams contained in the specified ancestor eObject
+ *
+ * @param notationResource
+ * @param eObject
+ *
+ * @return all the contained diagrams
+ *
+ */
+ public static List<Diagram> getDiagrams(Resource notationResource, EObject eObject) {
+ List<Diagram> diagrams = new LinkedList<Diagram>();
+ if(notationResource != null) {
+ for(EObject obj : notationResource.getContents()) {
+ if(obj instanceof Diagram) {
+ Diagram diagram = (Diagram)obj;
+ if (EcoreUtil.isAncestor(eObject, DiagramUtils.getOwner(diagram)))
+ diagrams.add(diagram);
+ }
+ }
+ }
+ return diagrams;
+ }
+
+ /**
+ * Gets the all the diagrams contained in the specified ancestor eObject
+ *
+ * @param notationResource
+ * @param eObject
+ * @param resolve
+ * the resource if true
+ *
+ * @return all the contained diagrams
+ */
+ public static List<Diagram> getDiagrams(Resource notationResource, EObject eObject, boolean resolve) {
+ if(notationResource != null && resolve) {
+ EcoreUtil.resolveAll(notationResource);
+ }
+ return getDiagrams(notationResource, eObject);
+ }
+
+ /**
+ * Helper to retrieve the Notation resource associated to a ModelSet. May be null.
+ *
+ * @param from
+ * @return
+ */
+ public static Resource getNotationResource(ModelSet from) {
+ IModel notationModel = from.getModel(NotationModel.MODEL_ID);
+ if(notationModel instanceof NotationModel) {
+ return ((NotationModel)notationModel).getResource();
+ }
+ return null;
+ }
+
+ /**
+ * Helper to retrieve the Notation resource associated to a ServicesRegistry. May be null.
+ *
+ * @param from
+ * @return
+ */
+ public static Resource getNotationResource(ServicesRegistry registry) {
+ try {
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(registry);
+ return getNotationResource(modelSet);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return null;
+ }
+ }
+}
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationLabelProvider.java
index cd8d0de611f..7a7c2daef82 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationLabelProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationLabelProvider.java
@@ -11,6 +11,8 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+import javax.swing.text.Element;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
@@ -19,15 +21,14 @@ import org.eclipse.gmf.runtime.notation.BasicCompartment;
import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistry;
-import org.eclipse.papyrus.infra.core.editorsfactory.PageIconsRegistry;
-import org.eclipse.papyrus.infra.core.extension.diagrameditor.PluggableEditorFactoryReader;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
import org.eclipse.papyrus.infra.gmfdiag.common.types.NotationTypesMap;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.NamedElement;
-import org.w3c.dom.Element;
/**
* A Label Provider for GMF Notation model
@@ -37,28 +38,27 @@ public class NotationLabelProvider extends EMFLabelProvider {
/** icon for a compartment */
public static final String ICON_COMPARTMENT = "/icons/none_comp_vis.gif"; //$NON-NLS-1$
- private IPageIconsRegistry pageIconsRegistry;
-
@Override
public void dispose() {
super.dispose();
- if(pageIconsRegistry != null) {
- pageIconsRegistry.dispose();
- pageIconsRegistry = null;
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ EObject eObject = EMFHelper.getEObject(element);
+ if (eObject != null) {
+ return getImage(eObject);
}
+ return super.getImage(element);
}
@Override
protected Image getImage(EObject element) {
if(element instanceof Diagram) {
- //return getPagesIconsRegistry().getEditorIcp
- if(pageIconsRegistry == null) {
- pageIconsRegistry = new PageIconsRegistry();
- PluggableEditorFactoryReader editorReader = new PluggableEditorFactoryReader(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
- editorReader.populate((PageIconsRegistry)pageIconsRegistry);
- }
-
- return pageIconsRegistry.getEditorIcon(element);
+ ViewPrototype proto = DiagramUtils.getPrototype((Diagram)element);
+ if (proto == null)
+ return null;
+ return proto.getIcon();
}
// if the element is a compartment
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
new file mode 100755
index 00000000000..4e78d0e5047
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Style;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.infra.viewpoints.style.PapyrusViewStyle;
+import org.eclipse.papyrus.infra.viewpoints.style.StylePackage;
+
+/**
+ * Utilities for the management of configuration-related data on views and diagrams
+ * @author Laurent Wouters
+ */
+public class DiagramUtils {
+
+ /**
+ * Gets the diagram associated to the given edit part
+ * @param part The edit part
+ * @return The diagram associated to the edit part, or <code>null</code> if none is found
+ */
+ public static Diagram getDiagramFrom(EditPart part) {
+ EditPart current = part;
+ while (current != null) {
+ Object model = current.getModel();
+ if (model instanceof Diagram)
+ return (Diagram)model;
+ current = current.getParent();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the owner of a diagram as it will appear in the model explorer.
+ * In the case where the diagram does not yet have a defined owner, the diagram's root element will be returned instead.
+ * @param diagram A diagram
+ * @return The diagram's owner
+ */
+ public static EObject getOwner(Diagram diagram) {
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null) {
+ PapyrusViewStyle pvs = (PapyrusViewStyle)style;
+ EObject value = pvs.getOwner();
+ if (value != null)
+ return value;
+ }
+ // This is the legacy fallback for old diagrams
+ return diagram.getElement();
+ }
+
+ /**
+ * Sets the owner of a diagram as it will appear in the model explorer
+ * @param diagram A diagram
+ * @param owner The new diagram's owner
+ */
+ public static void setOwner(Diagram diagram, EObject owner) {
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null) {
+ PapyrusViewStyle pvs = (PapyrusViewStyle)style;
+ pvs.setOwner(owner);
+ } else {
+ PapyrusViewStyle pvs = (PapyrusViewStyle)diagram.createStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ pvs.setOwner(owner);
+ }
+ }
+
+ /**
+ * Gets the prototype of a diagram
+ * @param diagram A diagram
+ * @return The diagram's prototype
+ */
+ public static ViewPrototype getPrototype(Diagram diagram) {
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null) {
+ PapyrusViewStyle pvs = (PapyrusViewStyle)style;
+ PapyrusView config = pvs.getConfiguration();
+ if (config != null) {
+ if (PolicyChecker.getCurrent().isInViewpoint(config))
+ return ViewPrototype.get(config);
+ return ViewPrototype.UNAVAILABLE_DIAGRAM;
+ }
+ return ViewPrototype.get(diagram.getType(), pvs.getOwner(), diagram.getElement());
+ }
+ // This is the legacy fallback for old diagrams
+ if ("Package".equals(diagram.getType())) {
+ for (ViewPrototype prototype : PolicyChecker.getCurrent().getAllPrototypes()) {
+ if ("UML Package Diagram".equals(prototype.getLabel()))
+ return prototype;
+ }
+ }
+ return ViewPrototype.get(diagram.getType(), diagram.getElement(), diagram.getElement());
+ }
+
+ /**
+ * Sets the prototype of a diagram
+ * @param diagram A diagram
+ * @param configuration The new diagram's prototype
+ */
+ public static void setPrototype(Diagram diagram, ViewPrototype prototype) {
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null) {
+ PapyrusViewStyle pvs = (PapyrusViewStyle)style;
+ pvs.setConfiguration(prototype.getConfiguration());
+ } else {
+ PapyrusViewStyle pvs = (PapyrusViewStyle)diagram.createStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ pvs.setConfiguration(prototype.getConfiguration());
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.controlmode/src/org/eclipse/papyrus/infra/gmfdiag/controlmode/ControlDiagramsCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.controlmode/src/org/eclipse/papyrus/infra/gmfdiag/controlmode/ControlDiagramsCommand.java
index 34ed42b72bc..08fb60c2c03 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.controlmode/src/org/eclipse/papyrus/infra/gmfdiag/controlmode/ControlDiagramsCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.controlmode/src/org/eclipse/papyrus/infra/gmfdiag/controlmode/ControlDiagramsCommand.java
@@ -99,7 +99,7 @@ public class ControlDiagramsCommand extends AbstractControlCommand {
if(notationResource == null) {
throw new ExecutionException("unable to retrieve old notation resource");
}
- return NotationUtils.getAllDescendantDiagramsInResource(getRequest().getTargetObject(), notationResource);
+ return NotationUtils.getDiagrams(notationResource, getRequest().getTargetObject());
}
/**
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF
index a0090e3f2c6..7ad5863dd55 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF
@@ -18,7 +18,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.emf.facet.efacet,
org.eclipse.papyrus.emf.facet.efacet.metamodel,
org.eclipse.papyrus.emf.facet.custom.metamodel,
- org.eclipse.papyrus.infra.emf
+ org.eclipse.papyrus.infra.emf,
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.0.0.qualifier
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/plugin.xml
index 90d477a5bca..6d23ed58823 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/plugin.xml
@@ -2,34 +2,9 @@
<?eclipse version="3.4"?>
<plugin>
-
-<extension point="org.eclipse.papyrus.emf.facet.util.emf.core.modeldeclaration">
- <modeldeclaration file="resources/PapyrusDiagram.custom"/>
-</extension>
-
- <!-- TODO: EMF-FACET
- <extension point="org.eclipse.papyrus.emf.facet.infra.query.registration">
- <modelqueryset file="resources/PapyrusNotationFacet.querySet">
- </modelqueryset>
- </extension>
-
- <extension point="org.eclipse.papyrus.emf.facet.infra.browser.custom.core.registration">
- <browserCustomization
- file="resources/PapyrusNotation.uiCustom"
- loadByDefault="true"/>
- </extension>
- <extension point="org.eclipse.papyrus.emf.facet.infra.browser.custom.core.registration">
- <browserCustomization
- file="resources/PapyrusNotationFacet.uiCustom"
- loadByDefault="true"/>
- </extension>
- <extension
- point="org.eclipse.papyrus.emf.facet.infra.facet.registration">
- <facetset
- file="resources/PapyrusNotationFacet.facetSet">
- </facetset>
+ <extension point="org.eclipse.papyrus.emf.facet.util.emf.core.modeldeclaration">
+ <modeldeclaration file="resources/PapyrusDiagram.custom"/>
</extension>
- -->
<extension
point="org.eclipse.ui.handlers">
<handler
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java
index c5c535df52d..c9ebb4e79b6 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java
@@ -20,6 +20,7 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager;
import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException;
import org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2;
@@ -41,7 +42,7 @@ public class GetContainedDiagrams extends AbstractEditorContainerQuery implement
while(roots.hasNext()) {
EObject root = roots.next();
if(root instanceof Diagram) {
- if(EcoreUtil.equals(((Diagram)root).getElement(), source)) {
+ if (EcoreUtil.equals(DiagramUtils.getOwner((Diagram) root), source)) {
result.add((Diagram)root);
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramIcon.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramIcon.java
index 23b836b4cf5..3572004ef38 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramIcon.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramIcon.java
@@ -14,6 +14,8 @@
package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
import org.eclipse.papyrus.emf.facet.custom.metamodel.custompt.IImage;
import org.eclipse.papyrus.emf.facet.custom.ui.ImageUtils;
import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager;
@@ -27,6 +29,7 @@ public class GetDiagramIcon extends AbstractGetEditorIconQuery implements IJavaQ
public IImage evaluate(Diagram source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException {
- return ImageUtils.wrap(org.eclipse.emf.common.util.URI.createPlatformPluginURI(getEditorRegistry(source).getEditorURLIcon(source), true).toString()); //$NON-NLS-1$
+ ViewPrototype prototype = DiagramUtils.getPrototype(source);
+ return ImageUtils.wrap(prototype.getIconURI());
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java
index 23e6be9f436..348eff81323 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager;
import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetReference;
@@ -46,7 +47,7 @@ public class IsDiagramContainer extends AbstractEditorContainerQuery implements
while(roots.hasNext()) {
EObject root = roots.next();
if(root instanceof Diagram) {
- if(EcoreUtil.equals(((Diagram)root).getElement(), source)) {
+ if (EcoreUtil.equals(DiagramUtils.getOwner((Diagram) root), source)) {
return true;
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/CreateDiagramWithNavigationHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/CreateDiagramWithNavigationHandler.java
deleted file mode 100644
index 3bc66d3ed60..00000000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/CreateDiagramWithNavigationHandler.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 Atos Origin.
- *
- *
- * 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:
- * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.navigation;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.commands.ICreationCommand;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.extension.commands.ICreationCondition;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers;
-import org.eclipse.papyrus.infra.widgets.toolbox.dialog.InformationDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * This command handler will try to create a diagram on the currently selected
- * element, using navigation if necessary. The action is always available and
- * the check is done in the run to avoid heavy navigation computation on each
- * selection change.
- *
- * @author mvelten
- *
- */
-public abstract class CreateDiagramWithNavigationHandler extends AbstractHandler {
-
- private ICreationCondition creationCondition;
-
- private ICreationCommand creationCommand;
-
- public CreateDiagramWithNavigationHandler(ICreationCommand creationCommand, ICreationCondition creationCondition) {
- super();
- this.creationCommand = creationCommand;
- this.creationCondition = creationCondition;
- }
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- NavigableElement navElement = getNavigableElementWhereToCreateDiagram(event);
- ServicesRegistry registry;
- try {
- registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return null;
- }
-
- if(navElement == null) {
- InformationDialog dialog = new InformationDialog(Display.getCurrent().getActiveShell(), "Impossible diagram creation", "It is not possible to create this diagram on the selected element.", null, null, SWT.OK, MessageDialog.WARNING, new String[]{ IDialogConstants.OK_LABEL });
- dialog.open();
- } else {
- createDiagram(navElement, registry);
- }
- return null;
- }
-
- private NavigableElement getNavigableElementWhereToCreateDiagram(ExecutionEvent event) {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if(selection.isEmpty()) {
- return null;
- }
-
- if(selection instanceof IStructuredSelection) {
- EObject selectedElement = EMFHelper.getEObject(((IStructuredSelection)selection).getFirstElement());
-
- if(selectedElement != null) {
- // First check if the current element can host the requested diagram
- if(creationCondition.create(selectedElement)) {
- return new ExistingNavigableElement(selectedElement, null);
- } else {
- List<NavigableElement> navElements = NavigationHelper.getInstance().getAllNavigableElements(selectedElement);
- // this will sort elements by navigation depth
- Collections.sort(navElements);
-
- for(NavigableElement navElement : navElements) {
- // ignore existing elements because we want a hierarchy to
- // be created if it is not on the current element
- if(navElement instanceof CreatedNavigableElement && creationCondition.create(navElement.getElement())) {
- return navElement;
- }
- }
- }
- }
- }
-
- return null;
- }
-
- private void createDiagram(NavigableElement navElement, ServicesRegistry registry) {
- ModelSet modelSet;
- try {
- modelSet = ServiceUtils.getInstance().getModelSet(registry);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return;
- }
-
- if(navElement != null && modelSet != null) {
- try {
- CompositeCommand command = NavigationHelper.getLinkCreateAndOpenNavigableDiagramCommand(navElement, creationCommand, null, modelSet);
- modelSet.getTransactionalEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
- } catch (Exception e) {
- }
- }
- }
-
- /**
- * Resolve semantic element
- *
- * @param object
- * the object to resolve
- * @return <code>null</code> or the semantic element associated to the
- * specified object
- */
- protected EObject resolveSemanticObject(Object object) {
- if(object instanceof EObject) {
- return (EObject)object;
- }
- Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(object);
- if(businessObject instanceof EObject) {
- return (EObject)businessObject;
- }
- return null;
- }
-
- @Override
- public void setEnabled(Object evaluationContext) {
- if(evaluationContext instanceof IEvaluationContext) {
- Object selectionVariable = ((IEvaluationContext)evaluationContext).getDefaultVariable();
-
- if(selectionVariable instanceof Collection<?>) {
- List<?> selection = (selectionVariable instanceof List<?>) ? (List<?>)selectionVariable : new java.util.ArrayList<Object>((Collection<?>)selectionVariable);
- if(selection.size() != 1) {
- setBaseEnabled(false);
- return;
- }
-
- EObject target = EMFHelper.getEObject(selection.get(0));
- setBaseEnabled(creationCondition.create(target));
- }
- }
- super.setEnabled(evaluationContext);
- }
-
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF
index d922ee2a532..cbdf8697d24 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF
@@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.0.0"
+ org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0"
Export-Package: org.eclipse.papyrus.infra.gmfdiag.properties.extension,
org.eclipse.papyrus.infra.gmfdiag.properties.modelelement
Bundle-Vendor: %Bundle-Vendor
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/notation.ctx b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/notation.ctx
index 530b8df9e75..484a6246643 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/notation.ctx
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/notation.ctx
@@ -37,9 +37,6 @@
<sections name="Single RelativeBendpoints" sectionFile="ui/SingleRelativeBendpoints.xwt">
<widget href="ui/SingleRelativeBendpoints.xwt#/"/>
</sections>
- <sections name="Single Diagram" sectionFile="ui/SingleDiagram.xwt">
- <widget href="ui/SingleDiagram.xwt#/"/>
- </sections>
<sections name="Single Image" sectionFile="ui/SingleImage.xwt">
<widget href="ui/SingleImage.xwt#/"/>
</sections>
@@ -184,18 +181,18 @@
<widget href="ui/SingleRulersAndGrid.xwt#/"/>
</sections>
</tabs>
- <views name="Single Diagram" sections="//@tabs.0/@sections.12" automaticContext="true" datacontexts="//@dataContexts.0/@elements.12">
+ <tabs label="General" id="general" category="org.eclipse.papyrus" priority="75">
+ <sections name="Single Diagram" sectionFile="ui/SingleDiagram.xwt">
+ <widget href="ui/SingleDiagram.xwt#/"/>
+ </sections>
+ </tabs>
+ <views name="Single Diagram" sections="//@tabs.2/@sections.0" automaticContext="true" datacontexts="//@dataContexts.0/@elements.12">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleDiagram">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Diagram"/>
</constraints>
</views>
- <views name="Single Decorable Element" sections="//@tabs.0/@sections.58" automaticContext="true" datacontexts="//@dataContexts.1/@elements.0">
- <constraints xsi:type="constraints:SimpleConstraint" name="isDecorableElementConstraint">
- <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.4"/>
- </constraints>
- </views>
<views name="Single Edge" sections="//@tabs.0/@sections.0" automaticContext="true" datacontexts="//@dataContexts.0/@elements.0">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleEdge">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
@@ -280,112 +277,112 @@
<properties xsi:type="constraints:ValueProperty" name="className" value="RelativeBendpoints"/>
</constraints>
</views>
- <views name="Single Image" sections="//@tabs.0/@sections.13" automaticContext="true" datacontexts="//@dataContexts.0/@elements.13">
+ <views name="Single Image" sections="//@tabs.0/@sections.12" automaticContext="true" datacontexts="//@dataContexts.0/@elements.13">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleImage">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Image"/>
</constraints>
</views>
- <views name="Single Guide" sections="//@tabs.0/@sections.14" automaticContext="true" datacontexts="//@dataContexts.0/@elements.14">
+ <views name="Single Guide" sections="//@tabs.0/@sections.13" automaticContext="true" datacontexts="//@dataContexts.0/@elements.14">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleGuide">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Guide"/>
</constraints>
</views>
- <views name="Single NodeEntry" sections="//@tabs.0/@sections.15" automaticContext="true" datacontexts="//@dataContexts.0/@elements.15">
+ <views name="Single NodeEntry" sections="//@tabs.0/@sections.14" automaticContext="true" datacontexts="//@dataContexts.0/@elements.15">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleNodeEntry">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="NodeEntry"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single StringToPropertyValueMapEntry" sections="//@tabs.0/@sections.16" automaticContext="true" datacontexts="//@dataContexts.0/@elements.16">
+ <views name="Single StringToPropertyValueMapEntry" sections="//@tabs.0/@sections.15" automaticContext="true" datacontexts="//@dataContexts.0/@elements.16">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleStringToPropertyValueMapEntry">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="StringToPropertyValueMapEntry"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single PropertyValue" sections="//@tabs.0/@sections.17" automaticContext="true" datacontexts="//@dataContexts.0/@elements.17">
+ <views name="Single PropertyValue" sections="//@tabs.0/@sections.16" automaticContext="true" datacontexts="//@dataContexts.0/@elements.17">
<constraints xsi:type="constraints:SimpleConstraint" name="isSinglePropertyValue">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="PropertyValue"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single StringObjectConverter" sections="//@tabs.0/@sections.18" automaticContext="true" datacontexts="//@dataContexts.0/@elements.18">
+ <views name="Single StringObjectConverter" sections="//@tabs.0/@sections.17" automaticContext="true" datacontexts="//@dataContexts.0/@elements.18">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleStringObjectConverter">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="StringObjectConverter"/>
</constraints>
</views>
- <views name="Single Shape" sections="//@tabs.0/@sections.19" automaticContext="true" datacontexts="//@dataContexts.0/@elements.19">
+ <views name="Single Shape" sections="//@tabs.0/@sections.18" automaticContext="true" datacontexts="//@dataContexts.0/@elements.19">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleShape">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Shape"/>
</constraints>
</views>
- <views name="Single Compartment" sections="//@tabs.0/@sections.20" automaticContext="true" datacontexts="//@dataContexts.0/@elements.20">
+ <views name="Single Compartment" sections="//@tabs.0/@sections.19" automaticContext="true" datacontexts="//@dataContexts.0/@elements.20">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Compartment"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single ListCompartment" sections="//@tabs.0/@sections.21" automaticContext="true" datacontexts="//@dataContexts.0/@elements.21">
+ <views name="Single ListCompartment" sections="//@tabs.0/@sections.20" automaticContext="true" datacontexts="//@dataContexts.0/@elements.21">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleListCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="ListCompartment"/>
</constraints>
</views>
- <views name="Single Connector" sections="//@tabs.0/@sections.22" automaticContext="true" datacontexts="//@dataContexts.0/@elements.22">
+ <views name="Single Connector" sections="//@tabs.0/@sections.21" automaticContext="true" datacontexts="//@dataContexts.0/@elements.22">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleConnector">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Connector"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single StandardDiagram" sections="//@tabs.0/@sections.23" automaticContext="true" datacontexts="//@dataContexts.0/@elements.23">
+ <views name="Single StandardDiagram" sections="//@tabs.0/@sections.22" automaticContext="true" datacontexts="//@dataContexts.0/@elements.23">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleStandardDiagram">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="StandardDiagram"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single DecorationNode" sections="//@tabs.0/@sections.24" automaticContext="true" datacontexts="//@dataContexts.0/@elements.24">
+ <views name="Single DecorationNode" sections="//@tabs.0/@sections.23" automaticContext="true" datacontexts="//@dataContexts.0/@elements.24">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleDecorationNode">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="DecorationNode"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single BasicDecorationNode" sections="//@tabs.0/@sections.25" automaticContext="true" datacontexts="//@dataContexts.0/@elements.25">
+ <views name="Single BasicDecorationNode" sections="//@tabs.0/@sections.24" automaticContext="true" datacontexts="//@dataContexts.0/@elements.25">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleBasicDecorationNode">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="BasicDecorationNode"/>
</constraints>
</views>
- <views name="Single BasicCompartment" sections="//@tabs.0/@sections.26" automaticContext="true" datacontexts="//@dataContexts.0/@elements.26">
+ <views name="Single BasicCompartment" sections="//@tabs.0/@sections.25" automaticContext="true" datacontexts="//@dataContexts.0/@elements.26">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleBasicCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="BasicCompartment"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single BasicSemanticCompartment" sections="//@tabs.0/@sections.27" automaticContext="true" datacontexts="//@dataContexts.0/@elements.27">
+ <views name="Single BasicSemanticCompartment" sections="//@tabs.0/@sections.26" automaticContext="true" datacontexts="//@dataContexts.0/@elements.27">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleBasicSemanticCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="BasicSemanticCompartment"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views name="Single SemanticListCompartment" sections="//@tabs.0/@sections.28" automaticContext="true" datacontexts="//@dataContexts.0/@elements.28">
+ <views name="Single SemanticListCompartment" sections="//@tabs.0/@sections.27" automaticContext="true" datacontexts="//@dataContexts.0/@elements.28">
<constraints xsi:type="constraints:SimpleConstraint" name="isSingleSemanticListCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="SemanticListCompartment"/>
@@ -398,209 +395,214 @@
<properties xsi:type="constraints:ValueProperty" name="className" value="org.eclipse.papyrus.infra.gmfdiag.properties.constraint.IsSingleDiagramEditorConstraint"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Edge" sections="//@tabs.0/@sections.29" automaticContext="true" datacontexts="//@dataContexts.0/@elements.0">
+ <views elementMultiplicity="-1" name="Multiple Edge" sections="//@tabs.0/@sections.28" automaticContext="true" datacontexts="//@dataContexts.0/@elements.0">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleEdge">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Edge"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Node" sections="//@tabs.0/@sections.30" automaticContext="true" datacontexts="//@dataContexts.0/@elements.1">
+ <views elementMultiplicity="-1" name="Multiple Node" sections="//@tabs.0/@sections.29" automaticContext="true" datacontexts="//@dataContexts.0/@elements.1">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleNode">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Node"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple LayoutConstraint" sections="//@tabs.0/@sections.31" automaticContext="true" datacontexts="//@dataContexts.0/@elements.2">
+ <views elementMultiplicity="-1" name="Multiple LayoutConstraint" sections="//@tabs.0/@sections.30" automaticContext="true" datacontexts="//@dataContexts.0/@elements.2">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleLayoutConstraint">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="LayoutConstraint"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Size" sections="//@tabs.0/@sections.32" automaticContext="true" datacontexts="//@dataContexts.0/@elements.3">
+ <views elementMultiplicity="-1" name="Multiple Size" sections="//@tabs.0/@sections.31" automaticContext="true" datacontexts="//@dataContexts.0/@elements.3">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleSize">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Size"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Location" sections="//@tabs.0/@sections.33" automaticContext="true" datacontexts="//@dataContexts.0/@elements.4">
+ <views elementMultiplicity="-1" name="Multiple Location" sections="//@tabs.0/@sections.32" automaticContext="true" datacontexts="//@dataContexts.0/@elements.4">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleLocation">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Location"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Bounds" sections="//@tabs.0/@sections.34" automaticContext="true" datacontexts="//@dataContexts.0/@elements.5">
+ <views elementMultiplicity="-1" name="Multiple Bounds" sections="//@tabs.0/@sections.33" automaticContext="true" datacontexts="//@dataContexts.0/@elements.5">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleBounds">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Bounds"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Ratio" sections="//@tabs.0/@sections.35" automaticContext="true" datacontexts="//@dataContexts.0/@elements.6">
+ <views elementMultiplicity="-1" name="Multiple Ratio" sections="//@tabs.0/@sections.34" automaticContext="true" datacontexts="//@dataContexts.0/@elements.6">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleRatio">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Ratio"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Anchor" sections="//@tabs.0/@sections.36" automaticContext="true" datacontexts="//@dataContexts.0/@elements.7">
+ <views elementMultiplicity="-1" name="Multiple Anchor" sections="//@tabs.0/@sections.35" automaticContext="true" datacontexts="//@dataContexts.0/@elements.7">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleAnchor">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Anchor"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Bendpoints" sections="//@tabs.0/@sections.37" automaticContext="true" datacontexts="//@dataContexts.0/@elements.8">
+ <views elementMultiplicity="-1" name="Multiple Bendpoints" sections="//@tabs.0/@sections.36" automaticContext="true" datacontexts="//@dataContexts.0/@elements.8">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleBendpoints">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Bendpoints"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple IdentityAnchor" sections="//@tabs.0/@sections.38" automaticContext="true" datacontexts="//@dataContexts.0/@elements.9">
+ <views elementMultiplicity="-1" name="Multiple IdentityAnchor" sections="//@tabs.0/@sections.37" automaticContext="true" datacontexts="//@dataContexts.0/@elements.9">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleIdentityAnchor">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="IdentityAnchor"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple View" sections="//@tabs.0/@sections.39" automaticContext="true" datacontexts="//@dataContexts.0/@elements.10">
+ <views elementMultiplicity="-1" name="Multiple View" sections="//@tabs.0/@sections.38" automaticContext="true" datacontexts="//@dataContexts.0/@elements.10">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleView">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="View"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple RelativeBendpoints" sections="//@tabs.0/@sections.40" automaticContext="true" datacontexts="//@dataContexts.0/@elements.11">
+ <views elementMultiplicity="-1" name="Multiple RelativeBendpoints" sections="//@tabs.0/@sections.39" automaticContext="true" datacontexts="//@dataContexts.0/@elements.11">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleRelativeBendpoints">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="RelativeBendpoints"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Diagram" sections="//@tabs.0/@sections.41" automaticContext="true" datacontexts="//@dataContexts.0/@elements.12">
+ <views elementMultiplicity="-1" name="Multiple Diagram" sections="//@tabs.0/@sections.40" automaticContext="true" datacontexts="//@dataContexts.0/@elements.12">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleDiagram">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Diagram"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Image" sections="//@tabs.0/@sections.42" automaticContext="true" datacontexts="//@dataContexts.0/@elements.13">
+ <views elementMultiplicity="-1" name="Multiple Image" sections="//@tabs.0/@sections.41" automaticContext="true" datacontexts="//@dataContexts.0/@elements.13">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleImage">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Image"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Guide" sections="//@tabs.0/@sections.43" automaticContext="true" datacontexts="//@dataContexts.0/@elements.14">
+ <views elementMultiplicity="-1" name="Multiple Guide" sections="//@tabs.0/@sections.42" automaticContext="true" datacontexts="//@dataContexts.0/@elements.14">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleGuide">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Guide"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple NodeEntry" sections="//@tabs.0/@sections.44" automaticContext="true" datacontexts="//@dataContexts.0/@elements.15">
+ <views elementMultiplicity="-1" name="Multiple NodeEntry" sections="//@tabs.0/@sections.43" automaticContext="true" datacontexts="//@dataContexts.0/@elements.15">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleNodeEntry">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="NodeEntry"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple StringToPropertyValueMapEntry" sections="//@tabs.0/@sections.45" automaticContext="true" datacontexts="//@dataContexts.0/@elements.16">
+ <views elementMultiplicity="-1" name="Multiple StringToPropertyValueMapEntry" sections="//@tabs.0/@sections.44" automaticContext="true" datacontexts="//@dataContexts.0/@elements.16">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleStringToPropertyValueMapEntry">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="StringToPropertyValueMapEntry"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple PropertyValue" sections="//@tabs.0/@sections.46" automaticContext="true" datacontexts="//@dataContexts.0/@elements.17">
+ <views elementMultiplicity="-1" name="Multiple PropertyValue" sections="//@tabs.0/@sections.45" automaticContext="true" datacontexts="//@dataContexts.0/@elements.17">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultiplePropertyValue">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="PropertyValue"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple StringObjectConverter" sections="//@tabs.0/@sections.47" automaticContext="true" datacontexts="//@dataContexts.0/@elements.18">
+ <views elementMultiplicity="-1" name="Multiple StringObjectConverter" sections="//@tabs.0/@sections.46" automaticContext="true" datacontexts="//@dataContexts.0/@elements.18">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleStringObjectConverter">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="StringObjectConverter"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Shape" sections="//@tabs.0/@sections.48" automaticContext="true" datacontexts="//@dataContexts.0/@elements.19">
+ <views elementMultiplicity="-1" name="Multiple Shape" sections="//@tabs.0/@sections.47" automaticContext="true" datacontexts="//@dataContexts.0/@elements.19">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleShape">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Shape"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Compartment" sections="//@tabs.0/@sections.49" automaticContext="true" datacontexts="//@dataContexts.0/@elements.20">
+ <views elementMultiplicity="-1" name="Multiple Compartment" sections="//@tabs.0/@sections.48" automaticContext="true" datacontexts="//@dataContexts.0/@elements.20">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Compartment"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple ListCompartment" sections="//@tabs.0/@sections.50" automaticContext="true" datacontexts="//@dataContexts.0/@elements.21">
+ <views elementMultiplicity="-1" name="Multiple ListCompartment" sections="//@tabs.0/@sections.49" automaticContext="true" datacontexts="//@dataContexts.0/@elements.21">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleListCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="ListCompartment"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple Connector" sections="//@tabs.0/@sections.51" automaticContext="true" datacontexts="//@dataContexts.0/@elements.22">
+ <views elementMultiplicity="-1" name="Multiple Connector" sections="//@tabs.0/@sections.50" automaticContext="true" datacontexts="//@dataContexts.0/@elements.22">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleConnector">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="Connector"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple StandardDiagram" sections="//@tabs.0/@sections.52" automaticContext="true" datacontexts="//@dataContexts.0/@elements.23">
+ <views elementMultiplicity="-1" name="Multiple StandardDiagram" sections="//@tabs.0/@sections.51" automaticContext="true" datacontexts="//@dataContexts.0/@elements.23">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleStandardDiagram">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="StandardDiagram"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple DecorationNode" sections="//@tabs.0/@sections.53" automaticContext="true" datacontexts="//@dataContexts.0/@elements.24">
+ <views elementMultiplicity="-1" name="Multiple DecorationNode" sections="//@tabs.0/@sections.52" automaticContext="true" datacontexts="//@dataContexts.0/@elements.24">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleDecorationNode">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="DecorationNode"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple BasicDecorationNode" sections="//@tabs.0/@sections.54" automaticContext="true" datacontexts="//@dataContexts.0/@elements.25">
+ <views elementMultiplicity="-1" name="Multiple BasicDecorationNode" sections="//@tabs.0/@sections.53" automaticContext="true" datacontexts="//@dataContexts.0/@elements.25">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleBasicDecorationNode">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="BasicDecorationNode"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple BasicCompartment" sections="//@tabs.0/@sections.55" automaticContext="true" datacontexts="//@dataContexts.0/@elements.26">
+ <views elementMultiplicity="-1" name="Multiple BasicCompartment" sections="//@tabs.0/@sections.54" automaticContext="true" datacontexts="//@dataContexts.0/@elements.26">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleBasicCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="BasicCompartment"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple BasicSemanticCompartment" sections="//@tabs.0/@sections.56" automaticContext="true" datacontexts="//@dataContexts.0/@elements.27">
+ <views elementMultiplicity="-1" name="Multiple BasicSemanticCompartment" sections="//@tabs.0/@sections.55" automaticContext="true" datacontexts="//@dataContexts.0/@elements.27">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleBasicSemanticCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="BasicSemanticCompartment"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
</constraints>
</views>
- <views elementMultiplicity="-1" name="Multiple SemanticListCompartment" sections="//@tabs.0/@sections.57" automaticContext="true" datacontexts="//@dataContexts.0/@elements.28">
+ <views elementMultiplicity="-1" name="Multiple SemanticListCompartment" sections="//@tabs.0/@sections.56" automaticContext="true" datacontexts="//@dataContexts.0/@elements.28">
<constraints xsi:type="constraints:SimpleConstraint" name="isMultipleSemanticListCompartment">
<constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.3"/>
<properties xsi:type="constraints:ValueProperty" name="nsUri" value="http://www.eclipse.org/gmf/runtime/1.0.2/notation"/>
<properties xsi:type="constraints:ValueProperty" name="className" value="SemanticListCompartment"/>
</constraints>
</views>
+ <views name="Single Decorable Element" sections="//@tabs.0/@sections.57" automaticContext="true" datacontexts="//@dataContexts.1/@elements.0">
+ <constraints xsi:type="constraints:SimpleConstraint" name="isDecorableElementConstraint">
+ <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.properties/model/Environment.xmi#//@constraintTypes.4"/>
+ </constraints>
+ </views>
<dataContexts name="notation" label="notation">
<elements name="Edge" supertypes="//@dataContexts.0/@elements.10">
<properties name="source" type="Reference"/>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt
index 0e7eb2296f9..d08acaed9e0 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt
@@ -11,6 +11,8 @@
<ppel:PropertiesLayout numColumns="1"></ppel:PropertiesLayout>
</Composite.layout>
<ppe:StringEditor input="{Binding}" property="notation:Diagram:name"></ppe:StringEditor>
- <ppe:StringLabel input="{Binding}" property="notation:View:type"></ppe:StringLabel>
+ <ppe:ReferenceLabel input="{Binding}" property="notation:View:prototype" readOnly="true" customLabel="View Type"></ppe:ReferenceLabel>
+ <ppe:ReferenceDialog input="{Binding}" property="notation:View:owner" customLabel="Owner"></ppe:ReferenceDialog>
+ <ppe:ReferenceDialog input="{Binding}" property="notation:View:element" customLabel="Root element"></ppe:ReferenceDialog>
</Composite>
</Composite> \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
index f85b81ae344..a85ef90af4c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
@@ -19,17 +19,28 @@ import org.eclipse.emf.databinding.FeaturePath;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.Style;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.infra.gmfdiag.properties.Activator;
import org.eclipse.papyrus.infra.gmfdiag.properties.databinding.GradientObservableValue;
+import org.eclipse.papyrus.infra.gmfdiag.properties.provider.ModelContentProvider;
+import org.eclipse.papyrus.infra.gmfdiag.properties.util.LegacyOwnerObservable;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.infra.viewpoints.style.StylePackage;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList;
import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue;
import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement;
+import org.eclipse.swt.graphics.Image;
/**
* A ModelElement to represent an element of the GMF Notation metamodel
@@ -65,7 +76,29 @@ public class GMFModelElement extends EMFModelElement {
}
@Override
+ protected boolean isFeatureEditable(String propertyPath) {
+ if (propertyPath.endsWith("owner")) {
+ return true;
+ }
+ return super.isFeatureEditable(propertyPath);
+ }
+
+ @Override
protected IObservable doGetObservable(String propertyPath) {
+ if (propertyPath.endsWith("owner")) {
+ Diagram diagram = (Diagram)source;
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null)
+ return new PapyrusObservableValue(style, StylePackage.Literals.PAPYRUS_VIEW_STYLE__OWNER, domain);
+ return new LegacyOwnerObservable(diagram, StylePackage.Literals.PAPYRUS_VIEW_STYLE__OWNER, domain);
+ } else if (propertyPath.endsWith("prototype")) {
+ Diagram diagram = (Diagram)source;
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null)
+ return new PapyrusObservableValue(style, StylePackage.Literals.PAPYRUS_VIEW_STYLE__CONFIGURATION, domain);
+ return new LegacyOwnerObservable(diagram, StylePackage.Literals.PAPYRUS_VIEW_STYLE__CONFIGURATION, domain);
+ }
+
FeaturePath featurePath = getFeaturePath(propertyPath);
EStructuralFeature feature = getFeature(propertyPath);
@@ -88,6 +121,22 @@ public class GMFModelElement extends EMFModelElement {
@Override
public ILabelProvider getLabelProvider(String propertyPath) {
+ if (propertyPath.endsWith("prototype")) {
+ return new ILabelProvider() {
+ public void addListener(ILabelProviderListener listener) { }
+ public void removeListener(ILabelProviderListener listener) { }
+ public void dispose() { }
+ public boolean isLabelProperty(Object element, String property) { return false; }
+ public Image getImage(Object element) {
+ ViewPrototype proto = DiagramUtils.getPrototype((Diagram)source);
+ return proto.getIcon();
+ }
+ public String getText(Object element) {
+ ViewPrototype proto = DiagramUtils.getPrototype((Diagram)source);
+ return proto.getQualifiedName();
+ }
+ };
+ }
try {
return ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, source).getLabelProvider();
} catch (ServiceException ex) {
@@ -96,4 +145,43 @@ public class GMFModelElement extends EMFModelElement {
}
}
+ /**
+ * @see org.eclipse.papyrus.views.properties.modelelement.EMFModelElement#getContentProvider(java.lang.String)
+ */
+ @Override
+ public IStaticContentProvider getContentProvider(String propertyPath) {
+ if (propertyPath.endsWith("element")) {
+ Diagram diagram = (Diagram)source;
+ return new ModelContentProvider(diagram, getRoot(diagram.getElement())) {
+ @Override
+ protected boolean isValid(EObject selection, Diagram diagram, ViewPrototype prototype) {
+ return PolicyChecker.getCurrent().canHaveNewView(selection, DiagramUtils.getOwner(diagram), prototype);
+ }
+ };
+ } else if (propertyPath.endsWith("owner")) {
+ Diagram diagram = (Diagram) source;
+ return new ModelContentProvider(diagram, getRoot(diagram.getElement())) {
+ @Override
+ protected boolean isValid(EObject selection, Diagram diagram, ViewPrototype prototype) {
+ return PolicyChecker.getCurrent().canHaveNewView(diagram.getElement(), selection, prototype);
+ }
+ };
+ }
+ return super.getContentProvider(propertyPath);
+ }
+
+ /**
+ * Gets the root EObject from the given one
+ * @param obj An object
+ * @return The root object which is an ancestor of the given one
+ */
+ private EObject getRoot(EObject obj) {
+ EObject current = obj;
+ EObject parent = obj.eContainer();
+ while (parent != null) {
+ current = parent;
+ parent = parent.eContainer();
+ }
+ return current;
+ }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/provider/ModelContentProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/provider/ModelContentProvider.java
new file mode 100755
index 00000000000..78e29021201
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/provider/ModelContentProvider.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.provider;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ui.ECoreModelContentProvider;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+
+/**
+ * Represents a simple ECore model content provider for the selection of a diagram's root model element
+ * @author Laurent Wouters
+ */
+public abstract class ModelContentProvider extends ECoreModelContentProvider implements IStaticContentProvider, IHierarchicContentProvider {
+
+ /**
+ * The diagram
+ */
+ private Diagram diagram;
+
+ /**
+ * Initializes the provider with the given root
+ * @param diagram The diagram for which a root model element is to be provided
+ * @param root The root object
+ */
+ public ModelContentProvider(Diagram diagram, EObject root) {
+ super(root);
+ this.diagram = diagram;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements()
+ */
+ public Object[] getElements() {
+ return getElements(null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider#isValidValue(java.lang.Object)
+ */
+ public boolean isValidValue(Object element) {
+ if (element == null)
+ return false;
+ if (!(element instanceof EObject))
+ return false;
+ ViewPrototype prototype = DiagramUtils.getPrototype(diagram);
+ if (prototype == null)
+ return false;
+ return isValid((EObject) element, diagram, prototype);
+ }
+
+ /**
+ * Determines whether the selection is valid
+ *
+ * @param selection
+ * The selection
+ * @param diagram
+ * The diagram
+ * @param prototype
+ * The diagram's prototype
+ * @return <code>true</code> if the selection is valid
+ */
+ protected abstract boolean isValid(EObject selection, Diagram diagram, ViewPrototype prototype);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/util/LegacyOwnerObservable.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/util/LegacyOwnerObservable.java
new file mode 100755
index 00000000000..8b941318fae
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/util/LegacyOwnerObservable.java
@@ -0,0 +1,158 @@
+/*****************************************************************************
+ * 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:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.util;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
+import org.eclipse.core.databinding.observable.value.ValueDiff;
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.Style;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.style.StylePackage;
+import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue;
+
+/**
+ * Represents the observable value of a diagram's owner in the case where the diagram does not yet have the viewpoints-compatible style for holding the value itself
+ * @author Laurent Wouters
+ */
+public class LegacyOwnerObservable extends AbstractObservableValue {
+
+ private EditingDomain domain;
+ private Diagram diagram;
+ private EReference reference;
+ private IChangeListener styleListener;
+ private IChangeListener valueListener;
+ private PapyrusObservableValue styleObservable;
+ private PapyrusObservableValue valueObservable;
+
+ /**
+ * Initializes the observables
+ * @param diagram The diagram to be observed
+ * @param domain The editing domain
+ */
+ public LegacyOwnerObservable(Diagram diagram, EReference feature, EditingDomain domain) {
+ super(Realm.getDefault());
+ this.domain = domain;
+ this.diagram = diagram;
+ this.reference = feature;
+ buildStyleListener();
+ this.styleObservable = new PapyrusObservableValue(diagram, NotationPackage.Literals.VIEW__STYLES, domain);
+ this.styleObservable.addChangeListener(styleListener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#isStale()
+ */
+ public boolean isStale() {
+ return (valueListener != null);
+ }
+
+ /**
+ * Builds the listener for the styles property of the diagram
+ */
+ private void buildStyleListener() {
+ this.styleListener = new IChangeListener() {
+ public void handleChange(ChangeEvent event) {
+ if (valueListener != null)
+ return;
+ Style style = LegacyOwnerObservable.this.diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ if (style != null)
+ buildValueListener(style);
+ }
+ };
+ }
+
+ /**
+ * Builds the listener for the EObjectValue property of the style
+ * @param style The style to be observed
+ */
+ private void buildValueListener(Style style) {
+ this.valueListener = new IChangeListener() {
+ public void handleChange(ChangeEvent event) {
+ fireValueChange(new ValueDiff() {
+ public Object getOldValue() { return null; }
+ public Object getNewValue() { return DiagramUtils.getOwner(diagram); }
+ });
+ }
+ };
+ valueObservable = new PapyrusObservableValue(style, reference, domain);
+ valueObservable.addChangeListener(valueListener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType()
+ */
+ public Object getValueType() {
+ return EcorePackage.Literals.EOBJECT;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue()
+ */
+ protected Object doGetValue() {
+ return DiagramUtils.getOwner(diagram);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object)
+ */
+ protected void doSetValue(Object value) {
+ Command emfCommand = getCommand((EObject) value);
+ domain.getCommandStack().execute(emfCommand);
+ }
+
+ private Command getCommand(final EObject newValue) {
+ final EObject oldValue = DiagramUtils.getOwner(diagram);
+
+ return new AbstractCommand("Change diagram's owner") {
+ private boolean createStyle = true;
+
+ public void execute() {
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ createStyle = (style == null);
+ DiagramUtils.setOwner(diagram, newValue);
+ }
+
+ public void redo() {
+ DiagramUtils.setOwner(diagram, newValue);
+ }
+
+ @Override
+ public void undo() {
+ if (createStyle) {
+ Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE);
+ diagram.getStyles().remove(style);
+ } else {
+ DiagramUtils.setOwner(diagram, oldValue);
+ }
+ }
+
+ @Override
+ public boolean prepare() {
+ return true;
+ }
+ };
+ }
+}

Back to the top