Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.classpath7
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.options7
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.project28
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF20
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/about.html28
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/build.properties8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/messages.properties22
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.properties16
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml37
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/schema/nestedEditor.exsd193
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/AbstractPapyrusGmfCreateDiagramCommandHandler.java355
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Activator.java278
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/DiagramsUtil.java75
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfEditorFactory.java219
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfMultiDiagramDocumentProvider.java1133
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Messages.java80
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/ModelManagerEditor.java594
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SemanticFromGMFElement.java44
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SynchronizableGmfDiagramEditor.java101
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/UMLDiagramEditorUtil.java37
20 files changed, 3282 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.classpath b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.options b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.options
new file mode 100644
index 00000000000..c6913fd8b04
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.options
@@ -0,0 +1,7 @@
+# Tracing options for the org.eclipse.uml2.diagram.clazz plug-in
+
+# Common issues
+org.eclipse.uml2.diagram.clazz/debug=false
+
+# Visual IDs
+org.eclipse.uml2.diagram.clazz/debug/visualID=false
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.project b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.project
new file mode 100644
index 00000000000..dd07a398bb9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.infra.core.adaptor.gmf</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
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
new file mode 100644
index 00000000000..72710102740
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.infra.core.adaptor.gmf
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.5.0",
+ org.eclipse.emf.ecore.edit;bundle-version="2.5.0",
+ org.eclipse.papyrus.infra.core;bundle-version="0.9.0",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0",
+ org.eclipse.gef;bundle-version="3.7.1",
+ org.eclipse.emf.workspace;bundle-version="1.4.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0"
+Bundle-Vendor: %providerName
+Bundle-Version: 0.9.0.qualifier
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.infra.core.adaptor.gmf.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.infra.core.adaptor.gmf;singleton:=true
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/about.html b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/about.html
new file mode 100644
index 00000000000..209103075a7
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>November 14, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/build.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/build.properties
new file mode 100644
index 00000000000..fd672fc8c77
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/build.properties
@@ -0,0 +1,8 @@
+#
+#Mon Sep 12 09:29:38 CEST 2011
+bin.includes=.options,META-INF/,plugin.properties,about.html,.,plugin.xml,schema/,messages.properties
+output..=bin/
+jars.compile.order=.
+src.includes=about.html,.options,META-INF/,plugin.properties,.,plugin.xml,schema/,messages.properties
+source..=src/
+bin..=bin/
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/messages.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/messages.properties
new file mode 100644
index 00000000000..17dfa067f09
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/messages.properties
@@ -0,0 +1,22 @@
+MultiPagesEditorActionBarContributor_PapyrusMenu=Papyrus Menu
+GmfMultiDiagramDocumentProvider_isModifiable=Updating cache failed
+GmfMultiDiagramDocumentProvider_handleElementContentChanged=Failed to refresh hierarchy for changed resource
+GmfMultiDiagramDocumentProvider_IncorrectInputError={1}
+GmfMultiDiagramDocumentProvider_NoDiagramInResourceError=Diagram is not present in resource
+GmfMultiDiagramDocumentProvider_DiagramLoadingError=Error loading diagram
+GmfMultiDiagramDocumentProvider_UnsynchronizedFileSaveError=The file has been changed on the file system
+GmfMultiDiagramDocumentProvider_SaveDiagramTask=Saving diagram
+GmfMultiDiagramDocumentProvider_SaveNextResourceTask=Saving {0}
+GmfMultiDiagramDocumentProvider_SaveAsOperation=Saving {0} diagram as
+ModelManagerEditor_SavingDeletedFile=The original file "{0}" has been deleted.
+ModelManagerEditor_SaveAsErrorTitle=Problem During Save As...
+ModelManagerEditor_SaveAsErrorMessage=Save could not be completed. Target file is already open in another editor.
+ModelManagerEditor_SaveErrorTitle=Save Problems
+ModelManagerEditor_SaveErrorMessage=Could not save file.
+AbstractPapyrusGmfCreateDiagramCommandHandler_NewDiagramName=The new diagram name:
+AbstractPapyrusGmfCreateDiagramCommandHandler_NotSupportedEditor=Current editor type not supported.
+AbstractPapyrusGmfCreateDiagramCommandHandler_SelectNewDiagramName=Enter a new diagram name
+AbstractPapyrusGmfCreateDiagramCommandHandler_UnableCreateModelAndDiagram=Unable to create model and diagram
+AbstractPapyrusGmfCreateDiagramCommandHandler_CreateDiagramCommandLabel=Creating diagram and model
+GmfEditorFactory_ErrorCreatingEditorPart=Can't create IEditorPart for gmf.Diagram
+GmfEditorFactory_ErrorRetrievingDiagram=Problem retrieving GMF Diagram.
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.properties
new file mode 100644
index 00000000000..f72830a71a2
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.properties
@@ -0,0 +1,16 @@
+#################################################################################
+# Copyright (c) 2008 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
+##################################################################################
+pluginName=UML Papyrus GMF Editor (Incubation)
+providerName=Eclipse Modeling Project
+
+
+
+
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
new file mode 100644
index 00000000000..2d5eb997b99
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+
+<plugin>
+ <extension-point id="nestedEditor" name="NestedEditor" schema="schema/nestedEditor.exsd"/>
+
+ <extension point="org.eclipse.team.core.fileTypes">
+ <?gmfgen generated="true"?>
+ <fileTypes
+ type="text"
+ extension="umlclass_diagram">
+ </fileTypes>
+ </extension>
+
+ <extension point="org.eclipse.emf.ecore.extension_parser">
+ <?gmfgen generated="true"?>
+ <parser
+ type="umlclass_diagram"
+ class="org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory">
+ </parser>
+ </extension>
+
+
+<extension
+ point="org.eclipse.papyrus.infra.core.papyrusDiagram">
+ <editorContext
+ contextClass="org.eclipse.papyrus.infra.core.adaptor.gmf.GmfEditorContext"
+ id="com.cea.papyrus.gmf.editor.context">
+ </editorContext>
+ </extension>
+
+
+
+
+
+
+</plugin>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/schema/nestedEditor.exsd b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/schema/nestedEditor.exsd
new file mode 100644
index 00000000000..542d08cb1c9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/schema/nestedEditor.exsd
@@ -0,0 +1,193 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="papyrus.gmf.multipages" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="papyrus.gmf.multipages" id="nestedEditor" name="NestedEditor"/>
+ </appinfo>
+ <documentation>
+ Deprecated
+Define a nested editor descriptor. This descriptor is used to add instance of the described editor to a multi diagram editor.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="editor" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="editor">
+ <annotation>
+ <documentation>
+ cc
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="createEditorButton" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ <attribute name="factoryClass" type="string" use="required">
+ <annotation>
+ <documentation>
+ The factory used to create an instance of the editor.
+The factory must implements org.eclipse.papyrus.infra.core.adaptor.gmf.extension.IEditorFactory
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.papyrus.infra.core.adaptor.gmf.extension.IEditorFactory"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="createEditorButton">
+ <annotation>
+ <appinfo>
+ <meta.element deprecated="true"/>
+ </appinfo>
+ <documentation>
+ Description of a toolbar button used to create a new editor.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="actionId" type="string" use="required">
+ <annotation>
+ <documentation>
+ ID used for the action.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="label" type="string" use="required">
+ <annotation>
+ <documentation>
+ Label used for the button
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="tooltip" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="image" type="string" use="required">
+ <annotation>
+ <documentation>
+ Icon used as button image.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="resource"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="disableImage" type="string">
+ <annotation>
+ <documentation>
+ Image used when button is disabled.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="resource"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="action" type="string" use="required">
+ <annotation>
+ <documentation>
+ The action class implementing the creation of the root object.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.papyrus.infra.core.adaptor.gmf.extension.ICreateDiagramAction"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiInfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ /*******************************************************************************
+ * Copyright (c) 2008 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:
+ * CEA LIST - initial API and implementation
+ *******************************************************************************/
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/AbstractPapyrusGmfCreateDiagramCommandHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/AbstractPapyrusGmfCreateDiagramCommandHandler.java
new file mode 100644
index 00000000000..b1195a015f1
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/AbstractPapyrusGmfCreateDiagramCommandHandler.java
@@ -0,0 +1,355 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+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.Path;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+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.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+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.core.utils.BusinessModelResolver;
+import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
+import org.eclipse.papyrus.infra.core.utils.OpenDiagramCommand;
+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 {
+
+ EObject container = null;
+ // if editor is open and active
+ if(getMultiDiagramEditor() != null) {
+ container = getSelectedElement();
+ }
+ runAsTransaction(container);
+ 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) throws ExecutionException {
+
+ DiResourceSet diResourceSet;
+ try {
+ diResourceSet = EditorUtils.getServiceRegistry().getService(DiResourceSet.class);
+ } catch (ServiceException e) {
+ throw new ExecutionException("Can't get diResourceSet", e);
+ }
+
+ runAsTransaction(diResourceSet, 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 DiResourceSet diResourceSet, final EObject container, String name) {
+ TransactionalEditingDomain dom = diResourceSet.getTransactionalEditingDomain();
+ CompositeCommand cmd = new CompositeCommand("Create diagram");
+ ICommand createCmd = getCreateDiagramCommand(diResourceSet, 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) {
+ Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(selection);
+ if(businessObject instanceof EObject) {
+ eObject = (EObject)businessObject;
+ }
+ }
+ 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 DiResourceSet diResourceSet, final EObject container, final String diagramName) {
+ TransactionalEditingDomain transactionalEditingDomain = diResourceSet.getTransactionalEditingDomain();
+ RecordingCommand command = new RecordingCommand(transactionalEditingDomain) {
+
+ @Override
+ protected void doExecute() {
+ runAsTransaction(diResourceSet, container, diagramName);
+ }
+ };
+ transactionalEditingDomain.getCommandStack().execute(command);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ICommand getCreateDiagramCommand(final DiResourceSet diResourceSet, final EObject container, final String diagramName) {
+ final Resource modelResource = diResourceSet.getAssociatedModelResource(container);
+ final Resource notationResource = diResourceSet.getAssociatedNotationResource(container);
+ final Resource diResource = diResourceSet.getAssociatedDiResource(container);
+
+ ArrayList<IFile> modifiedFiles = new ArrayList<IFile>();
+ modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(modelResource.getURI().toPlatformString(true))));
+ modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(notationResource.getURI().toPlatformString(true))));
+ modifiedFiles.add(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(diResource.getURI().toPlatformString(true))));
+
+ return new AbstractTransactionalCommand(diResourceSet.getTransactionalEditingDomain(), Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_CreateDiagramCommandLabel, modifiedFiles) {
+
+ @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 diagram = createDiagram(notationResource, model, name);
+
+ if(diagram != null) {
+ IPageMngr pageMngr = EditorUtils.getIPageMngr(diResource);
+ pageMngr.addPage(diagram);
+ return CommandResult.newOKCommandResult(diagram);
+ }
+ return CommandResult.newErrorCommandResult("Error during diagram creation");
+ }
+ };
+ }
+
+ /**
+ * Get the ServiceRegistry of the main editor.
+ *
+ * @return
+ */
+ protected ServicesRegistry getServiceRegistry() {
+ return EditorUtils.getServiceRegistry();
+ }
+
+ /**
+ * Get the ISashWindowsContentProvider from the main editor.
+ *
+ * @return
+ */
+ protected ISashWindowsContentProvider getISashWindowsContentProvider() {
+ return EditorUtils.getISashWindowsContentProvider();
+
+ }
+
+ /**
+ * 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;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Activator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Activator.java
new file mode 100644
index 00000000000..1590460ccda
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Activator.java
@@ -0,0 +1,278 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @generated
+ */
+public class Activator extends AbstractUIPlugin {
+
+ /**
+ * @generated
+ */
+ public static final String ID = "org.eclipse.papyrus.infra.core.adaptor.gmf"; //$NON-NLS-1$
+
+ /**
+ * @generated
+ */
+ public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint(ID);
+
+ /**
+ * @generated
+ */
+ private static Activator instance;
+
+ /**
+ * @generated
+ */
+ private ComposedAdapterFactory adapterFactory;
+
+ /**
+ * @generated
+ */
+ public Activator() {
+ }
+
+ /** Logging helper */
+ public static LogHelper log;
+
+ /**
+ * @generated
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ instance = this;
+ // register the login helper
+ log = new LogHelper(this);
+ PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, getPreferenceStore());
+ adapterFactory = createAdapterFactory();
+ }
+
+ /**
+ * @generated
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ adapterFactory.dispose();
+ adapterFactory = null;
+ log = null;
+ instance = null;
+ super.stop(context);
+ }
+
+ /**
+ * @generated
+ */
+ public static Activator getInstance() {
+ return instance;
+ }
+
+ /**
+ * @generated
+ */
+ protected ComposedAdapterFactory createAdapterFactory() {
+ List factories = new ArrayList();
+ // fillItemProviderFactories(factories);
+ return new ComposedAdapterFactory(factories);
+ }
+
+ /**
+ * @generated
+ */
+ protected void fillItemProviderFactoriesGen(List factories) {
+ factories.add(new EcoreItemProviderAdapterFactory());
+ factories.add(new ResourceItemProviderAdapterFactory());
+ factories.add(new ReflectiveItemProviderAdapterFactory());
+ }
+
+ /**
+ * Use alternative UMLItemProviderAdapterFactory insteadof UMLItemProviderAdapterFactory
+ *
+ * @see org.eclipse.emf.edit.provider.ComposedAdapterFactory#getFactoryForTypes(java.util.Collection)
+ * @generated NOT
+ */
+ // protected void fillItemProviderFactories(List factories) {
+ // factories.add(new AlternativeUMLItemProviderAdapterFactory(getPreferenceStore()));
+ // fillItemProviderFactoriesGen(factories);
+ // }
+
+ /**
+ * @generated
+ */
+ public AdapterFactory getItemProvidersAdapterFactory() {
+ return adapterFactory;
+ }
+
+ /**
+ * @generated
+ */
+ public ImageDescriptor getItemImageDescriptor(Object item) {
+ IItemLabelProvider labelProvider = (IItemLabelProvider)adapterFactory.adapt(item, IItemLabelProvider.class);
+ if(labelProvider != null) {
+ return ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(item));
+ }
+ return null;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in relative path.
+ *
+ * @generated
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getBundledImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path);
+ }
+
+ /**
+ * Respects images residing in any plug-in. If path is relative, then this bundle is looked up
+ * for the image, otherwise, for absolute path, first segment is taken as id of plug-in with
+ * image
+ *
+ * @generated
+ * @param path
+ * the path to image, either absolute (with plug-in id as first segment), or relative
+ * for bundled images
+ * @return the image descriptor
+ */
+ public static ImageDescriptor findImageDescriptor(String path) {
+ final IPath p = new Path(path);
+ if(p.isAbsolute() && p.segmentCount() > 1) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p.removeFirstSegments(1).makeAbsolute()
+ .toString());
+ } else {
+ return getBundledImageDescriptor(p.makeAbsolute().toString());
+ }
+ }
+
+ /**
+ * Returns string from plug-in's resource bundle
+ *
+ * @generated
+ */
+ public static String getString(String key) {
+ return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns an image for the image file at the given plug-in relative path. Client do not need to
+ * dispose this image. Images will be disposed automatically.
+ *
+ * @generated
+ * @param path
+ * the path
+ * @return image instance
+ */
+ public Image getBundledImage(String path) {
+ Image image = getImageRegistry().get(path);
+ if(image == null) {
+ getImageRegistry().put(path, getBundledImageDescriptor(path));
+ image = getImageRegistry().get(path);
+ }
+ return image;
+ }
+
+ /**
+ * @generated
+ */
+ public void logError(String error) {
+ logError(error, null);
+ }
+
+ /**
+ * @param throwable
+ * actual error or null could be passed
+ * @generated
+ */
+ public void logError(String error, Throwable throwable) {
+ if(error == null && throwable != null) {
+ error = throwable.getMessage();
+ }
+ getLog().log(new Status(IStatus.ERROR, Activator.ID, IStatus.OK, error, throwable));
+ debug(error, throwable);
+ }
+
+ /**
+ * @generated
+ */
+ public void logInfo(String message) {
+ logInfo(message, null);
+ }
+
+ /**
+ * @param throwable
+ * actual error or null could be passed
+ * @generated
+ */
+ public void logInfo(String message, Throwable throwable) {
+ if(message == null && throwable != null) {
+ message = throwable.getMessage();
+ }
+ getLog().log(new Status(IStatus.INFO, Activator.ID, IStatus.OK, message, throwable));
+ debug(message, throwable);
+ }
+
+ /**
+ * @generated
+ */
+ private void debug(String message, Throwable throwable) {
+ if(!isDebugging()) {
+ return;
+ }
+ if(message != null) {
+ System.err.println(message);
+ }
+ if(throwable != null) {
+ throwable.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in relative path.
+ *
+ * @param path
+ * the path
+ *
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(ID, path);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/DiagramsUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/DiagramsUtil.java
new file mode 100644
index 00000000000..05a0a21e2be
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/DiagramsUtil.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * 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.core.adaptor.gmf;
+
+import java.util.Collections;
+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.resource.ResourceSet;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
+
+
+public class DiagramsUtil {
+
+ /**
+ * Gets the diagrams associated to element.
+ *
+ * @param element
+ * @param resourceSet
+ * can be null, it will then try to retrieve it from the element.
+ * @return the list of diagrams associated with the given element
+ */
+ public static List<Diagram> getAssociatedDiagrams(EObject element, ResourceSet resourceSet) {
+ if(resourceSet == null) {
+ if(element != null && element.eResource() != null) {
+ resourceSet = element.eResource().getResourceSet();
+ }
+ }
+
+ if(resourceSet instanceof DiResourceSet) {
+ Resource notationResource = ((DiResourceSet)resourceSet).getAssociatedNotationResource(element);
+ return getAssociatedDiagramsFromNotationResource(element, notationResource);
+ }
+
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * Gets the diagrams associated to element.
+ *
+ * @param element
+ * @param notationResource
+ * the notation resource where to look for diagrams
+ * @return the list of diagrams associated with the given element
+ */
+ public static List<Diagram> getAssociatedDiagramsFromNotationResource(EObject element, Resource notationResource) {
+ if(notationResource != null) {
+ LinkedList<Diagram> diagrams = new LinkedList<Diagram>();
+ for(EObject eObj : notationResource.getContents()) {
+ if(eObj instanceof Diagram) {
+ Diagram diagram = (Diagram)eObj;
+ if(element.equals(diagram.getElement())) {
+ diagrams.add(diagram);
+ }
+ }
+ }
+ return diagrams;
+ }
+ return Collections.EMPTY_LIST;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfEditorFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfEditorFactory.java
new file mode 100644
index 00000000000..c3a68ba04a1
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfEditorFactory.java
@@ -0,0 +1,219 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import java.lang.reflect.Constructor;
+
+import org.eclipse.gef.ui.parts.GraphicalEditor;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.core.editor.BackboneException;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.AbstractEditorFactory;
+import org.eclipse.papyrus.infra.core.multidiagram.actionbarcontributor.ActionBarContributorRegistry;
+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.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorActionBarContributor;
+
+/**
+ * Base class of GmfEditor factories. Editor should subclass this class and provide a 0 args
+ * constructor initializing the super class.
+ *
+ * @author Cedric Dumoulin
+ * @author Remi Schnekenburger
+ * @author Patrick Tessier
+ */
+public class GmfEditorFactory extends AbstractEditorFactory {
+
+ /**
+ * Creates a new GmfEditorFactory.
+ *
+ * @param diagramClass
+ * expected Class of the diagram to create.
+ * @param expectedType
+ * expected diagram type (@see {@link Diagram#getType()})
+ */
+ protected GmfEditorFactory(Class<?> diagramClass, String expectedType) {
+ super(diagramClass, expectedType);
+ }
+
+ /**
+ * Return true if this PageModelFactory can create a PageModel for the specified pageIdentifier.
+ * The pageIdentifier is an instance of Diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.extension.diagrameditor.IPluggableEditorFactory#isPageModelFactoryFor(java.lang.Object)
+ * @param pageIdentifier
+ * @return
+ *
+ */
+ public boolean isPageModelFactoryFor(Object pageIdentifier) {
+
+ if(pageIdentifier instanceof Diagram) {
+ Diagram diagram = (Diagram)pageIdentifier;
+ // disable it when diagram is a proxy (dedicated factory will handle it)
+ if(!diagram.eIsProxy()) {
+ final String type = diagram.getType();
+ return getExpectedType().equals(type);
+ }
+ }
+ // no
+ return false;
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.extension.diagrameditor.IPluggableEditorFactory#createIPageModel(java.lang.Object)
+ * @param pageIdentifier
+ * @return
+ *
+ */
+ public IPageModel createIPageModel(Object pageIdentifier) {
+
+ return new GMFEditorModel((Diagram)pageIdentifier, getServiceRegistry());
+ }
+
+ /**
+ * IEditorModel handling creation of the requested Editor.
+ *
+ * @author dumoulin
+ *
+ */
+ class GMFEditorModel implements IEditorModel {
+
+ /**
+ * The Diagram object describing the diagram.
+ */
+ private Diagram diagram;
+
+ /**
+ * The servicesRegistry provided at creation.
+ */
+ private ServicesRegistry servicesRegistry;
+
+ /**
+ *
+ * Constructor.
+ */
+ public GMFEditorModel(Diagram pageIdentifier, ServicesRegistry servicesRegistry) {
+ diagram = pageIdentifier;
+ this.servicesRegistry = servicesRegistry;
+ }
+
+ /**
+ * Create the IEditor for the diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel#createIEditorPart()
+ * @return
+ * @throws PartInitException
+ *
+ */
+ public IEditorPart createIEditorPart() throws PartInitException {
+ GraphicalEditor editor;
+ try {
+ Constructor<?> c = getDiagramClass().getConstructor(ServicesRegistry.class, Diagram.class);
+ editor = (GraphicalEditor)c.newInstance(servicesRegistry, diagram);
+ return editor;
+
+ } catch (Exception e) {
+ // Lets propagate. This is an implementation problem that should be solved by
+ // programmer.
+ throw new PartInitException(Messages.GmfEditorFactory_ErrorCreatingEditorPart + diagram, e);
+ }
+
+ }
+
+ /**
+ * Get the action bar requested by the Editor.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel#getActionBarContributor()
+ * @return
+ *
+ */
+ public EditorActionBarContributor getActionBarContributor() {
+
+ String actionBarId = editorDescriptor.getActionBarContributorId();
+
+ // Do nothing if no EditorActionBarContributor is specify.
+ if(actionBarId == null || actionBarId.length() == 0) {
+ return null;
+ }
+
+ // Try to get it.
+
+ // Get ServiceRegistry
+ // ServicesRegistry serviceRegistry = getServicesRegistry();
+ ActionBarContributorRegistry registry;
+ try {
+ registry = (ActionBarContributorRegistry)servicesRegistry.getService(ActionBarContributorRegistry.class);
+ } catch (ServiceException e) {
+ // Service not found
+ // TODO Log the error
+ e.printStackTrace();
+ return null;
+ }
+
+ try {
+ return registry.getActionBarContributor(actionBarId);
+ } catch (BackboneException e) {
+ // TODO Log the error and throw an exception instead
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Get the underlying RawModel. Return the Diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getRawModel()
+ * @return
+ *
+ */
+ public Object getRawModel() {
+ return diagram;
+ }
+
+ /**
+ * Get the icon to be shown by Tabs
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabIcon()
+ * @return
+ *
+ */
+ public Image getTabIcon() {
+ ImageDescriptor imageDescriptor = getEditorDescriptor().getIcon();
+ if(imageDescriptor == null)
+ return null;
+
+ return imageDescriptor.createImage();
+ }
+
+ /**
+ * Get the title of the Diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabTitle()
+ * @return
+ *
+ */
+ public String getTabTitle() {
+ return diagram.getName();
+ }
+
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfMultiDiagramDocumentProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfMultiDiagramDocumentProvider.java
new file mode 100644
index 00000000000..6c1a9b3820a
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/GmfMultiDiagramDocumentProvider.java
@@ -0,0 +1,1133 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+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.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.MultiRule;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocumentProvider;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.EditorStatusCodes;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+/**
+ * @generated
+ */
+public class GmfMultiDiagramDocumentProvider extends AbstractDocumentProvider implements IDiagramDocumentProvider,
+ IEditingDomainProvider {
+
+ public static String EditingDomainID = "com.cea.papyrus.core.PapyrusEditingDomainID"; //$NON-NLS-1$
+
+ /**
+ * The shared ResourceSet.
+ */
+ private TransactionalEditingDomain sharedEditingDomain = null;
+
+ /**
+ * ResourceSet to use when creation EditingDomain. Can be null.
+ */
+ private ResourceSet resourceSet;
+
+ /**
+ * @param resourceSet
+ */
+ public GmfMultiDiagramDocumentProvider(ResourceSet resourceSet) {
+ super();
+ this.resourceSet = resourceSet;
+ }
+
+ /**
+ * @param resourceSet
+ */
+ public GmfMultiDiagramDocumentProvider(TransactionalEditingDomain editingDomain) {
+ super();
+ this.sharedEditingDomain = editingDomain;
+ configureEditingDomain(sharedEditingDomain);
+ }
+
+ /**
+ * Constructor.
+ */
+ public GmfMultiDiagramDocumentProvider() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @generated
+ */
+ protected ElementInfo createElementInfo(Object element) throws CoreException {
+ if(false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, NLS.bind(
+ Messages.GmfMultiDiagramDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ IEditorInput editorInput = (IEditorInput)element;
+ IDiagramDocument document = (IDiagramDocument)createDocument(editorInput);
+
+ ResourceSetInfo info = new ResourceSetInfo(document, editorInput);
+ info.setModificationStamp(computeModificationStamp(info));
+ info.fStatus = null;
+ return info;
+ }
+
+ /**
+ * @generated
+ */
+ protected IDocument createDocument(Object element) throws CoreException {
+ if(false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, NLS.bind(
+ Messages.GmfMultiDiagramDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ IDocument document = createEmptyDocument();
+ setDocumentContent(document, (IEditorInput)element);
+ setupDocument(element, document);
+ return document;
+ }
+
+ /**
+ * Sets up the given document as it would be provided for the given element. The content of the
+ * document is not changed. This default implementation is empty. Subclasses may reimplement.
+ *
+ * @param element
+ * the blue-print element
+ * @param document
+ * the document to set up
+ * @generated
+ */
+ protected void setupDocument(Object element, IDocument document) {
+ // for subclasses
+ }
+
+ /**
+ * @generated
+ */
+ private long computeModificationStamp(ResourceSetInfo info) {
+ int result = 0;
+ for(Iterator<Resource> it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = it.next();
+
+ // bug 347300: skip faulty URIs
+ if( isBadURI(nextResource)) {
+ continue;
+ }
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null) {
+ if(file.getLocation() != null) {
+ result += file.getLocation().toFile().lastModified();
+ } else {
+ result += file.getModificationStamp();
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Return true if the URI is a faulty URI, false otherwise.
+ * Faulty URI: scheme = pathmap, platform
+ * @param resource
+ * @return
+ */
+ private boolean isBadURI(Resource resource) {
+ try {
+ java.net.URI uri = new java.net.URI(resource.getURI().toString());
+ String scheme = uri.getScheme();
+ if( "pathmap".equals(scheme) || "platform".equals(scheme)) {
+ return true;
+ }
+
+ // not a bad uri
+ return false;
+ } catch (URISyntaxException e) {
+ return true;
+ }
+ }
+
+ /**
+ * @generated
+ */
+ protected IDocument createEmptyDocument() {
+ DiagramDocument document = new DiagramDocument();
+ document.setEditingDomain(createEditingDomain());
+ return document;
+ }
+
+ /**
+ * Create the editing Domain. All Editing Domain will be created with the same ResourceSet. The
+ * first creation will record the ResourceSet, other creation will use it.
+ */
+ private TransactionalEditingDomain createEditingDomain() {
+
+ TransactionalEditingDomain editingDomain = null;
+ // System.out.println(this.getClass().getSimpleName() + "- (" + this + ")");
+ // Check if edit domain exist
+ if(sharedEditingDomain != null) { // Already initialized
+ editingDomain = sharedEditingDomain;
+// System.out.println(this.getClass().getSimpleName()
+// + ".createEditingDomain() - got EditingDomain from previous call (" + editingDomain + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ return editingDomain;
+ }
+
+ // No editingDomain. Create and initialize a new one.
+
+ // Try to get a registered one if any
+ editingDomain = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(EditingDomainID);
+ if(editingDomain != null) {
+ // got it
+ sharedEditingDomain = editingDomain;
+ Activator.log.debug((this.getClass().getSimpleName()
+ + ".createEditingDomain() - got EditingDomain from REGISTRY (" + editingDomain + ")")); //$NON-NLS-1$ //$NON-NLS-2$
+ return editingDomain;
+ }
+
+ // Create EditingDomain using provided ResourceSet if any.
+ if(resourceSet == null) {
+ editingDomain = DiagramEditingDomainFactory.getInstance().createEditingDomain();
+ } else {
+ editingDomain = DiagramEditingDomainFactory.getInstance().createEditingDomain(resourceSet);
+ }
+ sharedEditingDomain = editingDomain;
+ editingDomain.setID(EditingDomainID); //$NON-NLS-1$
+ Activator.log.debug(this.getClass().getSimpleName()
+ + ".createEditingDomain() - create a new EditingDomain (" + editingDomain + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ configureEditingDomain(editingDomain);
+
+ return editingDomain;
+ }
+
+ /**
+ * Configure an EditingDomain suitable for GMF. This method should be called only once for an
+ * EditingDomain.
+ *
+ * @param editingDomain
+ */
+ private void configureEditingDomain(TransactionalEditingDomain editingDomain) {
+ // Add listener on resource change
+ final NotificationFilter diagramResourceModifiedFilter = NotificationFilter.createNotifierFilter(
+ editingDomain.getResourceSet()).and(NotificationFilter.createEventTypeFilter(Notification.ADD)).and(
+ NotificationFilter.createFeatureFilter(ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
+ editingDomain.getResourceSet().eAdapters().add(new Adapter() {
+
+ private Notifier myTarger;
+
+ public Notifier getTarget() {
+ return myTarger;
+ }
+
+ public boolean isAdapterForType(Object type) {
+ return false;
+ }
+
+ public void notifyChanged(Notification notification) {
+ if(diagramResourceModifiedFilter.matches(notification)) {
+ Object value = notification.getNewValue();
+ if(value instanceof Resource) {
+ ((Resource)value).setTrackingModification(true);
+ }
+ }
+ }
+
+ public void setTarget(Notifier newTarget) {
+ myTarger = newTarget;
+ }
+
+ });
+ }
+
+ /**
+ * @generated
+ */
+ protected void setDocumentContent(IDocument document, IEditorInput element) throws CoreException {
+ IDiagramDocument diagramDocument = (IDiagramDocument)document;
+ TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
+ if(element instanceof FileEditorInput) {
+ IStorage storage = ((FileEditorInput)element).getStorage();
+ Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor());
+ document.setContent(diagram);
+ } else if(element instanceof URIEditorInput) {
+ URI uri = ((URIEditorInput)element).getURI();
+ Resource resource = null;
+ try {
+ resource = domain.getResourceSet().getResource(uri.trimFragment(), false);
+ if(resource == null) {
+ resource = domain.getResourceSet().createResource(uri.trimFragment());
+ }
+ if(!resource.isLoaded()) {
+ try {
+ Map options = new HashMap(GMFResourceFactory.getDefaultLoadOptions());
+ // @see 171060
+ // options.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
+ // Boolean.TRUE);
+ resource.load(options);
+ } catch (IOException e) {
+ resource.unload();
+ throw e;
+ }
+ }
+ if(uri.fragment() != null) {
+ EObject rootElement = resource.getEObject(uri.fragment());
+ if(rootElement instanceof Diagram) {
+ document.setContent((Diagram)rootElement);
+ return;
+ }
+ } else {
+ for(Iterator it = resource.getContents().iterator(); it.hasNext();) {
+ Object rootElement = it.next();
+ if(rootElement instanceof Diagram) {
+ document.setContent((Diagram)rootElement);
+ return;
+ }
+ }
+ }
+ throw new RuntimeException(Messages.GmfMultiDiagramDocumentProvider_NoDiagramInResourceError);
+ } catch (Exception e) {
+ CoreException thrownExcp = null;
+ if(e instanceof CoreException) {
+ thrownExcp = (CoreException)e;
+ } else {
+ String msg = e.getLocalizedMessage();
+ thrownExcp = new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, msg != null ? msg
+ : Messages.GmfMultiDiagramDocumentProvider_DiagramLoadingError, e));
+ }
+ throw thrownExcp;
+ }
+ } else {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, NLS.bind(
+ Messages.GmfMultiDiagramDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ }
+
+ /**
+ * @generated
+ */
+ public long getModificationStamp(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ return computeModificationStamp(info);
+ }
+ return super.getModificationStamp(element);
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isDeleted(Object element) {
+ IDiagramDocument document = getDiagramDocument(element);
+ if(document != null) {
+ Resource diagramResource = document.getDiagram().eResource();
+ if(diagramResource != null) {
+ IFile file = WorkspaceSynchronizer.getFile(diagramResource);
+ return file == null || file.getLocation() == null || !file.getLocation().toFile().exists();
+ }
+ }
+ return super.isDeleted(element);
+ }
+
+ /**
+ * @generated
+ */
+ public ResourceSetInfo getResourceSetInfo(Object editorInput) {
+ return (ResourceSetInfo)super.getElementInfo(editorInput);
+ }
+
+ /**
+ * @generated
+ */
+ protected void disposeElementInfo(Object element, ElementInfo info) {
+ if(info instanceof ResourceSetInfo) {
+ ResourceSetInfo resourceSetInfo = (ResourceSetInfo)info;
+ resourceSetInfo.dispose();
+ }
+ super.disposeElementInfo(element, info);
+ }
+
+ /**
+ * @generated
+ */
+ protected void doValidateState(Object element, Object computationContext) throws CoreException {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ Collection files2Validate = new ArrayList();
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null && file.isReadOnly()) {
+ files2Validate.add(file);
+ }
+ }
+ ResourcesPlugin.getWorkspace().validateEdit(
+ (IFile[])files2Validate.toArray(new IFile[files2Validate.size()]), computationContext);
+ }
+
+ super.doValidateState(element, computationContext);
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isReadOnly(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ if(info.isUpdateCache()) {
+ try {
+ updateCache(element);
+ } catch (CoreException ex) {
+ Activator.getInstance().logError(Messages.GmfMultiDiagramDocumentProvider_isModifiable, ex);
+ // Error message to log was initially taken from
+ // org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
+ }
+ }
+ return info.isReadOnly();
+ }
+ return super.isReadOnly(element);
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isModifiable(Object element) {
+ if(!isStateValidated(element)) {
+ if(element instanceof FileEditorInput || element instanceof URIEditorInput) {
+ return true;
+ }
+ }
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ if(info.isUpdateCache()) {
+ try {
+ updateCache(element);
+ } catch (CoreException ex) {
+ Activator.getInstance().logError(Messages.GmfMultiDiagramDocumentProvider_isModifiable, ex);
+ // Error message to log was initially taken from
+ // org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
+ }
+ }
+ return info.isModifiable();
+ }
+ return super.isModifiable(element);
+ }
+
+ /**
+ * @generated
+ */
+ protected void updateCache(Object element) throws CoreException {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null && file.isReadOnly()) {
+ info.setReadOnly(true);
+ info.setModifiable(false);
+ return;
+ }
+ }
+ info.setReadOnly(false);
+ info.setModifiable(true);
+ return;
+ }
+ }
+
+ /**
+ * @generated
+ */
+ protected void doUpdateStateCache(Object element) throws CoreException {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ info.setUpdateCache(true);
+ }
+ super.doUpdateStateCache(element);
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isSynchronized(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ return info.isSynchronized();
+ }
+ return super.isSynchronized(element);
+ }
+
+ /**
+ * @generated
+ */
+ protected ISchedulingRule getResetRule(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ Collection rules = new ArrayList();
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null) {
+ rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(file));
+ }
+ }
+ return new MultiRule((ISchedulingRule[])rules.toArray(new ISchedulingRule[rules.size()]));
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected ISchedulingRule getSaveRule(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ Collection rules = new ArrayList();
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null) {
+ rules.add(computeSchedulingRule(file));
+ }
+ }
+ return new MultiRule((ISchedulingRule[])rules.toArray(new ISchedulingRule[rules.size()]));
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected ISchedulingRule getSynchronizeRule(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ Collection rules = new ArrayList();
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null) {
+ rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().refreshRule(file));
+ }
+ }
+ return new MultiRule((ISchedulingRule[])rules.toArray(new ISchedulingRule[rules.size()]));
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected ISchedulingRule getValidateStateRule(Object element) {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ Collection files = new ArrayList();
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ IFile file = WorkspaceSynchronizer.getFile(nextResource);
+ if(file != null) {
+ files.add(file);
+ }
+ }
+ return ResourcesPlugin.getWorkspace().getRuleFactory().validateEditRule(
+ (IFile[])files.toArray(new IFile[files.size()]));
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ private ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
+ if(toCreateOrModify.exists())
+ return ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(toCreateOrModify);
+
+ IResource parent = toCreateOrModify;
+ do {
+ /*
+ * XXX This is a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
+ * IResourceRuleFactory.createRule should iterate the hierarchy itself.
+ */
+ toCreateOrModify = parent;
+ parent = toCreateOrModify.getParent();
+ } while(parent != null && !parent.exists());
+
+ return ResourcesPlugin.getWorkspace().getRuleFactory().createRule(toCreateOrModify);
+ }
+
+ /**
+ * @generated
+ */
+ protected void doSynchronize(Object element, IProgressMonitor monitor) throws CoreException {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ for(Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ handleElementChanged(info, nextResource, monitor);
+ }
+ return;
+ }
+ super.doSynchronize(element, monitor);
+ }
+
+ /**
+ * @generated
+ */
+ protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
+ throws CoreException {
+ ResourceSetInfo info = getResourceSetInfo(element);
+ if(info != null) {
+ if(!overwrite && !info.isSynchronized()) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, IResourceStatus.OUT_OF_SYNC_LOCAL,
+ Messages.GmfMultiDiagramDocumentProvider_UnsynchronizedFileSaveError, null));
+ }
+ info.stopResourceListening();
+ fireElementStateChanging(element);
+ List resources = info.getResourceSet().getResources();
+ try {
+ monitor.beginTask(Messages.GmfMultiDiagramDocumentProvider_SaveDiagramTask, resources.size() + 1); // "Saving diagram"
+ for(Iterator it = resources.iterator(); it.hasNext();) {
+ Resource nextResource = (Resource)it.next();
+ monitor.setTaskName(NLS.bind(Messages.GmfMultiDiagramDocumentProvider_SaveNextResourceTask,
+ nextResource.getURI()));
+ if(nextResource.isLoaded() && !info.getEditingDomain().isReadOnly(nextResource)) {
+ try {
+ nextResource.save(UMLDiagramEditorUtil.getSaveOptions());
+ } catch (IOException e) {
+ fireElementStateChangeFailed(element);
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID,
+ EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage(), null));
+ }
+ }
+ monitor.worked(1);
+ }
+ monitor.done();
+ info.setModificationStamp(computeModificationStamp(info));
+ } catch (RuntimeException x) {
+ fireElementStateChangeFailed(element);
+ throw x;
+ } finally {
+ info.startResourceListening();
+ }
+ } else {
+ URI newResoruceURI;
+ List affectedFiles = null;
+ if(element instanceof FileEditorInput) {
+ IFile newFile = ((FileEditorInput)element).getFile();
+ affectedFiles = Collections.singletonList(newFile);
+ newResoruceURI = URI.createPlatformResourceURI(newFile.getFullPath().toString(), true);
+ } else if(element instanceof URIEditorInput) {
+ newResoruceURI = ((URIEditorInput)element).getURI();
+ } else {
+ fireElementStateChangeFailed(element);
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, NLS.bind(
+ Messages.GmfMultiDiagramDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ if(false == document instanceof IDiagramDocument) {
+ fireElementStateChangeFailed(element);
+ throw new CoreException(
+ new Status(
+ IStatus.ERROR,
+ Activator.ID,
+ 0,
+ "Incorrect document used: " + document + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument", null)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ IDiagramDocument diagramDocument = (IDiagramDocument)document;
+ final Resource newResource = diagramDocument.getEditingDomain().getResourceSet().createResource(
+ newResoruceURI);
+ final Diagram diagramCopy = (Diagram)EcoreUtil.copy(diagramDocument.getDiagram());
+ try {
+ new AbstractTransactionalCommand(diagramDocument.getEditingDomain(), NLS.bind(
+ Messages.GmfMultiDiagramDocumentProvider_SaveAsOperation, diagramCopy.getName()), affectedFiles) {
+
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ newResource.getContents().add(diagramCopy);
+ return CommandResult.newOKCommandResult();
+ }
+ }.execute(monitor, null);
+ newResource.save(UMLDiagramEditorUtil.getSaveOptions());
+ } catch (ExecutionException e) {
+ fireElementStateChangeFailed(element);
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, e.getLocalizedMessage(), null));
+ } catch (IOException e) {
+ fireElementStateChangeFailed(element);
+ throw new CoreException(new Status(IStatus.ERROR, Activator.ID, 0, e.getLocalizedMessage(), null));
+ }
+ newResource.unload();
+ }
+ }
+
+ /**
+ * @generated
+ */
+ protected void handleElementChanged(ResourceSetInfo info, Resource changedResource, IProgressMonitor monitor) {
+ IFile file = WorkspaceSynchronizer.getFile(changedResource);
+ if(file != null) {
+ try {
+ file.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ } catch (CoreException ex) {
+ Activator.getInstance().logError(Messages.GmfMultiDiagramDocumentProvider_handleElementContentChanged,
+ ex);
+ // Error message to log was initially taken from
+ // org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.FileDocumentProvider_handleElementContentChanged
+ }
+ }
+ changedResource.unload();
+
+ fireElementContentAboutToBeReplaced(info.getEditorInput());
+ removeUnchangedElementListeners(info.getEditorInput(), info);
+ info.fStatus = null;
+ try {
+ setDocumentContent(info.fDocument, info.getEditorInput());
+ } catch (CoreException e) {
+ info.fStatus = e.getStatus();
+ }
+ if(!info.fCanBeSaved) {
+ info.setModificationStamp(computeModificationStamp(info));
+ }
+ addUnchangedElementListeners(info.getEditorInput(), info);
+ fireElementContentReplaced(info.getEditorInput());
+ }
+
+ /**
+ * @generated
+ */
+ protected void handleElementMoved(IEditorInput input, URI uri) {
+ if(input instanceof FileEditorInput) {
+ IFile newFile = ResourcesPlugin.getWorkspace().getRoot().getFile(
+ new Path(URI.decode(uri.path())).removeFirstSegments(1));
+ fireElementMoved(input, newFile == null ? null : new FileEditorInput(newFile));
+ return;
+ }
+ // TODO: append suffix to the URI! (use diagram as a parameter)
+ fireElementMoved(input, new URIEditorInput(uri));
+ }
+
+ /**
+ * @generated
+ */
+ public IEditorInput createInputWithEditingDomain(IEditorInput editorInput, TransactionalEditingDomain domain) {
+ return editorInput;
+ }
+
+ /**
+ * @generated
+ */
+ public IDiagramDocument getDiagramDocument(Object element) {
+ IDocument doc = getDocument(element);
+ if(doc instanceof IDiagramDocument) {
+ return (IDiagramDocument)doc;
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected class ResourceSetInfo extends ElementInfo {
+
+ /**
+ * @generated
+ */
+ private long myModificationStamp = IResource.NULL_STAMP;
+
+ /**
+ * @generated
+ */
+ private WorkspaceSynchronizer mySynchronizer;
+
+ /**
+ * @generated
+ */
+ private Collection myUnSynchronizedResources = new ArrayList();
+
+ /**
+ * @generated
+ */
+ private IDiagramDocument myDocument;
+
+ /**
+ * @generated
+ */
+ private IEditorInput myEditorInput;
+
+ /**
+ * @generated
+ */
+ private boolean myUpdateCache = true;
+
+ /**
+ * @generated
+ */
+ private boolean myModifiable = false;
+
+ /**
+ * @generated
+ */
+ private boolean myReadOnly = true;
+
+ /**
+ * @generated
+ */
+ private ResourceSetModificationListener myResourceSetListener;
+
+ /**
+ * @generated
+ */
+ public ResourceSetInfo(IDiagramDocument document, IEditorInput editorInput) {
+ super(document);
+ myDocument = document;
+ myEditorInput = editorInput;
+ startResourceListening();
+ myResourceSetListener = new ResourceSetModificationListener(this);
+ getResourceSet().eAdapters().add(myResourceSetListener);
+ }
+
+ /**
+ * @generated
+ */
+ public long getModificationStamp() {
+ return myModificationStamp;
+ }
+
+ /**
+ * @generated
+ */
+ public void setModificationStamp(long modificationStamp) {
+ myModificationStamp = modificationStamp;
+ }
+
+ /**
+ * @generated
+ */
+ public TransactionalEditingDomain getEditingDomain() {
+ return myDocument.getEditingDomain();
+ }
+
+ /**
+ * @generated
+ */
+ public ResourceSet getResourceSet() {
+ return getEditingDomain().getResourceSet();
+ }
+
+ /**
+ * @generated
+ */
+ public IEditorInput getEditorInput() {
+ return myEditorInput;
+ }
+
+ /**
+ * @generated
+ */
+ public void dispose() {
+ stopResourceListening();
+ getResourceSet().eAdapters().remove(myResourceSetListener);
+ for(Iterator it = getResourceSet().getResources().iterator(); it.hasNext();) {
+ Resource resource = (Resource)it.next();
+ // Do not unload the resource because the DocumentProvider can be disposed while its
+ // Diagram node is
+ // kept for future re-openeing.
+ // resource.unload();
+ }
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isSynchronized() {
+ return myUnSynchronizedResources.size() == 0;
+ }
+
+ /**
+ * @generated
+ */
+ public void setUnSynchronized(Resource resource) {
+ myUnSynchronizedResources.add(resource);
+ }
+
+ /**
+ * @generated
+ */
+ public void setSynchronized(Resource resource) {
+ myUnSynchronizedResources.remove(resource);
+ }
+
+ /**
+ * @generated
+ */
+ public final void stopResourceListening() {
+ // mySynchronizer.dispose();
+ mySynchronizer = null;
+ }
+
+ /**
+ * @generated
+ */
+ public final void startResourceListening() {
+ // Do not listen because all document use the same EditingDomain
+ // mySynchronizer = new WorkspaceSynchronizer(getEditingDomain(), new
+ // SynchronizerDelegate());
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isUpdateCache() {
+ return myUpdateCache;
+ }
+
+ /**
+ * @generated
+ */
+ public void setUpdateCache(boolean update) {
+ myUpdateCache = update;
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isModifiable() {
+ return myModifiable;
+ }
+
+ /**
+ * @generated
+ */
+ public void setModifiable(boolean modifiable) {
+ myModifiable = modifiable;
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isReadOnly() {
+ return myReadOnly;
+ }
+
+ /**
+ * @generated
+ */
+ public void setReadOnly(boolean readOnly) {
+ myReadOnly = readOnly;
+ }
+
+ /**
+ * @generated
+ */
+ private class SynchronizerDelegate implements WorkspaceSynchronizer.Delegate {
+
+ /**
+ * @generated
+ */
+ public void dispose() {
+ }
+
+ /**
+ * @generated
+ */
+ public boolean handleResourceChanged(final Resource resource) {
+ synchronized(ResourceSetInfo.this) {
+ if(ResourceSetInfo.this.fCanBeSaved) {
+ ResourceSetInfo.this.setUnSynchronized(resource);
+ return true;
+ }
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ handleElementChanged(ResourceSetInfo.this, resource, null);
+ }
+ });
+ return true;
+ }
+
+ /**
+ * @generated
+ */
+ public boolean handleResourceDeleted(Resource resource) {
+ synchronized(ResourceSetInfo.this) {
+ if(ResourceSetInfo.this.fCanBeSaved) {
+ ResourceSetInfo.this.setUnSynchronized(resource);
+ return true;
+ }
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ fireElementDeleted(ResourceSetInfo.this.getEditorInput());
+ }
+ });
+ return true;
+ }
+
+ /**
+ * @generated
+ */
+ public boolean handleResourceMoved(Resource resource, final URI newURI) {
+ synchronized(ResourceSetInfo.this) {
+ if(ResourceSetInfo.this.fCanBeSaved) {
+ ResourceSetInfo.this.setUnSynchronized(resource);
+ return true;
+ }
+ }
+ if(myDocument.getDiagram().eResource() == resource) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ handleElementMoved(ResourceSetInfo.this.getEditorInput(), newURI);
+ }
+ });
+ } else {
+ handleResourceDeleted(resource);
+ }
+ return true;
+ }
+
+ }
+
+ }
+
+ /**
+ * @generated
+ */
+ private class ResourceSetModificationListener extends EContentAdapter {
+
+ /**
+ * @generated
+ */
+ private NotificationFilter myModifiedFilter;
+
+ /**
+ * @generated
+ */
+ private ResourceSetInfo myInfo;
+
+ /**
+ * @generated
+ */
+ public ResourceSetModificationListener(ResourceSetInfo info) {
+ myInfo = info;
+ myModifiedFilter = NotificationFilter.createEventTypeFilter(Notification.SET).or(
+ NotificationFilter.createEventTypeFilter(Notification.UNSET)).and(
+ NotificationFilter.createFeatureFilter(Resource.class, Resource.RESOURCE__IS_MODIFIED));
+ }
+
+ /**
+ * @generated
+ */
+ public void notifyChanged(Notification notification) {
+ if(notification.getNotifier() instanceof ResourceSet) {
+ super.notifyChanged(notification);
+ }
+ if(!notification.isTouch() && myModifiedFilter.matches(notification)) {
+ if(notification.getNotifier() instanceof Resource) {
+ Resource resource = (Resource)notification.getNotifier();
+ if(resource.isLoaded()) {
+ boolean modified = false;
+ for(Iterator it = myInfo.getResourceSet().getResources().iterator(); it.hasNext() && !modified;) {
+ Resource nextResource = (Resource)it.next();
+ if(nextResource.isLoaded()) {
+ modified = nextResource.isModified();
+ }
+ }
+ boolean dirtyStateChanged = false;
+ synchronized(myInfo) {
+ if(modified != myInfo.fCanBeSaved) {
+ myInfo.fCanBeSaved = modified;
+ dirtyStateChanged = true;
+ }
+ if(!resource.isModified()) {
+ myInfo.setSynchronized(resource);
+ }
+ }
+ if(dirtyStateChanged) {
+ fireElementDirtyStateChanged(myInfo.getEditorInput(), modified);
+
+ if(!modified) {
+ myInfo.setModificationStamp(computeModificationStamp(myInfo));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Return the editingDomain
+ */
+ public EditingDomain getEditingDomain() {
+ if(sharedEditingDomain == null) {
+ createEditingDomain();
+ }
+ return sharedEditingDomain;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Messages.java
new file mode 100644
index 00000000000..c3a6797ccf9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/Messages.java
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @generated
+ */
+public class Messages extends NLS {
+
+ /**
+ * @generated
+ */
+ static {
+ NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
+ }
+
+ /**
+ * @generated
+ */
+ private Messages() {
+ }
+
+ public static String MultiPagesEditorActionBarContributor_PapyrusMenu;
+
+ public static String AbstractPapyrusGmfCreateDiagramCommandHandler_CreateDiagramCommandLabel;
+
+ public static String AbstractPapyrusGmfCreateDiagramCommandHandler_NewDiagramName;
+
+ public static String AbstractPapyrusGmfCreateDiagramCommandHandler_NotSupportedEditor;
+
+ public static String AbstractPapyrusGmfCreateDiagramCommandHandler_SelectNewDiagramName;
+
+ public static String AbstractPapyrusGmfCreateDiagramCommandHandler_UnableCreateModelAndDiagram;
+
+ public static String GmfEditorFactory_ErrorCreatingEditorPart;
+
+ public static String GmfEditorFactory_ErrorRetrievingDiagram;
+
+ public static String GmfMultiDiagramDocumentProvider_isModifiable;
+
+ public static String GmfMultiDiagramDocumentProvider_handleElementContentChanged;
+
+ public static String GmfMultiDiagramDocumentProvider_IncorrectInputError;
+
+ public static String GmfMultiDiagramDocumentProvider_NoDiagramInResourceError;
+
+ public static String GmfMultiDiagramDocumentProvider_DiagramLoadingError;
+
+ public static String GmfMultiDiagramDocumentProvider_UnsynchronizedFileSaveError;
+
+ public static String GmfMultiDiagramDocumentProvider_SaveDiagramTask;
+
+ public static String GmfMultiDiagramDocumentProvider_SaveNextResourceTask;
+
+ public static String GmfMultiDiagramDocumentProvider_SaveAsOperation;
+
+ public static String ModelManagerEditor_SavingDeletedFile;
+
+ public static String ModelManagerEditor_SaveAsErrorTitle;
+
+ public static String ModelManagerEditor_SaveAsErrorMessage;
+
+ public static String ModelManagerEditor_SaveErrorTitle;
+
+ public static String ModelManagerEditor_SaveErrorMessage;
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/ModelManagerEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/ModelManagerEditor.java
new file mode 100644
index 00000000000..f1e898f02ae
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/ModelManagerEditor.java
@@ -0,0 +1,594 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import java.beans.PropertyChangeSupport;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.MEditingDomainElement;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.l10n.EditorMessages;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorMatchingStrategy;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+import org.eclipse.ui.part.FileEditorInput;
+import org.osgi.framework.Bundle;
+
+/**
+ * This class is used as an model manager for regular GMF Editor. All editor capabilities are
+ * neutralize, except the model load and save capabilities.
+ *
+ * @author dumoulin
+ *
+ */
+public class ModelManagerEditor {
+
+ public static final String DIAGRAM_ADDED = "DIAGRAM_ADDED"; //$NON-NLS-1$
+
+ public static final String DIAGRAM_MOVED = "DIAGRAM_MOVED"; //$NON-NLS-1$
+
+ public static final String DIAGRAM_REMOVED = "DIAGRAM_REMOVED"; //$NON-NLS-1$
+
+ /**
+ * The underlying document provider.
+ */
+ protected IDocumentProvider documentProvider;
+
+ /**
+ * EditorInput provided when the editor is created.
+ */
+ protected IEditorInput editorInput;
+
+ protected IEditorSite site;
+
+ /**
+ * Listener on diagram added/removed.
+ */
+ private PropertyChangeSupport diagramListListener = new PropertyChangeSupport(this);
+
+ /**
+ * Adapter listening to diagram addition/remove events
+ */
+ private Adapter adapter = new Adapter() {
+
+ Notifier notifier;
+
+ public Notifier getTarget() {
+ return notifier;
+ }
+
+ public boolean isAdapterForType(Object type) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /**
+ * Notifies that a change to some feature has occurred.
+ *
+ * @param notification
+ * a description of the change.
+ */
+ public void notifyChanged(Notification notification) {
+ // System.out.println("notifyChanged("+ notification +")");
+ // System.out.println("getEventType=" + notification.getEventType() );
+ // System.out.println("getFeature=" + notification.getFeature() );
+ // System.out.println("getNotifier=" + notification.getNotifier() );
+
+ int eventType = notification.getEventType();
+ if(eventType == Notification.ADD) {
+ Object newValue = notification.getNewValue();
+ if(newValue instanceof Diagram)
+ diagramListListener.firePropertyChange(DIAGRAM_ADDED, null, newValue);
+ } else if(eventType == Notification.MOVE) {
+ Object newValue = notification.getNewValue();
+ if(newValue instanceof Diagram)
+ diagramListListener.firePropertyChange(DIAGRAM_MOVED, null, newValue);
+
+ } else if(eventType == Notification.REMOVE) {
+ Object newValue = notification.getNewValue();
+ if(newValue == null)
+ Activator.log.debug(getClass().getName() + "- Warning: can't get removed object."); //$NON-NLS-1$
+
+ if(newValue instanceof Diagram)
+ diagramListListener.firePropertyChange(DIAGRAM_REMOVED, null, newValue);
+ }
+ }
+
+ public void setTarget(Notifier newTarget) {
+ notifier = newTarget;
+
+ }
+
+ };
+
+ /**
+ * @param hasFlyoutPalette
+ */
+ public ModelManagerEditor(IDocumentProvider documentProvider) {
+ this.documentProvider = documentProvider;
+ }
+
+ public IDocumentProvider getDocumentProvider() {
+ return documentProvider;
+ }
+
+ /**
+ *
+ */
+ public TransactionalEditingDomain getEditingDomain() {
+ IDocument document = getEditorInput() != null ? getDocumentProvider().getDocument(getEditorInput()) : null;
+ if(document instanceof IDiagramDocument) {
+ return ((IDiagramDocument)document).getEditingDomain();
+ }
+ return getEditorInput() instanceof MEditingDomainElement ? ((MEditingDomainElement)getEditorInput())
+ .getEditingDomain() : null;
+ }
+
+ /**
+ * @cdm
+ */
+ public void setInput(IEditorInput input) {
+ Activator.log.debug(this + ".setInput(IEditorInput input)"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @param site
+ * @param input
+ * @throws PartInitException
+ */
+ public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+ // System.out.println(this + ".init(IEditorSite site, IEditorInput input)");
+ this.editorInput = input;
+ this.site = site;
+ try {
+ getDocumentProvider().connect(input);
+ } catch (CoreException x) {
+ // code from DiagramDocumentEditor.setInput(IEditorInput)
+ String title = EditorMessages.Editor_error_setinput_title;
+ String msg = EditorMessages.Editor_error_setinput_message;
+ Shell shell = site.getShell();
+ ErrorDialog.openError(shell, title, msg, x.getStatus());
+ }
+ }
+
+ /**
+ * Returns diagram list listener. This listener send event whenever a diagram is added or
+ * removed to the eResource.
+ *
+ * @return the listener
+ */
+ public PropertyChangeSupport getDiagramListListener() {
+ return diagramListListener;
+ }
+
+ /**
+ * Called when the editor should be activated. Subclass should implements this method to
+ * register listeners to the model.
+ *
+ */
+ public void activate() {
+ getNotationModelEResource().eAdapters().add(adapter);
+
+ }
+
+ /**
+ * Called when the editor is deactivated.
+ *
+ */
+ public void deactivate() {
+ getNotationModelEResource().eAdapters().remove(adapter);
+ }
+
+ private Resource getNotationModelEResource() {
+ // Get the default diagram document
+ DiagramDocument document = (DiagramDocument)getDocumentProvider().getDocument(getEditorInput());
+ Diagram diagram = document.getDiagram();
+
+ return diagram.eResource();
+ }
+
+ /**
+ * Get the resource for notation model.
+ *
+ * @return
+ */
+ public Resource getNotationResource() {
+ return getNotationModelEResource();
+ }
+
+ /**
+ * Get the resource for the domain model.
+ *
+ * @return
+ */
+ public Resource getDomainResource() {
+ // Get the default diagram document
+ DiagramDocument document = (DiagramDocument)getDocumentProvider().getDocument(getEditorInput());
+ Diagram diagram = document.getDiagram();
+
+ EObject rootObject = diagram.getElement();
+ return rootObject.eResource();
+ }
+
+ /**
+ * @return the editorInput
+ */
+ public IEditorInput getEditorInput() {
+ return editorInput;
+ }
+
+ /**
+ * The <code>AbstractDiagramEditor</code> implementation of this <code>IEditorPart</code> method
+ * may be extended by subclasses.
+ *
+ * @param progressMonitor
+ * the progress monitor for communicating result state or <code>null</code>
+ */
+ public void doSave(IProgressMonitor progressMonitor) {
+
+ IDocumentProvider p = getDocumentProvider();
+ if(p == null)
+ return;
+
+ if(p.isDeleted(getEditorInput())) {
+
+ if(isSaveAsAllowed()) {
+
+ /*
+ * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the editors. Changed
+ * Behavior to make sure that if called inside a regular save (because of deletion
+ * of input element) there is a way to report back to the caller.
+ */
+ performSaveAs(progressMonitor);
+
+ } else {
+
+ Shell shell = getSite().getShell();
+ String title = EditorMessages.Editor_error_save_deleted_title;
+ String msg = EditorMessages.Editor_error_save_deleted_message;
+ MessageDialog.openError(shell, title, msg);
+ }
+
+ } else {
+ updateState(getEditorInput());
+ validateState(getEditorInput());
+ performSave(false, progressMonitor);
+ }
+ }
+
+ /**
+ * Updates the state of the given editor input such as read-only flag.
+ *
+ * @param input
+ * the input to be validated
+ *
+ */
+ protected void updateState(IEditorInput input) {
+ IDocumentProvider provider = getDocumentProvider();
+ try {
+
+ provider.updateStateCache(input);
+
+ // if (getDiagramEditPart() != null) {
+ // if(isEditable())
+ // getDiagramEditPart().enableEditMode();
+ // else
+ // getDiagramEditPart().disableEditMode();
+ // }
+
+ } catch (CoreException x) {
+ Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
+ ILog log = Platform.getLog(bundle);
+ log.log(x.getStatus());
+ }
+ }
+
+ /**
+ * Validates the state of the given editor input. The predominate intent of this method is to
+ * take any action probably necessary to ensure that the input can persistently be changed.
+ *
+ * @param input
+ * the input to be validated
+ *
+ */
+ protected void validateState(IEditorInput input) {
+
+ IDocumentProvider provider = getDocumentProvider();
+
+ try {
+
+ provider.validateState(input, getSite().getShell());
+
+ } catch (CoreException x) {
+ IStatus status = x.getStatus();
+ if(status == null || status.getSeverity() != IStatus.CANCEL) {
+ Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
+ ILog log = Platform.getLog(bundle);
+ log.log(x.getStatus());
+
+ Shell shell = getSite().getShell();
+ String title = EditorMessages.Editor_error_validateEdit_title;
+ String msg = EditorMessages.Editor_error_validateEdit_message;
+ ErrorDialog.openError(shell, title, msg, x.getStatus());
+ }
+ return;
+ }
+
+ // if (getDiagramEditPart() != null) {
+ // if(isEditable())
+ // getDiagramEditPart().enableEditMode();
+ // else
+ // getDiagramEditPart().disableEditMode();
+ // }
+
+ }
+
+ /**
+ * @generated
+ */
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ /**
+ * @generated
+ */
+ public void doSaveAs() {
+ performSaveAs(new NullProgressMonitor());
+ }
+
+ /**
+ * Performs the save and handles errors appropriately.
+ *
+ * @param overwrite
+ * indicates whether or not overwriting is allowed
+ * @param progressMonitor
+ * the monitor in which to run the operation
+ *
+ */
+ protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) {
+
+ IDocumentProvider provider = getDocumentProvider();
+ if(provider == null)
+ return;
+
+ try {
+
+ provider.aboutToChange(getEditorInput());
+ IEditorInput input = getEditorInput();
+ provider.saveDocument(progressMonitor, input, getDocumentProvider().getDocument(input), overwrite);
+ // editorSaved();
+
+ } catch (CoreException x) {
+ IStatus status = x.getStatus();
+ if(status == null || status.getSeverity() != IStatus.CANCEL)
+ handleExceptionOnSave(x, progressMonitor);
+ } finally {
+ provider.changed(getEditorInput());
+ }
+ }
+
+ /**
+ * @generated
+ */
+ protected void performSaveAs(IProgressMonitor progressMonitor) {
+ Shell shell = getSite().getShell();
+ IEditorInput input = getEditorInput();
+ SaveAsDialog dialog = new SaveAsDialog(shell);
+ IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput)input).getFile() : null;
+ if(original != null) {
+ dialog.setOriginalFile(original);
+ }
+ dialog.create();
+ IDocumentProvider provider = getDocumentProvider();
+ if(provider == null) {
+ // editor has been programmatically closed while the dialog was open
+ return;
+ }
+ if(provider.isDeleted(input) && original != null) {
+ String message = NLS.bind(Messages.ModelManagerEditor_SavingDeletedFile, original.getName());
+ dialog.setErrorMessage(null);
+ dialog.setMessage(message, IMessageProvider.WARNING);
+ }
+ if(dialog.open() == Window.CANCEL) {
+ if(progressMonitor != null) {
+ progressMonitor.setCanceled(true);
+ }
+ return;
+ }
+ IPath filePath = dialog.getResult();
+ if(filePath == null) {
+ if(progressMonitor != null) {
+ progressMonitor.setCanceled(true);
+ }
+ return;
+ }
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IFile file = workspaceRoot.getFile(filePath);
+ final IEditorInput newInput = new FileEditorInput(file);
+ // Check if the editor is already open
+ IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
+ IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getEditorReferences();
+ for(int i = 0; i < editorRefs.length; i++) {
+ if(matchingStrategy.matches(editorRefs[i], newInput)) {
+ MessageDialog.openWarning(shell, Messages.ModelManagerEditor_SaveAsErrorTitle,
+ Messages.ModelManagerEditor_SaveAsErrorMessage);
+ return;
+ }
+ }
+ boolean success = false;
+ try {
+ provider.aboutToChange(newInput);
+ // getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
+ // getDocumentProvider().getDocument(getEditorInput()), true);
+ getDocumentProvider().saveDocument(progressMonitor, newInput,
+ getDocumentProvider().getDocument(getEditorInput()), true);
+ success = true;
+ } catch (CoreException x) {
+ IStatus status = x.getStatus();
+ if(status == null || status.getSeverity() != IStatus.CANCEL) {
+ ErrorDialog.openError(shell, Messages.ModelManagerEditor_SaveErrorTitle,
+ Messages.ModelManagerEditor_SaveErrorMessage, x.getStatus());
+ }
+ } finally {
+ provider.changed(newInput);
+ if(success) {
+ setInput(newInput);
+ }
+ }
+ if(progressMonitor != null) {
+ progressMonitor.setCanceled(!success);
+ }
+ }
+
+ /**
+ * Retrieves the descriptor for this editor
+ *
+ * @return the editor descriptor
+ */
+ final protected IEditorDescriptor getEditorDescriptor() {
+ IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
+ IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
+ return editorDesc;
+ }
+
+ /**
+ * The number of re-entrances into error correction code while saving.
+ *
+ */
+ private int fErrorCorrectionOnSave;
+
+ /**
+ * Handles the given exception. If the exception reports an out-of-sync situation, this is
+ * reported to the user. Otherwise, the exception is generically reported.
+ *
+ * @param exception
+ * the exception to handle
+ * @param progressMonitor
+ * the progress monitor
+ */
+ protected void handleExceptionOnSave(CoreException exception, IProgressMonitor progressMonitor) {
+
+ try {
+ ++fErrorCorrectionOnSave;
+
+ Shell shell = getSite().getShell();
+
+ boolean isSynchronized = false;
+ IDocumentProvider p = getDocumentProvider();
+
+ isSynchronized = p.isSynchronized(getEditorInput());
+
+ if(isNotSynchronizedException(exception) && fErrorCorrectionOnSave == 1 && !isSynchronized) {
+ String title = EditorMessages.Editor_error_save_outofsync_title;
+ String msg = EditorMessages.Editor_error_save_outofsync_message;
+
+ if(MessageDialog.openQuestion(shell, title, msg))
+ performSave(true, progressMonitor);
+ else {
+ /*
+ * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits Set progress
+ * monitor to canceled in order to report back to enclosing operations.
+ */
+ if(progressMonitor != null)
+ progressMonitor.setCanceled(true);
+ }
+ } else {
+ String title = EditorMessages.Editor_error_save_title;
+ String msg = EditorMessages.Editor_error_save_message;
+ ErrorDialog.openError(shell, title, msg, exception.getStatus());
+
+ /*
+ * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits Set progress monitor
+ * to canceled in order to report back to enclosing operations.
+ */
+ if(progressMonitor != null)
+ progressMonitor.setCanceled(true);
+ }
+ } finally {
+ --fErrorCorrectionOnSave;
+ }
+ }
+
+ /**
+ * Tells whether the given core exception is exactly the exception which is thrown for a
+ * non-synchronized element.
+ * <p>
+ * XXX: After 3.1 this method must be delegated to the document provider see
+ * </p>
+ *
+ * @param ex
+ * the core exception
+ * @return <code>true</code> iff the given core exception is exactly the exception which is
+ * thrown for a non-synchronized element
+ *
+ */
+ private boolean isNotSynchronizedException(CoreException ex) {
+ if(ex == null)
+ return false;
+
+ IStatus status = ex.getStatus();
+ if(status == null || status instanceof MultiStatus)
+ return false;
+
+ if(status.getException() != null)
+ return false;
+
+ // Can't access IResourceStatus.OUT_OF_SYNC_LOCAL, using value: 274
+ return status.getCode() == 274;
+ }
+
+ /**
+ * @return the site
+ */
+ public IEditorSite getSite() {
+ return site;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SemanticFromGMFElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SemanticFromGMFElement.java
new file mode 100644
index 00000000000..d1b1fc795f3
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SemanticFromGMFElement.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.papyrus.infra.core.IElementWithSemantic;
+
+/**
+ * this class is used to obtain the semantic element for element of a gmf diagram
+ *
+ */
+public class SemanticFromGMFElement implements IElementWithSemantic {
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.IElementWithSemantic#getSemanticElement(java.lang.Object)
+ *
+ * @param wrapper can be for examplean editpart of gmf
+ * @return the semantic element linked to this or null element
+ */
+ public Object getSemanticElement(Object wrapper) {
+ if(wrapper instanceof IGraphicalEditPart){
+ return ((IGraphicalEditPart)wrapper).resolveSemanticElement();
+ }
+ if( wrapper instanceof IAdaptable){
+ return ((IAdaptable)wrapper).getAdapter(EObject.class);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SynchronizableGmfDiagramEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SynchronizableGmfDiagramEditor.java
new file mode 100644
index 00000000000..4b553193a58
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/SynchronizableGmfDiagramEditor.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl;
+import org.eclipse.gef.DefaultEditDomain;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
+import org.eclipse.papyrus.commands.CheckedDiagramCommandStack;
+import org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement;
+
+/**
+ /**
+ *
+ * This GMF editor contains a methods in order to reveal visual element from a list of semantic element.
+ *
+ */
+
+public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor implements IRevealSemanticElement {
+
+ public SynchronizableGmfDiagramEditor(boolean hasFlyoutPalette) {
+ super(hasFlyoutPalette);
+ }
+
+
+ /**
+ * reveal all editpart that represent an element in the given list.
+ * @see org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement#revealSemanticElement(java.util.List)
+ *
+ */
+ public void revealSemanticElement(List<?> elementList) {
+ //create an instance that can get semantic element from gmf
+ SemanticFromGMFElement semanticFromGMFElement= new SemanticFromGMFElement();
+
+ // get the graphical viewer
+ GraphicalViewer graphicalViewer =getGraphicalViewer() ;
+ if( graphicalViewer!=null){
+
+ //look for among all edit part if the semantic is contained in the list
+ Iterator<?> iter=graphicalViewer.getEditPartRegistry().values().iterator();
+ IGraphicalEditPart researchedEditPart=null;
+ while(iter.hasNext()&& researchedEditPart==null) {
+ Object currentEditPart = (Object)iter.next();
+ //look for only among IPrimary editpart to avoid compartment and labels of links
+ if(currentEditPart instanceof IPrimaryEditPart){
+ if(elementList.contains(semanticFromGMFElement.getSemanticElement(currentEditPart))){
+ researchedEditPart=((IGraphicalEditPart)currentEditPart);}
+ }
+
+ }
+ //an editpart has been found so put selection on it.
+ if(researchedEditPart!=null){
+ graphicalViewer.select(researchedEditPart);
+ }
+ }
+ }
+
+ /**
+ * Configures my diagram edit domain with its command stack.
+ * This method has been completely overridden in order to use a proxy stack.
+ */
+ @Override
+ protected void configureDiagramEditDomain() {
+
+ DefaultEditDomain editDomain = getEditDomain();
+
+ if(editDomain != null) {
+ CommandStack stack = editDomain.getCommandStack();
+ if(stack != null) {
+ // dispose the old stack
+ stack.dispose();
+ }
+
+ // create and assign the new stack
+ CheckedDiagramCommandStack diagramStack = new CheckedDiagramCommandStack(getDiagramEditDomain());
+
+ editDomain.setCommandStack(diagramStack);
+ }
+
+ DiagramEditDomain diagEditDomain = (DiagramEditDomain)getDiagramEditDomain();
+ diagEditDomain.setActionManager(createActionManager());
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/UMLDiagramEditorUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/UMLDiagramEditorUtil.java
new file mode 100644
index 00000000000..29d549ca7a6
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/core/adaptor/gmf/UMLDiagramEditorUtil.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.adaptor.gmf;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+
+/**
+ * @generated
+ */
+public class UMLDiagramEditorUtil {
+
+ /**
+ * @generated
+ */
+ public static Map getSaveOptions() {
+ Map saveOptions = new HashMap();
+ saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+ saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
+ return saveOptions;
+ }
+
+}

Back to the top