summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan GEOFFROY2014-07-07 05:52:28 (EDT)
committerJonathan GEOFFROY2014-07-07 05:52:28 (EDT)
commit38a310dba67466735d36492543d058eb12ffac0b (patch)
tree0d9798bd8ab0d072c1b55f1b02fb166de3ceb9fb
parent5787b36995a4487407f1febf7ba5079e1b14ddb9 (diff)
downloadorg.eclipse.papyrus-38a310dba67466735d36492543d058eb12ffac0b.zip
org.eclipse.papyrus-38a310dba67466735d36492543d058eb12ffac0b.tar.gz
org.eclipse.papyrus-38a310dba67466735d36492543d058eb12ffac0b.tar.bz2
Bug 438640 - [java reverse code] should allow a drag & drop way to runrefs/changes/95/29295/2
the reverse Detect drop into papyrus model editor & perform the reverse if selection is reversible. Perform reverse by using ReverseHandler Change-Id: I3f7756e8893ea823b3edd30912fd7754333d7e02 Signed-off-by: Jonathan GEOFFROY <geoffroy.jonathan@gmail.com>
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF1
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml7
-rwxr-xr-xextraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java103
-rwxr-xr-xextraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java60
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java19
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties2
7 files changed, 193 insertions, 1 deletions
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..b8c742b
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding//src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties=ISO-8859-1
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF
index cb0ac3f..3eb297c 100644
--- a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF
@@ -16,4 +16,5 @@ Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.papyrus.java.reverse.ui;singleton:=tr
ue
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.eclipse.papyrus.infra.gmfdiag.dnd.strategy
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml
index 8b7f78d..533d193 100644
--- a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml
@@ -105,5 +105,10 @@
name="Create Association From Property">
</command>
</extension>
-
+ <extension
+ point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy">
+ <strategy
+ strategy="org.eclipse.papyrus.java.reverse.ui.dnd.DropReverseStrategy">
+ </strategy>
+ </extension>
</plugin>
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java
new file mode 100755
index 0000000..6fd0888
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Jonathan Geoffroy.
+ *
+ *
+ * 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:
+ * Jonathan Geoffroy geoffroy.jonathan@gmail.com - initial implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.reverse.ui.dnd;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.java.reverse.ui.ReverseCodeHandler;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Command called when user drop Java Elements into diagram model (on Papyrus editor).
+ * Check for selected elements, and run reverse handler if all selected files are reversible.
+ *
+ * This command implements a Singleton Pattern. You should use ReverseCommand.getInstance() to receive a Singleton of this Command.
+ *
+ * @author Jonathan Geoffroy
+ *
+ */
+public class DropReverseCommand extends Command {
+
+ /**
+ * Singleton implementation of ReverseCommand
+ * Always return this instance of Reverse Command when ask for instance
+ *
+ * @see {getInstance()}
+ */
+ private static DropReverseCommand instance;
+
+ /**
+ * Constructor. Initialize the request for this ReverseCommand
+ */
+ private DropReverseCommand() {
+ super();
+ }
+
+ @Override
+ public boolean canExecute() {
+ // Find the type of each selected file (CompilationUnit, packages ...)
+ List selected; // The selected files from JDT
+
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+ if(!(selection instanceof IStructuredSelection)) {
+ return false;
+ }
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ selected = structuredSelection.toList();
+
+ // For each selected object, check if it's reversible.
+ for(Object s : selected) {
+ // We can only reverse Java Elements. Moreover, reversing projects is not available yet
+ if(!(s instanceof IJavaElement) || s instanceof IProject) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ ReverseCodeHandler reverse = new ReverseCodeHandler();
+ try {
+ reverse.execute(null);
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * return a singleton of this command
+ * Change the request if it differ from the previous calling
+ *
+ *
+ * @return a singleton of this command
+ */
+ public static DropReverseCommand getInstance(Request request) {
+ if(instance == null) {
+ instance = new DropReverseCommand();
+ }
+
+ return instance;
+ }
+}
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java
new file mode 100755
index 0000000..2ede84a
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Jonathan Geoffroy.
+ *
+ *
+ * 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:
+ * Jonathan Geoffroy geoffroy.jonathan@gmail.com - initial implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.reverse.ui.dnd;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy;
+import org.eclipse.swt.graphics.Image;
+
+
+public class DropReverseStrategy implements DropStrategy {
+ public DropReverseStrategy() {
+ }
+
+ @Override
+ public String getLabel() {
+ return Messages.DropReverseStrategy_LABEL;
+ }
+
+ @Override
+ public String getDescription() {
+ return Messages.DropReverseStrategy_DESCRIPTION;
+ }
+
+ @Override
+ public Image getImage() {
+ // No image to display
+ return null;
+ }
+
+ @Override
+ public String getID() {
+ return "org.eclipse.papyrus.java.reverse.ui.dnd.reversedropstrategy"; //$NON-NLS-1$
+ }
+
+ @Override
+ public Command getCommand(final Request request, final EditPart targetEditPart) {
+ return DropReverseCommand.getInstance(request);
+
+ }
+
+ @Override
+ public int getPriority() {
+ return 0;
+ }
+
+}
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java
new file mode 100644
index 0000000..3253c5e
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java
@@ -0,0 +1,19 @@
+package org.eclipse.papyrus.java.reverse.ui.dnd;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.java.reverse.ui.dnd.messages"; //$NON-NLS-1$
+
+ public static String DropReverseStrategy_DESCRIPTION;
+
+ public static String DropReverseStrategy_LABEL;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties
new file mode 100644
index 0000000..753937a
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties
@@ -0,0 +1,2 @@
+DropReverseStrategy_DESCRIPTION=Reverse all dropped classes into model
+DropReverseStrategy_LABEL=Reverse