Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreperico2009-12-04 10:39:29 +0000
committereperico2009-12-04 10:39:29 +0000
commitdc4581f2822929f57f54bf9efbac128440ac5c03 (patch)
tree39c4a648d907af9c00c24add962072f0b611b2ef /plugins/profile-tool
parent5bcbd0fc99f011861f7f066876edd4d5af4c3af9 (diff)
downloadorg.eclipse.papyrus-dc4581f2822929f57f54bf9efbac128440ac5c03.tar.gz
org.eclipse.papyrus-dc4581f2822929f57f54bf9efbac128440ac5c03.tar.xz
org.eclipse.papyrus-dc4581f2822929f57f54bf9efbac128440ac5c03.zip
Task 296901: [Profile] provide a way to generate profile based diagram
Diffstat (limited to 'plugins/profile-tool')
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/.classpath7
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/.project28
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/META-INF/MANIFEST.MF14
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/Activator.classbin0 -> 958 bytes
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.classbin0 -> 6267 bytes
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.classbin0 -> 537 bytes
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction$1.classbin0 -> 1046 bytes
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.classbin0 -> 4791 bytes
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/build.properties19
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/plugin.xml19
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/Activator.java65
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.java227
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.java32
-rw-r--r--plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.java118
15 files changed, 537 insertions, 0 deletions
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.classpath b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.project b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.project
new file mode 100644
index 00000000000..74665d4cff6
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.resource.migration</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/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.settings/org.eclipse.jdt.core.prefs b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..7bd4b87357c
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed Dec 02 09:11:51 CET 2009
+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/plugins/profile-tool/org.eclipse.papyrus.resource.migration/META-INF/MANIFEST.MF b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..9c92c074d0c
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Migration
+Bundle-SymbolicName: org.eclipse.papyrus.resource.migration;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.resource.migration.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.emf.ecore,
+ org.eclipse.papyrus.resource,
+ org.eclipse.emf.codegen.ecore
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/Activator.class b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/Activator.class
new file mode 100644
index 00000000000..f49433409f9
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/Activator.class
Binary files differ
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.class b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.class
new file mode 100644
index 00000000000..fd8bb3b5bbf
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.class
Binary files differ
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.class b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.class
new file mode 100644
index 00000000000..456c588677d
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.class
Binary files differ
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction$1.class b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction$1.class
new file mode 100644
index 00000000000..62e3400cf93
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction$1.class
Binary files differ
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.class b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.class
new file mode 100644
index 00000000000..3f3760f1f57
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/bin/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.class
Binary files differ
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/build.properties b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/build.properties
new file mode 100644
index 00000000000..e80ecd0db49
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/build.properties
@@ -0,0 +1,19 @@
+#/*****************************************************************************
+# * Copyright (c) 2009 Atos Origin.
+# *
+# *
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+# *
+# *****************************************************************************/
+
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/plugin.xml b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/plugin.xml
new file mode 100644
index 00000000000..765bb6fd926
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/plugin.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ id="org.eclipse.papyrus.resource.migration.contribution1"
+ nameFilter="*.genmodel"
+ objectClass="org.eclipse.core.resources.IFile">
+ <action
+ class="org.eclipse.papyrus.resource.migration.popup.actions.UpdateGenModelAction"
+ enablesFor="+"
+ id="org.eclipse.papyrus.resource.migration.newAction"
+ label="configure genmodel with Papyrus profile approach">
+ </action>
+ </objectContribution>
+ </extension>
+
+</plugin>
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/Activator.java b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/Activator.java
new file mode 100644
index 00000000000..c4327ea92c5
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/Activator.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.resource.migration;
+
+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.resource.migration";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (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/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.java b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.java
new file mode 100644
index 00000000000..4770253cbd6
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/GenModelUpdater.java
@@ -0,0 +1,227 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.resource.migration.controller;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.resource.ResourcePackage;
+import org.eclipse.papyrus.resource.migration.controller.exceptions.URINotValidException;
+
+/**
+ * This class makes comaptible a genmodel with Resource meta model
+ *
+ * @author tristan.faure@atosorigin.com
+ *
+ */
+public class GenModelUpdater {
+
+ /**
+ * The URI for Resource Genmodel
+ */
+ private static final URI uriForResourceGenModel = URI
+ .createURI("platform:/plugin/org.eclipse.papyrus.resource/model/resource.genmodel");
+
+ /**
+ * The URI for Resource Ecore meta model
+ */
+ private static final URI uriForEclassResourceEObject = URI
+ .createURI("platform:/plugin/org.eclipse.papyrus.resource/model/resource.ecore#//ResourceEObject");
+
+ /**
+ * instance of resource package used to reference usedGenpackage in the original genmodel
+ */
+ private ResourcePackage resourcePackage = ResourcePackage.eINSTANCE;
+
+ /**
+ * Eclass for resource Eobject
+ */
+ private EClass resourceEObjectEClass = null;
+
+ /**
+ * current Epackage for the meta model corresponding to the current genmodel
+ */
+ private EPackage currentEPackage = null;
+
+ /**
+ * Transform the genmodel sotred at the given URI to link it with Resource Meta model
+ *
+ * @param uri
+ * @throws URINotValidException
+ * @throws IOException
+ */
+ public void transform(URI uri) throws URINotValidException, IOException {
+ if (uri == null) {
+ throw new URINotValidException("uri is null");
+ }
+ ResourceSet set = new ResourceSetImpl();
+ try {
+ Resource resource = set.getResource(uri, true);
+ if (resource != null) {
+ EObject e = resource.getContents().get(0);
+ if (e instanceof GenModel) {
+ GenModel genmodel = (GenModel) e;
+ Resource toSave = update(genmodel);
+ if (toSave != null) {
+ resource.save(Collections.EMPTY_MAP);
+ toSave.save(Collections.EMPTY_MAP);
+ }
+ } else {
+ throw new URINotValidException("uri " + uri.toString() + "doesn't reference a genmodel");
+ }
+ }
+ // we have to unload the resource to free the memory
+ for (Resource r : set.getResources()) {
+ if (r.isLoaded()) {
+ try {
+ r.unload();
+ } catch (Exception e) {
+ // to prevent unload exception
+ }
+ }
+ }
+ } catch (RuntimeException e) {
+ throw new URINotValidException("uri " + uri.toString() + "not valid");
+ }
+ }
+
+ /**
+ * update the genmodel to reference Resource Meta model
+ *
+ * @param genmodel
+ * @return true if the resource has to be saved
+ */
+ private Resource update(GenModel genmodel) {
+ // does the genmodel already contain the resource ?
+ Resource result = null;
+ boolean found = false;
+ for (GenPackage p : genmodel.getUsedGenPackages()) {
+ found |= resourcePackage.equals(p.getEcorePackage());
+ }
+ if (!found) {
+ // we load the Resource GenModel
+ Resource resourceForResourceGenmodel = genmodel.eResource().getResourceSet().getResource(
+ uriForResourceGenModel, true);
+ if (resourceForResourceGenmodel != null) {
+ EObject root = resourceForResourceGenmodel.getContents().get(0);
+ if (root instanceof GenModel) {
+ GenModel model = (GenModel) root;
+ // Resource Genmodel is a used gen package for the current genmodel
+ genmodel.getUsedGenPackages().add(model.getGenPackages().get(0));
+ // load the eclass resource eobject
+ Resource resourceResource = genmodel.eResource().getResourceSet().getResource(
+ uriForEclassResourceEObject.trimFragment(), true);
+ if (resourceResource != null) {
+ // we get the ResourceEObject EClass
+ EObject resourceEObjectEobject = resourceResource.getEObject(uriForEclassResourceEObject
+ .fragment());
+ if (resourceEObjectEobject instanceof EClass) {
+ resourceEObjectEClass = (EClass) resourceEObjectEobject;
+ result = addResourceEobjectInheritance(genmodel);
+ }
+ }
+ }
+ }
+ }
+ // if not found we have to save
+ return result;
+ }
+
+ /**
+ * add the inheritance to each EObject
+ *
+ * @param genmodel
+ */
+ private Resource addResourceEobjectInheritance(GenModel genmodel) {
+ // we resolve to have access to all the eobjects
+ EcoreUtil.resolveAll(genmodel.eResource().getResourceSet());
+ Resource result = null;
+ List<GenPackage> packages = genmodel.getGenPackages();
+ if (packages.size() > 0) {
+ GenPackage genPackage = packages.get(0);
+ currentEPackage = genPackage.getEcorePackage();
+ result = currentEPackage.eResource();
+ manageEPackage(currentEPackage);
+ }
+ return result;
+ }
+
+ /**
+ * Recursive method to browse EPackages
+ *
+ * @param currentEPackage2
+ */
+ private void manageEPackage(EPackage currentEPackage2) {
+ for (EClassifier eclassifier : currentEPackage2.getEClassifiers()) {
+ if (eclassifier instanceof EClass) {
+ EClass eClass = (EClass) eclassifier;
+ manageEClass(eClass);
+ }
+ }
+ for (EPackage ePackage : currentEPackage2.getESubpackages()) {
+ manageEPackage(ePackage);
+ }
+
+ }
+
+ /**
+ * Recursive method to manage hierarchy tree
+ *
+ * @param eClass
+ */
+ private void manageEClass(EClass eClass) {
+ if (eClass != resourceEObjectEClass) {
+ if (eClass.getESuperTypes().size() == 0) {
+ if (isACorrectEPackage(eClass.getEPackage())) {
+ eClass.getESuperTypes().add(resourceEObjectEClass);
+ }
+ } else {
+ boolean toAdd = true;
+ for (EClass eClass2 : eClass.getESuperTypes()) {
+ toAdd &= !isACorrectEPackage(eClass2.getEPackage());
+ manageEClass(eClass2);
+ }
+ if (toAdd) {
+ eClass.getESuperTypes().add(resourceEObjectEClass);
+ }
+ }
+ }
+ }
+
+ /**
+ * determine if the ePackage given in parameter is a children of the current Epackage
+ *
+ * @param ePackage
+ * @return
+ */
+ private boolean isACorrectEPackage(EPackage ePackage) {
+ EPackage current = ePackage;
+ while (current != null && current != currentEPackage) {
+ current = current.getESuperPackage();
+ }
+ return current == currentEPackage;
+ }
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.java b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.java
new file mode 100644
index 00000000000..c12f614f686
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/controller/exceptions/URINotValidException.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.resource.migration.controller.exceptions;
+
+/**
+ * This exception is thrown when the uri is not valid
+ *
+ * @author tristan.faure@atosorigin.com
+ *
+ */
+public class URINotValidException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public URINotValidException(String string) {
+ super(string);
+ }
+}
diff --git a/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.java b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.java
new file mode 100644
index 00000000000..0d082bac971
--- /dev/null
+++ b/plugins/profile-tool/org.eclipse.papyrus.resource.migration/src/org/eclipse/papyrus/resource/migration/popup/actions/UpdateGenModelAction.java
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.resource.migration.popup.actions;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.resource.migration.controller.GenModelUpdater;
+import org.eclipse.papyrus.resource.migration.controller.exceptions.URINotValidException;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+public class UpdateGenModelAction implements IObjectActionDelegate {
+
+ private Shell shell;
+
+ /**
+ * Constructor for Action1.
+ */
+ public UpdateGenModelAction() {
+ super();
+ }
+
+ /**
+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ shell = targetPart.getSite().getShell();
+ }
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ if (PlatformUI.getWorkbench() != null) {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if (workbench.getActiveWorkbenchWindow() != null) {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window.getSelectionService() != null) {
+ ISelectionService service = window.getSelectionService();
+ ISelection selection = service.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {
+
+ public void run() {
+ runProcess(structuredSelection);
+ }
+ });
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * perform the process
+ *
+ * @param structuredSelection
+ */
+ private void runProcess(final IStructuredSelection structuredSelection) {
+ try {
+ Iterator<?> iterator = structuredSelection.iterator();
+ GenModelUpdater updater = new GenModelUpdater();
+ while (iterator.hasNext()) {
+ Object next = iterator.next();
+ if (next instanceof IFile) {
+ IFile ifile = (IFile) next;
+ updater.transform(URI.createURI(ifile.getLocationURI().toString()));
+ ifile.getParent().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
+ }
+ }
+ MessageDialog.openInformation(shell, "Finish", "The genmodel has been updated");
+ } catch (URINotValidException e) {
+ MessageDialog.openError(shell, "Error", e.getMessage());
+ e.printStackTrace();
+ } catch (IOException e) {
+ MessageDialog.openError(shell, "Error", "An error occurs during save process");
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @see IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}

Back to the top