summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-06-02 09:32:57 (EDT)
committerBenoit Maggi2014-06-02 09:32:57 (EDT)
commit4e6a7b333a21383e116854aa14bcdf86155c2059 (patch)
tree04e7bd703267186ad7995fcfa8b4e25da3b35e92
parent91223cdd788217a737501d5450c27b537983935f (diff)
downloadorg.eclipse.papyrus-4e6a7b333a21383e116854aa14bcdf86155c2059.zip
org.eclipse.papyrus-4e6a7b333a21383e116854aa14bcdf86155c2059.tar.gz
org.eclipse.papyrus-4e6a7b333a21383e116854aa14bcdf86155c2059.tar.bz2
Bug 365888 - [General] The copy/paste should be proposed with or withoutrefs/changes/19/27719/1
reference - merge the 2 messages.properties in one file - externalize string for paste preferences - add a combo box to choose to keep or not external references during copy Change-Id: I8311a4182689940a29628296d8785d318406f612 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-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.xml6
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java1
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java477
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfMultiDiagramDocumentProvider.java2317
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/Messages.java80
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/ModelManagerEditor.java1189
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java5
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java5
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/Messages.java150
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/messages.properties72
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferenceInitializer.java38
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferencesPage.java31
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java7
14 files changed, 2224 insertions, 2176 deletions
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
deleted file mode 100644
index 17dfa06..0000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/messages.properties
+++ /dev/null
@@ -1,22 +0,0 @@
-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.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
index e63fe12..07bbb44 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -299,4 +299,10 @@
strategy="org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DiagramPasteStrategy">
</strategy>
</extension>
+<extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferenceInitializer">
+ </initializer>
+</extension>
</plugin>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
index d00760e..0edd1e3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
@@ -52,6 +52,7 @@ import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.papyrus.infra.gmfdiag.common.messages.Messages;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.infra.services.edit.Activator;
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java
index 7774c4e..a8d5a0a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfEditorFactory.java
@@ -1,238 +1,239 @@
-/*****************************************************************************
- * Copyright (c) 2008, 2014 LIFL, CEA LIST, and others.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- * Christian W. Damus (CEA) - service hook for integrating tools into graphical editor (CDO)
- * Christian W. Damus (CEA) - bug 392301
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common;
-
-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.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
-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;
-
- private Image tabIcon;
-
- /**
- *
- * 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);
-
- IGraphicalEditorSupport editorSupport = servicesRegistry.getService(IGraphicalEditorSupport.class);
- editorSupport.initialize(editor);
-
- 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() {
- if(tabIcon == null) {
- ImageDescriptor imageDescriptor = DiagramUtils.getPrototype(diagram).getIconDescriptor();
- if(imageDescriptor != null) {
- tabIcon = imageDescriptor.createImage();
- }
- }
-
- return tabIcon;
- }
-
- /**
- * Get the title of the Diagram.
- *
- * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabTitle()
- * @return
- *
- */
- public String getTabTitle() {
- return diagram.getName();
- }
-
- @Override
- public void dispose() {
- if(tabIcon != null) {
- tabIcon.dispose();
- tabIcon = null;
- }
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 2014 LIFL, CEA LIST, and others.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - service hook for integrating tools into graphical editor (CDO)
+ * Christian W. Damus (CEA) - bug 392301
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common;
+
+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.papyrus.infra.gmfdiag.common.messages.Messages;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+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;
+
+ private Image tabIcon;
+
+ /**
+ *
+ * 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);
+
+ IGraphicalEditorSupport editorSupport = servicesRegistry.getService(IGraphicalEditorSupport.class);
+ editorSupport.initialize(editor);
+
+ 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() {
+ if(tabIcon == null) {
+ ImageDescriptor imageDescriptor = DiagramUtils.getPrototype(diagram).getIconDescriptor();
+ if(imageDescriptor != null) {
+ tabIcon = imageDescriptor.createImage();
+ }
+ }
+
+ return tabIcon;
+ }
+
+ /**
+ * Get the title of the Diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabTitle()
+ * @return
+ *
+ */
+ public String getTabTitle() {
+ return diagram.getName();
+ }
+
+ @Override
+ public void dispose() {
+ if(tabIcon != null) {
+ tabIcon.dispose();
+ tabIcon = null;
+ }
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfMultiDiagramDocumentProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfMultiDiagramDocumentProvider.java
index 2a55764..57c1559 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfMultiDiagramDocumentProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/GmfMultiDiagramDocumentProvider.java
@@ -1,1158 +1,1159 @@
-/*****************************************************************************
- * 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.gmfdiag.common;
-
-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 not
- */
- public ResourceSetInfo(IDiagramDocument document, IEditorInput editorInput) {
- super(document);
- myDocument = document;
- myEditorInput = editorInput;
- startResourceListening();
- for (Adapter a : getResourceSet().eAdapters()){
- if (a instanceof ResourceSetModificationListener){
- myResourceSetListener = (ResourceSetModificationListener) a ;
- break;
- }
- }
- if (myResourceSetListener == null){
- myResourceSetListener = new ResourceSetModificationListener();
- getResourceSet().eAdapters().add(myResourceSetListener);
- }
- myResourceSetListener.addResourceSet(this);
- }
-
- /**
- * @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();
- myResourceSetListener.removeResourceSet(this);
- if(myResourceSetListener.isEmpty()){
- 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 not
- */
- private class ResourceSetModificationListener extends EContentAdapter {
-
- /**
- * @generated
- */
- private NotificationFilter myModifiedFilter;
-
- /**
- * @generated not
- */
- private List<ResourceSetInfo> myInfos;
-
- /**
- * @generated not
- */
- public ResourceSetModificationListener() {
- myInfos = new ArrayList<GmfMultiDiagramDocumentProvider.ResourceSetInfo>();
- myModifiedFilter = NotificationFilter.createEventTypeFilter(Notification.SET).or(
- NotificationFilter.createEventTypeFilter(Notification.UNSET)).and(
- NotificationFilter.createFeatureFilter(Resource.class, Resource.RESOURCE__IS_MODIFIED));
- }
-
- public void addResourceSet(ResourceSetInfo info) {
- myInfos.add(info);
- }
-
- public boolean removeResourceSet(ResourceSetInfo info){
- return myInfos.remove(info);
- }
-
- public boolean isEmpty(){
- return myInfos.isEmpty();
- }
-
- /**
- * @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 = resource.getResourceSet().getResources().iterator(); it.hasNext() && !modified;) {
- Resource nextResource = (Resource)it.next();
- if(nextResource.isLoaded()) {
- modified = nextResource.isModified();
- }
- }
- for(ResourceSetInfo myInfo : myInfos){
- 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;
- }
-
-}
+/*****************************************************************************
+ * 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.gmfdiag.common;
+
+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.papyrus.infra.gmfdiag.common.messages.Messages;
+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 not
+ */
+ public ResourceSetInfo(IDiagramDocument document, IEditorInput editorInput) {
+ super(document);
+ myDocument = document;
+ myEditorInput = editorInput;
+ startResourceListening();
+ for (Adapter a : getResourceSet().eAdapters()){
+ if (a instanceof ResourceSetModificationListener){
+ myResourceSetListener = (ResourceSetModificationListener) a ;
+ break;
+ }
+ }
+ if (myResourceSetListener == null){
+ myResourceSetListener = new ResourceSetModificationListener();
+ getResourceSet().eAdapters().add(myResourceSetListener);
+ }
+ myResourceSetListener.addResourceSet(this);
+ }
+
+ /**
+ * @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();
+ myResourceSetListener.removeResourceSet(this);
+ if(myResourceSetListener.isEmpty()){
+ 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 not
+ */
+ private class ResourceSetModificationListener extends EContentAdapter {
+
+ /**
+ * @generated
+ */
+ private NotificationFilter myModifiedFilter;
+
+ /**
+ * @generated not
+ */
+ private List<ResourceSetInfo> myInfos;
+
+ /**
+ * @generated not
+ */
+ public ResourceSetModificationListener() {
+ myInfos = new ArrayList<GmfMultiDiagramDocumentProvider.ResourceSetInfo>();
+ myModifiedFilter = NotificationFilter.createEventTypeFilter(Notification.SET).or(
+ NotificationFilter.createEventTypeFilter(Notification.UNSET)).and(
+ NotificationFilter.createFeatureFilter(Resource.class, Resource.RESOURCE__IS_MODIFIED));
+ }
+
+ public void addResourceSet(ResourceSetInfo info) {
+ myInfos.add(info);
+ }
+
+ public boolean removeResourceSet(ResourceSetInfo info){
+ return myInfos.remove(info);
+ }
+
+ public boolean isEmpty(){
+ return myInfos.isEmpty();
+ }
+
+ /**
+ * @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 = resource.getResourceSet().getResources().iterator(); it.hasNext() && !modified;) {
+ Resource nextResource = (Resource)it.next();
+ if(nextResource.isLoaded()) {
+ modified = nextResource.isModified();
+ }
+ }
+ for(ResourceSetInfo myInfo : myInfos){
+ 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/gmfdiag/common/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/Messages.java
deleted file mode 100644
index 5a6c827..0000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/Messages.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*****************************************************************************
- * 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.gmfdiag.common;
-
-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/gmfdiag/common/ModelManagerEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/ModelManagerEditor.java
index 58f2881..e6ec658 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/ModelManagerEditor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/ModelManagerEditor.java
@@ -1,594 +1,595 @@
-/*****************************************************************************
- * 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.gmfdiag.common;
-
-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;
- }
-
-}
+/*****************************************************************************
+ * 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.gmfdiag.common;
+
+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.papyrus.infra.gmfdiag.common.messages.Messages;
+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/gmfdiag/common/commands/DefaultCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
index 6a11fb2..e203862 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
@@ -20,6 +20,8 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.AbstractOverrideableCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferencesPage;
/**
* Command that puts a list of object in the clipboard, and that copy them.
@@ -45,7 +47,8 @@ public class DefaultCopyCommand extends AbstractOverrideableCommand implements N
public DefaultCopyCommand(EditingDomain domain, PapyrusClipboard papyrusClipboard, Collection<EObject> pObjectsToPutInClipboard) {
super(domain);
objectsToPutInClipboard = new ArrayList<Object>();
- EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ Boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES);
+ EcoreUtil.Copier copier = new EcoreUtil.Copier(Boolean.TRUE, keepReferences);
copier.copyAll(pObjectsToPutInClipboard);
copier.copyReferences();
papyrusClipboard.addAllInternalCopyInClipboard(copier);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
index a3bd9b4..17dc091 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
@@ -26,6 +26,8 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferencesPage;
/**
* Command that puts a list of object in the clipboard
@@ -51,7 +53,8 @@ public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand imple
public DefaultDiagramCopyCommand(EditingDomain domain, PapyrusClipboard<Object> papyrusClipboard, Collection<IGraphicalEditPart> pObjectsToPutInClipboard) {
super(domain);
objectsToPutInClipboard = new ArrayList<Object>();
- EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ Boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES);
+ EcoreUtil.Copier copier = new EcoreUtil.Copier(Boolean.TRUE, keepReferences);
List<EObject> objectToCopy = new ArrayList<EObject>();
for(IGraphicalEditPart iGraphicalEditPart : pObjectsToPutInClipboard) {
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/Messages.java
index f126166..90d05f0 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/Messages.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/Messages.java
@@ -1,49 +1,101 @@
-/****************************************
- * Copyright (c) 2013, 2014 CEA and others.
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) - Initial API and implementation
- * Christian W. Damus (CEA) - bug 323802
- *
- */
-package org.eclipse.papyrus.infra.gmfdiag.common.messages;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.gmfdiag.common.messages.messages"; //$NON-NLS-1$
-
- public static String RollbackNotificationHistoryListener_exception;
-
- public static String RollbackNotificationHistoryListener_exceptionWithCause;
-
- public static String RollbackNotificationHistoryListener_readOnly;
-
- public static String RollbackNotificationHistoryListener_readOnlyWithCause;
-
- public static String RollbackNotificationHistoryListener_title;
-
- public static String RollbackNotificationHistoryListener_unknown;
-
- public static String RollbackNotificationHistoryListener_unknownWithCause;
-
- public static String UnitsUtils_Centimeters;
-
- public static String UnitsUtils_Inches;
-
- public static String UnitsUtils_Pixels;
-
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
+/****************************************
+ * Copyright (c) 2013, 2014 CEA and others.
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 323802
+ *
+ */
+package org.eclipse.papyrus.infra.gmfdiag.common.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.gmfdiag.common.messages.messages"; //$NON-NLS-1$
+
+ public static String RollbackNotificationHistoryListener_exception;
+
+ public static String RollbackNotificationHistoryListener_exceptionWithCause;
+
+ public static String RollbackNotificationHistoryListener_readOnly;
+
+ public static String RollbackNotificationHistoryListener_readOnlyWithCause;
+
+ public static String RollbackNotificationHistoryListener_title;
+
+ public static String RollbackNotificationHistoryListener_unknown;
+
+ public static String RollbackNotificationHistoryListener_unknownWithCause;
+
+ public static String UnitsUtils_Centimeters;
+
+ public static String UnitsUtils_Inches;
+
+ public static String UnitsUtils_Pixels;
+
+ 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;
+
+ public static String PastePreferencesPage_StrategiesDescription;
+
+ public static String PastePreferencesPage_PageTitle;
+
+ public static String PastePreferencesPage_PageDescription;
+
+ public static String PastePreferencesPage_KeepReferenceDescription;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/messages.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/messages.properties
index 700f3e2..9e46fd3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/messages.properties
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/messages/messages.properties
@@ -1,23 +1,49 @@
-#
-# Copyright (c) 2013, 2014 CEA and others.
-#
-# 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:
-# Vincent Lorenzo (CEA LIST) - Initial API and implementation
-# Christian W. Damus (CEA) - bug 323802
-#
-
-RollbackNotificationHistoryListener_exception=The operation was rolled back due to an uncaught exception.
-RollbackNotificationHistoryListener_exceptionWithCause=The operation was rolled back due to an uncaught exception relating to the following objects: {0}
-RollbackNotificationHistoryListener_readOnly=The operation was rolled back because it modified read-only objects.
-RollbackNotificationHistoryListener_readOnlyWithCause=The operation was rolled back because it modified read-only objects: {0}
-RollbackNotificationHistoryListener_title=Operation Rolled Back
-RollbackNotificationHistoryListener_unknown=The operation was rolled back for an unknown reason.
-RollbackNotificationHistoryListener_unknownWithCause=The operation was rolled back for an unknown reason relating to the following objects: {0}
-UnitsUtils_Centimeters=Centimeters
-UnitsUtils_Inches=Inches
-UnitsUtils_Pixels=Pixels
+#
+# Copyright (c) 2013, 2014 CEA and others.
+#
+# 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:
+# Vincent Lorenzo (CEA LIST) - Initial API and implementation
+# Christian W. Damus (CEA) - bug 323802
+#
+
+RollbackNotificationHistoryListener_exception=The operation was rolled back due to an uncaught exception.
+RollbackNotificationHistoryListener_exceptionWithCause=The operation was rolled back due to an uncaught exception relating to the following objects: {0}
+RollbackNotificationHistoryListener_readOnly=The operation was rolled back because it modified read-only objects.
+RollbackNotificationHistoryListener_readOnlyWithCause=The operation was rolled back because it modified read-only objects: {0}
+RollbackNotificationHistoryListener_title=Operation Rolled Back
+RollbackNotificationHistoryListener_unknown=The operation was rolled back for an unknown reason.
+RollbackNotificationHistoryListener_unknownWithCause=The operation was rolled back for an unknown reason relating to the following objects: {0}
+UnitsUtils_Centimeters=Centimeters
+UnitsUtils_Inches=Inches
+UnitsUtils_Pixels=Pixels
+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.
+PastePreferencesPage_PageTitle=Paste preferences
+PastePreferencesPage_StrategiesDescription=Select the paste strategies you wish to activate.
+PastePreferencesPage_PageDescription=Papyrus paste configuration.
+PastePreferencesPage_KeepReferenceDescription=Keep references
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferenceInitializer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferenceInitializer.java
new file mode 100644
index 0000000..fb12b77
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferenceInitializer.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+
+/**
+ * This preference initializer initializes Papyrus paste preferences
+ */
+public class PastePreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /**
+ * Initialize default preferences
+ */
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = getPreferenceStore();
+ store.setDefault(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES, Boolean.TRUE);
+ }
+
+ /**
+ * Get the preference store
+ */
+ protected IPreferenceStore getPreferenceStore() {
+ return Activator.getInstance().getPreferenceStore();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferencesPage.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferencesPage.java
index 0183865..d4837bf 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferencesPage.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PastePreferencesPage.java
@@ -11,13 +11,14 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
-import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.messages.Messages;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.StrategyEditor;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
@@ -26,24 +27,31 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
/**
* Allow to select strategies for Papyrus paste
*/
-public class PastePreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
-
+public class PastePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ /**
+ * Keep the references
+ */
+ public final static String KEEP_EXTERNAL_REFERENCES = "KEEP_EXTERNAL_REFERENCES"; //$NON-NLS-1$
+
+ /**
+ * Editor for managing paste strategies
+ */
private StrategyEditor editor;
public PastePreferencesPage() {
- super("Paste preferences", org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"));
+ super(Messages.PastePreferencesPage_PageTitle, org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"), FLAT); //$NON-NLS-1$
}
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getInstance().getPreferenceStore());
- setDescription("Papyrus paste configuration.\nSelect the paste strategies you wish to activate.");
+ setDescription(Messages.PastePreferencesPage_PageDescription);
}
@Override
protected Control createContents(Composite parent) {
- Composite self = new Composite(parent, SWT.NONE);
- self.setLayout(new GridLayout(1, true));
- editor = new StrategyEditor(self, SWT.NONE, PasteStrategyManager.getInstance());
+ Control self = super.createContents(parent);
+ editor = new StrategyEditor((Composite)self, SWT.NONE, PasteStrategyManager.getInstance(), Messages.PastePreferencesPage_StrategiesDescription);
editor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
return self;
}
@@ -57,4 +65,9 @@ public class PastePreferencesPage extends PreferencePage implements IWorkbenchPr
super.performDefaults();
}
+ @Override
+ protected void createFieldEditors() {
+ addField(new BooleanFieldEditor(KEEP_EXTERNAL_REFERENCES, Messages.PastePreferencesPage_KeepReferenceDescription, getFieldEditorParent()));
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java
index c28050b..6857843 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/StrategyEditor.java
@@ -53,8 +53,13 @@ public class StrategyEditor extends MultipleReferenceEditor {
protected IStrategyManager instance;
+
public StrategyEditor(Composite parent, int style, IStrategyManager instance2) {
- super(parent, style, true, true, STRATEGIES);
+ this(parent, style, instance2, STRATEGIES);
+ }
+
+ public StrategyEditor(Composite parent, int style, IStrategyManager instance2, String label) {
+ super(parent, style, true, true, label);
instance = instance2;
List<IStrategy> values = getStrategyManager().getAllStrategies();