Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-06-12 07:55:54 +0000
committercletavernie2012-06-12 07:55:54 +0000
commitab927a9bb386e26d03dc5fc7918bdbde971325b4 (patch)
tree4dc33296201a39e2b221a72ec4b1ad5c44a93023 /extraplugins/migration
parent33807d8f554053e28000a3eee1ce46c0e4e78ccd (diff)
downloadorg.eclipse.papyrus-ab927a9bb386e26d03dc5fc7918bdbde971325b4.tar.gz
org.eclipse.papyrus-ab927a9bb386e26d03dc5fc7918bdbde971325b4.tar.xz
org.eclipse.papyrus-ab927a9bb386e26d03dc5fc7918bdbde971325b4.zip
351802: [Constraints] The Property View constraints model should be more generic
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351802
Diffstat (limited to 'extraplugins/migration')
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.classpath7
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.project28
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/META-INF/MANIFEST.MF14
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/about.html28
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/build.properties8
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/icons/Customization.gifbin0 -> 341 bytes
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.properties3
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.xml60
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/Activator.java69
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/handler/MigrationHandler.java129
11 files changed, 353 insertions, 0 deletions
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.classpath b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.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/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.project b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.project
new file mode 100644
index 00000000000..a9e18b19d3d
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.views.properties.model.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/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.settings/org.eclipse.jdt.core.prefs b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..44217f8c068
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/.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/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/META-INF/MANIFEST.MF b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..f889cd62550
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.eclipse.papyrus.views.properties.model.migration;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.views.properties.model.migration.Activator
+Bundle-Vendor: %Bundle-Vendor
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/about.html b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/build.properties b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/build.properties
new file mode 100644
index 00000000000..b889851d8d6
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.properties,\
+ about.html,\
+ plugin.xml
+src.includes = about.html
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/icons/Customization.gif b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/icons/Customization.gif
new file mode 100644
index 00000000000..0b1be97b8cf
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/icons/Customization.gif
Binary files differ
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.properties b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.properties
new file mode 100644
index 00000000000..455f3ec9ac6
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.properties
@@ -0,0 +1,3 @@
+#Properties file for org.eclipse.papyrus.views.properties.model.migration
+Bundle-Vendor = Eclipse Modeling Project
+Bundle-Name = Properties view Migration (Incubation) \ No newline at end of file
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.xml b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.xml
new file mode 100644
index 00000000000..48c64aa19d0
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/plugin.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.eclipse.papyrus.views.properties.model.migration.handler.MigrationHandler"
+ description="Migrates the selected file to Papyrus 0.9.X"
+ id="org.eclipse.papyrus.views.properties.model.migration.migrate_0.9"
+ name="Migrate to Papyrus 0.9.X">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.views.properties.model.migration.handler.MigrationHandler"
+ commandId="org.eclipse.papyrus.views.properties.model.migration.migrate_0.9">
+ <activeWhen>
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <test
+ property="extension"
+ value="ctx">
+ </test>
+ </iterate>
+ </with>
+ </activeWhen>
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
+ <command
+ commandId="org.eclipse.papyrus.views.properties.model.migration.migrate_0.9"
+ icon="icons/Customization.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <test
+ property="extension"
+ value="ctx">
+ </test>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/Activator.java b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/Activator.java
new file mode 100644
index 00000000000..7af69dab2f7
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/Activator.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.properties.model.migration;
+
+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.views.properties.model.migration"; //$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)
+ */
+ @Override
+ 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)
+ */
+ @Override
+ 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/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/handler/MigrationHandler.java b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/handler/MigrationHandler.java
new file mode 100644
index 00000000000..96b36c3a6d8
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.views.properties.model.migration/src/org/eclipse/papyrus/views/properties/model/migration/handler/MigrationHandler.java
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.properties.model.migration.handler;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.views.properties.model.migration.Activator;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+public class MigrationHandler extends AbstractHandler {
+
+ public static final String ContextExtension = "ctx";
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if(workbench == null) {
+ return null;
+ }
+
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if(window == null) {
+ return null;
+ }
+
+ ISelection selection = window.getSelectionService().getSelection();
+ if(!(selection instanceof IStructuredSelection)) {
+ return null;
+ }
+
+ final IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+
+ Job migrationJob = new Job("Migrate selected files") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask(getName(), structuredSelection.size());
+
+ Iterator<?> iterator = structuredSelection.iterator();
+ while(iterator.hasNext()) {
+ Object selectedElement = iterator.next();
+ if(selectedElement instanceof IFile) {
+ IFile selectedFile = (IFile)selectedElement;
+ monitor.subTask("Migrating " + selectedFile.getName());
+
+ if(ContextExtension.equals(selectedFile.getFileExtension())) {
+ migrateFile(selectedFile);
+ }
+ }
+ monitor.worked(1);
+ }
+
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ };
+
+ migrationJob.setUser(true);
+ migrationJob.schedule();
+
+ return null;
+ }
+
+ private static void migrateFile(IFile file) {
+ //Ctx files weight between 4 and 400 kB, so it's probably ok to read their contents into a String
+ try {
+ InputStream stream = file.getContents();
+ String charset = file.getContentDescription().getCharset();
+
+ InputStreamReader reader = new InputStreamReader(stream, charset);
+
+ StringBuilder builder = new StringBuilder();
+ char[] buffer = new char[4096];
+
+ int result;
+ while((result = reader.read(buffer)) != -1) {
+ builder.append(buffer, 0, result);
+ }
+
+ String contents = builder.toString();
+
+ contents = contents.replaceAll("xmlns:contexts=\"http://www.eclipse.org/papyrus/properties/contexts\"", "xmlns:contexts=\"http://www.eclipse.org/papyrus/properties/contexts/0.9\"");
+
+ contents = contents.replaceAll("contexts:CompositeConstraint", "constraints:CompositeConstraint");
+ contents = contents.replaceAll("contexts:SimpleConstraint", "constraints:SimpleConstraint");
+ contents = contents.replaceAll("contexts:ValueProperty", "constraints:ValueProperty");
+ contents = contents.replaceAll("contexts:ReferenceProperty", "constraints:ReferenceProperty");
+
+ if(!contents.contains("xmlns:constraints=")) {
+ String source = "xmlns:contexts=\"http://www.eclipse.org/papyrus/properties/contexts/0.9\"";
+ String target = source + "\n\txmlns:constraints=\"http://www.eclipse.org/papyrus/constraints/0.9\"";
+ contents = contents.replace(source, target);
+ }
+
+ file.setContents(new ByteArrayInputStream(contents.getBytes(charset)), true, true, new NullProgressMonitor());
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ } catch (CoreException ex) {
+ Activator.log.error(ex);
+ }
+ }
+}

Back to the top