Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor')
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.classpath7
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.project28
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/META-INF/MANIFEST.MF25
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/build.properties9
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/PapyrusLogo16x16.gifbin561 -> 0 bytes
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/papyrus_compare_editor.gifbin956 -> 0 bytes
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/plugin.xml60
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/Activator.java77
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/BasicCompareAction.java262
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/FileCompareAction.java98
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusCompareEditor.java370
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelCompareActionBarContributor.java231
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelElementCompareEditorInput.java357
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcorePlatformUtil.java1982
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcoreResourceUtil.java1148
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceEditingDomainUtil.java321
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceTransactionUtil.java198
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusCompareAction.java154
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusSaveablesCompareEditorInput.java70
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalActionBarContributor.java111
-rw-r--r--sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalCompareEditor.java428
22 files changed, 0 insertions, 5944 deletions
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.classpath b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.classpath
deleted file mode 100644
index 2d1a4302f04..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.project b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.project
deleted file mode 100644
index 9bed46d4a5f..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.project
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.papyrus.emf.compare.transactional.editor</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.settings/org.eclipse.jdt.core.prefs b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index fd1db489110..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,8 +0,0 @@
-#Thu Oct 13 17:09:29 CEST 2011
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/META-INF/MANIFEST.MF b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/META-INF/MANIFEST.MF
deleted file mode 100644
index 1ea91756792..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,25 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: EMF-Compare With Command
-Bundle-SymbolicName: org.eclipse.papyrus.emf.compare.transactional.editor;singleton:=true
-Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.eclipse.papyrus.emf.compare.transactional.editor.Activator
-Bundle-Vendor: Eclipse Modeling Project
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.emf.ecore;bundle-version="2.7.0",
- org.eclipse.emf.compare;bundle-version="1.2.1",
- org.eclipse.compare;bundle-version="3.5.201",
- org.eclipse.emf.compare.diff;bundle-version="1.3.0",
- org.eclipse.emf.compare.ui,
- org.eclipse.emf.compare.match,
- org.eclipse.core.resources,
- org.eclipse.emf.transaction,
- org.eclipse.sphinx.emf.compare.ui,
- org.eclipse.sphinx.platform.ui,
- org.eclipse.sphinx.emf,
- org.eclipse.papyrus.log;bundle-version="0.8.2",
- org.eclipse.papyrus.uml.compare.ui;bundle-version="1.0.0",
- org.eclipse.pde;bundle-version="3.6.100"
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Bundle-ActivationPolicy: lazy
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/build.properties b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/build.properties
deleted file mode 100644
index 2aaf819ba36..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/build.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- plugin.xml,\
- icons/
-src.includes = icons/,\
- plugin.xml,\
- src/
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/PapyrusLogo16x16.gif b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/PapyrusLogo16x16.gif
deleted file mode 100644
index 8a31f458379..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/PapyrusLogo16x16.gif
+++ /dev/null
Binary files differ
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/papyrus_compare_editor.gif b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/papyrus_compare_editor.gif
deleted file mode 100644
index e817df6ff0c..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/icons/papyrus_compare_editor.gif
+++ /dev/null
Binary files differ
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/plugin.xml b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/plugin.xml
deleted file mode 100644
index 70dec336661..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/plugin.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension
- point="org.eclipse.ui.editors">
- <editor
- class="org.eclipse.papyrus.emf.compare.transactional.editor.PapyrusCompareEditor"
- contributorClass="org.eclipse.papyrus.emf.compare.transactional.editor.PapyrusModelCompareActionBarContributor"
- default="true"
- id="org.eclipse.papyrus.emf.compare.editor"
- name="EMF-Compare Editor With Command">
- <contentTypeBinding
- contentTypeId="org.eclipse.uml2.uml">
- </contentTypeBinding>
- </editor>
- <editor
- class="org.eclipse.papyrus.emf.compare.transactional.editor.v2.TransactionalCompareEditor"
- contributorClass="org.eclipse.papyrus.emf.compare.transactional.editor.v2.TransactionalActionBarContributor"
- default="true"
- id="org.eclipse.papyrus.emf.compare.transactional.editor"
- name="Transactional EMF-Compare Editor ">
- <contentTypeBinding
- contentTypeId="org.eclipse.uml2.uml">
- </contentTypeBinding>
- </editor>
- </extension>
- <extension
- point="org.eclipse.ui.popupMenus">
- <objectContribution
- adaptable="false"
- id="org.eclipse.papyrus.uml.compare.ui"
- objectClass="org.eclipse.core.resources.IFile">
- <action
- class="org.eclipse.papyrus.emf.compare.transactional.editor.FileCompareAction"
- enablesFor="2+"
- id="PapyrusCompareWithEachOther"
- label="Papyrus Compare"
- menubarPath="compareWithMenu/compareWithGroup"
- tooltip="Papyrus Compare">
- </action>
- </objectContribution>
- </extension>
- <extension
- point="org.eclipse.ui.popupMenus">
- <objectContribution
- adaptable="false"
- id="org.eclipse.papyrus.emf.compare.transactional.editor.objectContribution1"
- objectClass="org.eclipse.core.resources.IFile">
- <action
- class="org.eclipse.papyrus.emf.compare.transactional.editor.v2.PapyrusCompareAction"
- enablesFor="2+"
- id="org.eclipse.papyrus.emf.compare.transactional.editor.action1"
- label="Papyrus Compare Action V2"
- menubarPath="compareWithMenu/compareWithGroup"
- tooltip="Papyrus Compare V2">
- </action>
- </objectContribution>
- </extension>
-
-</plugin>
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/Activator.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/Activator.java
deleted file mode 100644
index 82704ec8c6b..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/Activator.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.eclipse.papyrus.emf.compare.transactional.editor;
-
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.papyrus.log.LogHelper;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.papyrus.emf.compare.transactional.editor"; //$NON-NLS-1$
-
- // The shared instance
- private static Activator plugin;
-
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /**
- * Returns the image from the given path.
- *
- * @param path the path the image to be displayed
- * @return the image found
- * FIXME
- */
- public static Image getImage(String path) {
- final ImageRegistry registry = getDefault().getImageRegistry();
- Image image = registry.get(path);
- if(image == null) {
- registry.put(path, Activator.imageDescriptorFromPlugin(PLUGIN_ID, path));
- image = registry.get(path);
- }
- return image;
-
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- log = new LogHelper(plugin);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
- /** The log service */
- public static LogHelper log;
-
-
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/BasicCompareAction.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/BasicCompareAction.java
deleted file mode 100644
index df31cd7c653..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/BasicCompareAction.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2010 See4sys 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:
- * See4sys - Initial API and implementation
- *
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.internal.ComparePreferencePage;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSnapshot;
-import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot;
-import org.eclipse.emf.compare.diff.metamodel.DiffFactory;
-import org.eclipse.emf.compare.diff.metamodel.DiffModel;
-import org.eclipse.emf.compare.diff.service.DiffService;
-import org.eclipse.emf.compare.match.metamodel.MatchModel;
-import org.eclipse.emf.compare.match.service.MatchService;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.emf.compare.transactional.editor.sphinx.EcorePlatformUtil;
-import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry;
-
-import org.eclipse.sphinx.platform.ui.util.ExtendedPlatformUI;
-import org.eclipse.sphinx.platform.util.PlatformLogUtil;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IReusableEditor;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.actions.BaseSelectionListenerAction;
-import org.eclipse.sphinx.emf.compare.ui.internal.messages.Messages;
-
-/**
- * Duplicate code from Sphinx
- */
-@SuppressWarnings("restriction")
-public class BasicCompareAction extends BaseSelectionListenerAction implements ISelectionChangedListener {
-
- /**
- * The comparison snapshot owning the match and diff models. This snapshot is needed in order to create the compare
- * editor input.
- */
- protected ComparisonSnapshot comparisonSnapshot;
-
- /**
- * The selected objects that must be compared.
- */
- protected List<WeakReference<EObject>> selectedObjects = null;
- /**
- * The selected files that must be compared.
- */
- protected List<WeakReference<IFile>> selectedFiles = null;
-
- /**
- * Constructor.
- */
- public BasicCompareAction() {
- //super(Messages.action_compareWithEachOther);
- super("With Each Other");
- // TODO Add action description
- // setDescription(TO BE DEFINED);
- }
-
- /**
- * @param selection
- * The selection in the viewer onto which this action should perform an operation.
- * @return <ul>
- * <li><tt><b>true</b>&nbsp;&nbsp;</tt> if compare action is available (i.e. if {@link IStructuredSelection
- * selection} matches enablement criteria);</li>
- * <li><tt><b>false</b>&nbsp;</tt> otherwise.</li>
- * </ul>
- */
- @Override
- public boolean updateSelection(IStructuredSelection selection) {
- Assert.isNotNull(selection);
-
- if (selection.size() != 2) {
- return false;
- }
-
- // Reset attributes
- comparisonSnapshot = null;
- selectedFiles = null;
- selectedObjects = null;
-
- for (Iterator<?> it = selection.iterator(); it.hasNext();) {
- Object obj = it.next();
-
- if (obj instanceof EObject) {
- if (selectedObjects == null) {
- selectedObjects = new ArrayList<WeakReference<EObject>>();
- }
- selectedObjects.add(new WeakReference<EObject>((EObject) obj));
- } else if (obj instanceof IFile) {
- IFile file = (IFile) obj;
- if (MetaModelDescriptorRegistry.INSTANCE.getDescriptor(file) != null) {
- if (selectedFiles == null) {
- selectedFiles = new ArrayList<WeakReference<IFile>>();
- }
- selectedFiles.add(new WeakReference<IFile>(file));
- }
- }
- }
- return selectedFiles != null ? selectedFiles.size() == 2 : false ^ selectedObjects != null ? selectedObjects.size() == 2 : false;
- }
-
- @Override
- public void run() {
- EObject leftObject = null;
- EObject rightObject = null;
- if (selectedObjects != null && selectedObjects.size() == 2) {
- leftObject = selectedObjects.get(0).get();
- rightObject = selectedObjects.get(1).get();
- } else if (selectedFiles != null && selectedFiles.size() == 2) {
- leftObject = getModelRoot(selectedFiles.get(0).get());
- rightObject = getModelRoot(selectedFiles.get(1).get());
- }
- if (leftObject == null || rightObject == null) {
- return;
- }
- try {
- MatchModel matchModel = MatchService.doContentMatch(leftObject, rightObject, Collections.EMPTY_MAP);
- DiffModel diffModel = DiffService.doDiff(matchModel);
-
- comparisonSnapshot = createComparisonSnapshot(matchModel, diffModel);
-
- CompareEditorInput input = getCompareEditorInput();
- IWorkbenchPage page = ExtendedPlatformUI.getActivePage();
- IReusableEditor editor = getReusableEditor();
-
- openCompareEditor(input, page, editor);
-
- } catch (InterruptedException ex) {
- Activator.log.error(ex);//PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- } finally {
- }
- }
-
- /**
- * @param file
- * The file whose root model object must be returned.
- * @return The root object of the model contained in the specified {@link IFile file}.
- */
- protected EObject getModelRoot(IFile file) {
- Assert.isNotNull(file);
-
- // Get model from workspace file and force it to be loaded in case that this has not been done yet
- return EcorePlatformUtil.loadModelRoot(file);
- }
-
- protected ComparisonSnapshot createComparisonSnapshot(MatchModel matchModel, DiffModel diffModel) {
- ComparisonResourceSnapshot snapshot = DiffFactory.eINSTANCE.createComparisonResourceSnapshot();
- snapshot.setDate(Calendar.getInstance().getTime());
- snapshot.setDiff(diffModel);
- snapshot.setMatch(matchModel);
- return snapshot;
- }
-
- protected CompareEditorInput getCompareEditorInput() {
- CompareEditorInput input = new PapyrusModelElementCompareEditorInput(comparisonSnapshot);
-
- CompareConfiguration configuration = input.getCompareConfiguration();
- if (configuration != null) {
- IPreferenceStore ps = configuration.getPreferenceStore();
- if (ps != null) {
- configuration.setProperty(CompareConfiguration.USE_OUTLINE_VIEW, Boolean.valueOf(ps
- .getBoolean(ComparePreferencePage.USE_OUTLINE_VIEW)));
- }
- }
- return input;
- }
-
- protected IReusableEditor getReusableEditor() {
- return null;
- }
-
- /**
- * Performs the comparison described by the given input and opens a compare editor on the result.
- *
- * @param input
- * the input on which to open the compare editor
- * @param page
- * the workbench page on which to create a new compare editor
- * @param editor
- * if not null the input is opened in this editor
- * @see CompareEditorInput
- */
- protected void openCompareEditor(final CompareEditorInput input, final IWorkbenchPage page, final IReusableEditor editor) {
- Runnable runnable = new Runnable() {
- public void run() {
- if (editor != null && !editor.getSite().getShell().isDisposed()) {
- // Reuse the given editor
- editor.setInput(input);
- return;
- }
- if (page != null) {
- // Open new CompareEditor on page
- try {
- page.openEditor(input, getCompareEditorId(input));
- } catch (PartInitException e) {
- Activator.log.error(e);
-// PlatformLogUtil.logAsError(Activator.getPlugin(), e);
- MessageDialog.openError(ExtendedPlatformUI.getActiveShell(), Messages.error_openEditorError, e.getMessage());
- }
- } else {
- String msg = Messages.error_noActiveWorkbenchPage;
- Activator.log.error(new NullPointerException(msg));//TODO bad, no?
- //PlatformLogUtil.logAsError(Activator.getPlugin(), new NullPointerException(msg));
- MessageDialog.openError(ExtendedPlatformUI.getActiveShell(), Messages.error_openEditorError, msg);
- }
- }
- };
-
- Display display = ExtendedPlatformUI.getDisplay();
- if (display != null) {
- display.syncExec(runnable);
- } else {
- runnable.run();
- }
- }
-
- /**
- * Returns the identifier of the compare editor to open.
- * <p>
- * Inheriting clients may override this method in order to specify the identifier of another compare editor (e.g.
- * according to the type of the specified input).
- *
- * @param input
- * The {@linkplain CompareEditorInput editor input} for which a compare editor is supposed to be opened.
- * @return The identifier of the compare editor to open.
- */
- protected String getCompareEditorId(CompareEditorInput input) {
- // Use our own ModelCompareEditor rather than Eclipse's org.eclipse.compare.CompareEditor
- return PapyrusCompareEditor.ID;
- }
-
- @Override
- public void setEnabled(boolean enabled) {
- // TODO Auto-generated method stub
- super.setEnabled(enabled);
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/FileCompareAction.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/FileCompareAction.java
deleted file mode 100644
index 0b469cdfd98..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/FileCompareAction.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2010 See4sys 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:
- * See4sys - Initial API and implementation
- *
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor;
-
-import org.eclipse.compare.internal.CompareEditor;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-//import org.eclipse.sphinx.emf.compare.ui.editor.ModelCompareEditor;
-import org.eclipse.sphinx.platform.ui.util.SelectionUtil;
-import org.eclipse.sphinx.platform.util.ExtendedPlatform;
-import org.eclipse.sphinx.platform.util.ReflectUtil;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-/**
- * Action for comparing {@link IFile file}s in the workspace. Overrides Eclipse-defined action behind "Compare With >
- * Each Other" popup menu to make sure that {@link ModelCompareEditor} rather than Eclipse's {@link CompareEditor} is
- * opened when selected {@link IFile file}s are model files.
- *
- * @see ModelCompareEditor
- */
-@SuppressWarnings("restriction")
-public class FileCompareAction implements IObjectActionDelegate {
-
- private BasicCompareAction modelCompareActionDelegate = new BasicCompareAction();
- private IObjectActionDelegate eclipseCompareActionDelegate;
-
- @SuppressWarnings("unchecked")
- public FileCompareAction() {
- // Ensure backward compatibility with Eclipse 3.4.x and earlier
- try {
- String eclipseCompareActionClassName;
- if (ExtendedPlatform.getFeatureVersionOrdinal() >= 35) {
- eclipseCompareActionClassName = "org.eclipse.team.internal.ui.actions.CompareAction"; //$NON-NLS-1$
- } else {
- eclipseCompareActionClassName = "org.eclipse.compare.internal.CompareAction"; //$NON-NLS-1$
- }
- Class<IObjectActionDelegate> eclipseCompareActionClass = (Class<IObjectActionDelegate>) getClass().getClassLoader().loadClass(
- eclipseCompareActionClassName);
- eclipseCompareActionDelegate = eclipseCompareActionClass.newInstance();
- } catch (Exception ex) {
- // Ignore exception
- }
- }
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- if (eclipseCompareActionDelegate != null) {
- eclipseCompareActionDelegate.setActivePart(action, targetPart);
- }
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- // Propagate selection to delegates
- if (eclipseCompareActionDelegate != null) {
- eclipseCompareActionDelegate.selectionChanged(action, selection);
- }
- modelCompareActionDelegate.selectionChanged(SelectionUtil.getStructuredSelection(selection));
-
- // Update enablement state
- if (action != null) {
- action.setEnabled(isEclipseCompareActionEnabled() | modelCompareActionDelegate.isEnabled());
- }
- }
-
- public void run(IAction action) {
- if (modelCompareActionDelegate.isEnabled()) {
- modelCompareActionDelegate.run();
- } else if (isEclipseCompareActionEnabled()) {
- eclipseCompareActionDelegate.run(action);
- }
- }
-
- private boolean isEclipseCompareActionEnabled() {
- try {
- // Retrieve Eclipse compare action enablement state reflectively to be compatible with Eclipse 3.4.x and
- // Eclipse 3.5.x
- if (eclipseCompareActionDelegate != null) {
- return (Boolean) ReflectUtil.invokeMethod(eclipseCompareActionDelegate, "isEnabled"); //$NON-NLS-1$
- }
- } catch (Exception ex) {
- // Ignore exception
- }
- return false;
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusCompareEditor.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusCompareEditor.java
deleted file mode 100644
index 33c05176f71..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusCompareEditor.java
+++ /dev/null
@@ -1,370 +0,0 @@
-package org.eclipse.papyrus.emf.compare.transactional.editor;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.internal.CompareEditor;
-import org.eclipse.core.commands.operations.IOperationHistory;
-import org.eclipse.core.commands.operations.IOperationHistoryListener;
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.commands.operations.ObjectUndoContext;
-import org.eclipse.core.commands.operations.OperationHistoryEvent;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.emf.workspace.IWorkspaceCommandStack;
-import org.eclipse.emf.workspace.ResourceUndoContext;
-import org.eclipse.papyrus.emf.compare.transactional.editor.sphinx.WorkspaceEditingDomainUtil;
-import org.eclipse.sphinx.emf.workspace.ui.saving.BasicModelSaveablesProvider.SiteNotifyingSaveablesLifecycleListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.ISaveablesLifecycleListener;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.SaveablesLifecycleEvent;
-
-
-/**
- *
- * Duplicate code from ModelCompareEditor
- *
- */
-@SuppressWarnings("restriction")//we suppres the warning for CompareEditor
-public class PapyrusCompareEditor extends CompareEditor implements IEditingDomainProvider{
-
- /**
- * The identifier of this editor (as contributed).
- */
- public static String ID = "org.eclipse.papyrus.emf.compare.editor"; //$NON-NLS-1$
-
- /**
- * The undo context for this compare editor.
- */
- protected IUndoContext undoContext;
-
- private IOperationHistoryListener affectedObjectsListener;
-
- /**
- * Default constructor.
- */
- public PapyrusCompareEditor() {
- // Create undo context
- undoContext = new ObjectUndoContext(this, ID);
-
- }
-
- @Override
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {
- super.init(site, input);
-
- // First do not keep duplicated editing domain entries
- Set<TransactionalEditingDomain> editingDomains = new HashSet<TransactionalEditingDomain>();
- for (TransactionalEditingDomain editingDomain : getEditingDomains()) {
- if (editingDomain != null) {
- editingDomains.add(editingDomain);
- }
- }
- if (editingDomains.isEmpty()) {
- Activator.log.error(new RuntimeException("Editing domain not found"));
-// PlatformLogUtil.logAsError(Activator.getPlugin(), new RuntimeException(EMFMessages.error_notFound_editingDomain));
- }
- // Then creates and registers listeners on resulting editing domains
- for (TransactionalEditingDomain editingDomain : editingDomains) {
- addTransactionalEditingDomainListeners(editingDomain);
- }
- }
-
- @Override
- public void dispose() {
- for (TransactionalEditingDomain editingDomain : getEditingDomains()) {
- if (editingDomain != null) {
- removeTransactionalEditingDomainListeners(editingDomain);
- }
- }
-
- for (IOperationHistory operationHistory : getOperationHistories()) {
- if (operationHistory != null) {
- operationHistory.dispose(getUndoContext(), true, true, true);
- }
- }
- super.dispose();
- }
-
- protected void addTransactionalEditingDomainListeners(TransactionalEditingDomain editingDomain) {
- if (editingDomain != null) {
- // Create and register IOperationHistoryListener that detects changed objects
- affectedObjectsListener = createAffectedObjectsListener();
- Assert.isNotNull(affectedObjectsListener);
- ((IWorkspaceCommandStack) editingDomain.getCommandStack()).getOperationHistory().addOperationHistoryListener(affectedObjectsListener);
- }
- }
-
- protected void removeTransactionalEditingDomainListeners(TransactionalEditingDomain editingDomain) {
- if (editingDomain != null) {
- if (affectedObjectsListener != null) {
- IOperationHistory operationHistory = ((IWorkspaceCommandStack) editingDomain.getCommandStack()).getOperationHistory();
- operationHistory.removeOperationHistoryListener(affectedObjectsListener);
- }
- }
- }
-
- /**
- * Creates and returns the {@linkplain IOperationHistoryListener listener} to add on the
- * {@linkplain IOperationHistory operation history} of {@linkplain TransactionalEditingDomain editing domain}'s
- * {@linkplain IWorkspaceCommandStack command stack}.
- * <p>
- * The listener's implementation that is provided here aims at updating {@linkplain IUndoableOperation operation}'s
- * context by first removing default {@linkplain IUndoContext undo context} and second by adding
- * {@linkplain IUndoContext undo context} encapsulated by this editor.
- * <p>
- * Clients may override this default implementation.
- *
- * @return The {@linkplain IOperationHistoryListener operation history listener} to register on the command stack of
- * the concerned editing domain.
- */
- protected IOperationHistoryListener createAffectedObjectsListener() {
- return new IOperationHistoryListener() {
-
- public void historyNotification(final OperationHistoryEvent event) {
- IUndoableOperation operation = event.getOperation();
- if (event.getEventType() == OperationHistoryEvent.ABOUT_TO_EXECUTE) {
- handleOperationAboutToExecute(operation);
- } else if (event.getEventType() == OperationHistoryEvent.DONE || event.getEventType() == OperationHistoryEvent.UNDONE
- || event.getEventType() == OperationHistoryEvent.REDONE) {
- Set<?> affectedResources = ResourceUndoContext.getAffectedResources(operation);
- Resource[] resources = getModelRootsResources();
- boolean isLeftResourceAffected = resources[0] != null ? affectedResources.contains(resources[0]) : false;
- boolean isRightResourceAffected = resources[1] != null ? affectedResources.contains(resources[1]) : false;
- if (isLeftResourceAffected || isRightResourceAffected) {
- handleOperationFinished(operation);
- }
- }
- }
-
- private void handleOperationAboutToExecute(final IUndoableOperation operation) {
- if (operation.canUndo()) {
- IWorkbenchPartSite site = getSite();
- if (site != null) {
- site.getShell().getDisplay().syncExec(new Runnable() {
- public void run() {
- if (isActivePart()) {
- Resource[] resources = getModelRootsResources();
- for (Resource resource : resources) {
- TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
- if (editingDomain != null && editingDomain.getCommandStack() instanceof IWorkspaceCommandStack) {
- IWorkspaceCommandStack cmdStack = (IWorkspaceCommandStack) editingDomain.getCommandStack();
- IUndoContext defaultUndoContext = cmdStack.getDefaultUndoContext();
- if (defaultUndoContext != null) {
- // Remove default undo context and this editor's undo context
- operation.removeContext(defaultUndoContext);
- }
- }
- }
- operation.addContext(getUndoContext());
- }
- }
- });
- }
- }
- }
-
- private void handleOperationFinished(final IUndoableOperation operation) {
- getSite().getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- // Update editor part name
- // FIXME Not needed for the moment.
- // setPartName(getModelRootsNames());
- }
- });
- }
- };
- }
-
- /**
- * @return
- */
- public ISaveablesLifecycleListener createModelSaveablesLifecycleListener() {
- return new SiteNotifyingSaveablesLifecycleListener(this) {
- @Override
- public void handleLifecycleEvent(SaveablesLifecycleEvent event) {
- super.handleLifecycleEvent(event);
-
- if (event.getEventType() == SaveablesLifecycleEvent.DIRTY_CHANGED) {
- firePropertyChange(PROP_DIRTY);
- }
- }
- };
- }
-
- @Override
- public boolean isSaveOnCloseNeeded() {
- // Model-based editors don't need to be saved when being closed even if the model is dirty, because they don't
- // own the model. The model is loaded, managed, and saved globally, i.e. it is not destroyed but stays there
- // when editors are being closed.
- return false;
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- // TODO Modify implementation as soon as saving as diff model would be available.
- return false;
- }
-
- @Override
- public Object getAdapter(@SuppressWarnings("rawtypes") Class key) {
- if (key.equals(IUndoContext.class)) {
- // Used by undo/redo actions to get their undo context
- return getUndoContext();
- } else {
- return super.getAdapter(key);
- }
- }
-
- /**
- * @return The {@linkplain IUndoContext undo context} associated to this compare editor.
- */
- public IUndoContext getUndoContext() {
- return undoContext;
- }
-
- /**
- * @return An array of {@linkplain TransactionalEditingDomain editing domain}s which size is 2 and where at index 0
- * is editing domain from left, at index 1 is editing domain from right.
- */
- public TransactionalEditingDomain[] getEditingDomains() {
- TransactionalEditingDomain[] editingDomains = new TransactionalEditingDomain[2];
- EObject[] modelRoots = getModelRoots();
- if (modelRoots[0] != null) {
- editingDomains[0] = WorkspaceEditingDomainUtil.getEditingDomain(modelRoots[0]);
- }
- if (modelRoots[1] != null) {
- editingDomains[1] = WorkspaceEditingDomainUtil.getEditingDomain(modelRoots[1]);
- }
- if (editingDomains[0] == null && editingDomains[1] == null) {
- Activator.log.error(new RuntimeException("No editing domain found")); //$NON-NLS-1$
-// PlatformLogUtil.logAsError(Activator.getPlugin(), new RuntimeException("No editing domain found")); //$NON-NLS-1$
- }
- return editingDomains;
- }
-
- protected IOperationHistory[] getOperationHistories() {
- IOperationHistory[] operationHistories = new IOperationHistory[2];
- TransactionalEditingDomain[] editingDomains = getEditingDomains();
- for (int i = 0; i < 2; i++) {
- if (editingDomains[i] != null) {
- operationHistories[i] = ((IWorkspaceCommandStack) editingDomains[i].getCommandStack()).getOperationHistory();
- }
- }
- return operationHistories;
- }
-
- /**
- * @return The root objects of the model part that are currently being compared in this editor or an empty array if
- * no such objects are available. Anyway, always returns an array of {@linkplain EObject}s which size is 2
- * and where at index 0 is the left root and at index 1 is the right root.
- */
- public EObject[] getModelRoots() {
- EObject[] modelRoots = new EObject[2];
- IEditorInput editorInput = getEditorInput();
- if (editorInput instanceof PapyrusModelElementCompareEditorInput) {
- modelRoots = ((PapyrusModelElementCompareEditorInput) editorInput).getModelRoots();
- }
- return modelRoots;
- }
-
- /**
- * <p>
- * <table>
- * <tr valign=top>
- * <td><b>Note</b>&nbsp;&nbsp;</td>
- * <td>Whatever the model roots are (i.e. if <code>null</code> or not), this method returns an array of
- * {@linkplain Resource}s whose size is 2.</td>
- * </tr>
- * </table>
- *
- * @return
- */
- protected Resource[] getModelRootsResources() {
- Resource[] resources = new Resource[2];
- EObject[] modelRoots = getModelRoots();
- for (int i = 0; i < 2; i++) {
- EObject modelRoot = modelRoots[i];
- if (modelRoot != null) {
- resources[i] = modelRoot.eResource();
- }
- }
- return resources;
- }
-
- protected String getModelRootsNames() {
- String[] labels = new String[2];
- EObject[] modelRoots = getModelRoots();
- AdapterFactoryItemDelegator[] itemDelegators = getItemDelegators();
- for (int i = 0; i < 2; i++) {
- if (modelRoots[i] != null && itemDelegators[i] != null) {
- // Label of model root
- labels[i] = itemDelegators[i].getText(modelRoots[i]);
- }
- }
- if (labels[0] != null && labels[1] != null) {
- return labels[0] + " <---> " + labels[1]; //$NON-NLS-1$
- } else {
- return ((CompareEditorInput) getEditorInput()).getTitle();
- }
- }
-
- protected AdapterFactory[] getAdapterFactories() {
- AdapterFactory[] adapterFactories = new AdapterFactory[2];
- TransactionalEditingDomain[] editingDomains = getEditingDomains();
- for (int i = 0; i < 2; i++) {
- TransactionalEditingDomain editingDomain = editingDomains[i];
- if (editingDomain != null) {
- adapterFactories[i] = ((AdapterFactoryEditingDomain) editingDomain).getAdapterFactory();
- }
- }
- return adapterFactories;
- }
-
- protected AdapterFactoryItemDelegator[] getItemDelegators() {
- AdapterFactoryItemDelegator[] itemDelegators = new AdapterFactoryItemDelegator[2];
- AdapterFactory[] adapterFactories = getAdapterFactories();
- for (int i = 0; i < 2; i++) {
- AdapterFactory adapterFactory = adapterFactories[i];
- if (adapterFactory != null) {
- itemDelegators[i] = new AdapterFactoryItemDelegator(adapterFactory);
- }
- }
- return itemDelegators;
- }
-
- protected boolean isActivePart() {
- return this == getSite().getWorkbenchWindow().getPartService().getActivePart();
- }
-
- @Override
- public void setInput(IEditorInput input) {
- if (input instanceof PapyrusModelElementCompareEditorInput) {
- super.setInput(input);
- } else {
- Activator.log.error(new RuntimeException("Invalid editor input (must be an instance of ModelElementCompareEditorInput)"));
-// PlatformLogUtil.logAsError(Activator.getPlugin(), new RuntimeException(Messages.error_invalidEditorInput));
- }
- Image im = org.eclipse.papyrus.emf.compare.transactional.editor.Activator.getImage("/icons/PapyrusLogo16x16.gif");
- //TODO
- setTitleImage(im);
- setPartName("Papyrus Compare");
- }
-
- public TransactionalEditingDomain getEditingDomain() {
- return getEditingDomains()[0];
- }
-
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelCompareActionBarContributor.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelCompareActionBarContributor.java
deleted file mode 100644
index 97e1787804c..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelCompareActionBarContributor.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2010 See4sys 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:
- * See4sys - Initial API and implementation
- *
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.commands.operations.IOperationHistoryListener;
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.commands.operations.OperationHistoryEvent;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
-import org.eclipse.emf.edit.ui.action.RedoAction;
-import org.eclipse.emf.edit.ui.action.UndoAction;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.IWorkspaceCommandStack;
-import org.eclipse.emf.workspace.ResourceUndoContext;
-import org.eclipse.emf.workspace.ui.actions.RedoActionWrapper;
-import org.eclipse.emf.workspace.ui.actions.UndoActionWrapper;
-import org.eclipse.papyrus.emf.compare.transactional.editor.sphinx.WorkspaceEditingDomainUtil;
-import org.eclipse.sphinx.emf.compare.ui.editor.ModelCompareEditor;
-import org.eclipse.sphinx.emf.workspace.domain.WorkspaceEditingDomainManager;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorActionBarContributor;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionFactory;
-
-/**
- * An implementation of {@linkplain IEditorActionBarContributor action bar contributor} that is dedicated to
- * {@linkplain ModelCompareEditor model compare editor}s.
- * <p>
- * Brings support for undo/redo actions.
- */
-public class PapyrusModelCompareActionBarContributor extends EditingDomainActionBarContributor {
-
- /**
- * The {@linkplain IOperationHistoryListener operation history listener} responsible for setting editing domain on
- * <em>undo</em>/<em>redo</em> actions as soon as an operation (on the command stack of that precise editing domain)
- * has been finished.
- */
- protected IOperationHistoryListener historyListener;
-
- /**
- * Default constructor that creates a new instance of this contributor.
- */
- public PapyrusModelCompareActionBarContributor() {
- super(ADDITIONS_LAST_STYLE);
- }
-
- /**
- * Creates the {@linkplain IOperationHistoryListener operation history listener} that is responsible for setting
- * editing domain on <em>undo</em>/<em>redo</em> actions as soon as an operation (on the command stack of that
- * precise editing domain) has been finished.
- *
- * @return The {@linkplain IOperationHistoryListener operation history listener} to add on the concerned editing
- * domain's command stack.
- */
- protected IOperationHistoryListener createOperationHistoryListener() {
- return new IOperationHistoryListener() {
- public void historyNotification(OperationHistoryEvent event) {
- if (event.getEventType() == OperationHistoryEvent.DONE || event.getEventType() == OperationHistoryEvent.UNDONE
- || event.getEventType() == OperationHistoryEvent.REDONE) {
- IUndoContext[] contexts = event.getOperation().getContexts();
- for (IUndoContext context : contexts) {
- if (PapyrusCompareEditor.ID.equals(context.getLabel())) {
- Set<Resource> affectedResources = ResourceUndoContext.getAffectedResources(event.getOperation());
- TransactionalEditingDomain editingDomain = null;
- for (Resource resource : affectedResources) {
- TransactionalEditingDomain domain = WorkspaceEditingDomainUtil.getEditingDomain(resource);
- if (editingDomain != null && editingDomain != domain) {
- //
- // !! Important Note !!
- // For the moment, the case where two elements from different editing domain are
- // compared is not really supported because we do not know very well the expected
- // behavior of such a kind of comparison.
- //
- UnsupportedOperationException ex = new UnsupportedOperationException("Several editing domains"); //$NON-NLS-1$
- //PlatformLogUtil.logAsWarning(Activator.getPlugin(), ex);
- Activator.log.error(ex);
- editingDomain = null;
- break;
- } else {
- editingDomain = domain;
- }
- }
- if (editingDomain != null) {
- // Set editing domain on Undo/Redo actions
- if (undoAction != null) {
- undoAction.setEditingDomain(editingDomain);
- }
- if (redoAction != null) {
- redoAction.setEditingDomain(editingDomain);
- }
- }
- break;
- }
- }
- }
- }
- };
- }
-
- @Override
- public void init(IActionBars actionBars) {
- super.init(actionBars);
-
- historyListener = createOperationHistoryListener();
-
- ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
-
- // Override the superclass implementation of these actions
- undoAction = createUndoAction();
- undoAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
- actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
-
- redoAction = createRedoAction();
- redoAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
- actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
- }
-
- /**
- * Returns the {@linkplain RedoAction} this action bar contributor must provide. Default implementation creates a
- * new instance of {@linkplain RedoActionWrapper}; clients may override this method in order to create another kind
- * of action instead.
- *
- * @return The {@linkplain RedoAction} this action bar contributor must provide.
- */
- // FIXME Uncomment @Override once we don't need to support Eclipse 3.5 any longer
- // @Override
- protected RedoAction createRedoAction() {
- return new RedoActionWrapper();
- }
-
- /**
- * Returns the {@linkplain UndoAction} this action bar contributor must provide. Default implementation creates a
- * new instance of {@linkplain UndoActionWrapper}; clients may override this method in order to create another kind
- * of action instead.
- *
- * @return The {@linkplain UndoAction} this action bar contributor must provide.
- */
- // FIXME Uncomment @Override once we don't need to support Eclipse 3.5 any longer
- // @Override
- protected UndoAction createUndoAction() {
- return new UndoActionWrapper();
- }
-
- @Override
- public void setActiveEditor(IEditorPart part) {
- if (part != activeEditor) {
- if (activeEditor != null) {
- deactivate();
- }
- if (part instanceof PapyrusCompareEditor) {
- activeEditor = part;
- activate();
- }
- }
- }
-
- @Override
- public void dispose() {
- super.dispose();
-
- if (historyListener != null) {
- List<TransactionalEditingDomain> editingDomains = WorkspaceEditingDomainManager.INSTANCE.getEditingDomainMapping().getEditingDomains();
- for (TransactionalEditingDomain editingDomain : editingDomains) {
- ((IWorkspaceCommandStack) editingDomain.getCommandStack()).getOperationHistory().removeOperationHistoryListener(historyListener);
- }
- }
- historyListener = null;
- }
-
- @Override
- public void deactivate() {
- activeEditor.removePropertyListener(this);
-
- undoAction.setActiveWorkbenchPart(null);
- redoAction.setActiveWorkbenchPart(null);
- }
-
- /**
- * @return The {@linkplain TransactionalEditingDomain editing domain}s of the objects being compared (retrieves them
- * directly from {@linkplain ModelCompareEditor}).
- */
- protected Set<TransactionalEditingDomain> getEditingDomainsFromCompareEditor() {
- Set<TransactionalEditingDomain> editingDomains = new HashSet<TransactionalEditingDomain>();
- for (TransactionalEditingDomain editingDomain : ((PapyrusCompareEditor) activeEditor).getEditingDomains()) {
- if (editingDomain != null) {
- editingDomains.add(editingDomain);
- }
- }
- return editingDomains;
- }
-
- @Override
- public void activate() {
- if (historyListener != null) {
- for (TransactionalEditingDomain editingDomain : getEditingDomainsFromCompareEditor()) {
- ((IWorkspaceCommandStack) editingDomain.getCommandStack()).getOperationHistory().addOperationHistoryListener(historyListener);
- }
- }
-
- activeEditor.addPropertyListener(this);
-
- undoAction.setActiveWorkbenchPart(activeEditor);
- redoAction.setActiveWorkbenchPart(activeEditor);
-
- update();
- }
-
- @Override
- public void update() {
- undoAction.update();
- redoAction.update();
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelElementCompareEditorInput.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelElementCompareEditorInput.java
deleted file mode 100644
index ff110f9030d..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/PapyrusModelElementCompareEditorInput.java
+++ /dev/null
@@ -1,357 +0,0 @@
-package org.eclipse.papyrus.emf.compare.transactional.editor;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.CompareViewerPane;
-import org.eclipse.compare.IViewerCreator;
-import org.eclipse.compare.Splitter;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSetSnapshot;
-import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSnapshot;
-import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot;
-import org.eclipse.emf.compare.match.metamodel.MatchModel;
-import org.eclipse.emf.compare.ui.ModelCompareInput;
-import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput;
-import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer;
-import org.eclipse.emf.compare.ui.viewer.structure.ModelStructureMergeViewer;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.emf.compare.transactional.editor.sphinx.EcoreResourceUtil;
-import org.eclipse.papyrus.uml.compare.ui.merge.viewer.PapyrusContentMergeViewerCreator;
-import org.eclipse.papyrus.uml.compare.ui.structure.viewer.UMLStructureMergeViewerCreator;
-import org.eclipse.sphinx.emf.compare.ui.ModelElementCompareInput;
-import org.eclipse.sphinx.emf.compare.ui.editor.ModelCompareEditor;
-import org.eclipse.sphinx.emf.compare.ui.internal.Activator;
-import org.eclipse.sphinx.emf.compare.ui.internal.messages.Messages;
-import org.eclipse.sphinx.emf.compare.ui.viewer.content.ModelElementContentMergeViewer;
-import org.eclipse.sphinx.emf.resource.ExtendedResource;
-import org.eclipse.sphinx.emf.workspace.saving.ModelSaveManager;
-import org.eclipse.sphinx.emf.workspace.ui.saving.BasicModelSaveablesProvider;
-import org.eclipse.sphinx.platform.util.PlatformLogUtil;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.ISaveablesLifecycleListener;
-import org.eclipse.ui.ISaveablesSource;
-import org.eclipse.ui.Saveable;
-import org.eclipse.ui.navigator.SaveablesProvider;
-
-/**
- * Duplicate code from ModelElementCompareEditorInput
- */
-public class PapyrusModelElementCompareEditorInput extends ModelCompareEditorInput implements ISaveablesSource {
-
- /**
- * The two {@linkplain EObject}s that are currently being compared.
- * <p>
- * <code>modelRoots[0]</code> is the <b>left</b> model root object;<br>
- * <code>modelRoots[1]</code> is the <b>right</b> model root object.
- */
- private EObject[] modelRoots;
-
- protected SaveablesProvider modelSaveablesProvider;
-
- /**
- * This is a temporary editing domain used to load distant files.
- */
- protected TransactionalEditingDomain editingDomain;
-
- /**
- * This constructor takes a {@link ModelInputSnapshot} as input.
- *
- * @param snapshot
- * The {@link ComparisonSnapshot} loaded from an emfdiff.
- */
- public PapyrusModelElementCompareEditorInput(ComparisonSnapshot snapshot) {
- super(snapshot);
- }
-
- /**
- * Internal convenient method allowing to easily retrieve the match model for this compare editor input.
- *
- * @return The {@linkplain MatchModel match model} provided by the {@linkplain ModelCompareInput} encapsulated in
- * this {@linkplain ModelCompareEditorInput compare editor input}.
- */
- protected MatchModel getMatchModel() {
- Object matchModel = null;
- if(preparedInput != null) {
- matchModel = preparedInput.getMatch();
- } else if(inputSnapshot != null) {
- if(inputSnapshot instanceof ComparisonResourceSnapshot) {
- matchModel = ((ComparisonResourceSnapshot)inputSnapshot).getMatch();
- } else if(inputSnapshot instanceof ComparisonResourceSetSnapshot) {
- matchModel = ((ComparisonResourceSetSnapshot)inputSnapshot).getMatchResourceSet();
- }
- } else {
- IStatus warning = new Status(IStatus.WARNING, Activator.getPlugin().getSymbolicName(), Messages.warning_inputsNull, new NullPointerException());
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), warning);
- }
- return matchModel instanceof MatchModel ? (MatchModel)matchModel : null;
- }
-
- /**
- * Returns the save options to consider while saving the underlying model being edited. Default implementation
- * returns the default save options provided by the Sphinx EMF platform utility {@linkplain EcoreResourceUtil}.
- * Clients may override this method in order to specify custom options.
- *
- * @return The save options to consider while saving the underlying model being edited.
- */
- protected Map<?, ?> getSaveOptions() {
- return EcoreResourceUtil.getDefaultSaveOptions();
- }
-
- @Override
- public boolean isDirty() {
- boolean isDirty = false;
- for(Object modelRoot : getModelRoots()) {
- if(modelRoot instanceof EObject) {
- // Return true if the model, this editor or both are dirty
- isDirty = isDirty || ModelSaveManager.INSTANCE.isDirty(((EObject)modelRoot).eResource());
- }
- }
- return isDirty;
- }
-
- protected void init() {
- if(modelSaveablesProvider == null) {
- modelSaveablesProvider = createModelSaveablesProvider();
- if(getWorkbenchPart() instanceof PapyrusCompareEditor) {
- ISaveablesLifecycleListener modelSaveablesLifecycleListener = ((PapyrusCompareEditor)getWorkbenchPart()).createModelSaveablesLifecycleListener();
- modelSaveablesProvider.init(modelSaveablesLifecycleListener);
- } else {
- if(getWorkbenchPart() == null) {
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), new NullPointerException(Messages.warning_workbenchPartNull));
- } else {
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), new RuntimeException(Messages.warning_workbenchPartInstanceofModelCompareEditor));
- }
- }
- }
- }
-
- /**
- * @return The root object of the model part that is currently being edited in this editor or <code>null</code> if
- * no such is available.
- */
- public EObject[] getModelRoots() {
- if(modelRoots == null) {
- modelRoots = new EObject[2];
- }
-
- MatchModel matchModel = getMatchModel();
-
- if(matchModel != null) {
- if(modelRoots[0] == null || modelRoots[0].eIsProxy() || modelRoots[0].eResource() == null || !modelRoots[0].eResource().isLoaded()) {
- EList<EObject> leftRoots = matchModel.getLeftRoots();
- modelRoots[0] = leftRoots.get(0);
- }
- if(modelRoots[1] == null || modelRoots[1].eIsProxy() || modelRoots[1].eResource() == null || !modelRoots[1].eResource().isLoaded()) {
- EList<EObject> rightRoots = matchModel.getRightRoots();
- modelRoots[1] = rightRoots.get(0);
- }
- } else {
- IStatus warning = new Status(IStatus.WARNING, Activator.getPlugin().getSymbolicName(), Messages.warning_inputMatchModelNull, new NullPointerException());
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), warning);
- }
- return modelRoots;
- }
-
- @Override
- protected ModelContentMergeViewer createMergeViewer(CompareViewerPane pane, CompareConfiguration compareConfig) {
-// return super.createMergeViewer(pane, compareConfig);
-//we provide a Papyrus ContentMergeViewer
- IViewerCreator creator = new PapyrusContentMergeViewerCreator();
- return (ModelContentMergeViewer)creator.createViewer(pane, compareConfig);
-// return new ModelElementContentMergeViewer(pane, compareConfig);
- }
-
- @Override
- protected ModelCompareInput createModelCompareInput(ComparisonSnapshot snap) {
- if(snap instanceof ComparisonResourceSetSnapshot) {
- return new ModelElementCompareInput(((ComparisonResourceSetSnapshot)snap).getMatchResourceSet(), ((ComparisonResourceSetSnapshot)snap).getDiffResourceSet());
- }
- return new ModelElementCompareInput(((ComparisonResourceSnapshot)snap).getMatch(), ((ComparisonResourceSnapshot)snap).getDiff());
- }
-
- protected SaveablesProvider createModelSaveablesProvider() {
- return new BasicModelSaveablesProvider();
- }
-
- /**
- * @see Bug 892 - Indicate files being compared in compare editor tab title
- * @see #setTitle(String)
- */
- @Override
- protected Object prepareInput(IProgressMonitor monitor) {
- init();
- String title;
- Object input = super.prepareInput(monitor);
- String leftLabel = getLeftLabel();
- String rightLabel = getRightLabel();
- String ancestorLabel = getAncestorLabel();
- if(ancestorLabel == null) {
- title = NLS.bind(Messages.twoWay_title, leftLabel, rightLabel);
- } else {
- title = NLS.bind(Messages.threeWay_title, new String[]{ ancestorLabel, leftLabel, rightLabel });
- }
- setTitle(title);
- return input;
- }
-
- /**
- * Returns the label of the left compared object to use it in the title and the tool tip of the compare editor.
- *
- * @return As specified above.
- */
- protected String getRightLabel() {
- String rightLabel;
- EObject rightRoot = getModelRoots()[1];
- Resource rightResource = preparedInput.getRightResource();
- EObject rightModelRoot = EcoreResourceUtil.getModelRoot(rightResource);
- rightLabel = rightResource.getURI().toPlatformString(true);
- if(rightRoot != rightModelRoot) {
- String fragment = rightResource.getURIFragment(rightRoot);
- fragment = fragment.lastIndexOf(ExtendedResource.URI_QUERY_SEPARATOR) == -1 ? "" : fragment.substring(0, fragment.lastIndexOf(ExtendedResource.URI_QUERY_SEPARATOR)); //$NON-NLS-1$
- rightLabel = rightLabel.concat(ExtendedResource.URI_FRAGMENT_SEPARATOR + fragment);
- }
- return rightLabel;
- }
-
- /**
- * Returns the label of the right compared object to use it in the title and the tool tip of the compare editor.
- *
- * @return As specified above.
- */
- protected String getLeftLabel() {
- String leftLabel;
- EObject leftRoot = getModelRoots()[0];
- Resource leftResource = preparedInput.getLeftResource();
- EObject leftModelRoot = EcoreResourceUtil.getModelRoot(leftResource);
- leftLabel = leftResource.getURI().toPlatformString(true);
- if(leftRoot != leftModelRoot) {
- String fragment = leftResource.getURIFragment(leftRoot);
- fragment = fragment.lastIndexOf(ExtendedResource.URI_QUERY_SEPARATOR) == -1 ? "" : fragment.substring(0, fragment.lastIndexOf(ExtendedResource.URI_QUERY_SEPARATOR)); //$NON-NLS-1$
- leftLabel = leftLabel.concat(ExtendedResource.URI_FRAGMENT_SEPARATOR + fragment);
- }
- return leftLabel;
- }
-
- /**
- * Returns the label of the ancestor object in case of three way comparison.
- *
- * @return As specified above.
- */
- // TODO aakar We should handle three way comparison
- protected String getAncestorLabel() {
- Resource ancestorResource = preparedInput.getAncestorResource();
- if(ancestorResource != null) {
- return ancestorResource.getURI().toString();
- }
- return null;
- }
-
- @Override
- public String getToolTipText() {
- if(preparedInput != null) {
- String leftLabel = getLeftLabel();
- String rightLabel = getRightLabel();
- String ancestorLabel = getAncestorLabel();
- if(ancestorLabel == null) {
- return NLS.bind(Messages.twoWay_tooltip, leftLabel, rightLabel);
- } else {
- return NLS.bind(Messages.threeWay_tooltip, new Object[]{ ancestorLabel, leftLabel, rightLabel });
- }
- }
- // Fall back
- return super.getToolTipText();
- }
-
- @Override
- public void saveChanges(IProgressMonitor monitor) {
- for(Object modelRoot : getModelRoots()) {
- if(modelRoot instanceof EObject) {
- // Save the all dirty resources of underlying model
- ModelSaveManager.INSTANCE.saveModel(((EObject)modelRoot).eResource(), getSaveOptions(), false, monitor);
- }
- }
- }
-
- public Saveable[] getActiveSaveables() {
- return getSaveables();
- }
-
- public Saveable[] getSaveables() {
- Set<Saveable> saveables = new HashSet<Saveable>();
- if(modelSaveablesProvider != null) {
- Saveable leftSaveable = modelSaveablesProvider.getSaveable(getModelRoots()[0].eResource());
- if(leftSaveable != null) {
- saveables.add(leftSaveable);
- }
- Saveable rightSaveable = modelSaveablesProvider.getSaveable(getModelRoots()[1].eResource());
- if(rightSaveable != null) {
- saveables.add(rightSaveable);
- }
- }
- return saveables.toArray(new Saveable[saveables.size()]);
-
- }
-
- public TransactionalEditingDomain getEditingDomain() {
- return editingDomain;
- }
-
- public TransactionalEditingDomain setEditingDomain(TransactionalEditingDomain editingDomain) {
- return this.editingDomain = editingDomain;
- }
-
- @Override
- protected void finalize() throws Throwable {
- if(modelSaveablesProvider != null) {
- modelSaveablesProvider.dispose();
- modelSaveablesProvider = null;
- }
- if(editingDomain != null) {
- editingDomain.dispose();
- }
- super.finalize();
- }
-
- //TODO
- @Override
- public void setDirty(boolean dirty) {
- // TODO Auto-generated method stub
- super.setDirty(dirty);
- }
-
-
- //we override this method to provide the Papyrus Structural Viewer
- /**
- * {@inheritDoc}
- *
- * @see CompareEditorInput#createOutlineContents(Composite, int)
- */
- @Override
- public Control createOutlineContents(Composite parent, int direction) {
-
-
- final Splitter splitter = new Splitter(parent, direction);
-
- final CompareViewerPane pane = new CompareViewerPane(splitter, SWT.NONE);
- IViewerCreator creator = new UMLStructureMergeViewerCreator();
- //structureMergeViewer = new ModelStructureMergeViewer(pane, getCompareConfiguration());
- structureMergeViewer = (ModelStructureMergeViewer)creator.createViewer(pane, getCompareConfiguration());
- pane.setContent(structureMergeViewer.getTree());
-
- structureMergeViewer.setInput(preparedInput);
-
- return splitter;
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcorePlatformUtil.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcorePlatformUtil.java
deleted file mode 100644
index 67c1d923fb3..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcorePlatformUtil.java
+++ /dev/null
@@ -1,1982 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2011 See4sys, itemis 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:
- * See4sys - Initial API and implementation
- * itemis - [346715] IMetaModelDescriptor methods of MetaModelDescriptorRegistry taking EObject or Resource arguments should not start new EMF transactions
- *
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor.sphinx;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.IOperationHistory;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.MultiRule;
-import org.eclipse.emf.common.command.BasicCommandStack;
-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.FeatureMap;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.provider.IWrapperItemProvider;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.sphinx.emf.Activator;
-import org.eclipse.sphinx.emf.edit.TransientItemProvider;
-import org.eclipse.sphinx.emf.internal.messages.Messages;
-import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor;
-import org.eclipse.sphinx.emf.model.IModelDescriptor;
-import org.eclipse.sphinx.emf.model.ModelDescriptorRegistry;
-import org.eclipse.sphinx.emf.resource.ModelResourceDescriptor;
-import org.eclipse.sphinx.emf.saving.SaveIndicatorUtil;
-import org.eclipse.sphinx.emf.scoping.IResourceScope;
-import org.eclipse.sphinx.platform.util.ExtendedPlatform;
-import org.eclipse.sphinx.platform.util.PlatformLogUtil;
-import org.eclipse.sphinx.platform.util.ReflectUtil;
-import org.eclipse.sphinx.platform.util.StatusUtil;
-import org.xml.sax.SAXException;
-
-/**
- * Eclipse platform utility class.
- * <p>
- * Provides a set of methods allowing to handle resources, to load or save models, to retrieve a file from a resource
- * (and vice-versa), etc.
- */
-public final class EcorePlatformUtil {
-
- // Prevent from instantiation
- private EcorePlatformUtil() {
- }
-
- /**
- * Converts given {@link IPath path} into a workspace-relative platform resource {@link URI} if possible or an
- * absolute file {@link URI} otherwise. Returns given {@link IPath} as indeterminate (scheme-less) {@link URI} if
- * none of both is possible.
- *
- * @param path
- * The {@link IPath path} for which to create the {@link URI}; must not be <code>null</code>.
- * @return Workspace-relative platform resource {@link URI} or absolute file {@link URI} for given {@link IPath
- * path} or given {@link IPath} as indeterminate (scheme-less) {@link URI} otherwise.
- */
- public static URI createURI(IPath path) {
- Assert.isNotNull(path);
-
- URI uri = URI.createURI(path.toString(), true);
- URI convertedURI = EcoreResourceUtil.convertToPlatformResourceURI(uri);
- if (!convertedURI.isPlatformResource()) {
- convertedURI = EcoreResourceUtil.convertToAbsoluteFileURI(convertedURI);
- }
- return convertedURI;
- }
-
- public static IPath createPath(URI uri) {
- Assert.isNotNull(uri);
-
- if (uri.isPlatform()) {
- return new Path(uri.toPlatformString(true)).removeTrailingSeparator();
- } else if (uri.isFile()) {
- return new Path(uri.toFileString()).removeTrailingSeparator();
- } else {
- return new Path(uri.toString()).removeTrailingSeparator();
- }
- }
-
- /**
- * Converts the given {@link IPath path} into an absolute file {@linkplain URI}.
- *
- * @param path
- * The {@link Path path} for which an {@linkplain URI} is to be created.
- * @return The absolute file {@linkplain URI} for the given {@link IPath path} or an {@link URI} corresponding to
- * given {@link IPath path} as is if no conversion is possible.
- */
- public static URI createAbsoluteFileURI(IPath path) {
- URI uri = createURI(path);
- return EcoreResourceUtil.convertToAbsoluteFileURI(uri);
- }
-
- /**
- * Converts the given {@link URI uri} into an absolute file location, <em>i.e.</em> into a {@linkplain IPath path}.
- *
- * @param uri
- * The file {@linkplain URI} for which an absolute file {@linkplain IPath location} must be created.
- * @return The absolute file {@linkplain IPath location} for the given file {@link URI uri}.
- */
- public static IPath createAbsoluteFileLocation(URI uri) {
- uri = EcoreResourceUtil.convertToAbsoluteFileURI(uri);
- String uriString;
- if (uri.isFile()) {
- uriString = uri.toFileString();
- } else {
- uriString = uri.toString();
- }
- return new Path(uriString).removeTrailingSeparator();
- }
-
- /**
- * Converts the given {@link IPath path} into an absolute file {@linkplain IPath location}.
- *
- * @param path
- * The file path for which an absolute file {@linkplain IPath location} must be created.
- * @return The absolute file {@linkplain IPath location} for the given file {@link IPath path}.
- */
- public static IPath convertToAbsoluteFileLocation(IPath path) {
- URI uri = createAbsoluteFileURI(path);
- String uriString;
- if (uri.isFile()) {
- uriString = uri.toFileString();
- } else {
- uriString = uri.toString();
- }
- return new Path(uriString).removeTrailingSeparator();
- }
-
- /**
- * Reads the model namespace (i.e. XML namespace) of given {@link IFile file}. Returns a meaningful result only if
- * the {@link IFile file} is an XML document.
- *
- * @param file
- * The {@link IFile file} to investigate.
- * @return The model namespace denoted in the specified {@link IFile file} or <code>null</code> if the file is
- * either a non-XML file or an XML file which is not well-formed or has no model namespace.
- */
- public static String readModelNamespace(IFile file) {
- if (file != null && file.isAccessible()) {
- URI uri = createURI(file.getFullPath());
- return EcoreResourceUtil.readModelNamespace(null, uri);
- }
- return null;
- }
-
- /**
- * Reads the target namespace of given {@link IFile file}. Returns a meaningful result only if given {@link IFile
- * file} is an XML document.
- *
- * @param file
- * The {@link IFile file} to investigate.
- * @return The target namespace denoted in given {@link IFile file} or <code>null</code> if the {@link IFile file}
- * is either a not an XML file or an XML file which is not well-formed or has no target namespace.
- */
- public static String readTargetNamespace(IFile file) {
- return readTargetNamespace(file, (String[]) null);
- }
-
- /**
- * @param file
- * @param targetNamespaceExcludePatterns
- * @return
- */
- public static String readTargetNamespace(IFile file, String... targetNamespaceExcludePatterns) {
- if (file != null && file.isAccessible()) {
- URI uri = createURI(file.getFullPath());
- return EcoreResourceUtil.readTargetNamespace(null, uri, targetNamespaceExcludePatterns);
- }
- return null;
- }
-
- /**
- * Retrieves the XML comments located above the root element in given {@link IFile file}. Returns a meaningful
- * result only if given {@link IFile file} is an XML document.
- *
- * @param file
- * The {@link IFile file} to investigate.
- * @return Collection of strings representing the retrieved XML comments or empty collection if no such could be
- * found.
- */
- public static Collection<String> readRootElementComments(IFile file) {
- if (file != null && file.isAccessible()) {
- URI uri = createURI(file.getFullPath());
- return EcoreResourceUtil.readRootElementComments(null, uri);
- }
- return Collections.emptyList();
- }
-
- /**
- * Retrieves the {@link EObject root object} of the model contained in given {@link IFile file}. Returns
- * <code>null</code> if the {@link IFile file} has not been loaded yet.
- *
- * @param file
- * The {@link IFile file} containing the model.
- * @return The {@link EObject root object} of the model in given {@link IFile file} or <tt>null</tt> if the
- * {@link IFile file} has not been loaded yet or is empty.
- * @see #getModelRoot(TransactionalEditingDomain, IFile)
- */
- public static EObject getModelRoot(IFile file) {
- TransactionalEditingDomain editingDomain = WorkspaceEditingDomainUtil.getEditingDomain(file);
- if (editingDomain != null) {
- return getModelRoot(editingDomain, file);
- }
- return null;
- }
-
- /**
- * Retrieves the {@link EObject root object} of the model contained in given {@link IFile file} using given
- * {@link TransactionalEditingDomain editing domain}. Returns <tt>null</tt> if the {@link IFile file} has not been
- * loaded into the {@link TransactionalEditingDomain editing domain}'s {@link ResourceSet resource set} yet or is
- * empty.
- *
- * @param editingDomain
- * The {@linkplain TransactionalEditingDomain editing domain} the specified {@link IFile file} belongs
- * to; must not be <code>null</code>.
- * @param file
- * The {@linkplain IFile file} containing the model; must not be <code>null</code>.
- * @return The {@linkplain EObject root object} of the model in given {@link IFile file} or <tt>null</tt> if that
- * {@linkplain IFile file} has not been loaded into the specified {@linkplain TransactionalEditingDomain
- * editing domain}'s {@linkplain ResourceSet resource set} yet.
- */
- public static EObject getModelRoot(final TransactionalEditingDomain editingDomain, final IFile file) {
- if (editingDomain != null && file != null) {
- try {
- return TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<EObject>() {
- public void run() {
- URI uri = createURI(file.getFullPath());
- setResult(EcoreResourceUtil.getModelRoot(editingDomain.getResourceSet(), uri));
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return null;
- }
-
- /**
- * Loads the model contained in given {@link IFile file} using {@link EcoreResourceUtil#getDefaultLoadOptions()
- * default load options} and returns its {@link EObject root object}. Returns <tt>null</tt> if the {@link IFile
- * file} is empty.
- * <p>
- * Note: Calling this method involves retrieving the {@link TransactionalEditingDomain editing domain} behind the
- * given file. In case that the {@link IFile file} has not been loaded yet this is done by analyzing the its content
- * type. However, if it happens that the {@link IFile file}'s content type is retrieved for the very first time this
- * operation is somewhat costly in terms of runtime performance. Therefore, when the
- * {@link TransactionalEditingDomain editing domain} is already available prior to calling this method it is
- * recommended to use {@link #loadModelRoot(TransactionalEditingDomain, IFile)} instead.
- *
- * @param file
- * The {@link IFile file} containing the model.
- * @return The {@link EObject root object} of the model in given {@link IFile file} or <tt>null</tt> if the
- * {@link IFile file} is empty.
- * @see EcoreResourceUtil#getDefaultLoadOptions()
- * @see #loadModelRoot(TransactionalEditingDomain, IFile)
- */
- public static EObject loadModelRoot(IFile file) {
- return loadModelRoot(file, EcoreResourceUtil.getDefaultLoadOptions());
- }
-
- /**
- * Loads the model contained in given {@link IFile file} using given load options and returns its {@link EObject
- * root object}. Returns <tt>null</tt> if the {@link IFile file} is empty.
- * <p>
- * Note: Calling this method involves retrieving the {@link TransactionalEditingDomain editing domain} behind the
- * given file. In case that the {@link IFile file} has not been loaded yet this is done by analyzing the its content
- * type. However, if it happens that the {@link IFile file}'s content type is retrieved for the very first time this
- * operation is somewhat costly in terms of runtime performance. Therefore, when the
- * {@link TransactionalEditingDomain editing domain} is already available prior to calling this method it is
- * recommended to use {@link #loadModelRoot(TransactionalEditingDomain, IFile, Map)} instead.
- *
- * @param file
- * The {@link IFile file} containing the model.
- * @param options
- * The options to be used for loading the model.
- * @return The {@link EObject root object} of the model in given {@link IFile file} or <tt>null</tt> if the
- * {@link IFile file} is empty.
- * @see #loadModelRoot(TransactionalEditingDomain, IFile, Map)
- */
- public static EObject loadModelRoot(IFile file, Map<?, ?> options) {
- TransactionalEditingDomain editingDomain = WorkspaceEditingDomainUtil.getEditingDomain(file);
- if (editingDomain != null) {
- return loadModelRoot(editingDomain, file, options);
- }
- return null;
- }
-
- /**
- * Loads the model contained in given {@link IFile file} into given {@link TransactionalEditingDomain editing
- * domain} using {@link EcoreResourceUtil#getDefaultLoadOptions() default load options} and returns its
- * {@link EObject root object}. Returns <tt>null</tt> if the {@link IFile file} is empty.
- *
- * @param file
- * The {@link IFile file} containing the model.
- * @param editingDomain
- * The {@link TransactionalEditingDomain editing domain} the {@link IFile file} belongs to.
- * @param options
- * The options to be used for loading the model.
- * @return The {@link EObject root object} of the model in given {@link IFile file} or <tt>null</tt> if the
- * {@link IFile file} is empty.
- * @see EcoreResourceUtil#getDefaultLoadOptions()
- */
- public static EObject loadModelRoot(TransactionalEditingDomain editingDomain, IFile file) {
- return loadModelRoot(editingDomain, file, EcoreResourceUtil.getDefaultLoadOptions());
- }
-
- /**
- * Loads the model contained in given {@link IFile file} into given {@link TransactionalEditingDomain editing
- * domain} using given load options and returns its {@link EObject root object}. Returns <tt>null</tt> if the
- * {@link IFile file} is empty.
- *
- * @param file
- * The {@link IFile file} containing the model; must not be <code>null</code>.
- * @param editingDomain
- * The {@link TransactionalEditingDomain editing domain} the {@link IFile file} belongs to; must not be
- * <code>null</code>.
- * @param options
- * The options to be used for loading the model.
- * @return The {@link EObject root object} of the model in given {@link IFile file} or <tt>null</tt> if the
- * {@link IFile file} is empty.
- */
- public static EObject loadModelRoot(final TransactionalEditingDomain editingDomain, final IFile file, final Map<?, ?> options) {
- if (editingDomain != null && file != null) {
- try {
- return TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<EObject>() {
- public void run() {
- URI uri = createURI(file.getFullPath());
- setResult(EcoreResourceUtil.loadModelRoot(editingDomain.getResourceSet(), uri, options));
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return null;
- }
-
- /**
- * Tests if the given {@link Resource resource} is loaded in the {@link ResourceSet resource set} of given
- * {@link TransactionalEditingDomain editingDomain}.
- *
- * @param editingDomain
- * The {@link TransactionalEditingDomain editing domain} with the {@link ResourceSet resource set} to be
- * investigated.
- * @param resource
- * The {@link Resource resource} that may or not be loaded.
- * @return <code>true</code> if specified {@link Resource resource} is loaded in {@link ResourceSet resource set} of
- * given {@link TransactionalEditingDomain editingDomain}; <code>false</code> otherwise.
- */
- public static boolean isResourceLoaded(final TransactionalEditingDomain editingDomain, final Resource resource) {
- if (editingDomain != null && resource != null) {
- try {
- return TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<Boolean>() {
- public void run() {
- setResult(EcoreResourceUtil.isResourceLoaded(editingDomain.getResourceSet(), resource.getURI()));
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return false;
- }
-
- /**
- * Tests if the given {@link IFile file} is loaded in the {@link ResourceSet resource set} of some
- * {@link TransactionalEditingDomain editingDomain}.
- *
- * @param file
- * The {@link IFile file} that may or not be loaded.
- * @return <code>true</code> if specified {@link IFile file} is loaded in {@link ResourceSet resource set} of some
- * {@link TransactionalEditingDomain editingDomain}; <code>false</code> otherwise.
- */
- public static boolean isFileLoaded(IFile file) {
- return WorkspaceEditingDomainUtil.getCurrentEditingDomain(file) != null;
- }
-
- /**
- * Tests if the given {@link IFile file} is loaded in the {@link ResourceSet resource set} of the given
- * {@link TransactionalEditingDomain editingDomain}.
- *
- * @param editingDomain
- * The {@link TransactionalEditingDomain editing domain} with the {@link ResourceSet resource set} to be
- * investigated.
- * @param file
- * The {@link IFile file} that may or not be loaded.
- * @return <code>true</code> if specified {@link IFile file} is loaded in {@link ResourceSet resource set} of given
- * {@link TransactionalEditingDomain editingDomain}; <code>false</code> otherwise.
- */
- public static boolean isFileLoaded(final TransactionalEditingDomain editingDomain, final IFile file) {
- if (editingDomain != null && file != null) {
- try {
- return TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<Boolean>() {
- public void run() {
- URI uri = createURI(file.getFullPath());
- setResult(EcoreResourceUtil.isResourceLoaded(editingDomain.getResourceSet(), uri));
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return false;
- }
-
- /**
- * Returns the {@linkplain IFile file} corresponding to the specified {@linkplain Object object}.
- * <p>
- * The supported object types are:
- * <ul>
- * <li>{@linkplain org.eclipse.core.resources.IFile}</li>
- * <li>{@linkplain org.eclipse.emf.common.util.URI}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.resource.Resource}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.EObject}</li>
- * <li>{@linkplain org.eclipse.emf.edit.provider.IWrapperItemProvider}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.util.FeatureMap.Entry}</li>
- * </ul>
- *
- * @param object
- * The object from which a file must be returned.
- * @return The underlying file from the given object.
- */
- public static IFile getFile(Object object) {
- if (object instanceof IFile) {
- return (IFile) object;
- } else if (object instanceof URI) {
- return getFile((URI) object);
- } else if (object instanceof Resource) {
- return getFile((Resource) object);
- } else if (object instanceof EObject) {
- return getFile((EObject) object);
- } else if (object instanceof IWrapperItemProvider) {
- return getFile((IWrapperItemProvider) object);
- } else if (object instanceof FeatureMap.Entry) {
- return getFile((FeatureMap.Entry) object);
- } else if (object instanceof TransientItemProvider) {
- return getFile((TransientItemProvider) object);
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain IFile file} corresponding to the given {@linkplain org.eclipse.emf.common.util.URI}.
- *
- * @param uri
- * The {@linkplain URI} of the file to return.
- * @return The file corresponding to the specified {@link URI uri}.
- */
- public static IFile getFile(URI uri) {
- if (uri != null && Platform.isRunning()) {
- try {
- return (IFile) ReflectUtil.invokeInvisibleMethod(WorkspaceSynchronizer.class, "getFile", new Object[] { uri, //$NON-NLS-1$
- EcoreResourceUtil.getURIConverter(), false });
- } catch (Exception ex) {
- // Ignore exception
- }
- }
- return null;
- }
-
- /**
- * Retrieves the {@link IFile file} corresponding to the given <code>resource</code>.
- *
- * @param resource
- * The {@link Resource resource} for which the file is to be returned.
- * @return The file corresponding to the specified <code>resource</code>.
- */
- public static IFile getFile(final Resource resource) {
- if (resource != null && Platform.isRunning()) {
- return WorkspaceSynchronizer.getFile(resource);
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain IFile file} owning to the given {@linkplain org.eclipse.emf.ecore.EObject}.
- *
- * @param eObject
- * The {@linkplain EObject} whose file must be returned.
- * @return The file containing the specified {@link EObject eObject}.
- */
- public static IFile getFile(final EObject eObject) {
- if (eObject != null) {
- return getFile(eObject.eResource());
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain IFile file} owning the given
- * {@linkplain org.eclipse.emf.edit.provider.IWrapperItemProvider}.
- * <p>
- * First retrieves the owner of the {@link IWrapperItemProvider provider}; then, if owner is an {@linkplain EObject}
- * delegates to {@linkplain #getFile(EObject)} else delegates to {@linkplain #getFile(Object)}.
- *
- * @param provider
- * The {@linkplain IWrapperItemProvider} whose file must be returned.
- * @return The file containing the specified {@link IWrapperItemProvider provider}; <code>null</code> if that
- * provider is <code>null</code>.
- */
- public static IFile getFile(final IWrapperItemProvider provider) {
- if (provider != null) {
- Object owner = provider.getOwner();
- if (owner instanceof EObject) {
- return getFile((EObject) owner);
- } else {
- Object unwrapped = AdapterFactoryEditingDomain.unwrap(provider);
- return getFile(unwrapped);
- }
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain IFile file} matching the given {@link FeatureMap.Entry entry}.
- * <p>
- * First unwraps the {@link FeatureMap.Entry entry}; then, delegates to {@linkplain #getFile(Object)}.
- *
- * @param entry
- * The {@linkplain FeatureMap.Entry} whose underlying file must be returned.
- * @return The file under the specified {@link FeatureMap.Entry entry}.
- */
- public static IFile getFile(FeatureMap.Entry entry) {
- Object unwrapped = AdapterFactoryEditingDomain.unwrap(entry);
- return getFile(unwrapped);
- }
-
- /**
- * Retrieves the {@linkplain IFile file} owning the given {@linkplain TransientItemProvider}.
- * <p>
- * First retrieves the owner of the {@link TransientItemProvider provider}; then, if owner is an
- * {@linkplain EObject} delegates to {@linkplain #getFile(EObject)} else delegates to {@linkplain #getFile(Object)}.
- *
- * @param provider
- * The {@linkplain TransientItemProvider} whose file must be returned.
- * @return The file containing the specified {@link TransientItemProvider provider}; <code>null</code> if that
- * provider is <code>null</code>.
- */
- public static IFile getFile(final TransientItemProvider provider) {
- if (provider != null) {
- Object target = provider.getTarget();
- if (target instanceof EObject) {
- return getFile((EObject) target);
- }
- }
- return null;
- }
-
- /**
- * Returns the {@linkplain Resource resource} corresponding to the specified {@linkplain Object object}.
- * <p>
- * The supported object types are:
- * <ul>
- * <li>{@linkplain org.eclipse.core.resources.IFile}</li>
- * <li>{@linkplain org.eclipse.emf.common.util.URI}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.resource.Resource}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.EObject}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.util.FeatureMap.Entry}</li>
- * <li>{@linkplain org.eclipse.emf.edit.provider.IWrapperItemProvider}</li>
- * </ul>
- * <p>
- * If the type of the specified object does not belongs to that list of supported types, <code>null</code> is
- * returned.
- *
- * @param object
- * The object from which a resource must be returned.
- * @return The underlying resource from the given object.
- */
- public static Resource getResource(Object object) {
- if (object instanceof IFile) {
- return getResource((IFile) object);
- } else if (object instanceof URI) {
- return getResource((URI) object);
- } else if (object instanceof Resource) {
- return (Resource) object;
- } else if (object instanceof EObject) {
- return getResource((EObject) object);
- } else if (object instanceof IWrapperItemProvider) {
- return getResource((IWrapperItemProvider) object);
- } else if (object instanceof FeatureMap.Entry) {
- return getResource((FeatureMap.Entry) object);
- } else if (object instanceof TransientItemProvider) {
- return getResource((TransientItemProvider) object);
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} corresponding to the given {@link IFile file}.
- *
- * @param file
- * The {@linkplain IFile file} whose {@link Resource resource} is to be returned.
- * @return The resource corresponding to the specified {@link IFile file}.
- */
- public static Resource getResource(final IFile file) {
- final TransactionalEditingDomain editingDomain = WorkspaceEditingDomainUtil.getCurrentEditingDomain(file);
- if (editingDomain != null) {
- try {
- return TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<Resource>() {
- public void run() {
- URI uri = createURI(file.getFullPath());
- setResult(editingDomain.getResourceSet().getResource(uri, false));
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return null;
- }
-
- /**
- * Returns the {@linkplain Resource resource} corresponding to the specified {@link URI uri}.
- *
- * @param uri
- * The {@linkplain URI} of the resource to return.
- * @return The resource corresponding to the specified {@link URI uri}.
- */
- public static Resource getResource(final URI uri) {
- IFile file = getFile(uri);
- final TransactionalEditingDomain editingDomain = WorkspaceEditingDomainUtil.getCurrentEditingDomain(file);
- if (editingDomain != null) {
- try {
- return TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<Resource>() {
- public void run() {
- setResult(editingDomain.getResourceSet().getResource(uri.trimFragment(), false));
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} corresponding to the given {@link EObject object}.
- *
- * @param eObject
- * The {@linkplain EObject object} whose {@link Resource resource} is to be returned.
- * @return The resource corresponding to the specified {@link EObject object}.
- */
- public static Resource getResource(final EObject eObject) {
- return EcoreResourceUtil.getResource(eObject);
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} owning the given {@link IWrapperItemProvider provider}.
- * <p>
- * First retrieves the owner of the {@link IWrapperItemProvider provider}; then, if owner is an {@linkplain EObject}
- * returns its resource, else delegates to {@linkplain #getResource(Object)}.
- *
- * @param provider
- * The {@linkplain IWrapperItemProvider} whose resource must be returned.
- * @return The resource containing the specified {@link IWrapperItemProvider provider}; <code>null</code> if that
- * provider is <code>null</code>.
- */
- public static Resource getResource(final IWrapperItemProvider provider) {
- return EcoreResourceUtil.getResource(provider);
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} matching the given {@link FeatureMap.Entry entry}.
- * <p>
- * First unwraps the {@link FeatureMap.Entry entry}; then, delegates to {@linkplain #getResource(Object)}.
- *
- * @param entry
- * The {@linkplain FeatureMap.Entry} whose underlying resource must be returned.
- * @return The resource under the specified {@link FeatureMap.Entry entry}.
- */
- public static Resource getResource(FeatureMap.Entry entry) {
- return EcoreResourceUtil.getResource(entry);
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} owning the given {@link TransientItemProvider provider}.
- * <p>
- * First retrieves the owner of the {@link TransientItemProvider provider}; then, if owner is an
- * {@linkplain EObject} returns its resource.
- *
- * @param provider
- * The {@linkplain TransientItemProvider} whose resource must be returned.
- * @return The resource containing the specified {@link TransientItemProvider provider}; <code>null</code> if that
- * provider is <code>null</code>.
- */
- public static Resource getResource(final TransientItemProvider provider) {
- return EcoreResourceUtil.getResource(provider);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the contextObject.
- *
- * @param contextObject
- * The Object used to research resources in the model.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context object's
- * {@link IModelDescriptor model descriptor} must be considered for the research.
- * @return The resources in the context object's model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(Object contextObject, boolean includeReferencedModels) {
- if (contextObject instanceof IModelDescriptor) {
- return getResourcesInModel((IModelDescriptor) contextObject, includeReferencedModels);
- } else if (contextObject instanceof IFile) {
- return getResourcesInModel((IFile) contextObject, includeReferencedModels);
- } else if (contextObject instanceof URI) {
- return getResourcesInModel((URI) contextObject, includeReferencedModels);
- } else if (contextObject instanceof Resource) {
- return getResourcesInModel((Resource) contextObject, includeReferencedModels);
- } else if (contextObject instanceof EObject) {
- return getResourcesInModel((EObject) contextObject, includeReferencedModels);
- } else if (contextObject instanceof IWrapperItemProvider) {
- return getResourcesInModel((IWrapperItemProvider) contextObject, includeReferencedModels);
- } else if (contextObject instanceof FeatureMap.Entry) {
- return getResourcesInModel((FeatureMap.Entry) contextObject, includeReferencedModels);
- } else if (contextObject instanceof TransientItemProvider) {
- return getResourcesInModel((TransientItemProvider) contextObject, includeReferencedModels);
- }
- return Collections.emptyList();
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} provided in argument .
- *
- * @param modelDescriptor
- * The {@link IModelDescriptor model descriptor} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context
- * {@link IModelDescriptor model descriptor} must be considered for the research.
- * @return The {@link Resource resource}s owned by the {@link IModelDescriptor model descriptor}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(IModelDescriptor modelDescriptor, boolean includeReferencedModels) {
- if (modelDescriptor != null) {
- return modelDescriptor.getLoadedResources(includeReferencedModels);
- }
- return Collections.emptySet();
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context {@link IFile file}.
- * If the given {@link IFile file} doesn't belong to any {@link IModelDescriptor model descriptor}, resources in
- * context{@link ResourceSet} will be returned
- *
- * @param contextFile
- * The {@link IFile file} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context {@link IFile
- * file}'s {@link IModelDescriptor model descriptor} must be considered for the research.
- * @return The resources in the context {@link IFile file}'s model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(IFile contextFile, boolean includeReferencedModels) {
- IModelDescriptor modelDescriptor = ModelDescriptorRegistry.INSTANCE.getModel(contextFile);
- if (modelDescriptor != null) {
- return modelDescriptor.getLoadedResources(includeReferencedModels);
- }
- return getResourcesInContext(contextFile);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context {@link URI uri}.
- *
- * @param contextURI
- * The {@link URI uri} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context {@link URI uri}
- * 's {@link IModelDescriptor model descriptor} must be considered for the research.
- * @return The resources in the context {@link URI uri}'s model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(URI contextURI, boolean includeReferencedModels) {
- Resource contextResource = getResource(contextURI);
- return getResourcesInModel(contextResource, includeReferencedModels);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context {@link Resource
- * resource}.If the given {@link Resource contextResource} doesn't belong to any {@link IModelDescriptor model
- * descriptor}, resources in context{@link ResourceSet} will be returned
- *
- * @param contextResource
- * The {@link Resource resource} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context
- * {@link Resource resource} 's {@link IModelDescriptor model descriptor} must be considered for the
- * research.
- * @return The resources in the context {@link Resource resource}'s model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(Resource contextResource, boolean includeReferencedModels) {
- IModelDescriptor modelDescriptor = ModelDescriptorRegistry.INSTANCE.getModel(contextResource);
- if (modelDescriptor != null) {
- return modelDescriptor.getLoadedResources(includeReferencedModels);
- }
- return getResourcesInContext(contextResource);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context {@link EObject
- * eobject}.
- *
- * @param contextEObject
- * The {@link EObject eobject} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context {@link EObject
- * eobject}'s {@link IModelDescriptor model descriptor} must be considered for the research.
- * @return The resources in the context {@link EObject eobject}'s model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(EObject contextEObject, boolean includeReferencedModels) {
- Resource contextResource = contextEObject.eResource();
- return getResourcesInModel(contextResource, includeReferencedModels);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context
- * {@link IWrapperItemProvider provider}.
- *
- * @param contextProvider
- * The {@link IWrapperItemProvider provider} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context
- * {@link IWrapperItemProvider provider}'s {@link IModelDescriptor model descriptor} must be considered
- * for the research.
- * @return The resources in the context {@link IWrapperItemProvider provider}'s model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(IWrapperItemProvider contextProvider, boolean includeReferencedModels) {
- Resource contextResource = getResource(contextProvider);
- return getResourcesInModel(contextResource, includeReferencedModels);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context
- * {@link FeatureMap.Entry feature map entry}.
- *
- * @param contextEntry
- * The {@link FeatureMap.Entry feature map entry} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context
- * {@link FeatureMap.Entry feature map entry}'s {@link IModelDescriptor model descriptor} must be
- * considered for the research.
- * @return The resources in the context {@link FeatureMap.Entry feature map entry}'s model.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModel(FeatureMap.Entry contextEntry, boolean includeReferencedModels) {
- Resource contextResource = getResource(contextEntry);
- return getResourcesInModel(contextResource, includeReferencedModels);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model descriptor} of the context
- * {@link TransientItemProvider provider}.
- *
- * @param contextProvider
- * The {@link TransientItemProvider provider} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context
- * {@link TransientItemProvider provider}'s {@link IModelDescriptor model descriptor} must be considered
- * for the research.
- * @return The resources in the context {@link TransientItemProvider provider}'s model.
- * @since 2.1
- */
- public static Collection<Resource> getResourcesInModel(TransientItemProvider contextProvider, boolean includeReferencedModels) {
- Resource contextResource = getResource(contextProvider);
- return getResourcesInModel(contextResource, includeReferencedModels);
- }
-
- /**
- * Returns all resources owned by the {@link IModelDescriptor model}s of given {@link IMetaModelDescriptor
- * metamodel} in the context {@link IContainer container}.
- *
- * @param contextContainer
- * The {@link IContainer container} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IModelDescriptor model descriptors} referenced by the context
- * {@link IContainer container}'s {@link IModelDescriptor model descriptor} must be considered for the
- * research.
- * @return The resources in the context {@link IContainer container}'s models.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInModels(IContainer contextContainer, IMetaModelDescriptor mmDescriptor,
- boolean includeReferencedModels) {
- Collection<Resource> resourcesInModels = new HashSet<Resource>();
- Collection<IModelDescriptor> modelDescriptors = ModelDescriptorRegistry.INSTANCE.getModels(contextContainer, mmDescriptor);
- for (IModelDescriptor modelDescriptor : modelDescriptors) {
- resourcesInModels.addAll(modelDescriptor.getLoadedResources(includeReferencedModels));
- }
- return resourcesInModels;
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the contextObject.
- *
- * @param contextObject
- * The Object used to research resources in the model.
- * @param includeReferencedScopes
- * Determines if the {@link IResourceScope model resource scope} referenced by the context object's
- * {@link IResourceScope model resource scope} must be considered for the research.
- * @return The resources in the context object's {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(Object contextObject, boolean includeReferencedScopes) {
- if (contextObject instanceof IModelDescriptor) {
- return getResourcesInScope((IModelDescriptor) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof IFile) {
- return getResourcesInScope((IFile) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof URI) {
- return getResourcesInScope((URI) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof Resource) {
- return getResourcesInScope((Resource) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof EObject) {
- return getResourcesInScope((EObject) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof IWrapperItemProvider) {
- return getResourcesInScope((IWrapperItemProvider) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof FeatureMap.Entry) {
- return getResourcesInScope((FeatureMap.Entry) contextObject, includeReferencedScopes);
- } else if (contextObject instanceof TransientItemProvider) {
- return getResourcesInScope((TransientItemProvider) contextObject, includeReferencedScopes);
- }
- return Collections.emptyList();
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} provided in argument .
- *
- * @param modelDescriptor
- * The {@link IModelDescriptor model descriptor} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link IResourceScope model resource scope} must be considered for the research.
- * @return The {@link Resource resource}s owned by the {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(IModelDescriptor modelDescriptor, boolean includeReferencedScopes) {
- if (modelDescriptor != null) {
- TransactionalEditingDomain editingDomain = modelDescriptor.getEditingDomain();
- return modelDescriptor.getScope().getLoadedResources(editingDomain, includeReferencedScopes);
- }
- return Collections.emptySet();
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link IFile file}. If the given {@link IFile file} does not belong to any
- * {@link IModelDescriptor model descriptor}, resources in context {@link ResourceSet} will be returned.
- *
- * @param contextFile
- * The {@link IFile file} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context {@link IFile
- * file}'s {@link IResourceScope model resource scope} must be considered for the research.
- * @return The resources in the context {@link IFile file}'s {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(IFile contextFile, boolean includeReferencedScopes) {
- IModelDescriptor modelDescriptor = ModelDescriptorRegistry.INSTANCE.getModel(contextFile);
- if (modelDescriptor != null) {
- return getResourcesInScope(modelDescriptor, includeReferencedScopes);
- }
- return getResourcesInContext(contextFile);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link URI uri}.
- *
- * @param contextURI
- * The {@link URI uri} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context {@link URI
- * uri}'s {@link IResourceScope model resource scope} must be considered for the research.
- * @return The resources in the context {@link URI uri}'s {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(URI contextURI, boolean includeReferencedScopes) {
- Resource contextResource = getResource(contextURI);
- return getResourcesInScope(contextResource, includeReferencedScopes);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link Resource resource}.If the given {@link Resource contextResource} does not
- * belong to any {@link IModelDescriptor model descriptor}, resources in context {@link ResourceSet} will be
- * returned.
- *
- * @param contextResource
- * The {@link Resource resource} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link Resource resource}'s {@link IResourceScope model resource scope} must be considered for the
- * research.
- * @return The resources in the context {@link Resource resource}'s {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(Resource contextResource, boolean includeReferencedScopes) {
- IModelDescriptor modelDescriptor = ModelDescriptorRegistry.INSTANCE.getModel(contextResource);
- if (modelDescriptor != null) {
- return getResourcesInScope(modelDescriptor, includeReferencedScopes);
- }
- return getResourcesInContext(contextResource);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link EObject eObject}.
- *
- * @param contextEObject
- * The {@link EObject eObject} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link EObject eObject}'s {@link IResourceScope model resource scope} must be considered for the
- * research.
- * @return The resources in the context {@link EObject eObject}'s {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(EObject contextEObject, boolean includeReferencedScopes) {
- Resource contextResource = contextEObject.eResource();
- return getResourcesInScope(contextResource, includeReferencedScopes);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link IWrapperItemProvider provider}.
- *
- * @param contextProvider
- * The {@link IWrapperItemProvider provider} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link IWrapperItemProvider provider}'s {@link IResourceScope model resource scope} must be considered
- * for the research.
- * @return The resources in the context {@link IWrapperItemProvider provider}'s {@link IResourceScope model resource
- * scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(IWrapperItemProvider contextProvider, boolean includeReferencedScopes) {
- Resource contextResource = getResource(contextProvider);
- return getResourcesInScope(contextResource, includeReferencedScopes);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link FeatureMap.Entry feature map entry}.
- *
- * @param contextEntry
- * The {@link FeatureMap.Entry feature map entry} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link FeatureMap.Entry feature map entry}'s {@link IResourceScope model resource scope} must be
- * considered for the research.
- * @return The resources in the context {@link FeatureMap.Entry feature map entry}'s {@link IResourceScope model
- * resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScope(FeatureMap.Entry contextEntry, boolean includeReferencedScopes) {
- Resource contextResource = getResource(contextEntry);
- return getResourcesInScope(contextResource, includeReferencedScopes);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope} of the {@link IModelDescriptor
- * model descriptor} of the context {@link TransientItemProvider provider}.
- *
- * @param contextProvider
- * The {@link TransientItemProvider provider} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link TransientItemProvider provider}'s {@link IResourceScope model resource scope} must be
- * considered for the research.
- * @return The resources in the context {@link TransientItemProvider provider}'s {@link IResourceScope model
- * resource scope}.
- * @since 2.1
- */
- public static Collection<Resource> getResourcesInScope(TransientItemProvider contextProvider, boolean includeReferencedScopes) {
- Resource contextResource = getResource(contextProvider);
- return getResourcesInScope(contextResource, includeReferencedScopes);
- }
-
- /**
- * Returns all resources owned by the {@link IResourceScope model resource scope}s of the {@link IModelDescriptor
- * model descriptor}s of the context {@link IContainer container}.
- *
- * @param contextContainer
- * The {@link IContainer container} used as context object for investigation.
- * @param includeReferencedModels
- * Determines if the {@link IResourceScope model resource scopes} referenced by the context
- * {@link IContainer container}'s {@link IResourceScope model resource scope} must be considered for the
- * research.
- * @return The resources in the context {@link IContainer container}'s {@link IResourceScope model resource scope}.
- * @since 0.7.0
- */
- public static Collection<Resource> getResourcesInScopes(IContainer contextContainer, boolean includeReferencedScopes) {
- Collection<Resource> resourcesInScopes = new HashSet<Resource>();
- Collection<IModelDescriptor> modelDescriptors = ModelDescriptorRegistry.INSTANCE.getModels(contextContainer);
- for (IModelDescriptor modelDescriptor : modelDescriptors) {
- resourcesInScopes.addAll(getResourcesInScope(modelDescriptor, includeReferencedScopes));
- }
- return resourcesInScopes;
- }
-
- private static Collection<Resource> getResourcesInContext(Object contextObject) {
- Resource resource = EcoreResourceUtil.getResource(contextObject);
- if (resource != null) {
- ResourceSet resourceSet = resource.getResourceSet();
- if (resourceSet != null) {
- return resourceSet.getResources();
- }
- return Collections.singletonList(resource);
- }
- return Collections.emptySet();
- }
-
- public static ISchedulingRule createSaveNewSchedulingRule(Collection<ModelResourceDescriptor> modelResourceDescriptors) {
- if (modelResourceDescriptors != null) {
- Set<IPath> paths = new HashSet<IPath>();
- for (ModelResourceDescriptor descriptor : modelResourceDescriptors) {
- paths.add(descriptor.getPath());
- }
- return ExtendedPlatform.createSaveNewSchedulingRule(paths);
- }
- return null;
- }
-
- /**
- * Creates the {@linkplain ISchedulingRule scheduling rule} that is required for saving the specified
- * {@link Resource resource}.
- *
- * @param resource
- * The {@linkplain Resource resource} to be saved.
- * @return The {@linkplain ISchedulingRule scheduling rule} required for saving the given {@link Resource resource}.
- */
- public static ISchedulingRule createSaveSchedulingRule(Resource resource) {
- if (resource != null) {
- IFile modelFile = getFile(resource);
- return ExtendedPlatform.createSaveSchedulingRule(modelFile);
- }
- return null;
- }
-
- /**
- * Creates the {@linkplain ISchedulingRule scheduling rule} that are required for saving the specified
- * {@link Resource resource}s.
- *
- * @param resources
- * The {@linkplain Resource resource}s to be saved (for which scheduling rules must be created.
- * @return The scheduling {@linkplain MultiRule rule}s required for saving the given {@link Resource resources}.
- */
- public static ISchedulingRule createSaveSchedulingRule(Collection<Resource> resources) {
- if (resources != null) {
- /*
- * Performance optimization: Create a scheduling rule on a per resource basis only if number of resources is
- * reasonably low.
- */
- if (resources.size() < ExtendedPlatform.LIMIT_INDIVIDUAL_RESOURCES_SCHEDULING_RULE) {
- Set<ISchedulingRule> rules = new HashSet<ISchedulingRule>();
- for (Resource resource : resources) {
- ISchedulingRule schedulingRule = createSaveSchedulingRule(resource);
- if (schedulingRule != null) {
- rules.add(schedulingRule);
- }
- }
- return MultiRule.combine(rules.toArray(new ISchedulingRule[rules.size()]));
- } else {
- // Return workspace root as scheduling rule otherwise
- return ResourcesPlugin.getWorkspace().getRoot();
- }
- }
- return null;
- }
-
- private static ISchedulingRule createSaveSchedulingRule(Map<TransactionalEditingDomain, Collection<Resource>> resources) {
- if (resources != null) {
- Collection<Resource> allResources = new HashSet<Resource>();
- for (Collection<Resource> resourcesInEditingDomain : resources.values()) {
- allResources.addAll(resourcesInEditingDomain);
- }
- return createSaveSchedulingRule(allResources);
- }
- return null;
- }
-
- /**
- * Add a new model {@link Resource} to the provided {@link TransactionalEditingDomain} , created by using
- * {@link EObject} modelRoot as based for the containing model.
- *
- * @param editingDomain
- * The {@link TransactionalEditingDomain} where to add new resource.
- * @param path
- * The relative {@link IPath} of the new {@link Resource}.
- * @param contentTypeId
- * The contenType ID of the contained model.
- * @param modelRoot
- * The root element of the model to include in the new {@link Resource}.
- * @param async
- * Boolean parameter to determine if the execution must be synchronous or asynchronous.
- * @param monitor
- * The {@link IProgressMonitor}.
- */
- public static void addNewModelResource(TransactionalEditingDomain editingDomain, IPath path, final String contentTypeId, EObject modelRoot,
- boolean async, IProgressMonitor monitor) {
- addNewModelResources(editingDomain, Collections.singletonList(new ModelResourceDescriptor(modelRoot, path, contentTypeId)), async, monitor);
- }
-
- /**
- * * Add a new {@link Resource resource}s described by modelResourceDescriptors to the provided
- * {@link TransactionalEditingDomain editingDomain} .
- *
- * @param editingDomain
- * The {@link TransactionalEditingDomain} where to add new resource.
- * @param modelResourceDescriptors
- * The list of {@link ModelResourceDescriptor} describing new resources to add.
- * @param async
- * Boolean parameter to determine if the execution must be synchronous or asynchronous.
- * @param monitor
- * The {@link IProgressMonitor}.
- */
- public static void addNewModelResources(final TransactionalEditingDomain editingDomain,
- final Collection<ModelResourceDescriptor> modelResourceDescriptors, boolean async, final IProgressMonitor monitor) {
- if (modelResourceDescriptors != null && editingDomain != null && modelResourceDescriptors.size() > 0) {
- ISchedulingRule rule = createSaveNewSchedulingRule(modelResourceDescriptors);
- if (async) {
- Job job = new Job(modelResourceDescriptors.size() == 1 ? Messages.job_addingNewModelResource : Messages.job_addingNewModelResources) {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- try {
- runAddNewModelResources(editingDomain, modelResourceDescriptors, monitor);
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
- }
- };
- job.setRule(rule);
- job.setPriority(Job.BUILD);
- job.schedule();
- } else {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- runAddNewModelResources(editingDomain, modelResourceDescriptors, monitor);
- }
- };
- try {
- ResourcesPlugin.getWorkspace().run(runnable, rule, 0, monitor);
- } catch (CoreException ex) {
- PlatformLogUtil.logAsError(Activator.getDefault(), ex);
- }
- }
- }
-
- }
-
- private static void runAddNewModelResources(final TransactionalEditingDomain editingDomain,
- final Collection<ModelResourceDescriptor> modelResourceDescriptors, IProgressMonitor monitor) throws CoreException {
- Assert.isNotNull(editingDomain);
- Assert.isNotNull(modelResourceDescriptors);
- SubMonitor progress = SubMonitor.convert(monitor, modelResourceDescriptors.size() == 1 ? Messages.task_addingNewModelResource
- : Messages.task_addingNewModelResources, 1);
-
- Map<String, Object> transactionOptions = WorkspaceTransactionUtil.getDefaultSaveNewTransactionOptions();
- String label = modelResourceDescriptors.size() == 1 ? Messages.operation_addingNewModelResource : Messages.operation_addingNewModelResources;
- final IUndoableOperation operation = new AbstractEMFOperation(editingDomain, label, transactionOptions) {
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- SubMonitor progress = SubMonitor.convert(monitor, modelResourceDescriptors.size());
- for (ModelResourceDescriptor descriptor : modelResourceDescriptors) {
- progress.subTask(NLS.bind(Messages.subtask_addingResource, descriptor.getPath().toString()));
-
- // Convert path to URI
- URI uri = URI.createPlatformResourceURI(descriptor.getPath().toString(), true);
-
- // add new resource
- EcoreResourceUtil.addNewModelResource(editingDomain.getResourceSet(), uri, descriptor.getContentTypeId(),
- descriptor.getModelRoot());
-
- progress.worked(1);
- }
- }
- };
-
- try {
- // Execute save operation as IWorkspaceRunnable on workspace in order to avoid resource change
- // notifications during transaction execution
- /*
- * !! Important Note !! Only set IWorkspace.AVOID_UPDATE flag but don't define any scheduling
- * restrictions for the save operation right here (this must only be done on outer workspace jobs or
- * workspace runnables from which this method is called). Otherwise it would be likely to end up in
- * deadlocks with operations which already have acquired exclusive access to the workspace but are
- * waiting for exclusive access to the model (i.e. for the transaction).
- */
- ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, monitor);
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
-
- }
-
- @Override
- public boolean canUndo() {
- // Avoid the save operation to appear in the undo menu
- return false;
- }
- };
- IOperationHistory history = WorkspaceTransactionUtil.getOperationHistory(editingDomain);
- try {
- history.execute(operation, progress.newChild(1), null);
- } catch (ExecutionException ex) {
- IStatus status = StatusUtil.createErrorStatus(Activator.getPlugin(), ex);
- throw new CoreException(status);
- }
- }
-
- public static void saveNewModelResource(TransactionalEditingDomain editingDomain, IPath path, final String contentTypeId, EObject modelRoot,
- boolean async, IProgressMonitor monitor) {
- saveNewModelResources(editingDomain, Collections.singletonList(new ModelResourceDescriptor(modelRoot, path, contentTypeId)),
- EcoreResourceUtil.getDefaultSaveOptions(), async, monitor);
- }
-
- public static void saveNewModelResources(TransactionalEditingDomain editingDomain, Collection<ModelResourceDescriptor> modelResourceDescriptors,
- boolean async, IProgressMonitor monitor) {
- saveNewModelResources(editingDomain, modelResourceDescriptors, EcoreResourceUtil.getDefaultSaveOptions(), async, monitor);
- }
-
- public static void saveNewModelResource(TransactionalEditingDomain editingDomain, IPath path, final String contentTypeId, EObject modelRoot,
- Map<?, ?> options, boolean async, IProgressMonitor monitor) {
- saveNewModelResources(editingDomain, Collections.singletonList(new ModelResourceDescriptor(modelRoot, path, contentTypeId)), options, async,
- monitor);
- }
-
- public static void saveNewModelResources(final TransactionalEditingDomain editingDomain,
- final Collection<ModelResourceDescriptor> modelResourceDescriptors, final Map<?, ?> options, boolean async, IProgressMonitor monitor) {
-
- if (modelResourceDescriptors != null && editingDomain != null && modelResourceDescriptors.size() > 0) {
- ISchedulingRule rule = createSaveNewSchedulingRule(modelResourceDescriptors);
- if (async) {
- Job job = new Job(modelResourceDescriptors.size() == 1 ? Messages.job_savingNewModelResource : Messages.job_savingNewModelResources) {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- try {
- runSaveNewModelResources(editingDomain, modelResourceDescriptors, options, monitor);
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
- }
- };
- job.setRule(rule);
- job.setPriority(Job.BUILD);
- job.schedule();
- } else {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- runSaveNewModelResources(editingDomain, modelResourceDescriptors, options, monitor);
- }
- };
- try {
- ResourcesPlugin.getWorkspace().run(runnable, rule, 0, monitor);
- } catch (CoreException ex) {
- PlatformLogUtil.logAsError(Activator.getDefault(), ex);
- }
- }
- }
- }
-
- /**
- * @param editingDomain
- * The {@link TransactionalEditingDomain editing domain} onto which a write-transaction must be created
- * in order to safely perform the saving; must not be <code>null</code>.
- * @param path
- * The {@link IPath path} of the new file to save; must not be <code>null</code>.
- * @param contentType
- * @param modelRoot
- * @param options
- * @param monitor
- */
- private static void runSaveNewModelResources(final TransactionalEditingDomain editingDomain,
- final Collection<ModelResourceDescriptor> modelResourceDescriptors, final Map<?, ?> options, IProgressMonitor monitor)
- throws CoreException {
- Assert.isNotNull(editingDomain);
- Assert.isNotNull(modelResourceDescriptors);
- SubMonitor progress = SubMonitor.convert(monitor, modelResourceDescriptors.size() == 1 ? Messages.task_savingNewModelResource
- : Messages.task_savingNewModelResources, 1);
-
- Map<String, Object> transactionOptions = WorkspaceTransactionUtil.getDefaultSaveNewTransactionOptions();
- String label = modelResourceDescriptors.size() == 1 ? Messages.operation_savingNewModelResource : Messages.operation_savingNewModelResources;
- final IUndoableOperation operation = new AbstractEMFOperation(editingDomain, label, transactionOptions) {
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- SubMonitor progress = SubMonitor.convert(monitor, modelResourceDescriptors.size());
- for (ModelResourceDescriptor descriptor : modelResourceDescriptors) {
- progress.subTask(NLS.bind(Messages.subtask_savingResource, descriptor.getPath().toString()));
-
- // Convert path to URI
- URI uri = URI.createPlatformResourceURI(descriptor.getPath().toString(), true);
-
- try {
- // Save new resource
- /*
- * !! Important Note !! Resource must be saved before marking it as freshly saved
- * because otherwise the resource would loose its dirty state and consequently not be
- * saved at all.
- */
- EcoreResourceUtil.saveNewModelResource(editingDomain.getResourceSet(), uri, descriptor.getContentTypeId(),
- descriptor.getModelRoot(), options);
-
- // Mark resource as freshly saved in order to avoid that it gets automatically reloaded
- SaveIndicatorUtil.setSaved(editingDomain, descriptor.getModelRoot().eResource());
- } catch (Exception ex) {
- // Log exception in Error Log
- /*
- * !! Important Note !! The exception has already been recorded as error on the resource
- * and is principally subject to being converted to a problem marker later on (see
- * org.eclipse.sphinx.emf.util.EcoreResourceUtil.saveModelResource(Resource, Map<?,?>)
- * and org.eclipse.sphinx.emf.internal.resource.ResourceProblemHandler for details).
- * However, this is a new resource which had never saved before and does not yet exist
- * in the file system. As a consequence, there is no target to which the problem marker
- * could be attached and the problem behind this exception would remain unperceiveable
- * if we wouldn't log anything at this point.
- */
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
-
- progress.worked(1);
- }
- }
- };
-
- try {
- // Execute save operation as IWorkspaceRunnable on workspace in order to avoid resource change
- // notifications during transaction execution
- /*
- * !! Important Note !! Only set IWorkspace.AVOID_UPDATE flag but don't define any scheduling
- * restrictions for the save operation right here (this must only be done on outer workspace jobs or
- * workspace runnables from which this method is called). Otherwise it would be likely to end up in
- * deadlocks with operations which already have acquired exclusive access to the workspace but are
- * waiting for exclusive access to the model (i.e. for the transaction).
- */
- ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, monitor);
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
- }
-
- @Override
- public boolean canUndo() {
- // Avoid the save operation to appear in the undo menu
- return false;
- }
- };
- IOperationHistory history = WorkspaceTransactionUtil.getOperationHistory(editingDomain);
- try {
- history.execute(operation, progress.newChild(1), null);
- } catch (ExecutionException ex) {
- IStatus status = StatusUtil.createErrorStatus(Activator.getPlugin(), ex);
- throw new CoreException(status);
- }
- }
-
- /**
- * Saves all modified resources of the model behind the specified object (<em>i.e.</em> all resources in the context
- * of the given object).
- *
- * @param contextResource
- * The object resource identifying the model to save.
- * @param async
- * If <code>true</code>, model will be saved within a workspace job.
- * @param monitor
- * The progress monitor to use for showing save process progress.
- */
- public static void saveModel(Object contextObject, boolean async, IProgressMonitor monitor) {
- saveModel(contextObject, EcoreResourceUtil.getDefaultSaveOptions(), async, monitor);
- }
-
- /**
- * Saves all modified, writable models from a given context object.
- *
- * @param contextObject
- * The object context identifying the models to save.
- * @param options
- * The save options.
- * @param async
- * When passing <code>true</code> the model will be saved within a workspace job.
- * @param monitor
- * The progress monitor to use for showing save process progress.
- */
- // TODO Make sure that this method can also be used for contextObjects in resources which are located outside the
- // Eclipse workspace (only ISchedulingRule creation and IWorkspaceRunnable usages need to be adapted)
- public static void saveModel(Object contextObject, final Map<?, ?> options, boolean async, IProgressMonitor monitor) {
- if (contextObject instanceof IProject) {
- saveProject((IProject) contextObject, options, async, monitor);
- return;
- }
-
- SubMonitor progress = SubMonitor.convert(monitor, 100);
- Collection<Resource> resourcesInModel = new ArrayList<Resource>(getResourcesInModel(contextObject, true));
- final Map<TransactionalEditingDomain, Collection<Resource>> resourcesToSave = detectResourcesToSave(resourcesInModel,
- progress.newChild(async ? 100 : 5));
- if (resourcesToSave.size() > 0) {
- ISchedulingRule rule = createSaveSchedulingRule(resourcesToSave);
- if (async) {
- Job job = new Job(Messages.job_savingModel) {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- try {
- runSaveModelResources(resourcesToSave, options, monitor);
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
- }
- };
-
- job.setRule(rule);
- job.setPriority(Job.BUILD);
- job.schedule();
- } else {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- runSaveModelResources(resourcesToSave, options, monitor);
- }
- };
- try {
- ResourcesPlugin.getWorkspace().run(runnable, rule, 0, progress.newChild(95));
- } catch (CoreException ex) {
- PlatformLogUtil.logAsError(Activator.getDefault(), ex);
- }
- }
- }
- }
-
- /**
- * Saves all modified {@link Resource resource}s of all models behind the specified {@link IProject project}
- * including all referenced projects ( <em>i.e.</em> all resources in the context of the given project).
- *
- * @param project
- * The {@link IProject project} identifying the models to save.
- * @param async
- * If <code>true</code>, models will be saved within a workspace job.
- * @param monitor
- * The progress monitor to use for showing save process progress.
- */
- public static void saveProject(IProject project, boolean async, IProgressMonitor monitor) {
- saveProject(project, EcoreResourceUtil.getDefaultSaveOptions(), async, monitor);
- }
-
- /**
- * Saves all modified {@link Resource}s of all models behind the specified project including all referenced
- * {@link IProject}s ( <em>i.e.</em> all resources in the context of the given project).
- *
- * @param project
- * The {@link IProject project} identifying the models to save.
- * @param options
- * The save options.
- * @param async
- * If <code>true</code>, models will be saved within a workspace job.
- * @param monitor
- * The progress monitor to use for showing save process progress.
- */
- public static void saveProject(IProject project, final Map<?, ?> options, boolean async, IProgressMonitor monitor) {
- SubMonitor progress = SubMonitor.convert(monitor, 100);
- Collection<Resource> resourcesInProject = new ArrayList<Resource>(getResourcesInScopes(project, true));
- final Map<TransactionalEditingDomain, Collection<Resource>> resourcesToSave = detectResourcesToSave(resourcesInProject,
- progress.newChild(async ? 100 : 5));
- if (resourcesToSave.size() > 0) {
- ISchedulingRule rule = createSaveSchedulingRule(resourcesToSave);
- if (async) {
- Job job = new Job(resourcesToSave.size() == 1 ? Messages.job_savingModel : Messages.job_savingModels) {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- try {
- runSaveModelResources(resourcesToSave, options, monitor);
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
- }
- };
- job.setRule(rule);
- job.setPriority(Job.BUILD);
- job.schedule();
- } else {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- runSaveModelResources(resourcesToSave, options, monitor);
- }
- };
- try {
- ResourcesPlugin.getWorkspace().run(runnable, rule, 0, progress.newChild(95));
- } catch (CoreException ex) {
- PlatformLogUtil.logAsError(Activator.getDefault(), ex);
- }
- }
- }
- }
-
- private static Map<TransactionalEditingDomain, Collection<Resource>> detectResourcesToSave(Collection<Resource> resources,
- IProgressMonitor monitor) {
- SubMonitor progress = SubMonitor.convert(monitor, resources.size());
-
- Map<TransactionalEditingDomain, Collection<Resource>> resourcesToSave = new HashMap<TransactionalEditingDomain, Collection<Resource>>();
- for (Resource resource : resources) {
- TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
- if (editingDomain != null) {
- if (isResourceToSave(editingDomain, resource)) {
- Collection<Resource> resourcesToSaveInEditingDomain = resourcesToSave.get(editingDomain);
- if (resourcesToSaveInEditingDomain == null) {
- resourcesToSaveInEditingDomain = new HashSet<Resource>();
- resourcesToSave.put(editingDomain, resourcesToSaveInEditingDomain);
- }
- resourcesToSaveInEditingDomain.add(resource);
- }
- }
- progress.worked(1);
- }
- return resourcesToSave;
- }
-
- private static boolean isResourceToSave(TransactionalEditingDomain editingDomain, Resource contextResource) {
- Assert.isNotNull(editingDomain);
- return !editingDomain.isReadOnly(contextResource) && SaveIndicatorUtil.isDirty(editingDomain, contextResource);
- }
-
- /**
- * Saves model {@link Resource resource}s.
- *
- * @param resourcesToSave
- * The {@link TransactionalEditingDomain editing domain}s with the corresponding resources to save; must
- * not be <code>null</code>.
- * @param options
- * The save options.
- * @param monitor
- * The progress monitor to use (can be <code>null</code>).
- */
- private static void runSaveModelResources(final Map<TransactionalEditingDomain, Collection<Resource>> resourcesToSave, final Map<?, ?> options,
- IProgressMonitor monitor) throws CoreException {
- Assert.isNotNull(resourcesToSave);
- final SubMonitor progress = SubMonitor.convert(monitor, resourcesToSave.size());
-
- for (final TransactionalEditingDomain editingDomain : resourcesToSave.keySet()) {
- progress.setTaskName(resourcesToSave.get(editingDomain).size() == 1 ? Messages.task_savingModelResource
- : Messages.task_savingModelResources);
-
- /*
- * !! Important Note !! The saving of model resources as such does not imply any modifications of the
- * resource set and therefore could be done in a read transaction. However, it is possible that the
- * resources to be saved have a org.eclipse.emf.ecore.xmi.ResoureHandler registered upon them and that the
- * ResourceHandler#preSave() method performs some resource set modifying operations. In order to avoid
- * IllegalStateExceptions telling that the resource set cannot be modified without a write transaction in
- * such cases the whole save operation must be executed in a write transaction.
- */
- Map<String, Object> transactionOptions = WorkspaceTransactionUtil.getDefaultSaveTransactionOptions();
- String label = resourcesToSave.get(editingDomain).size() == 1 ? Messages.operation_savingModelResource
- : Messages.operation_savingModelResources;
- final IUndoableOperation operation = new AbstractEMFOperation(editingDomain, label, transactionOptions) {
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- SubMonitor progress = SubMonitor.convert(monitor, resourcesToSave.get(editingDomain).size());
- for (Resource resource : resourcesToSave.get(editingDomain)) {
- progress.subTask(NLS.bind(Messages.subtask_savingResource, resource.getURI().toString()));
-
- try {
- // Save resource
- /*
- * !! Important Note !! Resource must be saved before marking it as freshly saved
- * because otherwise the resource would loose its dirty state and consequently not
- * be saved at all.
- */
- EcoreResourceUtil.saveModelResource(resource, options);
-
- // Mark resource as freshly saved in order to avoid that it gets automatically
- // reloaded
- SaveIndicatorUtil.setSaved(editingDomain, resource);
- } catch (Exception ex) {
- // Ignore exception, it has already been recorded as error on resource and will be
- // converted to a problem marker later on (see
- // org.eclipse.sphinx.emf.util.EcoreResourceUtil.saveModelResource(Resource,
- // Map<?,?>) and org.eclipse.sphinx.emf.internal.resource.ResourceProblemHandler for
- // details)
- }
-
- progress.worked(1);
- }
-
- // Refresh command stack state of associated editing domain
- ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
- }
- };
-
- try {
- // Execute save operation as IWorkspaceRunnable on workspace in order to avoid resource
- // change notifications during transaction execution
- /*
- * !! Important Note !! Only set IWorkspace.AVOID_UPDATE flag but don't define any scheduling
- * restrictions for the save operation right here (this must only be done on outer workspace
- * jobs or workspace runnables from which this method is called). Otherwise it would be likely
- * to end up in deadlocks with operations which already have acquired exclusive access to the
- * workspace but are waiting for exclusive access to the model (i.e. for the transaction).
- */
- ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, progress.newChild(1));
- return Status.OK_STATUS;
- } catch (CoreException ex) {
- return ex.getStatus();
- }
- }
-
- @Override
- public boolean canUndo() {
- // Avoid that save operation appears in the undo menu
- return false;
- }
- };
-
- IOperationHistory history = WorkspaceTransactionUtil.getOperationHistory(editingDomain);
- try {
- history.execute(operation, progress.newChild(1), null);
- } catch (ExecutionException ex) {
- IStatus status = StatusUtil.createErrorStatus(Activator.getPlugin(), ex);
- throw new CoreException(status);
- }
- }
- }
-
- /**
- * Unloads the model contained in given {@link IFile file}.
- *
- * @param file
- * The {@link IFile file} containing the model.
- * @see #unloadFile(TransactionalEditingDomain, IFile)
- */
- public static void unloadFile(IFile file) {
- /*
- * !! Important Note !! For the sake of robustness, it is necessary to consider all editing domains but not only
- * the one which would be returned by WorkspaceEditingDomainUtil#getCurrentEditingDomain(IFile). Although not
- * really intended by Sphinx workspace management it might anyway happen that the same file gets loaded into
- * multiple editing domains. Typical reasons for this are e.g. lazy loading of one file from multiple other
- * files which are in different editing domains or programatic action by some application. We then have to make
- * sure that the given file gets unloaded from all editing domains it is in.
- */
- Collection<TransactionalEditingDomain> editingDomains = WorkspaceEditingDomainUtil.getAllEditingDomains();
- for (TransactionalEditingDomain editingDomain : editingDomains) {
- if (EcorePlatformUtil.isFileLoaded(editingDomain, file)) {
- unloadFile(editingDomain, file);
- }
- }
- }
-
- /**
- * Unloads the model contained in given {@linkplain IFile file} from given {@linkplain TransactionalEditingDomain
- * editing domain}.
- *
- * @param file
- * The {@linkplain IFile file} containing the model.
- * @param editingDomain
- * The {@linkplain TransactionalEditingDomain editing domain} the <code>file</code> belongs to.
- */
- public static void unloadFile(final TransactionalEditingDomain editingDomain, final IFile file) {
- if (editingDomain != null && file != null) {
- try {
- editingDomain.runExclusive(new Runnable() {
- public void run() {
- try {
- URI uri = createURI(file.getFullPath());
- EcoreResourceUtil.unloadResource(editingDomain.getResourceSet(), uri);
- } catch (RuntimeException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- }
-
- /**
- * Unloads the models contained in given {@linkplain IFile file}s from given {@linkplain TransactionalEditingDomain
- * editing domain} inside a read-only transaction.
- *
- * @param files
- * The {@link IFile file}s containing the models.
- * @param editingDomain
- * The {@link TransactionalEditingDomain editing domain} the {@link IFile file}s belong to.
- * @since 0.7.0
- */
- public static void unloadFiles(final TransactionalEditingDomain editingDomain, final Collection<IFile> files, final boolean memoryOptimized,
- IProgressMonitor monitor) throws OperationCanceledException {
- if (editingDomain != null && files != null && files.size() > 0) {
- final SubMonitor progress = SubMonitor.convert(monitor, Messages.task_unloadingModelFiles, files.size());
- if (progress.isCanceled()) {
- throw new OperationCanceledException();
- }
-
- try {
- editingDomain.runExclusive(new Runnable() {
- public void run() {
- for (IFile file : files) {
- progress.subTask(NLS.bind(Messages.subtask_unloadingModelFile, file.getFullPath().toString()));
-
- try {
- URI uri = createURI(file.getFullPath());
- EcoreResourceUtil.unloadResource(editingDomain.getResourceSet(), uri, memoryOptimized);
- } catch (RuntimeException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
-
- progress.worked(1);
- if (progress.isCanceled()) {
- throw new OperationCanceledException();
- }
- editingDomain.yield();
- }
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- }
-
- /**
- * Unloads the specified {@linkplain Resource resource}s from given {@linkplain TransactionalEditingDomain editing
- * domain} inside a read-only transaction.
- *
- * @param memoryOptimized
- * @param resources
- * The resources to unload.
- * @param editingDomain
- * The editing domain owning {@link Resource resource}s.
- * @since 0.7.0
- */
- public static void unloadResources(final TransactionalEditingDomain editingDomain, final Collection<Resource> resources,
- final boolean memoryOptimized, IProgressMonitor monitor) throws OperationCanceledException {
- if (editingDomain != null && resources != null && resources.size() > 0) {
- final SubMonitor progress = SubMonitor.convert(monitor, Messages.task_unloadingModelResources, resources.size());
- if (progress.isCanceled()) {
- throw new OperationCanceledException();
- }
-
- try {
- editingDomain.runExclusive(new Runnable() {
- public void run() {
- List<Resource> safeResources = new ArrayList<Resource>(resources);
- for (Resource resource : safeResources) {
- progress.subTask(NLS.bind(Messages.subtask_unloadingModelResource, resource.getURI().toString()));
-
- try {
- if (editingDomain.getResourceSet().getResources().contains(resource)) {
- EcoreResourceUtil.unloadResource(resource, memoryOptimized);
- }
- } catch (RuntimeException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
-
- progress.worked(1);
- if (progress.isCanceled()) {
- throw new OperationCanceledException();
- }
- editingDomain.yield();
- }
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- }
-
- /**
- * Unloads all {@linkplain Resource resource}s from given {@linkplain TransactionalEditingDomain editing domain}
- * inside a read-only transaction.
- *
- * @param editingDomain
- * The editing domain owning {@link Resource resource}s.
- */
- public static void unloadAllResources(final TransactionalEditingDomain editingDomain, IProgressMonitor monitor) throws OperationCanceledException {
- if (editingDomain != null) {
- final SubMonitor progress = SubMonitor.convert(monitor, Messages.task_unloadingModelResources, editingDomain.getResourceSet()
- .getResources().size());
- if (progress.isCanceled()) {
- throw new OperationCanceledException();
- }
-
- try {
- editingDomain.runExclusive(new Runnable() {
- public void run() {
- List<Resource> safeResources = new ArrayList<Resource>(editingDomain.getResourceSet().getResources());
- for (Resource resource : safeResources) {
- progress.subTask(NLS.bind(Messages.subtask_unloadingModelResource, resource.getURI().toString()));
-
- try {
- EcoreResourceUtil.unloadResource(resource, true);
- } catch (RuntimeException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
-
- progress.worked(1);
- if (progress.isCanceled()) {
- throw new OperationCanceledException();
- }
- editingDomain.yield();
- }
- }
- });
- } catch (InterruptedException ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- }
-
- /**
- * Parses given {@link IFile file} and validates it against XSD schema with specified {@link URL url}. Raises an
- * exception if the {@link IFile file}'s content is not compliant with respect to XSD schema.
- *
- * @param file
- * The {@link IFile file} to be validated.
- * @param schemaURL
- * The {@link URL url} of the XSD schema to be used for validation.
- * @throws SAXException
- * @throws IOException
- */
- public static void validate(IFile file, URL schemaURL) throws SAXException, IOException {
- Assert.isNotNull(file);
-
- URI uri = createURI(file.getFullPath());
- EcoreResourceUtil.validate(uri, schemaURL);
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcoreResourceUtil.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcoreResourceUtil.java
deleted file mode 100644
index fb8358afe32..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/EcoreResourceUtil.java
+++ /dev/null
@@ -1,1148 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2011 See4sys, BMW Car IT, itemis 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:
- * See4sys - Initial API and implementation
- * BMW Car IT - Added/Updated javadoc
- * itemis - [346715] IMetaModelDescriptor methods of MetaModelDescriptorRegistry taking EObject or Resource arguments should not start new EMF transactions
- * itemis - [357962] Make sure that problems occurring when saving model elements in a new resource are not recorded as errors/warnings on resource
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor.sphinx;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.XMLConstants;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.CommonPlugin;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.common.util.WrappedException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ContentHandler;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.URIConverter;
-import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
-import org.eclipse.emf.ecore.util.FeatureMap;
-import org.eclipse.emf.ecore.xmi.XMIException;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.provider.IWrapperItemProvider;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.sphinx.emf.Activator;
-import org.eclipse.sphinx.emf.edit.TransientItemProvider;
-import org.eclipse.sphinx.emf.internal.messages.Messages;
-import org.eclipse.sphinx.emf.resource.ExtendedResource;
-import org.eclipse.sphinx.emf.resource.ExtendedResourceAdapterFactory;
-import org.eclipse.sphinx.emf.resource.ScopingResourceSetImpl;
-import org.eclipse.sphinx.platform.util.ExtendedPlatform;
-import org.eclipse.sphinx.platform.util.PlatformLogUtil;
-import org.eclipse.sphinx.platform.util.XMLRootElementHandler;
-import org.xml.sax.SAXException;
-
-/**
- * Utility class for resource management.
- */
-public final class EcoreResourceUtil {
-
- // Prevent from instantiation
- private EcoreResourceUtil() {
- }
-
- /**
- * Returns an instance of {@link ExtensibleURIConverterImpl} where the URI mappings are initialized in such a way
- * that normalization of non-platform:/resource {@link URI}s which reference resources inside the workspace yields
- * the corresponding platform:/resource {@link URI}s.
- *
- * @return An instance of {@link ExtensibleURIConverterImpl} containing URI mappings for normalizing
- * non-platform:/resource {@link URI}s referencing workspace resources to corresponding platform:/resource
- * {@link URI}s.
- */
- public static URIConverter getURIConverter() {
- return getURIConverter(null);
- }
-
- /**
- * Returns the {@link URIConverter URI converter} of given {@link ResourceSet resource set}. If no
- * {@link ResourceSet resource set} is provided an instance of {@link ExtensibleURIConverterImpl} is returned
- * instead. In both cases, the {@link URIConverter URI converter}'s URI mappings are initialized in such a way that
- * normalization of non-platform:/resource {@link URI}s which reference resources inside the workspace yields the
- * corresponding platform:/resource {@link URI}s.
- *
- * @param resourceSet
- * The {@link ResourceSet resource set} whose {@link URIConverter URI converter} is to be retrieved.
- * @return The {@link URIConverter URI converter} of given {@link ResourceSet resource set}, or an instance of
- * {@link ExtensibleURIConverterImpl} if no such is provided, containing URI mappings for normalizing
- * non-platform:/resource {@link URI}s referencing workspace resources to corresponding platform:/resource
- * {@link URI}s.
- */
- public static URIConverter getURIConverter(ResourceSet resourceSet) {
- // Retrieve or create URI converter
- URIConverter uriConverter;
- if (resourceSet != null) {
- uriConverter = resourceSet.getURIConverter();
- } else {
- uriConverter = new ExtensibleURIConverterImpl();
- }
- if (Platform.isRunning()) {
- // Initialize URI mappings
- IPath workspaceRootPath = ResourcesPlugin.getWorkspace().getRoot().getFullPath().addTrailingSeparator();
- URI workspaceRootURI = URI.createPlatformResourceURI(workspaceRootPath.toString(), true);
-
- IPath workspaceRootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().addTrailingSeparator();
- URI workspaceRootLocationURI = URI.createURI(workspaceRootLocation.toString(), true);
- URI workspaceRootLocationFileURI = URI.createFileURI(workspaceRootLocation.toString());
-
- uriConverter.getURIMap().put(workspaceRootLocationURI, workspaceRootURI);
- uriConverter.getURIMap().put(workspaceRootLocationFileURI, workspaceRootURI);
- }
- return uriConverter;
- }
-
- /**
- * Converts given {@link URI} into an absolute file {@link URI}.
- *
- * @param uri
- * The {@link URI} to be converted.
- * @return Absolute file {@link URI} for the given {@link URI} or given {@link URI} if no conversion is possible.
- */
- public static URI convertToAbsoluteFileURI(URI uri) {
- Assert.isNotNull(uri);
-
- // FIXME File bug to EMF: CommonPlugin.asLocalURI() is unable to convert URIs that start with a driver letter
- // (IOException raised and caught internally)
- if (!uri.isRelative() && uri.scheme().matches("[A-Z]")) { //$NON-NLS-1$
- uri = URI.createFileURI(uri.toString());
- }
-
- // Try to convert given URI to absolute file URI right away
- URI convertedURI = CommonPlugin.asLocalURI(uri);
-
- // Resulting URI still relative?
- if (convertedURI.isRelative()) {
- // Normalize given URI and try to convert it again
- uri = getURIConverter().normalize(uri);
- convertedURI = CommonPlugin.asLocalURI(uri);
- }
-
- return convertedURI;
- }
-
- /**
- * Converts given URI into a platform resource URI.
- *
- * @param uri
- * The {@link URI} to be converted.
- * @return platform resource URI for the given URI or given URI if it references a location outside the workspace or
- * platform is not available.
- */
- public static URI convertToPlatformResourceURI(URI uri) {
- Assert.isNotNull(uri);
-
- // Already a platform resource URI?
- if (uri.isPlatformResource()) {
- return uri;
- } else {
- // Try to convert given URI to platform resource URI
- return getURIConverter().normalize(uri);
- }
- }
-
- /**
- * Proves if resource specified by an URI exists.
- *
- * @param uri
- * The URI to prove Returns <b>true</b> only if the URI represents a file and if this file exists.
- */
- public static boolean exists(URI uri) {
- if (uri != null) {
- return getURIConverter().exists(uri, null);
- }
- return false;
- }
-
- /**
- * Returns the id of the content type of the file behind given {@link URI}.
- *
- * @param uri
- * The {@link URI} whose content type id is to be established.
- * @return The id of the content type of the file behind given {@link URI}, or <code>null</code> if given
- * {@link URI} references a resource which is no file (e.g., a folder or project), or a file that does not
- * exist or has no content type.
- */
- public static String getContentTypeId(URI uri) {
- if (uri != null) {
- try {
- Map<String, ?> contentDescription = getURIConverter().contentDescription(uri, null);
- return (String) contentDescription.get(ContentHandler.CONTENT_TYPE_PROPERTY);
- } catch (Exception ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
- return null;
- }
-
- /**
- * Determines if {@link Resource resource} behind specified {@link URI} is read-only. Returns <code>false</code> if
- * this resource does not exist.
- *
- * @param uri
- * The {@link URI} identifying the {@link Resource resource} to be investigated.
- * @return <code>true</code> if {@link Resource resource} behind specified {@link URI} is read-only, and
- * <code>false</code> otherwise.
- */
- public static boolean isReadOnly(URI uri) {
- if (uri != null) {
- Map<String, ?> attributes = getURIConverter().getAttributes(uri, null);
- Object readOnly = attributes.get(URIConverter.ATTRIBUTE_READ_ONLY);
- return readOnly instanceof Boolean && (Boolean) readOnly;
- }
- return false;
- }
-
- /**
- * Reads the model namespace (i.e. XML namespace) of given {@link Resource resource}. Returns a meaningful result
- * only if given {@link Resource resource} is an XML document.
- *
- * @param resource
- * The {@link Resource resource} to investigate.
- * @return The model namespace denoted in given {@link Resource resource} or <code>null</code> if the
- * {@link Resource resource} is either a non-XML file or an XML file which is not well-formed or has no
- * model namespace.
- */
- public static String readModelNamespace(Resource resource) {
- if (resource != null) {
- return readModelNamespace(EcoreResourceUtil.getURIConverter(resource.getResourceSet()), resource.getURI());
- }
- return null;
- }
-
- /**
- * Reads the model namespace (i.e. XML namespace) of resource behind given {@link URI}. Returns a meaningful result
- * only if the resource in question is an XML document.
- *
- * @param uriConverter
- * The {@link URIConverter uriConverter} used to create {@link InputStream inputstream} . May be
- * <code>null</code>.
- * @param uri
- * The {@link URI uri} of the resource to investigate.
- * @return The model namespace denoted in resource behind given {@link URI} or <code>null</code> if the resource in
- * question is either a non-XML file or an XML file which is not well-formed or has no model namespace.
- */
- public static String readModelNamespace(URIConverter uriConverter, URI uri) {
- String namespace = null;
- if (exists(uri)) {
- InputStream inputStream = null;
- try {
- uriConverter = uriConverter != null ? uriConverter : new ExtensibleURIConverterImpl();
- inputStream = uriConverter.createInputStream(uri);
- XMLRootElementHandler handler = new XMLRootElementHandler();
- handler.parseContents(inputStream);
- namespace = handler.getRootElementNamespace();
- } catch (SAXException ex) {
- // Ignore parse exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (IOException ex) {
- // Ignore I/O exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (Exception ex) {
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), ex);
- } finally {
- ExtendedPlatform.safeClose(inputStream);
- }
- }
- return namespace;
- }
-
- /**
- * Reads the target namespace of given {@link Resource resource}. Returns a meaningful result only if given
- * {@link Resource resource} is an XML document.
- *
- * @param resource
- * The {@link Resource resource} to investigate.
- * @return The target namespace denoted in given {@link Resource resource} or <code>null</code> if the
- * {@link Resource resource} is either a not an XML file or an XML file which is not well-formed or has no
- * target namespace.
- */
- public static String readTargetNamespace(Resource resource) {
- return readTargetNamespace(resource, (String[]) null);
- }
-
- public static String readTargetNamespace(Resource resource, String... targetNamespaceExcludePatterns) {
- if (resource != null) {
- return readTargetNamespace(getURIConverter(resource.getResourceSet()), resource.getURI(), targetNamespaceExcludePatterns);
- }
- return null;
- }
-
- /**
- * Reads the target namespace of the resource behind given {@link URI}. Returns a meaningful result only if the
- * resource in question is an XML document.
- *
- * @param uriConverter
- * The {@link URIConverter uriConverter} used to create {@link InputStream input stream} . May be
- * <code>null</code>.
- * @param uri
- * The {@link URI uri} of the resource to investigate.
- * @return The target namespace denoted in resource behind given {@link URI} or <code>null</code> if the resource in
- * question is either a not an XML file or an XML file which is not well-formed or has no target namespace.
- */
- public static String readTargetNamespace(URIConverter uriConverter, URI uri) {
- return readTargetNamespace(uriConverter, uri, (String[]) null);
- }
-
- public static String readTargetNamespace(URIConverter uriConverter, URI uri, String... targetNamespaceExcludePatterns) {
- String targetNamespace = null;
- if (exists(uri)) {
- InputStream inputStream = null;
- try {
- uriConverter = uriConverter != null ? uriConverter : new ExtensibleURIConverterImpl();
- inputStream = uriConverter.createInputStream(uri);
- XMLRootElementHandler handler = new XMLRootElementHandler();
- if (targetNamespaceExcludePatterns != null) {
- handler.seTargetNamespaceExcludePatterns(targetNamespaceExcludePatterns);
- }
- handler.parseContents(inputStream);
- targetNamespace = handler.getTargetNamespace();
- } catch (SAXException ex) {
- // Ignore parse exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (IOException ex) {
- // Ignore I/O exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (Exception ex) {
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), ex);
- } finally {
- ExtendedPlatform.safeClose(inputStream);
- }
- }
- return targetNamespace;
- }
-
- /**
- * Retrieves the XML comments located above the root element in given {@link Resource resource}. Returns a
- * meaningful result only if given {@link Resource resource} is an XML document.
- *
- * @param resource
- * The {@link Resource resource} to investigate.
- * @return Collection of strings representing the retrieved XML comments or empty collection if no such could be
- * found.
- */
- public static Collection<String> readRootElementComments(Resource resource) {
- if (resource != null) {
- return readRootElementComments(getURIConverter(resource.getResourceSet()), resource.getURI());
- }
- return Collections.emptyList();
- }
-
- /**
- * Retrieves the XML comments located above the root element in resource behind given {@link URI}. Returns a
- * meaningful result only if the resource in question is an XML document.
- *
- * @param uriConverter
- * The {@link URIConverter uriConverter} used to create {@link InputStream input stream} . May be
- * <code>null</code>.
- * @param uri
- * The {@link URI uri} of the resource to investigate.
- * @return Collection of strings representing the retrieved XML comments or empty collection if no such could be
- * found.
- */
- public static Collection<String> readRootElementComments(URIConverter uriConverter, URI uri) {
- Collection<String> comments = new ArrayList<String>();
-
- if (exists(uri)) {
- InputStream inputStream = null;
- try {
- uriConverter = uriConverter != null ? uriConverter : new ExtensibleURIConverterImpl();
- inputStream = uriConverter.createInputStream(uri);
- XMLRootElementHandler handler = new XMLRootElementHandler();
- // Parse and retrieve comments above root element
- handler.parseContents(inputStream, true);
- comments = handler.getRootElementComments();
- } catch (SAXException ex) {
- // Ignore parse exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (IOException ex) {
- // Ignore I/O exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (Exception ex) {
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), ex);
- } finally {
- ExtendedPlatform.safeClose(inputStream);
- }
- }
- return comments;
- }
-
- /**
- * Reads the XSI schema location of given {@link Resource resource} and extracts pairs of namespace and schema URIs
- * from it (see http://www.w3.org/TR/xmlschema-0/#schemaLocation for details). Returns a meaningful result only if
- * given {@link Resource resource} is an XML document.
- *
- * @param resource
- * The {@link Resource resource} to investigate.
- * @return Pairs of namespace and schema URIs in given {@link Resource resource} or an empty map if the
- * {@link Resource resource} is either a non-XML file or an XML file which is not well-formed or has no XSI
- * schema location.
- */
- public static Map<String, String> readSchemaLocationEntries(Resource resource) {
- if (resource != null) {
- return readSchemaLocationEntries(getURIConverter(resource.getResourceSet()), resource.getURI());
- }
- return Collections.emptyMap();
- }
-
- /**
- * Reads the XSI schema location of the resource behind given {@link URI} and extracts pairs of namespace and schema
- * URIs from it (see http://www.w3.org/TR/xmlschema-0/#schemaLocation for details). Returns a meaningful result only
- * if the resource in question is an XML document.
- *
- * @param uriConverter
- * The {@link URIConverter uriConverter} used to create {@link InputStream input stream} . May be
- * <code>null</code>.
- * @param uri
- * The {@link URI uri} of the {@link Resource resource} to investigate.
- * @return Pairs of namespace and schema URIs in resource behind given {@link URI} or an empty map if the resource
- * in question is either a non-XML file or an XML file which is not well-formed or has no XSI schema
- * location.
- */
- public static Map<String, String> readSchemaLocationEntries(URIConverter uriConverter, URI uri) {
- String schemaLocation = null;
- if (exists(uri)) {
- InputStream inputStream = null;
- try {
- uriConverter = uriConverter != null ? uriConverter : new ExtensibleURIConverterImpl();
- inputStream = uriConverter.createInputStream(uri);
- XMLRootElementHandler handler = new XMLRootElementHandler();
- handler.parseContents(inputStream);
- schemaLocation = handler.getSchemaLocation();
- } catch (SAXException ex) {
- // Ignore parse exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (IOException ex) {
- // Ignore I/O exceptions because we might be face to non-XML files or XML files
- // which are not well-formed - that's o.k. simply return null
- } catch (Exception ex) {
- PlatformLogUtil.logAsWarning(Activator.getPlugin(), ex);
- } finally {
- ExtendedPlatform.safeClose(inputStream);
- }
- }
- Map<String, String> schemaLocationEntries = new HashMap<String, String>();
- if (schemaLocation != null) {
- String[] schemaLocationTokens = schemaLocation.split(" "); //$NON-NLS-1$
- for (int i = 0; i + 1 < schemaLocationTokens.length; i = i + 2) {
- schemaLocationEntries.put(schemaLocationTokens[i], schemaLocationTokens[i + 1]);
- }
- }
- return schemaLocationEntries;
- }
-
- /**
- * Returns a set of default options which can be used for loading a Resource.
- *
- * @return A set of default options for loading a Resource.
- */
- public static Map<?, ?> getDefaultLoadOptions() {
- HashMap<Object, Object> options = new HashMap<Object, Object>(1);
-
- // Be fault-tolerant and enable files which are partially broken to be loaded
- options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
-
- return options;
- }
-
- /**
- * Returns a map with the default options for resource saving.
- *
- * @return This method will return an empty map.
- */
- public static Map<?, ?> getDefaultSaveOptions() {
- return Collections.emptyMap();
- }
-
- /**
- * Retrieves the top level EObject contained within a resource.
- *
- * @param resource
- * Some model resource
- * @return The first EObject from the resource's content. Returns <code>null</code> if:
- * <ul>
- * <li><code>resource</code> is <code>null</code>;</li>
- * <li><code>resource</code> has no content;</li>
- * <li>content does not contain an EObject as its first element.</li>
- * </ul>
- */
- public static EObject getModelRoot(Resource resource) {
- if (resource != null) {
- EList<EObject> contents = resource.getContents();
- if (contents.size() > 0) {
- return resource.getContents().get(0);
- }
- }
- return null;
- }
-
- /**
- * Returns the root element of the model owned by the resource specified by the given URI. Does not explicitly ask
- * the loading of the resource if it has not already been loaded in resource set.
- *
- * @param resourceSet
- * The resource set into which model resource must be loaded.
- * @param uri
- * The URI to resolve; i.e. the URI of the model resource to load.
- * @return The root of the loaded model or <code>null</code> if underlying resource has not been loaded.
- */
- public static EObject getModelRoot(ResourceSet resourceSet, URI uri) {
- return loadModelRoot(resourceSet, uri, null, false);
- }
-
- /**
- * Returns the element of the model owned by the resource specified by the given URI and pointed by the given
- * fragment. Does not explicitly ask the loading of the resource if it has not already been loaded in resource set.
- *
- * @param resourceSet
- * The resource set into which model resource must be loaded.
- * @param uri
- * The URI to resolve; i.e. the URI of the model resource to load.
- * @return The element of the loaded model pointed by the fragment of the uri or <code>null</code> if underlying
- * resource has not been loaded.
- */
- public static EObject getModelFragment(ResourceSet resourceSet, URI uri) {
- return loadModelFragment(resourceSet, uri, false);
- }
-
- /**
- * Returns the element of the model pointed by the fragment owned by the resource specified by the given {@link URI
- * uri}. Asks the loading of the resource if it has not already been loaded in resource set.
- *
- * @param resourceSet
- * The resource set into which model resource must be loaded.
- * @param uri
- * The {@link URI uri} containing a fragment to resolve; i.e. the URI of the model resource to load
- * append with the reference to the model object.
- * @return The object of the loaded model referenced by the fragment, or <code>null</code> if the URI cannot be
- * resolved to an existing file.
- */
- public static EObject loadModelFragment(ResourceSet resourceSet, URI uri) {
- return loadModelFragment(resourceSet, uri, true);
- }
-
- private static EObject loadModelFragment(ResourceSet resourceSet, URI uri, boolean loadOnDemand) {
- Assert.isNotNull(resourceSet);
- Assert.isNotNull(uri);
-
- if (uri.hasFragment()) {
- // Try to convert given URI to platform:/resource URI if not yet so
- /*
- * !! Important Note !! This is necessary in order to avoid that resources which are located inside the
- * workspace get loaded multiple times just because they are referenced by URIs with different schemes. If
- * given resource set were an instance of ResourceSetImpl this extra conversion wouldn't be necessary.
- * org.eclipse.emf.ecore.resource.ResourceSet.getResource(URI, boolean) normalizes and compares given URI
- * and to normalized copies of URIs of already present resources and thereby avoids multiple loading of same
- * resources on its own. This is however not true when ExtendedResourceSetImpl or a subclass of it is used.
- * Herein, URI normalization and comparison has been removed from
- * org.eclipse.sphinx.emf.resource.ExtendedResourceSetImpl.getResource(URI, boolean) in order to increase
- * runtime performance.
- */
- if (!uri.isPlatform()) {
- uri = convertToPlatformResourceURI(uri);
- }
-
- return resourceSet.getEObject(uri, loadOnDemand);
- }
- return null;
- }
-
- /**
- * Returns the root element of the model owned by the resource specified by the given URI. Asks the loading of the
- * resource if it has not already been loaded in resource set.
- *
- * @param resourceSet
- * The resource set into which model resource must be loaded.
- * @param uri
- * The URI to resolve; i.e. the URI of the model resource to load.
- * @param options
- * The load options. If <code>null</code>, default loading options are used.
- * @return The root of the loaded model.
- */
- public static EObject loadModelRoot(ResourceSet resourceSet, URI uri, Map<?, ?> options) {
- return loadModelRoot(resourceSet, uri, options, true);
- }
-
- /**
- * Loads a model from a {@link java.io.File File} in a given {@link ResourceSet}.
- * <p>
- * This will return the first root of the loaded model, other roots can be accessed via the resource's content.
- * </p>
- *
- * @param resourceSet
- * The {@link ResourceSet} to load the model in.
- * @param file
- * {@link java.io.File File} containing the model to be loaded.
- * @param options
- * The load options. If <code>null</code>, default loading options are used.
- * @return The model loaded from the file.
- * @throws IOException
- * If the given file does not exist.
- */
- public static EObject loadModelRoot(ResourceSet resourceSet, File file, Map<?, ?> options) throws IOException {
- Assert.isNotNull(file);
- return loadModelRoot(resourceSet, URI.createFileURI(file.getPath()), options);
- }
-
- /**
- * Returns the {@linkplain Resource resource} corresponding to the specified {@linkplain Object object}.
- * <p>
- * The supported object types are:
- * <ul>
- * <li>{@linkplain org.eclipse.emf.ecore.resource.Resource}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.EObject}</li>
- * <li>{@linkplain org.eclipse.emf.ecore.util.FeatureMap.Entry}</li>
- * <li>{@linkplain org.eclipse.emf.edit.provider.IWrapperItemProvider}</li>
- * </ul>
- * <p>
- * If the type of the specified object does not belongs to that list of supported types, <code>null</code> is
- * returned.
- *
- * @param object
- * The object from which a resource must be returned.
- * @return The underlying resource from the given object.
- */
- public static Resource getResource(Object object) {
- if (object instanceof Resource) {
- return (Resource) object;
- } else if (object instanceof EObject) {
- return getResource((EObject) object);
- } else if (object instanceof IWrapperItemProvider) {
- return getResource((IWrapperItemProvider) object);
- } else if (object instanceof FeatureMap.Entry) {
- return getResource((FeatureMap.Entry) object);
- } else if (object instanceof TransientItemProvider) {
- return getResource((TransientItemProvider) object);
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} corresponding to the given {@link EObject object}.
- *
- * @param eObject
- * The {@linkplain EObject object} whose {@link Resource resource} is to be returned.
- * @return The resource corresponding to the specified {@link EObject object}.
- */
- public static Resource getResource(final EObject eObject) {
- if (eObject != null) {
- return eObject.eResource();
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} owning the given {@link IWrapperItemProvider provider}.
- * <p>
- * First retrieves the owner of the {@link IWrapperItemProvider provider}; then, if owner is an {@linkplain EObject}
- * returns its resource, else delegates to {@linkplain #getResource(Object)}.
- *
- * @param provider
- * The {@linkplain IWrapperItemProvider} whose resource must be returned.
- * @return The resource containing the specified {@link IWrapperItemProvider provider}; <code>null</code> if that
- * provider is <code>null</code>.
- */
- public static Resource getResource(final IWrapperItemProvider provider) {
- if (provider != null) {
- Object owner = provider.getOwner();
- if (owner instanceof EObject) {
- return ((EObject) owner).eResource();
- } else {
- Object unwrapped = AdapterFactoryEditingDomain.unwrap(provider);
- return getResource(unwrapped);
- }
- }
- return null;
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} matching the given {@link FeatureMap.Entry entry}.
- * <p>
- * First unwraps the {@link FeatureMap.Entry entry}; then, delegates to {@linkplain #getResource(Object)}.
- *
- * @param entry
- * The {@linkplain FeatureMap.Entry} whose underlying resource must be returned.
- * @return The resource under the specified {@link FeatureMap.Entry entry}.
- */
- public static Resource getResource(FeatureMap.Entry entry) {
- Object unwrapped = AdapterFactoryEditingDomain.unwrap(entry);
- return getResource(unwrapped);
- }
-
- /**
- * Retrieves the {@linkplain Resource resource} owning the given {@link TransientItemProvider provider}.
- * <p>
- * First retrieves the owner of the {@link TransientItemProvider provider}; then, if owner is an
- * {@linkplain EObject} returns its resource, else delegates to {@linkplain #getResource(Object)}.
- *
- * @param provider
- * The {@linkplain TransientItemProvider} whose resource must be returned.
- * @return The resource containing the specified {@link IWrapperItemProvider provider}; <code>null</code> if that
- * provider is <code>null</code>.
- */
- public static Resource getResource(TransientItemProvider provider) {
- if (provider != null) {
- Notifier target = provider.getTarget();
- if (target instanceof EObject) {
- return ((EObject) target).eResource();
- }
- }
- return null;
- }
-
- /**
- * Returns the contents of given Resource. If the provided Resource is
- * <tt>null<tt> the method will return an empty list.
- *
- * @param resource
- * @return The content of the given <code>resource</code> or an empty list if no Resource is provided.
- */
- public static EList<EObject> getResourceContents(Resource resource) {
- if (resource != null) {
- return resource.getContents();
- }
- return new BasicEList<EObject>(0);
- }
-
- /**
- * Returns the name of the model for the provided model root.
- *
- * @param modelRoot
- * Can either be an EObject or a Resource.
- * @return The name of the model specified by the given <code>modelRoot</code>.
- */
- public static String getModelName(Notifier modelRoot) {
- EObject modelContent = null;
- if (modelRoot instanceof EObject) {
- modelContent = (EObject) modelRoot;
- }
- if (modelRoot instanceof Resource) {
- modelContent = EcoreResourceUtil.getModelRoot((Resource) modelRoot);
- }
- if (modelContent != null) {
- String modelPackageName = modelContent.eClass().getEPackage().getName();
- return modelPackageName.substring(0, 1).toUpperCase() + modelPackageName.substring(1);
- }
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Proves if the model with the specified {@link URI uri} is already loaded into the given {@link ResourceSet
- * resourceSet}.
- *
- * @param resourceSet
- * The resource set to search resource in.
- * @param uri
- * The URI of the concerned resource.
- * @return <ul>
- * <li><tt><b>true</b>&nbsp;&nbsp;</tt> if resource set contains the model with specified the URI;</li>
- * <li><tt><b>false</b>&nbsp;</tt> otherwise.</li>
- * </ul>
- */
- public static boolean isResourceLoaded(ResourceSet resourceSet, URI uri) {
- if (resourceSet != null && uri != null) {
- Resource resource = resourceSet.getResource(uri, false);
- return resource != null && resource.isLoaded();
- }
- return false;
- }
-
- /**
- * Create the new model given by the {@link EObject modelRoot} parameter. The method will create a new Resource
- * specified by a given URI and content type id. The new created resource will be added to a given ResourceSet.
- *
- * @param resourceSet
- * The ResourceSet to which the new Resource is added.
- * @param uri
- * The URI specifying the location to which the Resource is to be saved to.
- * @param contentTypeId
- * The id of the content type of which new created Resource shall be of.
- * @param modelRoot
- * Can either be an EObject or a Resource.
- * @since 0.7.0
- */
- public static Resource addNewModelResource(ResourceSet resourceSet, URI uri, String contentTypeId, EObject modelRoot) {
- if (uri != null && modelRoot != null) {
- try {
- // Create new ResourceSet if none has been provided
- if (resourceSet == null) {
- resourceSet = new ScopingResourceSetImpl();
- }
-
- // Unload and remove model resource if it is already loaded
- Resource resource = resourceSet.getResource(uri, false);
- if (resource != null) {
- try {
- unloadResource(resource);
- } catch (Exception ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
- }
- }
-
- // Create and add new model resource to the resourceSet
- resource = resourceSet.createResource(uri, contentTypeId);
- if (resource != null) {
- resource.getContents().add(modelRoot);
- }
- return resource;
- } catch (Exception ex) {
- throw new WrappedException(ex);
- }
- }
- return null;
- }
-
- /**
- * The {@link Resource} provided as argument will be added to the given ResourceSet if it is not already inside.
- *
- * @param resourceSet
- * The resourceSet where to add resources
- * @param resource
- * The resource to add
- * @since 0.7.0
- */
- public static void addModelResource(ResourceSet resourceSet, Resource resource) {
- if (resource != null) {
- // Create new ResourceSet if none has been provided
- if (resourceSet == null) {
- resourceSet = new ScopingResourceSetImpl();
- }
-
- // Add resource to resourceSet if not already present
- if (resourceSet.getResource(resource.getURI(), false) == null) {
- resourceSet.getResources().add(resource);
- }
- }
- }
-
- /**
- * Saves the new model given by the {@link EObject modelRoot} parameter. The method will create a new Resource
- * specified by a given URI and content type id. The new created resource will be added to a given ResourceSet and
- * saved.
- *
- * @param resourceSet
- * The ResourceSet to which the new Resource is added.
- * @param uri
- * The URI specifying the location to which the Resource is to be saved to.
- * @param contentTypeId
- * The id of the content type of which new created Resource shall be of.
- * @param modelRoot
- * Can either be an EObject or a Resource.
- * @param options
- * The save options.
- * @see #getDefaultSaveOptions()
- */
- public static void saveNewModelResource(ResourceSet resourceSet, URI uri, String contentTypeId, EObject modelRoot, Map<?, ?> options) {
- // Create new model resource and add it to the provided ResourceSet
- Resource resource = addNewModelResource(resourceSet, uri, contentTypeId, modelRoot);
-
- // Save the newly created resource
- saveModelResource(resource, options);
- }
-
- /**
- * Saves the specified <code>resource</code>.
- *
- * @param resource
- * The {@link Resource resource} to be saved.
- * @param options
- * The save options.
- * @see #getDefaultSaveOptions()
- */
- public static void saveModelResource(Resource resource, Map<?, ?> options) {
- if (resource != null) {
- try {
- resource.save(options);
- } catch (IOException ex) {
- // Record exception as error on resource
- Throwable cause = ex.getCause();
- Exception exception = cause instanceof Exception ? (Exception) cause : ex;
- URI uri = resource.getURI();
- resource.getErrors()
- .add(new XMIException(NLS.bind(Messages.error_problemOccurredWhenSavingResource, uri.toString()), exception, uri.toString(),
- 1, 1));
-
- // Re-throw exception
- throw new WrappedException(ex);
- }
- }
- }
-
- /**
- * Unloads given {@link Resource resource} and removes it from underlying {@link ResourceSet resourceSet}.
- *
- * @param resource
- * The resource to be unloaded.
- */
- public static void unloadResource(Resource resource) {
- unloadResource(resource, false);
- }
-
- /**
- * Unloads given {@link Resource resource} and removes it from underlying {@link ResourceSet resourceSet}.
- *
- * @param resource
- * The resource to be unloaded.
- * @param memoryOptimized
- * Will activate the memory optimization option for unloading the resource. This is only available if the
- * resource is an XMLResource.
- */
- public static void unloadResource(Resource resource, boolean memoryOptimized) {
- if (resource != null) {
- try {
- // Perform resource unload, either memory optimized or normally
- if (memoryOptimized) {
- ExtendedResource extendedResource = ExtendedResourceAdapterFactory.INSTANCE.adapt(resource);
- if (extendedResource != null) {
- Map<Object, Object> defaultLoadOptions = extendedResource.getDefaultLoadOptions();
- defaultLoadOptions.put(ExtendedResource.OPTION_UNLOAD_MEMORY_OPTIMIZED, Boolean.TRUE);
- }
- }
- resource.unload();
- } catch (Exception ex) {
- throw new WrappedException(ex);
- } finally {
- // Remove resource from ResourceSet
- ResourceSet resourceSet = resource.getResourceSet();
- if (resourceSet != null) {
- resourceSet.getResources().remove(resource);
- }
- }
- }
- }
-
- /**
- * Unloads the resource with the specified URI from the given resource set.
- *
- * @param resourceSet
- * A resource set from which the model's resource should be unloaded.
- * @param uri
- * The URI of the resource to unload.
- */
- public static void unloadResource(ResourceSet resourceSet, URI uri) {
- unloadResource(resourceSet, uri, false);
- }
-
- /**
- * Unloads the resource with the specified URI from the given resource set.
- * <p>
- * It is recommended to call this method inside a write-transaction (see
- * {@link EcorePlatformUtil#unloadFile(ResourceSet, IPath)}).
- *
- * @param resourceSet
- * A resource set from which the model's resource should be unloaded.
- * @param uri
- * The URI of the resource to unload.
- * @param memoryOptimized
- * Will activate the memory optimization option for unloading the resource. This is only available if the
- * resource is an XMLResource.
- */
- public static void unloadResource(ResourceSet resourceSet, URI uri, boolean memoryOptimized) {
- if (resourceSet != null && uri != null) {
- // Get resource and unload it
- Resource resource = resourceSet.getResource(uri, false);
- unloadResource(resource, memoryOptimized);
- }
- }
-
- /**
- * Parses {@link Resource resource} with given {@link URI uri} and validates it against XSD schema with specified
- * {@link URL url}. Raises an exception if the {@link Resource resource}'s content is not compliant with respect to
- * XSD schema.
- *
- * @param uri
- * The {@link URI uri} of the {@link Resource resource} to be validated.
- * @param schemaURL
- * The {@link URL url} of the XSD schema to be used for validation.
- * @throws SAXException
- * @throws IOException
- */
- public static void validate(URI uri, URL schemaURL) throws SAXException, IOException {
- Assert.isNotNull(uri);
-
- // 1. Lookup a factory for the W3C XML Schema language
- SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
- // 2. Compile the schema
- Schema schema = factory.newSchema(schemaURL);
-
- // 3. Get a validator from the schema
- Validator validator = schema.newValidator();
-
- // 4. Load the resource and validate it
- InputStream stream = null;
- try {
- stream = URIConverter.INSTANCE.createInputStream(uri);
- Source source = new StreamSource(stream);
- validator.validate(source);
- } finally {
- ExtendedPlatform.safeClose(stream);
- }
- }
-
- /**
- * Loads from resource set the resource specified by the given URI, or try to load the URI if not in resource set.
- *
- * @param resourceSet
- * The resource set into which model resource must be loaded.
- * @param uri
- * The URI to resolve; <em>i.e.</em> the URI of the model resource to load.
- * @param options
- * The loading options.
- * @param loadOnDemand
- * If <code>true</code>, creates and loads the resource if it does not already exist.
- * @return The resource resolved by the specified URI, or <code>null</code> if there is not one and it is not being
- * demand loaded.
- */
- private static Resource loadModelResource(ResourceSet resourceSet, URI uri, Map<?, ?> options, boolean loadOnDemand) {
- Assert.isNotNull(uri);
-
- // Create new ResourceSet if none has been provided
- if (resourceSet == null) {
- resourceSet = new ScopingResourceSetImpl();
- }
-
- // Try to convert given URI to platform:/resource URI if not yet so
- /*
- * !! Important Note !! This is necessary in order to avoid that resources which are located inside the
- * workspace get loaded multiple times just because they are referenced by URIs with different schemes. If given
- * resource set were an instance of ResourceSetImpl this extra conversion wouldn't be necessary.
- * org.eclipse.emf.ecore.resource.ResourceSet.getResource(URI, boolean) normalizes and compares given URI and to
- * normalized copies of URIs of already present resources and thereby avoids multiple loading of same resources
- * on its own. This is however not true when ExtendedResourceSetImpl or a subclass of it is used. Herein, URI
- * normalization and comparison has been removed from
- * org.eclipse.sphinx.emf.resource.ExtendedResourceSetImpl.getResource(URI, boolean) in order to increase
- * runtime performance.
- */
- if (!uri.isPlatform()) {
- uri = convertToPlatformResourceURI(uri);
- }
-
- // Just get model resource if it is already loaded
- Resource resource = resourceSet.getResource(uri, false);
-
- // Load it using specified options if not done so yet and a demand load has been requested
- if ((resource == null || !resource.isLoaded()) && loadOnDemand) {
- if (exists(uri)) {
- if (resource == null) {
- String contentType = getContentTypeId(uri);
- resource = resourceSet.createResource(uri, contentType);
- }
- if (resource != null) {
- try {
- // Capture errors and warnings encountered during resource creation
- /*
- * !! Important note !! This is necessary because the resource's errors and warnings are
- * automatically cleared when the loading begins. Therefore, if we don't retrieve them at this
- * point all previously encountered errors and warnings would be lost (see
- * org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(InputStream, Map<?, ?>) for details)
- */
- List<Diagnostic> creationErrors = new ArrayList<Diagnostic>(resource.getErrors());
- List<Diagnostic> creationWarnings = new ArrayList<Diagnostic>(resource.getWarnings());
-
- // Load resource
- resource.load(options);
-
- // Make sure that no empty resources are kept in resource set
- if (resource.getContents().isEmpty()) {
- unloadResource(resource, true);
- }
-
- // Restore creation time errors and warnings
- resource.getErrors().addAll(creationErrors);
- resource.getWarnings().addAll(creationWarnings);
- } catch (IOException ex) {
- // Capture errors and warnings encountered during resource load attempt
- /*
- * !! Important note !! This is necessary because the resource's errors and warnings are
- * automatically cleared when it gets unloaded. Therefore, if we don't retrieve them at this
- * point all encountered errors and warnings encountered during loading would be lost (see
- * org.eclipse.emf.ecore.resource.impl.ResourceImpl.doUnload() for details)
- */
- List<Diagnostic> loadErrors = new ArrayList<Diagnostic>(resource.getErrors());
- List<Diagnostic> loadWarnings = new ArrayList<Diagnostic>(resource.getWarnings());
-
- // Make sure that resource gets unloaded and removed from resource set again
- try {
- unloadResource(resource, true);
- } catch (Exception e) {
- // Log unload problem in Error Log but don't let it go along as runtime exception. It is
- // most likely just a consequence of the load problems encountered before and therefore
- // should not prevent those from being restored as errors and warnings on resource.
- PlatformLogUtil.logAsError(Activator.getPlugin(), e);
- }
-
- // Restore load time errors and warnings on resource
- resource.getErrors().addAll(loadErrors);
- resource.getWarnings().addAll(loadWarnings);
-
- // Re-throw exception
- throw new WrappedException(ex);
- }
- }
- }
- }
- return resource;
- }
-
- /**
- * Loads the model from the resource specified by the given URI and returns its root element.
- *
- * @param resourceSet
- * The resource set into which model resource must be loaded.
- * @param uri
- * The URI to resolve; <em>i.e.</em> the URI of the model resource to load.
- * @param options
- * The load options. If <code>null</code>, default loading options are used.
- * @param loadOnDemand
- * If <code>true</code>, creates and loads the resource if it does not already exist.
- * @return The root of the loaded model; can be <code>null</code> if resource is not loaded resource set.
- */
- private static EObject loadModelRoot(ResourceSet resourceSet, URI uri, Map<?, ?> options, boolean loadOnDemand) {
- // Use default loading options when no specified
- if (options == null) {
- options = getDefaultLoadOptions();
- }
-
- // Load resource from resource set
- Resource resource = loadModelResource(resourceSet, uri, options, loadOnDemand);
-
- // Obtain and return resource content
- return getModelRoot(resource);
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceEditingDomainUtil.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceEditingDomainUtil.java
deleted file mode 100644
index 0cdfaa2404d..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceEditingDomainUtil.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2010 See4sys, BMW Car IT 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:
- * See4sys - Initial API and implementation
- * BMW Car IT - Added/Updated javadoc
- *
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor.sphinx;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Platform;
-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.FeatureMap;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.edit.provider.IWrapperItemProvider;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.sphinx.emf.domain.IContainerEditingDomainProvider;
-import org.eclipse.sphinx.emf.edit.TransientItemProvider;
-import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor;
-import org.eclipse.sphinx.emf.model.IModelDescriptor;
-
-/**
- * This utility class is intended to retrieve an {@linkplain EditingDomain} in various ways.
- */
-public final class WorkspaceEditingDomainUtil {
-
- // Prevent from instantiation
- private WorkspaceEditingDomainUtil() {
- }
-
- /**
- * Returns the {@link TransactionalEditingDomain editing domain} which currently contains the given {@link IFile
- * file} in its {@link ResourceSet resource set}.
- *
- * @param file
- * The {@link IFile file} whose current {@link TransactionalEditingDomain editing domain} is to be
- * retrieved.
- * @return The {@link TransactionalEditingDomain editing domain} which contains the given {@link IFile file}, or
- * <code>null</code> if given {@link IFile file} isn't contained in any {@link TransactionalEditingDomain
- * editing domain}.
- */
- public static TransactionalEditingDomain getCurrentEditingDomain(IFile file) {
- for (TransactionalEditingDomain editingDomain : getEditingDomains(ResourcesPlugin.getWorkspace().getRoot())) {
- if (EcorePlatformUtil.isFileLoaded(editingDomain, file)) {
- return editingDomain;
- }
- }
- return null;
- }
-
- /**
- * Returns the {@link TransactionalEditingDomain editing domain} to which the given {@link IFile file} is mapped.
- * The mapped {@link TransactionalEditingDomain editing domain} is the {@link TransactionalEditingDomain editing
- * domain} which is used as target when loading the {@link IFile file} from the workspace.
- * <p>
- * Even though the mapped {@link TransactionalEditingDomain editing domain} represents the primary
- * {@link TransactionalEditingDomain editing domain} for the given {@link IFile file} it still may happen that the
- * {@link IFile file} gets loaded in another or "foreign" {@link TransactionalEditingDomain editing domain}. Typical
- * reasons for this are e.g. lazy loading of one file from multiple other files which are in different
- * {@link TransactionalEditingDomain editing domain}s or programatic action by some application.
- * <p>
- *
- * @param file
- * The {@link IFile file} whose mapped {@link TransactionalEditingDomain editing domain} is to be
- * retrieved.
- * @return The {@link TransactionalEditingDomain editing domain} to which the given {@link IFile file} is mapped, or
- * <code>null</code> if given {@link IFile file} isn't mapped to any {@link TransactionalEditingDomain
- * editing domain}.
- */
- public static TransactionalEditingDomain getMappedEditingDomain(IFile file) {
- if (file != null) {
- IEditingDomainProvider provider = (IEditingDomainProvider) Platform.getAdapterManager().loadAdapter(file,
- IEditingDomainProvider.class.getName());
- if (provider != null) {
- EditingDomain editingDomain = provider.getEditingDomain();
- if (editingDomain instanceof TransactionalEditingDomain) {
- return (TransactionalEditingDomain) editingDomain;
- }
- }
- }
- return null;
- }
-
- /**
- * Retrieves the {@link TransactionalEditingDomain editing domain} which the given {@link Object object} belongs to.
- * The following types of {@link Object object}s are supported:
- * <p>
- * <ul>
- * <li>{@linkplain EObject}</li>
- * <li>{@linkplain FeatureMap.Entry}</li>
- * <li>{@linkplain IEditingDomainProvider}</li>
- * <li>{@linkplain IFile}</li>
- * <li>{@linkplain IModelDescriptor}</li>
- * <li>{@linkplain IWrapperProviderItem}</li>
- * <li>{@linkplain Resource}</li>
- * <li>{@linkplain ResourceSet}</li>
- * <li>{@linkplain Transaction}</li>
- * <li>{@linkplain TransactionalEditingDomain}</li>
- * <li>{@linkplain URI}</li>
- * </ul>
- * <p>
- * Note that it is not possible to obtain a single {@link TransactionalEditingDomain editing domain} from a
- * {@linkplain IContainer}. You can however retrieve the collection of {@link TransactionalEditingDomain editing
- * domain}s available on a {@linkplain IContainer} by calling {@linkplain #getEditingDomains(IContainer)}.
- *
- * @param object
- * The object whose corresponding {@link TransactionalEditingDomain editing domain} must be returned.
- * @return The EditingDomain the <code>object</code> corresponds with or <code>null</code> if the
- * <code>object</code> cannot be mapped to an {@link TransactionalEditingDomain editing domain}.
- * @see org.eclipse.sphinx.emf.workspace.domain.WorkspaceEditingDomainManager#getEditingDomainMapping()
- * @see #getEditingDomains(IContainer)
- */
- public static TransactionalEditingDomain getEditingDomain(Object object) {
- if (object instanceof IModelDescriptor) {
- return getEditingDomain((IModelDescriptor) object);
- } else if (object instanceof IFile) {
- return getEditingDomain((IFile) object);
- } else if (object instanceof URI) {
- return getEditingDomain((URI) object);
- } else if (object instanceof Resource) {
- // If resource is not yet or not anymore in a resource set, then try to figure out which editing domain it
- // would belong to if it were in a resource set
- Resource resource = (Resource) object;
- if (resource.getResourceSet() == null) {
- return getEditingDomain(EcorePlatformUtil.getFile(resource));
- }
- } else if (object instanceof IWrapperItemProvider) {
- return getEditingDomain((IWrapperItemProvider) object);
- } else if (object instanceof FeatureMap.Entry) {
- return getEditingDomain((FeatureMap.Entry) object);
- } else if (object instanceof TransientItemProvider) {
- return getEditingDomain((TransientItemProvider) object);
- }
-
- return object != null ? TransactionUtil.getEditingDomain(object) : null;
- }
-
- /**
- * Retrieves the {@link TransactionalEditingDomain editing domain} behind given {@link IModelDescriptor model
- * descriptor}.
- *
- * @param modelDescriptor
- * The {@link IModelDescriptor model descriptor} whose {@link TransactionalEditingDomain editing domain}
- * is to be retrieved.
- * @return The {@link TransactionalEditingDomain editing domain} behind given {@link IModelDescriptor model
- * descriptor} or <code>null</code> if no such could be retrieved.
- */
- public static TransactionalEditingDomain getEditingDomain(IModelDescriptor modelDescriptor) {
- if (modelDescriptor != null) {
- return modelDescriptor.getEditingDomain();
- }
- return null;
- }
-
- /**
- * Retrieves the {@link TransactionalEditingDomain editing domain} corresponding to the given {@link IFile file}.
- * Tries at first to determine the {@link TransactionalEditingDomain editing domain} which currently contains the
- * given {@link IFile file} in its {@link ResourceSet resource set} and returns it if successful. Otherwise, the
- * {@link TransactionalEditingDomain editing domain} to which the given {@link IFile file} is mapped is returned.
- *
- * @param file
- * The {@link IFile file} whose {@link TransactionalEditingDomain is to be retrieved}.
- * @return The {@link TransactionalEditingDomain editing domain} the given file belongs to, or <code>null</code> if
- * given {@link IFile file} doesn't belong to any {@link TransactionalEditingDomain editing domain}.
- * @see #getCurrentEditingDomain(IFile)
- * @see #getMappedEditingDomain(IFile)
- */
- public static TransactionalEditingDomain getEditingDomain(IFile file) {
- TransactionalEditingDomain editingDomain = getCurrentEditingDomain(file);
- if (editingDomain != null) {
- return editingDomain;
- }
- return getMappedEditingDomain(file);
- }
-
- /**
- * Retrieves the EditingDomain by a URI. Consults the active mapping to map a resource to its
- * {@link TransactionalEditingDomain editing domain}.
- *
- * @param uri
- * An URI (file, EMF Object's URI)
- * @return The {@link TransactionalEditingDomain editing domain} associated with the given URI. Returns
- * <code>null</code> if the URI cannot be resolved to workspace file or no
- * {@link TransactionalEditingDomain editing domain} can be mapped through the active mapping.
- */
- public static TransactionalEditingDomain getEditingDomain(URI uri) {
- IFile file = EcorePlatformUtil.getFile(uri);
- return getEditingDomain(file);
- }
-
- /**
- * Retrieves the {@link TransactionalEditingDomain editing domain} corresponding to the object wrapped in the given
- * IWrapperItemProvider.
- *
- * @param wrapperItemProvider
- * The IWrapperItemProvider wrapping the Object for which the {@link TransactionalEditingDomain editing
- * domain} is to be retrieved.
- * @return The {@link TransactionalEditingDomain editing domain} the wrapped Object is associated with or
- * <code>null</code> if the Object cannot be mapped to an {@link TransactionalEditingDomain editing domain}.
- */
- public static TransactionalEditingDomain getEditingDomain(IWrapperItemProvider wrapperItemProvider) {
- if (wrapperItemProvider != null) {
- Object unwrapped = AdapterFactoryEditingDomain.unwrap(wrapperItemProvider);
- TransactionalEditingDomain editingDomain = getEditingDomain(unwrapped);
- if (editingDomain != null) {
- return editingDomain;
- }
- return getEditingDomain(wrapperItemProvider.getOwner());
- }
- return null;
- }
-
- /**
- * Returns the {@link TransactionalEditingDomain editing domain} for the value Object of the given FeatureMap.Entry.
- *
- * @param entry
- * A FeatureMap.Entry holding the Object for which the {@link TransactionalEditingDomain editing domain}
- * is to be retrieved.
- * @return The EditingDomain the Object held by the given <code>entry</entry> corresponds with or <code>null</code>
- * if the Object cannot be mapped to an {@link TransactionalEditingDomain editing domain}.
- */
- public static TransactionalEditingDomain getEditingDomain(FeatureMap.Entry entry) {
- Object unwrapped = AdapterFactoryEditingDomain.unwrap(entry);
- return getEditingDomain(unwrapped);
- }
-
- /**
- * Returns the {@link TransactionalEditingDomain editing domain} for the value Object of the given
- * ItemProviderAdapter.
- *
- * @param provider
- * An ItemProviderAdapter holding the Object for which the {@link TransactionalEditingDomain editing
- * domain} is to be retrieved.
- * @return The EditingDomain the Target held by the given
- * <code>provider</entry> corresponds with or <code>null</code> if the Object cannot be mapped to an
- * {@link TransactionalEditingDomain editing domain}.
- */
- public static TransactionalEditingDomain getEditingDomain(TransientItemProvider provider) {
- Object target = provider.getTarget();
- return getEditingDomain(target);
- }
-
- /**
- * Retrieves the {@link TransactionalEditingDomain editing domain} corresponding to the specified meta-model
- * descriptor for the given context container.
- *
- * @param container
- * The container to consider as context object in order to retrieve the right
- * {@link TransactionalEditingDomain editing domain}.
- * @param mmDescriptor
- * A meta-model descriptor.
- * @return The {@link TransactionalEditingDomain editing domain} for the specified meta-model descriptor and the
- * specified context container or <code>null</code> if it cannot be mapped to any
- * {@link TransactionalEditingDomain editing domain}.
- */
- public static TransactionalEditingDomain getEditingDomain(IContainer container, IMetaModelDescriptor mmDescriptor) {
- if (container != null) {
- IContainerEditingDomainProvider provider = (IContainerEditingDomainProvider) Platform.getAdapterManager().loadAdapter(container,
- IContainerEditingDomainProvider.class.getName());
- if (provider != null) {
- return provider.getEditingDomain(mmDescriptor);
- }
- }
- return null;
- }
-
- /**
- * Returns all {@link TransactionalEditingDomain editing domain}s in the given {@link IContainer container} (i.e.
- * {@link IWorkspaceRoot workspace root}, {@link IProject project} or {@link IFolder folder}).
- *
- * @return The collection of {@link TransactionalEditingDomain editing domain}s in given {@link IContainer
- * container}.
- */
- public static Collection<TransactionalEditingDomain> getEditingDomains(IContainer container) {
- IContainerEditingDomainProvider provider = (IContainerEditingDomainProvider) Platform.getAdapterManager().loadAdapter(container,
- IContainerEditingDomainProvider.class.getName());
- if (provider != null) {
- return provider.getEditingDomains();
- }
- return Collections.emptyList();
- }
-
- /**
- * Returns all {@link TransactionalEditingDomain editing domain}s that exist in the workspace.
- * <p>
- * This is a convenience method, fully equivalent to:
- *
- * <pre>
- * WorkspaceEditingDomainUtil.getEditingDomains(ResourcesPlugin.getWorkspace().getRoot());
- * </pre>
- *
- * </p>
- * * @return The collection of {@link TransactionalEditingDomain editing domain}s in the workspace.
- */
- public static Collection<TransactionalEditingDomain> getAllEditingDomains() {
- return getEditingDomains(ResourcesPlugin.getWorkspace().getRoot());
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceTransactionUtil.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceTransactionUtil.java
deleted file mode 100644
index df0d6dba57e..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/sphinx/WorkspaceTransactionUtil.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2008-2010 See4sys, BMW Car IT 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:
- * See4sys - Initial API and implementation
- * BMW Car IT - Added/Updated javadoc
- *
- * </copyright>
- */
-package org.eclipse.papyrus.emf.compare.transactional.editor.sphinx;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.IOperationHistory;
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.commands.operations.OperationHistoryFactory;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.impl.TransactionImpl;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.emf.workspace.IWorkspaceCommandStack;
-import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl;
-import org.eclipse.osgi.util.NLS;
-
-/**
- * An utility class providing helper methods for handling and executing transactions on an EMF model.
- */
-public final class WorkspaceTransactionUtil {
-
- // Prevent from instantiation
- private WorkspaceTransactionUtil() {
- }
-
- /**
- * Returns the IOperationHistory for the given EditingDomain.
- *
- * @param editingDomain
- * The EditingDomain for which the IOperationHistory is to be retrieved.
- * @return The IOperationHistory of the given <code>edingDomain</code>.
- */
- public static IOperationHistory getOperationHistory(TransactionalEditingDomain editingDomain) {
- if (editingDomain != null) {
- CommandStack commandStack = editingDomain.getCommandStack();
- if (commandStack instanceof IWorkspaceCommandStack) {
- return ((IWorkspaceCommandStack) commandStack).getOperationHistory();
- }
- }
- return OperationHistoryFactory.getOperationHistory();
- }
-
- /**
- * Returns the IUndoContext for the given EditingDomain.
- *
- * @param editingDomain
- * The EditingDomain for which the IUndoContext is to be retrieved.
- * @return The IUndoContext of the given <code>edingDomain</code>.
- */
- public static IUndoContext getUndoContext(TransactionalEditingDomain editingDomain) {
- if (editingDomain != null) {
- CommandStack commandStack = editingDomain.getCommandStack();
- if (commandStack instanceof WorkspaceCommandStackImpl) {
- return IOperationHistory.GLOBAL_UNDO_CONTEXT;
- }
- }
- return (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
- }
-
- /**
- * Returns a default set of options which can be used for executing an operation within a transaction.
- *
- * @return The default options for executing an operation in a transaction.
- */
- public static Map<String, Object> getDefaultTransactionOptions() {
- Map<String, Object> options = new HashMap<String, Object>();
- options.put(TransactionImpl.BLOCK_CHANGE_PROPAGATION, Boolean.TRUE);
- options.put(Transaction.OPTION_NO_VALIDATION, Boolean.TRUE);
- return options;
- }
-
- /**
- * Returns a default set of options which can be used for executing an operation saving a new model within a write
- * transaction.
- *
- * @return The default options for executing a save new operation in a transaction.
- */
- public static Map<String, Object> getDefaultSaveNewTransactionOptions() {
- Map<String, Object> options = WorkspaceTransactionUtil.getDefaultTransactionOptions();
- options.put(Transaction.OPTION_NO_UNDO, Boolean.TRUE);
- return options;
- }
-
- /**
- * Returns a default set of options which can be used for executing an operation saving an existing model within a
- * write transaction.
- *
- * @return The default options for executing a save operation in a transaction.
- */
- public static Map<String, Object> getDefaultSaveTransactionOptions() {
- Map<String, Object> options = WorkspaceTransactionUtil.getDefaultTransactionOptions();
- options.put(Transaction.OPTION_NO_UNDO, Boolean.TRUE);
- options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
- options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE);
- return options;
- }
-
- /**
- * Executes a write operation in a write transaction .
- *
- * @param editingDomain
- * The Transactional Editing domain receiving the transaction .
- * @param runnable
- * The runnable defining the run method .
- * @param operationLabel
- * The label of the operation to execute .
- * @throws OperationCanceledException
- * Thrown when the transaction is cancelled by the user.
- * @throws ExecutionException
- * Thrown when the transaction could not be completed to an Exception.
- **/
- public static void executeInWriteTransaction(TransactionalEditingDomain editingDomain, Runnable runnable, String operationLabel)
- throws OperationCanceledException, ExecutionException {
- executeInWriteTransaction(editingDomain, runnable, operationLabel, getOperationHistory(editingDomain), getDefaultTransactionOptions(), null);
- }
-
- /**
- * Execute a write operation in a write transaction.
- *
- * @param editingDomain
- * The {@linkplain TransactionalEditingDomain editing domain} receiving the transaction.
- * @param runnable
- * The {@linkplain Runnable runnable} defining the run method.
- * @param operationLabel
- * The label of the operation to execute.
- * @param operationHistory
- * The {@linkplain IOperationHistory operation history} to store the executed operation.
- * @param transactionOptions
- * The options to set the transaction.
- * @param monitor
- * The {@linkplain IProgressMonitor progress monitor} to use during operation execution.
- * @throws OperationCanceledException
- * Thrown when the transaction is canceled by the user.
- * @throws ExecutionException
- * Thrown when the transaction could not be completed to an Exception.
- * @since 0.7.0
- **/
- public static void executeInWriteTransaction(TransactionalEditingDomain editingDomain, final Runnable runnable, final String operationLabel,
- IOperationHistory operationHistory, final Map<String, Object> transactionOptions, IProgressMonitor monitor)
- throws OperationCanceledException, ExecutionException {
- Assert.isNotNull(editingDomain);
- Assert.isNotNull(runnable);
-
- String safeLabel = operationLabel == null ? "Unnamed operation" : operationLabel; //$NON-NLS-1$
- IUndoableOperation operation = new AbstractEMFOperation(editingDomain, safeLabel, transactionOptions) {
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- try {
- runnable.run();
- return Status.OK_STATUS;
- } catch (RuntimeException ex) {
- if (ex instanceof OperationCanceledException) {
- throw (OperationCanceledException) ex;
- } else {
- throw new ExecutionException(NLS.bind(" {0} transaction failed", operationLabel), ex);
- //throw new ExecutionException(NLS.bind(Messages.problem_transactionFailed, operationLabel), ex);
- }
- }
- }
-
- @Override
- public boolean canUndo() {
- return transactionOptions.get(Transaction.OPTION_NO_UNDO) != Boolean.TRUE;
- }
- };
- // Perform the execution of the transaction.
- IStatus status = operationHistory.execute(operation, monitor, null);
-
- if (status.getSeverity() == IStatus.CANCEL) {
- throw new OperationCanceledException();
- }
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusCompareAction.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusCompareAction.java
deleted file mode 100644
index a5513ef71fb..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusCompareAction.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.papyrus.emf.compare.transactional.editor.v2;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.compare.*;
-import org.eclipse.compare.internal.CompareUIPlugin;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.emf.compare.transactional.editor.Activator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.team.internal.ui.TeamUIMessages;
-import org.eclipse.team.internal.ui.Utils;
-import org.eclipse.team.internal.ui.actions.TeamAction;
-import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
-import org.eclipse.team.internal.ui.synchronize.SaveablesCompareEditorInput;
-import org.eclipse.ui.*;
-
-/**
- *
- * Duplicate code from TeamAction
- *
- */
-public class PapyrusCompareAction extends TeamAction {
-
-
-
- protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
-
- IResource[] selectedResources = getSelectedResources();
-
- ITypedElement ancestor = null;
- ITypedElement left = null;
- ITypedElement right = null;
-
- if(selectedResources.length == 2) {
- if(selectedResources[0] != null)
- left = getElementFor(selectedResources[0]);
-
- if(selectedResources[1] != null)
- right = getElementFor(selectedResources[1]);
-
- } else if(selectedResources.length == 3) {
- // prompt for ancestor
- SelectAncestorDialog dialog = new SelectAncestorDialog(getShell(), selectedResources);
- int code = dialog.open();
- if(code != Window.OK)
- return;
-
- ancestor = getElementFor(dialog.ancestorResource);
- left = getElementFor(dialog.leftResource);
- right = getElementFor(dialog.rightResource);
- } else {
- return;
- }
- openInCompare(ancestor, left, right);
- }
-
- private void openInCompare(ITypedElement ancestor, ITypedElement left, ITypedElement right) {
-
- IWorkbenchPage workBenchPage = getTargetPage();
- CompareEditorInput input = new PapyrusSaveablesCompareEditorInput(ancestor, left, right, workBenchPage) ;
-
- try {
- workBenchPage.openEditor(input, "org.eclipse.papyrus.emf.compare.transactional.editor", true);
- } catch (PartInitException e) {
- Activator.log.error(e);
- }
- }
-
- public boolean isEnabled() {
- int l = getSelectedResources().length;
- return l == 2 || l == 3;
- }
-
- private ITypedElement getElementFor(IResource resource) {
- return SaveablesCompareEditorInput.createFileElement((IFile)resource);
- }
-
- // see
- // org.eclipse.compare.internal.ResourceCompareInput.SelectAncestorDialog
- private class SelectAncestorDialog extends MessageDialog {
-
- private IResource[] theResources;
-
- IResource ancestorResource;
-
- IResource leftResource;
-
- IResource rightResource;
-
- private Button[] buttons;
-
- public SelectAncestorDialog(Shell parentShell, IResource[] theResources) {
- super(parentShell, TeamUIMessages.SelectAncestorDialog_title, null, TeamUIMessages.SelectAncestorDialog_message, MessageDialog.QUESTION, new String[]{ IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
- this.theResources = theResources;
- }
-
- protected Control createCustomArea(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new GridLayout());
- buttons = new Button[3];
- for(int i = 0; i < 3; i++) {
- buttons[i] = new Button(composite, SWT.RADIO);
- buttons[i].addSelectionListener(selectionListener);
- buttons[i].setText(NLS.bind(TeamUIMessages.SelectAncestorDialog_option, theResources[i].getFullPath().toPortableString()));
- buttons[i].setFont(parent.getFont());
- // set initial state
- buttons[i].setSelection(i == 0);
- }
- pickAncestor(0);
- return composite;
- }
-
- private void pickAncestor(int i) {
- ancestorResource = theResources[i];
- leftResource = theResources[i == 0 ? 1 : 0];
- rightResource = theResources[i == 2 ? 1 : 2];
- }
-
- private SelectionListener selectionListener = new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- Button selectedButton = (Button)e.widget;
- if(!selectedButton.getSelection())
- return;
- for(int i = 0; i < 3; i++)
- if(selectedButton == buttons[i])
- pickAncestor(i);
- }
- };
- }
-
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusSaveablesCompareEditorInput.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusSaveablesCompareEditorInput.java
deleted file mode 100644
index a698971b702..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/PapyrusSaveablesCompareEditorInput.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.eclipse.papyrus.emf.compare.transactional.editor.v2;
-
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.CompareViewerPane;
-import org.eclipse.compare.CompareViewerSwitchingPane;
-import org.eclipse.compare.ITypedElement;
-import org.eclipse.compare.internal.CompareStructureViewerSwitchingPane;
-import org.eclipse.compare.structuremergeviewer.IDiffContainer;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.emf.compare.transactional.editor.Activator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.team.internal.ui.synchronize.SaveablesCompareEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.Saveable;
-
-
-public class PapyrusSaveablesCompareEditorInput extends SaveablesCompareEditorInput {
-
- private String TRANSACTIONAL_COMPARE_EDITOR_IMAGE_PATH = "icons/papyrus_compare_editor.gif";
-private ITypedElement left;
-
-//TODO create an interface?
-public ITypedElement getLeft() {
- return left;
-}
-
-
-//TODO create an interface?
-public ITypedElement getRight() {
- return right;
-}
-
-
-
-private ITypedElement right;
- public PapyrusSaveablesCompareEditorInput(ITypedElement ancestor, ITypedElement left, ITypedElement right, IWorkbenchPage page) {
- super(ancestor, left, right, page);
- this.left = left;
- this.right = right;
- }
-
-
-
- protected Image fgTitleImage;
-
-
- public Image getTitleImage() {
- if(fgTitleImage == null) {
- fgTitleImage = Activator.getImage(TRANSACTIONAL_COMPARE_EDITOR_IMAGE_PATH);
- }
- return fgTitleImage;
- }
-
-
- public ImageDescriptor getImageDescriptor() {
- return ImageDescriptor.createFromImage(getTitleImage());
- }
-
- public String getToolTipText() {
- return getTitle();
- }
-
- public String getTitle() {
- String title = super.getTitle();
- return title.replaceFirst("Compare", "PapyrusCompare");
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalActionBarContributor.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalActionBarContributor.java
deleted file mode 100644
index bbc3cd56bac..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalActionBarContributor.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package org.eclipse.papyrus.emf.compare.transactional.editor.v2;
-
-import java.awt.color.ProfileDataException;
-import java.util.EventObject;
-import java.util.Set;
-import java.util.jar.Manifest;
-
-import org.eclipse.core.commands.operations.IOperationHistoryListener;
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.commands.operations.OperationHistoryEvent;
-import org.eclipse.emf.common.command.CommandStackListener;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.ResourceUndoContext;
-import org.eclipse.sphinx.emf.compare.ui.editor.ModelCompareEditor;
-import org.eclipse.sphinx.emf.compare.ui.internal.Activator;
-import org.eclipse.sphinx.emf.util.WorkspaceEditingDomainUtil;
-import org.eclipse.sphinx.platform.util.PlatformLogUtil;
-import org.eclipse.ui.IEditorPart;
-
-
-public class TransactionalActionBarContributor extends EditingDomainActionBarContributor {
-
- //TODO useful?
-//not used!
- protected IOperationHistoryListener historyListener;
-
- public void init(org.eclipse.ui.IActionBars actionBars) {
- super.init(actionBars);
- historyListener = createOperationHistoryListener();
-
- }
-
- /**
- * Creates the {@linkplain IOperationHistoryListener operation history listener} that is responsible for setting
- * editing domain on <em>undo</em>/<em>redo</em> actions as soon as an operation (on the command stack of that
- * precise editing domain) has been finished.
- *
- * @return The {@linkplain IOperationHistoryListener operation history listener} to add on the concerned editing
- * domain's command stack.
- */
- protected IOperationHistoryListener createOperationHistoryListener() {
- return new IOperationHistoryListener() {
-
- public void historyNotification(OperationHistoryEvent event) {
- if(event.getEventType() == OperationHistoryEvent.DONE || event.getEventType() == OperationHistoryEvent.UNDONE || event.getEventType() == OperationHistoryEvent.REDONE) {
- undoAction.update();
- redoAction.update();
- // IUndoContext[] contexts = event.getOperation().getContexts();
- // for (IUndoContext context : contexts) {
- // if (ModelCompareEditor.ID.equals(context.getLabel())) {
- // Set<Resource> affectedResources = ResourceUndoContext.getAffectedResources(event.getOperation());
- // TransactionalEditingDomain editingDomain = null;
- // for (Resource resource : affectedResources) {
- // TransactionalEditingDomain domain = WorkspaceEditingDomainUtil.getEditingDomain(resource);
- // if (editingDomain != null && editingDomain != domain) {
- // //
- // // !! Important Note !!
- // // For the moment, the case where two elements from different editing domain are
- // // compared is not really supported because we do not know very well the expected
- // // behavior of such a kind of comparison.
- // //
- // UnsupportedOperationException ex = new UnsupportedOperationException("Several editing domains"); //$NON-NLS-1$
- // PlatformLogUtil.logAsWarning(Activator.getPlugin(), ex);
- // editingDomain = null;
- // break;
- // } else {
- // editingDomain = domain;
- // }
- // }
- // if (editingDomain != null) {
- // // Set editing domain on Undo/Redo actions
- // if (undoAction != null) {
- // undoAction.setEditingDomain(editingDomain);
- // }
- // if (redoAction != null) {
- // redoAction.setEditingDomain(editingDomain);
- // }
- // }
- // break;
- // }
- // }
- }
- }
- };
- }
-
- private TransactionalEditingDomain domain;
-
- @Override
- public void activate() {
- IEditorPart part = getActiveEditor();
- if(part instanceof IEditingDomainProvider) {
- domain = (TransactionalEditingDomain)((IEditingDomainProvider)part).getEditingDomain();
- domain.getCommandStack().addCommandStackListener(new CommandStackListener() {
-
- public void commandStackChanged(EventObject event) {
- // TODO Auto-generated method stub
- undoAction.update();
- redoAction.update();
- //TODO : try to refresh the editor!
- //getActiveEditor().getEditorInput().
- }
- });
- }
- // TODO Auto-generated method stub
- super.activate();
- }
-}
diff --git a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalCompareEditor.java b/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalCompareEditor.java
deleted file mode 100644
index 7d7bac69752..00000000000
--- a/sandbox/PapyrusEMFCompareV1/deprecated/org.eclipse.papyrus.emf.compare.transactional.editor/src/org/eclipse/papyrus/emf/compare/transactional/editor/v2/TransactionalCompareEditor.java
+++ /dev/null
@@ -1,428 +0,0 @@
-package org.eclipse.papyrus.emf.compare.transactional.editor.v2;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.ITypedElement;
-import org.eclipse.compare.internal.CompareEditor;
-import org.eclipse.core.commands.operations.IOperationHistory;
-import org.eclipse.core.commands.operations.IOperationHistoryListener;
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.commands.operations.ObjectUndoContext;
-import org.eclipse.core.commands.operations.OperationHistoryEvent;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.emf.workspace.IWorkspaceCommandStack;
-import org.eclipse.emf.workspace.ResourceUndoContext;
-import org.eclipse.papyrus.emf.compare.transactional.editor.Activator;
-import org.eclipse.sphinx.emf.workspace.ui.saving.BasicModelSaveablesProvider.SiteNotifyingSaveablesLifecycleListener;
-import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.ISaveablesLifecycleListener;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.SaveablesLifecycleEvent;
-
-
-@SuppressWarnings("restriction")
-//remove the warning for CompareEditor which is internal
-public class TransactionalCompareEditor extends CompareEditor implements IEditingDomainProvider/*,ICustomEditingDomainProvider/*implements IEditingDomainItemProvider*/{
-
- /**
- * The identifier of this editor (as contributed).
- */
- public static String ID = "org.eclipse.papyrus.emf.compare.transactional.editor";
-
- /**
- * The undo context for this compare editor.
- */
- protected IUndoContext undoContext;
-
- //TODO not used for the moment
- private IOperationHistoryListener affectedObjectsListener;
-
- /**
- * Default constructor.
- */
- public TransactionalCompareEditor() {
- // Create undo context
- undoContext = new ObjectUndoContext(this, ID);
- }
-
- @Override
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {
-// super.init(site, input);
-
- // First do not keep duplicated editing domain entries
-// Set<TransactionalEditingDomain> editingDomains = new HashSet<TransactionalEditingDomain>();
-// for (TransactionalEditingDomain editingDomain : getEditingDomains()) {
-// if (editingDomain != null) {
-// editingDomains.add(editingDomain);
-// }
-// }
-// if (editingDomains.isEmpty()) {
-// Activator.log.error(new RuntimeException("Editing domain not found"));
-// }
-
- // Then creates and registers listeners on resulting editing domains
-// for (TransactionalEditingDomain editingDomain : editingDomains) {
-// //TODO
-// //addTransactionalEditingDomainListeners(editingDomain);
-// }
- }
-
- /**
- * @return An array of {@linkplain TransactionalEditingDomain editing domain}s which size is 2 and where at index 0
- * is editing domain from left, at index 1 is editing domain from right.
- */
- private TransactionalEditingDomain[] editingDomains ;
- public TransactionalEditingDomain[] getEditingDomains() {
- if(editingDomains==null){
- //TransactionalEditingDomain[] editingDomains = new TransactionalEditingDomain[2];
- editingDomains = new TransactionalEditingDomain[2];
- EObject[] modelRoots = getModelRoots();
-// IFile[] modelRoots = getModelRoots();
- if (modelRoots[0] != null) {
-// editingDomains[0] = WorkspaceEditingDomainUtil.getEditingDomain(modelRoots[0]);
-// System.out.println("editingDomain file 1 = " + editingDomains[0]);
- }
- if (modelRoots[1] != null) {
-// editingDomains[1] = WorkspaceEditingDomainUtil.getEditingDomain(modelRoots[1]);
-// System.out.println("editingDomain file 2 = " + editingDomains[1]);
- }
-// if (editingDomains[0] == null && editingDomains[1] == null) {
-// Activator.log.error(new RuntimeException("No editing domain found")); //$NON-NLS-1$
-// PlatformLogUtil.logAsError(Activator.getPlugin(), new RuntimeException("No editing domain found")); //$NON-NLS-1$
-// }
-
- //TODO
-// editingDomains[0] = new TransactionalE
- TransactionalEditingDomain editingDomain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
- editingDomains[0] = editingDomain;
- editingDomains[1] = editingDomain;
- }
- return editingDomains;
- }
-
- /**
- * @return The root objects of the model part that are currently being compared in this editor or an empty array if
- * no such objects are available. Anyway, always returns an array of {@linkplain EObject}s which size is 2
- * and where at index 0 is the left root and at index 1 is the right root.
- */
- public EObject[] getModelRoots() {
-// public IFile[] getModelRoots() {
-// List<IFile>
- IFile[] files = new IFile[2];
- EObject[] modelRoots = new EObject[2];
- IEditorInput editorInput = getEditorInput();
- ITypedElement left = null;
- ITypedElement right = null;
-
- if(editorInput instanceof PapyrusSaveablesCompareEditorInput){
- left = ((PapyrusSaveablesCompareEditorInput)editorInput).getLeft();
- right = ((PapyrusSaveablesCompareEditorInput)editorInput).getRight();
- }else if(editorInput instanceof CompareEditorInput){
- //TODO manage other case?
- }
-
- if(left instanceof LocalResourceTypedElement){
- IResource res = ((LocalResourceTypedElement)left).getResource();
- if(res instanceof IFile){
- files[0] = (IFile)res;
- }
- }
-
- if(right instanceof LocalResourceTypedElement){
- IResource res = ((LocalResourceTypedElement)right).getResource();
- if(res instanceof IFile){
- files[1] = (IFile)res;
- }
- }
-
- return modelRoots;
-// return files;
- }
-
- //IEditingDomainProvider
-// public Collection<?> getChildren(Object object) {
-// // TODO Auto-generated method stub
-// return null;
-// }
-//
-// public Object getParent(Object object) {
-// // TODO Auto-generated method stub
-// return null;
-// }
-//
-// public Collection<?> getNewChildDescriptors(Object object, EditingDomain editingDomain, Object sibling) {
-// // TODO Auto-generated method stub
-// return null;
-// }
-//
-// public Command createCommand(Object object, EditingDomain editingDomain, Class<? extends Command> commandClass, CommandParameter commandParameter) {
-// // TODO Auto-generated method stub
-// return null;
-// }
-
-
- @Override
- public void dispose() {
- for (TransactionalEditingDomain editingDomain : getEditingDomains()) {
- if (editingDomain != null) {
- removeTransactionalEditingDomainListeners(editingDomain);
- }
- }
-
- for (IOperationHistory operationHistory : getOperationHistories()) {
- if (operationHistory != null) {
- operationHistory.dispose(getUndoContext(), true, true, true);
- }
- }
- super.dispose();
- }
-
- protected void addTransactionalEditingDomainListeners(TransactionalEditingDomain editingDomain) {
- if (editingDomain != null) {
- // Create and register IOperationHistoryListener that detects changed objects
- affectedObjectsListener = createAffectedObjectsListener();
- Assert.isNotNull(affectedObjectsListener);
- ((IWorkspaceCommandStack) editingDomain.getCommandStack()).getOperationHistory().addOperationHistoryListener(affectedObjectsListener);
- }
- }
-
- protected void removeTransactionalEditingDomainListeners(TransactionalEditingDomain editingDomain) {
- if (editingDomain != null) {
- if (affectedObjectsListener != null) {
- IOperationHistory operationHistory = ((IWorkspaceCommandStack) editingDomain.getCommandStack()).getOperationHistory();
- operationHistory.removeOperationHistoryListener(affectedObjectsListener);
- }
- }
- }
-
- /**
- * Creates and returns the {@linkplain IOperationHistoryListener listener} to add on the
- * {@linkplain IOperationHistory operation history} of {@linkplain TransactionalEditingDomain editing domain}'s
- * {@linkplain IWorkspaceCommandStack command stack}.
- * <p>
- * The listener's implementation that is provided here aims at updating {@linkplain IUndoableOperation operation}'s
- * context by first removing default {@linkplain IUndoContext undo context} and second by adding
- * {@linkplain IUndoContext undo context} encapsulated by this editor.
- * <p>
- * Clients may override this default implementation.
- *
- * @return The {@linkplain IOperationHistoryListener operation history listener} to register on the command stack of
- * the concerned editing domain.
- */
- protected IOperationHistoryListener createAffectedObjectsListener() {
- return new IOperationHistoryListener() {
-
- public void historyNotification(final OperationHistoryEvent event) {
- IUndoableOperation operation = event.getOperation();
- if (event.getEventType() == OperationHistoryEvent.ABOUT_TO_EXECUTE) {
- handleOperationAboutToExecute(operation);
- } else if (event.getEventType() == OperationHistoryEvent.DONE || event.getEventType() == OperationHistoryEvent.UNDONE
- || event.getEventType() == OperationHistoryEvent.REDONE) {
- Set<?> affectedResources = ResourceUndoContext.getAffectedResources(operation);
- Resource[] resources = getModelRootsResources();
- boolean isLeftResourceAffected = resources[0] != null ? affectedResources.contains(resources[0]) : false;
- boolean isRightResourceAffected = resources[1] != null ? affectedResources.contains(resources[1]) : false;
- if (isLeftResourceAffected || isRightResourceAffected) {
- handleOperationFinished(operation);
- }
- }
- }
-
- private void handleOperationAboutToExecute(final IUndoableOperation operation) {
- if (operation.canUndo()) {
- IWorkbenchPartSite site = getSite();
- if (site != null) {
- site.getShell().getDisplay().syncExec(new Runnable() {
- public void run() {
- if (isActivePart()) {
- Resource[] resources = getModelRootsResources();
- for (Resource resource : resources) {
- TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
- if (editingDomain != null && editingDomain.getCommandStack() instanceof IWorkspaceCommandStack) {
- IWorkspaceCommandStack cmdStack = (IWorkspaceCommandStack) editingDomain.getCommandStack();
- IUndoContext defaultUndoContext = cmdStack.getDefaultUndoContext();
- if (defaultUndoContext != null) {
- // Remove default undo context and this editor's undo context
- operation.removeContext(defaultUndoContext);
- }
- }
- }
- operation.addContext(getUndoContext());
- }
- }
- });
- }
- }
- }
-
- private void handleOperationFinished(final IUndoableOperation operation) {
- getSite().getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- // Update editor part name
- // FIXME Not needed for the moment.
- // setPartName(getModelRootsNames());
- }
- });
- }
- };
- }
-
- /**
- * @return
- */
- public ISaveablesLifecycleListener createModelSaveablesLifecycleListener() {
- return new SiteNotifyingSaveablesLifecycleListener(this) {
- @Override
- public void handleLifecycleEvent(SaveablesLifecycleEvent event) {
- super.handleLifecycleEvent(event);
-
- if (event.getEventType() == SaveablesLifecycleEvent.DIRTY_CHANGED) {
- firePropertyChange(PROP_DIRTY);
- }
- }
- };
- }
-
- @Override
- public boolean isSaveOnCloseNeeded() {
- // Model-based editors don't need to be saved when being closed even if the model is dirty, because they don't
- // own the model. The model is loaded, managed, and saved globally, i.e. it is not destroyed but stays there
- // when editors are being closed.
- return false;
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- // TODO Modify implementation as soon as saving as diff model would be available.
- return false;
- }
-
- @Override
- public Object getAdapter(@SuppressWarnings("rawtypes") Class key) {
- if (key.equals(IUndoContext.class)) {
- // Used by undo/redo actions to get their undo context
- return getUndoContext();
- } else {
- return super.getAdapter(key);
- }
- }
-
- /**
- * @return The {@linkplain IUndoContext undo context} associated to this compare editor.
- */
- public IUndoContext getUndoContext() {
- return undoContext;
- }
-
-
- protected IOperationHistory[] getOperationHistories() {
- IOperationHistory[] operationHistories = new IOperationHistory[2];
- TransactionalEditingDomain[] editingDomains = getEditingDomains();
- for (int i = 0; i < 2; i++) {
- if (editingDomains[i] != null) {
- operationHistories[i] = ((IWorkspaceCommandStack) editingDomains[i].getCommandStack()).getOperationHistory();
- }
- }
- return operationHistories;
- }
-
- /**
- * <p>
- * <table>
- * <tr valign=top>
- * <td><b>Note</b>&nbsp;&nbsp;</td>
- * <td>Whatever the model roots are (i.e. if <code>null</code> or not), this method returns an array of
- * {@linkplain Resource}s whose size is 2.</td>
- * </tr>
- * </table>
- *
- * @return
- */
- protected Resource[] getModelRootsResources() {
- Resource[] resources = new Resource[2];
- EObject[] modelRoots = getModelRoots();
- for (int i = 0; i < 2; i++) {
- EObject modelRoot = modelRoots[i];
- if (modelRoot != null) {
- resources[i] = modelRoot.eResource();
- }
- }
- return resources;
- }
-
- protected String getModelRootsNames() {
- String[] labels = new String[2];
- EObject[] modelRoots = getModelRoots();
- AdapterFactoryItemDelegator[] itemDelegators = getItemDelegators();
- for (int i = 0; i < 2; i++) {
- if (modelRoots[i] != null && itemDelegators[i] != null) {
- // Label of model root
- labels[i] = itemDelegators[i].getText(modelRoots[i]);
- }
- }
- if (labels[0] != null && labels[1] != null) {
- return labels[0] + " <---> " + labels[1]; //$NON-NLS-1$
- } else {
- return ((CompareEditorInput) getEditorInput()).getTitle();
- }
- }
-
- protected AdapterFactory[] getAdapterFactories() {
- AdapterFactory[] adapterFactories = new AdapterFactory[2];
- TransactionalEditingDomain[] editingDomains = getEditingDomains();
- for (int i = 0; i < 2; i++) {
- TransactionalEditingDomain editingDomain = editingDomains[i];
- if (editingDomain != null) {
- adapterFactories[i] = ((AdapterFactoryEditingDomain) editingDomain).getAdapterFactory();
- }
- }
- return adapterFactories;
- }
-
- protected AdapterFactoryItemDelegator[] getItemDelegators() {
- AdapterFactoryItemDelegator[] itemDelegators = new AdapterFactoryItemDelegator[2];
- AdapterFactory[] adapterFactories = getAdapterFactories();
- for (int i = 0; i < 2; i++) {
- AdapterFactory adapterFactory = adapterFactories[i];
- if (adapterFactory != null) {
- itemDelegators[i] = new AdapterFactoryItemDelegator(adapterFactory);
- }
- }
- return itemDelegators;
- }
-
- protected boolean isActivePart() {
- return this == getSite().getWorkbenchWindow().getPartService().getActivePart();
- }
-
- public TransactionalEditingDomain getEditingDomain() {
- return getEditingDomains()[0];
- }
-
-
-
-// @Override
-// public void setInput(IEditorInput input) {
-// if (input instanceof ModelElementCompareEditorInput) {
-// super.setInput(input);
-// } else {
-// PlatformLogUtil.logAsError(Activator.getPlugin(), new RuntimeException(Messages.error_invalidEditorInput));
-// }
-// }
-}

Back to the top