Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/.classpath7
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/.project28
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/META-INF/MANIFEST.MF17
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/build.properties5
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/plugin.pdoc4
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/plugin.xml27
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/Activator.java54
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/handler/EMFSaveAsHandler.java183
9 files changed, 332 insertions, 0 deletions
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/.classpath b/sandbox/org.eclipse.papyrus.infra.emf.export/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/.project b/sandbox/org.eclipse.papyrus.infra.emf.export/.project
new file mode 100644
index 00000000000..7035fae65a5
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.infra.emf.export</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/org.eclipse.papyrus.infra.emf.export/.settings/org.eclipse.jdt.core.prefs b/sandbox/org.eclipse.papyrus.infra.emf.export/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..44217f8c068
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+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/org.eclipse.papyrus.infra.emf.export/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.infra.emf.export/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..8a189800c1c
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Export EMF (Incubation)
+Bundle-SymbolicName: org.eclipse.papyrus.infra.emf.export;singleton:=true
+Bundle-Version: 0.10.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.infra.emf.export.Activator
+Bundle-Vendor: Eclipse Modeling Language
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.emf.edit.ui;bundle-version="2.8.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="0.9.1",
+ org.eclipse.ui.ide,
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.9.1"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/build.properties b/sandbox/org.eclipse.papyrus.infra.emf.export/build.properties
new file mode 100644
index 00000000000..6f20375d6c7
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/plugin.pdoc b/sandbox/org.eclipse.papyrus.infra.emf.export/plugin.pdoc
new file mode 100644
index 00000000000..e164d7294e3
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/plugin.pdoc
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<doc:Documentation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:doc="http://www.eclipse.org/papyrus/documentation/plugin/documentation" description="This plugin provides action to export a part of an EMF-Model in a new file">
+ <referent firstName="vincent" lastName="lorenzo" eMail="vincent.lorenzo@cea.fr" currentCompany="CEA-LIST"/>
+</doc:Documentation>
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/plugin.xml b/sandbox/org.eclipse.papyrus.infra.emf.export/plugin.xml
new file mode 100644
index 00000000000..fd7bba65e88
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/plugin.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.eclipse.papyrus.infra.emf.export.handler.EMFSaveAsHandler"
+ description="Allow to do a &quot;Save As&quot; of a part of a model"
+ id="org.eclipse.papyrus.infra.emf.export.save.as.command"
+ name="EMF Save As">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <command
+ commandId="org.eclipse.papyrus.infra.emf.export.save.as.command"
+ label="&quot;Save As&quot; a part of the model"
+ style="push"
+ tooltip="&quot;Save As&quot; a part of the model">
+ </command>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/Activator.java b/sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/Activator.java
new file mode 100644
index 00000000000..2f20ca23d43
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/Activator.java
@@ -0,0 +1,54 @@
+package org.eclipse.papyrus.infra.emf.export;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+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.infra.emf.export"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (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(this);
+ }
+
+ /*
+ * (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;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/handler/EMFSaveAsHandler.java b/sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/handler/EMFSaveAsHandler.java
new file mode 100644
index 00000000000..cb71e4abc37
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.export/src/org/eclipse/papyrus/infra/emf/export/handler/EMFSaveAsHandler.java
@@ -0,0 +1,183 @@
+package org.eclipse.papyrus.infra.emf.export.handler;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.internal.resources.File;
+import org.eclipse.core.internal.resources.Workspace;
+import org.eclipse.core.internal.resources.WorkspaceRoot;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.notify.AdapterFactory;
+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.resource.URIConverter;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.emf.export.Activator;
+import org.eclipse.papyrus.infra.widgets.editors.InputDialog;
+import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+
+
+public class EMFSaveAsHandler extends AbstractHandler {
+
+ private ITreeContentProvider contentProvider = null;
+
+ private ILabelProvider labelProvider = null;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ResourceSet set = new ResourceSetImpl();
+ final Resource selectedResource = getSelectedResource(set);
+
+ // the dialog used to choose a file to browse
+ final CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(Display.getCurrent().getActiveShell(), getLabelProvider(), getContentProvider());
+ dialog.setTitle("Browse Model");
+ dialog.setMessage("Select the elements to export");
+ dialog.setInput(selectedResource);
+
+ if(dialog.open() == Window.OK) {
+ final Object[] selectedEObject = dialog.getResult();
+ final Collection<EObject> toExport = new ArrayList<EObject>();
+ for(final Object current : selectedEObject) {
+ assert current instanceof EObject;
+ toExport.add((EObject)current);
+ }
+
+ SaveAsDialog saveAsDialog = new SaveAsDialog(Display.getCurrent().getActiveShell());
+// saveAsDialog.setTitle("Select the destination for the exported elements"); //without effect
+ if(saveAsDialog.open() == Window.OK) {
+ Resource newResource = createNewResource(set, saveAsDialog.getResult());
+ newResource.getContents().addAll(toExport);
+ try {
+ newResource.save(Collections.emptyMap());
+ selectedResource.save(Collections.emptyMap());
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ return getSelectedResource(new ResourceSetImpl()) != null;
+ }
+
+ /**
+ * FIXME : use the label provider service
+ * @return
+ * the label provider to use
+ */
+ public ILabelProvider getLabelProvider() {
+ if(labelProvider == null) {
+ final AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ labelProvider = new AdapterFactoryLabelProvider(factory);
+ }
+ return labelProvider;
+ }
+
+ /**
+ * FIXME : use the content provider service
+ * @return
+ * the content provider to use
+ */
+ public ITreeContentProvider getContentProvider() {
+ final AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ if(contentProvider == null) {
+ contentProvider = new AdapterFactoryContentProvider(factory) {
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof Resource) {
+ return ((Resource)inputElement).getContents().toArray();
+ } else {
+ return super.getElements(inputElement);
+ }
+ }
+ };
+ }
+ return contentProvider;
+ }
+
+ /**
+ *
+ * @param set
+ * a resource set
+ * @return
+ * the selected resource
+ */
+ protected Resource getSelectedResource(final ResourceSet set) {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ final Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
+ String pathName = "";
+ Resource res = null;
+ if(selectedElement instanceof IAdaptable) {
+ final File file = (File)((IAdaptable)selectedElement).getAdapter(IFile.class);
+ if(file!=null){
+ if(selectedElement instanceof File) {
+ pathName = ((File)selectedElement).getFullPath().toString();
+ }
+ final URI uri = URI.createFileURI(pathName);
+ res = set.getResource(uri, true);
+ }
+ }
+ return res;
+ }
+
+ /**
+ *
+ * @param set
+ * the resourceset to use
+ * @param iPath
+ * a path
+ * @return
+ * the created resource with the wanted path
+ */
+ protected Resource createNewResource(final ResourceSet set, final IPath iPath) {
+// EcoreResourceUtil.
+// URIConverter converter = set.getURIConverter();
+// converter.
+// IPath wsPath = ResourcesPlugin.getWorkspace().getDescription()
+// java.io.File file = iPath.toFile();
+// file.
+// URI.createPlatformResourceURI(pathName)
+
+ //FIXME : the references to the new files are stored with OS path (F:/....)
+ IPath fullPath = ResourcesPlugin.getWorkspace().getRoot().getFile(iPath).getLocation();
+// fullPath.get
+ final URI uri = URI.createFileURI(fullPath.toFile().getAbsolutePath());
+ String device = iPath.getDevice();
+ final Resource newResource = set.createResource(uri);
+ return newResource;
+ }
+
+}

Back to the top