Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse')
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java54
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DisplayReverse.java181
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DndReverseCodeHandler.java246
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java287
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java19
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java196
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/TreeSelectionList.java153
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/DndReverseCodeDialog.java93
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java332
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java281
-rwxr-xr-xextraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java103
-rwxr-xr-xextraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java60
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java19
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties2
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/handlers/CreateAssociationFromPropertyHandler.java286
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties2
16 files changed, 2314 insertions, 0 deletions
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java
new file mode 100644
index 00000000000..2ac94758559
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java
@@ -0,0 +1,54 @@
+package org.eclipse.papyrus.java.reverse.ui;
+
+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.java.reverse.ui";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (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/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DisplayReverse.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DisplayReverse.java
new file mode 100644
index 00000000000..caac0a8c995
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DisplayReverse.java
@@ -0,0 +1,181 @@
+/*****************************************************************************
+ * 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;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * Command which allow to display java elements into papyrus diagram.
+ * The java element must exists into papyrus model (for example by using reverse plugin)
+ *
+ * @author Jonathan Geoffroy
+ *
+ */
+public class DisplayReverse {
+
+ private static final String MODEL_TYPE = "2005", PACKAGE_TYPE = "2007", CU_TYPE = "2008"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /**
+ * items to display into papyrus diagram
+ */
+ private List<IJavaElement> items;
+
+ /**
+ * Contains all uml resources.
+ * Used to improve research into umlModel.
+ */
+ private Map<String, NamedElement> umlModelNames;
+
+ /**
+ * Graphical container for the reverse result
+ */
+ private Diagram diagram;
+
+ /**
+ * model to display into diagram. Null if user doesn't want to display any model
+ */
+ private Model model;
+
+ /**
+ * Constructor.
+ *
+ * @param items
+ * items to display into papyrus diagram
+ * @param diagram
+ * container where to display items
+ * @param umlModel
+ * resource representing the papyrus uml model
+ * @param model
+ * model to display into diagram. Null if user doesn't want to display any model
+ */
+ public DisplayReverse(List<IJavaElement> items, Diagram diagram, Resource umlModel, Model model) {
+ super();
+ this.items = items;
+ this.diagram = diagram;
+ this.model = model;
+
+ // Change uml model collection to improve search
+ umlModelNames = new HashMap<String, NamedElement>();
+ TreeIterator<EObject> tree = umlModel.getAllContents();
+ while (tree.hasNext()) {
+ for (EObject o : tree.next().eContents()) {
+ /*
+ * Only add reversable elements.
+ * The non Named element cannot been added into model (comments ...)
+ */
+ if (o instanceof NamedElement) {
+ // Add it into items to display
+ NamedElement e = (NamedElement) o;
+ umlModelNames.put(e.getName(), e);
+ }
+ }
+ }
+
+
+ }
+
+ /**
+ * Execute the display command.
+ * Should call this method when you want display the selection into papyrus diagram.
+ *
+ * @throws JavaModelException
+ */
+ public void execute() throws JavaModelException {
+ // Display the model
+ if (model != null) {
+ display(model.getName(), MODEL_TYPE);
+ }
+
+ // Cross selection to display each selected item
+ for (IJavaElement item : items) {
+ scanJavaElement(item);
+ }
+ }
+
+ /**
+ * Scan a Compilation Unit item
+ * Just display it
+ *
+ * @param item
+ * a selection compilation unit
+ */
+ private void scanCU(ICompilationUnit item) {
+ String itemName = item.getElementName().substring(0, item.getElementName().length() - 5); // remove ".java" to the compilation unit name
+ display(itemName, CU_TYPE);
+ }
+
+ /**
+ * Scan a package.
+ * Display it and cross its childs to display all sub-packages (and recursively)
+ *
+ * @param item
+ * the package to scan
+ * @throws JavaModelException
+ */
+ private void scanPackage(IPackageFragment item) throws JavaModelException {
+ String itemName = item.getElementName();
+ display(itemName, PACKAGE_TYPE);
+ }
+
+ /**
+ * scan and display a JavaElement by delegates to scan{typeOfJavaElement}
+ *
+ * @param item
+ * the item to display
+ * @throws JavaModelException
+ */
+ private void scanJavaElement(IJavaElement item) throws JavaModelException {
+ try {
+ switch (item.getElementType()) {
+ case IJavaElement.PACKAGE_FRAGMENT:
+ scanPackage((IPackageFragment) item);
+ break;
+ case IJavaElement.COMPILATION_UNIT:
+ scanCU((ICompilationUnit) item);
+ break;
+ }
+ } catch (NullPointerException e) {
+ System.err.println(item.getElementName() + "is NOT in selected uml model"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Display an element into papyrus diagram
+ *
+ * @param itemName
+ * the name of element to display
+ */
+ private void display(String itemName, String type) {
+ EObject item = this.umlModelNames.get(itemName);
+ if (!diagram.getChildren().contains(item)) {
+ ViewService.createNode(diagram, item, type, new PreferencesHint("org.eclipse.papyrus.uml.diagram.clazz")); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DndReverseCodeHandler.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DndReverseCodeHandler.java
new file mode 100644
index 00000000000..5c5568282c7
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DndReverseCodeHandler.java
@@ -0,0 +1,246 @@
+/*****************************************************************************
+ * 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;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.TreeSet;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.impl.ShapeImpl;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.java.reverse.ui.dialog.DndReverseCodeDialog;
+import org.eclipse.papyrus.java.reverse.ui.dialog.ReverseCodeDialog;
+import org.eclipse.papyrus.uml.diagram.common.util.MDTUtil;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * Handler to display reverse result into current papyrus diagram
+ * This Handler is activated when user drag'n'drop java resource into papyrus diagram.<br>
+ * It display just non displayed java resource.
+ * Moreover, it use DndReverseCodeDialog to know if it have to display model, packages and CompilationUnit or not.
+ *
+ * @author Jonathan Geoffroy
+ *
+ */
+public class DndReverseCodeHandler extends ReverseCodeHandler {
+
+ /**
+ * true if and only if user want to display reversed compilation unit
+ */
+ private boolean displayCU;
+
+ /**
+ * true if and only if user want to display reversed packages
+ */
+ private boolean displayPackages;
+
+ /**
+ * true if and only if user want to display reversed model
+ */
+ private boolean displayModel;
+
+ @Override
+ /**
+ * Find all resource to display (selection - resources which are already in the diagram), run the reverse command, before running the display command<br/>
+ * @see org.eclipse.papyrus.java.reverse.ui.ReverseCodeHandler#doExecute(org.eclipse.papyrus.java.reverse.ui.dialog.ReverseCodeDialog)
+ *
+ * @param dialog
+ */
+ protected void doExecute(ReverseCodeDialog dialog) {
+ // Get user preferences on dialog
+ DndReverseCodeDialog dndDialog = (DndReverseCodeDialog) dialog;
+ displayModel = dndDialog.displayModel();
+ displayPackages = dndDialog.displayPackages();
+ displayCU = dndDialog.displayCU();
+
+ // get current selection
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+ TreeSelection treeSelection = (TreeSelection) selection;
+
+ // Find active papyrus diagram
+ Diagram diagram = null;
+ IEditorPart activeEditor = MDTUtil.getActiveEditor();
+ if (activeEditor != null) {
+ if (activeEditor instanceof IMultiDiagramEditor) {
+ diagram = (Diagram) ((IMultiDiagramEditor) activeEditor).getAdapter(Diagram.class);
+ }
+ }
+
+ // Remove items already in diagram from selection
+ List<IJavaElement> listSelection;
+ try {
+ listSelection = selectionMinusAlreadyInDiagram(treeSelection, diagram);
+ } catch (JavaModelException e1) {
+ e1.printStackTrace();
+ return;
+ }
+
+ // Run the reverse
+ super.doExecute(dialog);
+
+ // Find model to display
+ Model model = null;
+ if (displayModel) {
+ String modelName = dndDialog.getValue();
+ model = getModelToDisplay(diagram, modelName);
+ }
+
+ // Run the reverse displayer
+ DisplayReverse displayReverse = new DisplayReverse(listSelection, diagram, getUmlResource(), model);
+ try {
+ displayReverse.execute();
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ protected ReverseCodeDialog getDialog(Shell shell, String modelUid) {
+ return new DndReverseCodeDialog(shell, modelUid, null, null);
+ }
+
+ /**
+ *
+ * @param selection
+ * java resources selected
+ * @param diagram
+ * opened papyrus diagram
+ * @return selection - resources already in diagram
+ * @throws JavaModelException
+ */
+ private List<IJavaElement> selectionMinusAlreadyInDiagram(TreeSelection selection, Diagram diagram) throws JavaModelException {
+ // Add all diagram elements to Set
+ TreeSet<String> alreadyExists = new TreeSet<String>();
+ EList diagramList = diagram.getChildren();
+ Iterator diagramIt = diagramList.iterator();
+ ShapeImpl item;
+ NamedElement e;
+ while (diagramIt.hasNext()) {
+ item = (ShapeImpl) diagramIt.next();
+ e = (NamedElement) (item.getElement());
+ alreadyExists.add(e.getName());
+ }
+
+ // remove all elements of Set from selection
+ TreeSelectionList selectionList = new TreeSelectionList(selection, displayPackages, displayCU);
+ ListIterator<IJavaElement> selectionIterator = selectionList.listIterator();
+ String selectionItemName;
+ while (selectionIterator.hasNext()) {
+ selectionItemName = getName(selectionIterator.next());
+ if (selectionItemName != null && alreadyExists.contains(selectionItemName)) {
+ selectionIterator.remove();
+ }
+ }
+
+ return selectionList;
+ }
+
+ /**
+ * Find the name of <code>item</code> For java compilation unit, remove ".java" extension
+ *
+ * @param item
+ * @return the name of item.
+ */
+ private String getName(IJavaElement item) {
+ String name = item.getElementName();
+ if (item instanceof ICompilationUnit) {
+ return name.substring(0, name.length() - 5);
+ }
+ return name;
+ }
+
+ /**
+ * find a model named <code>modelName</code>
+ *
+ * @param modelName
+ * the name of the model the find
+ * @return the model which named <code>modelName</code>, or null if it doesn't exists into the current papyrus uml resource
+ */
+ public Model getModel(String modelName) {
+ TreeIterator<EObject> tree = getUmlResource().getAllContents();
+ while (tree.hasNext()) {
+ for (EObject o : tree.next().eContents()) {
+ if (o instanceof Model) {
+ // Add it into items to display
+ Model model = (Model) o;
+
+ // Search for model
+ if (model.getName().equals(modelName)) {
+ System.out.println("model = " + model);
+ return model;
+ }
+ }
+ }
+ }
+ System.out.println("model = null");
+ return null;
+ }
+
+ /**
+ * find the model named <code>modelName</code>, and get it only if it has to be displayed
+ *
+ * @param diagram
+ * active papyrus diagram
+ * @param modelName
+ * the name of the model to find
+ * @return model corresponding to the modelName if it has to be displayed, i.e. if it doesn't already displayed into the diagram, or null
+ * otherwise
+ */
+ private Model getModelToDisplay(Diagram diagram, String modelName) {
+ Model model = getModel(modelName);
+ if (model != null && !isInDiagram(diagram, model)) {
+ System.out.println("display model " + model);
+ return model;
+ }
+ System.out.println("don't display model");
+ return null;
+ }
+
+ /**
+ *
+ * @param diagram
+ * @param model
+ * @return true if model is in diagram
+ */
+ private boolean isInDiagram(Diagram diagram, Model model) {
+ EList diagramList = diagram.getChildren();
+ Iterator diagramIt = diagramList.iterator();
+ ShapeImpl item;
+ while (diagramIt.hasNext()) {
+ item = (ShapeImpl) diagramIt.next();
+ if (item.getElement() == model) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java
new file mode 100644
index 00000000000..a9190952dcc
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java
@@ -0,0 +1,287 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui;
+
+import japa.parser.JavaParser;
+import japa.parser.ParseException;
+import japa.parser.ast.CompilationUnit;
+
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+
+import javagen.umlparser.CompilationUnitAnalyser;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Package;
+
+/**
+ * @author dumoulin
+ *
+ */
+public class JavaCodeReverse {
+
+ CompilationUnitAnalyser javaAnalyser;
+
+ /**
+ * Constructor.
+ *
+ * @param model
+ */
+ public JavaCodeReverse(Resource model) {
+ javaAnalyser = new CompilationUnitAnalyser(model);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param model
+ */
+ public JavaCodeReverse(Package rootPackage, String generatedPackageName, List<String> searchPaths) {
+ javaAnalyser = new CompilationUnitAnalyser(rootPackage, generatedPackageName, searchPaths);
+ }
+
+
+ /**
+ * @throws CoreException
+ * @throws ParseException
+ *
+ */
+ public void reverseResource(IResource resource) throws ParseException, CoreException {
+ System.out.println("reverseResource(" + resource.getName() + ")");
+
+ if (resource instanceof IFile) {
+ reverseFile((IFile) resource);
+ } else if (resource instanceof IFolder) {
+ reverseFolder((IFolder) resource);
+ } else if (resource instanceof IProject) {
+ reverseProject((IProject) resource);
+ }
+
+ }
+
+ /**
+ * Walk throw each file in folder
+ *
+ * @param resource
+ * @param model
+ * @throws CoreException
+ * @throws ParseException
+ */
+ private void reverseFolder(IFolder folder) throws CoreException, ParseException {
+
+ for (IResource resource : folder.members()) {
+ reverseResource(resource);
+ }
+
+ }
+
+ /**
+ * Walk throw each file in folder
+ *
+ * @param resource
+ * @param model
+ * @throws CoreException
+ * @throws ParseException
+ */
+ private void reverseProject(IProject folder) throws CoreException, ParseException {
+
+ for (IResource resource : folder.members()) {
+ reverseResource(resource);
+ }
+
+ }
+
+ /**
+ * Reverse a file
+ *
+ * @param resource
+ * @throws CoreException
+ * @throws ParseException
+ */
+ private void reverseFile(IFile file) throws ParseException, CoreException {
+ System.out.println("try to reverseFile(" + file.getName() + ")");
+ if (!"java".equals(file.getFileExtension())) {
+ return;
+ }
+
+ System.out.println("reverseFile(" + file.getName() + ")");
+
+ CompilationUnit cu = JavaParser.parse(file.getContents());
+ javaAnalyser.processCompilationUnit(cu);
+ }
+
+ /**
+ * @throws CoreException
+ * @throws ParseException
+ *
+ */
+ public void reverseJavaElement(IJavaElement element) throws ParseException, CoreException
+ {
+ System.out.println("reverseJavaElement(" + element.getElementName() + ")");
+
+ if (element instanceof ITypeRoot)
+ {
+ reverseCompilationUnit((ITypeRoot) element);
+ }
+ else if (element instanceof IPackageFragment)
+ {
+ reversePackageFragment((IPackageFragment) element);
+ }
+ else if (element instanceof IPackageFragmentRoot)
+ {
+ reversePackageFragmentRoot((IPackageFragmentRoot) element);
+ }
+ else
+ {
+ System.err.println("Can't reverse Java Element " + element);
+ }
+
+ }
+
+ /**
+ *
+ * @param element
+ * @throws ParseException
+ * @throws CoreException
+ */
+ private void reversePackageFragmentRoot(IPackageFragmentRoot element) throws ParseException, CoreException {
+
+ System.out.println("reversePackageFragmentRoot(" + element.getElementName() + ")");
+
+ IJavaElement[] children = element.getChildren();
+ for (IJavaElement child : children) {
+ reverseJavaElement(child);
+ }
+
+ }
+
+ /**
+ *
+ * @param element
+ * @throws ParseException
+ * @throws CoreException
+ */
+ private void reversePackageFragment(IPackageFragment element) throws ParseException, CoreException {
+
+ System.out.println("reversePackageFragment(" + element.getElementName() + ")");
+
+ IJavaElement[] children = element.getChildren();
+ for (IJavaElement child : children) {
+ reverseJavaElement(child);
+ }
+ }
+
+ /**
+ * Reverse a file
+ *
+ * @param resource
+ * @throws CoreException
+ * @throws ParseException
+ */
+ private void reverseCompilationUnit(ITypeRoot unit) throws ParseException, CoreException {
+ System.out.println("try to reverseUnit(" + unit.getElementName() + ")");
+ System.out.println("file type=(" + unit.getElementType() + ")");
+
+ String source = unit.getSource();
+ if (source == null)
+ {
+ System.err.println("No source attached to unit '" + unit.getElementName() + "'");
+ return;
+ }
+
+
+ CompilationUnit cu = JavaParser.parse(new StringReader(source));
+ javaAnalyser.processCompilationUnit(cu);
+ }
+
+ /**
+ * Real Implementation of the command.
+ *
+ * @param generationPackageName
+ * @param searchPaths
+ */
+ public void executeCodeReverse(Resource umlResource, String generationPackageName, List<String> searchPaths) {
+ System.out.println("executeCodeReverse()");
+
+ // Get current selection
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+
+ TreeSelection treeSelection = (TreeSelection) selection;
+ // String filename = treeSelection.
+ @SuppressWarnings("rawtypes")
+ Iterator iter = treeSelection.iterator();
+ while (iter.hasNext()) {
+ Object obj = iter.next();
+ // Translate java ICompilationUnit to Iresource
+ if (obj instanceof ICompilationUnit) {
+ ICompilationUnit u = (ICompilationUnit) obj;
+ try {
+ obj = u.getCorrespondingResource();
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (obj instanceof IPackageFragment)
+ {
+ IPackageFragment u = (IPackageFragment) obj;
+ try {
+ IResource res = u.getCorrespondingResource();
+ if (res != null) {
+ obj = res;
+ }
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ // This happen when selection is an element from a jar
+ if (obj instanceof IJavaElement)
+ {
+ IJavaElement u = (IJavaElement) obj;
+ try {
+
+ reverseJavaElement(u);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ // This is a regular java file
+ if (obj instanceof IResource)
+ {
+ try {
+ reverseResource((IResource) obj);
+ } catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ System.out.println("reverse done");
+
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java
new file mode 100644
index 00000000000..38577506c0d
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java
@@ -0,0 +1,19 @@
+package org.eclipse.papyrus.java.reverse.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.java.reverse.ui.messages"; //$NON-NLS-1$
+
+ public static String ReverseCodeHandler_NoModelError_Message;
+
+ public static String ReverseCodeHandler_NoModelError_Title;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java
new file mode 100644
index 00000000000..433344eba35
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java
@@ -0,0 +1,196 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.java.reverse.ui.dialog.ReverseCodeDialog;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.uml2.uml.Package;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class ReverseCodeHandler extends AbstractHandler implements IHandler {
+
+ private static String DefaultGenerationModeleName = "generated";
+
+ /**
+ * Method called when button is pressed.
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // Try to find uml resource
+ final Resource umlResource;
+ try {
+ umlResource = getUmlResource();
+ } catch (NullPointerException e) {
+ // No uml resource available. User must open a model. We open an error dialog with an explicit message to advice user.
+ Shell shell = HandlerUtil.getActiveShell(event);
+ Status errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ReverseCodeHandler_NoModelError_Title);
+ ErrorDialog.openError(shell, "", Messages.ReverseCodeHandler_NoModelError_Message, errorStatus);
+
+ // Stop the reverse execution.
+ return null;
+ }
+ ;
+
+ String modelUid = getModelUid(umlResource);
+ System.out.println("Model uid :" + modelUid);
+
+ // Get reverse parameters from a dialog
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getShell();
+ // ReverseCodeDialog dialog = new ReverseCodeDialog(shell, DefaultGenerationPackageName, Arrays.asList("generated") );
+ final ReverseCodeDialog dialog = getDialog(shell, modelUid);
+
+ int res = dialog.open();
+ // System.out.println("dialog result =" + res);
+ if (res == Window.CANCEL) {
+ System.out.println("Canceled by user.");
+ return null;
+ }
+
+ // Execute the reverse with provided parameters
+ TransactionalEditingDomain editingDomain;
+ try {
+ editingDomain = getEditingDomain();
+ } catch (ServiceException e) {
+ // Can't get editing domain
+ e.printStackTrace();
+ throw new ExecutionException(e.getMessage());
+ }
+
+ RecordingCommand command = new RecordingCommand(editingDomain, "Reverse Java Code") {
+
+ @Override
+ protected void doExecute() {
+ ReverseCodeHandler.this.doExecute(dialog);
+ }
+
+ };
+
+ editingDomain.getCommandStack().execute(command);
+
+
+ return null;
+ }
+
+ /**
+ * Find the modelUid name contains into umlResource taken in parameter
+ *
+ * @param umlResource
+ * @return the modelUid name
+ */
+ private String getModelUid(Resource umlResource) {
+ // Try to compute a uid identifying the model. Used to store user settings.
+ String modelUid = umlResource.getURI().toPlatformString(true);
+ if (modelUid == null) {
+ System.err.println("Can't compute relatif model uid. Use absolute one");
+ modelUid = umlResource.getURI().path();
+ }
+ return modelUid;
+ }
+
+ /**
+ * Command ran in a RecordingCommand, after the dialog
+ * Run the @link{JavaCodeReverse.executeCodeReverse}
+ * Shall be override to change command behavior
+ */
+ protected void doExecute(ReverseCodeDialog dialog) {
+ // Create searchpaths. Add the rootmodelname as prefix.
+ final List<String> searchPaths = Arrays.asList(dialog.getSearchPath());
+ Resource umlResource = getUmlResource();
+ String packageName = getPackageName(dialog);
+ JavaCodeReverse reverse = new JavaCodeReverse(getRootPackage(umlResource), packageName, searchPaths);
+ reverse.executeCodeReverse(umlResource, packageName, searchPaths);
+ }
+
+ /**
+ * The dialog used for user.
+ *
+ * @param shell
+ * @param modelUid
+ * @return the dialog to show to user
+ */
+ protected ReverseCodeDialog getDialog(Shell shell, String modelUid) {
+ return new ReverseCodeDialog(shell, modelUid, null, null);
+ }
+
+ /**
+ * Find the name of the model provided by the dialog
+ *
+ * @param dialog
+ * opened dialog to user
+ * @return the name of the model. If the user has changed this name, return the name provided by the user; return the default model name
+ * otherwise.
+ */
+ protected String getPackageName(ReverseCodeDialog dialog) {
+ String generationPackageName = dialog.getValue();
+ if (generationPackageName == null || generationPackageName.length() == 0) {
+ generationPackageName = DefaultGenerationModeleName;
+ }
+ return generationPackageName;
+ }
+
+ /**
+ * Get the uml resource used by the model.
+ *
+ * @return the Uml Resource
+ */
+ protected Resource getUmlResource() {
+ Resource umlResource = UmlUtils.getUmlModel().getResource();
+ return umlResource;
+ }
+
+ /**
+ * Get the name of the root model.
+ *
+ * @return
+ */
+ protected Package getRootPackage(Resource umlResource) {
+ Package rootPackage = (Package) umlResource.getContents().get(0);
+ return rootPackage;
+ }
+
+ /**
+ * Get the current MultiDiagramEditor.
+ *
+ * @return
+ */
+ protected IMultiDiagramEditor getMultiDiagramEditor() {
+ return EditorUtils.getMultiDiagramEditor();
+ }
+
+ /**
+ * Get the main editing doamin.
+ *
+ * @return
+ * @throws ServiceException
+ */
+ protected TransactionalEditingDomain getEditingDomain() throws ServiceException {
+ return ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/TreeSelectionList.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/TreeSelectionList.java
new file mode 100644
index 00000000000..370a9c0319e
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/TreeSelectionList.java
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * 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;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.TreeSelection;
+
+/**
+ * Transform a TreeSelection collection, provided by java resource selection, into a java List (java.util.List). <br>
+ * Add each element of TreeSelection which have to be displayed. i.e. include packages if <code>includePackages</code> == true; include compilation
+ * unit if <code>inclupdeCU</code> == true<br/>
+ * Note the each element of TreeSelection is a IJavaElement.
+ *
+ * @author Jonathan Geoffroy
+ *
+ */
+public class TreeSelectionList extends LinkedList<IJavaElement> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5749380826507346600L;
+
+ /**
+ * True if and only if this list includes packages
+ */
+ private boolean includePackages;
+
+ /**
+ * True if and only if this list includes packages
+ */
+ private boolean includeCU;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param treeSelection
+ * java resources selection
+ * @param includePackages
+ * True if and only if this list includes packages from <code>treeSelection</code>
+ * @param includeCU
+ * True if and only if this list includes compilation units from <code>treeSelection</code>
+ * @throws JavaModelException
+ */
+ public TreeSelectionList(TreeSelection treeSelection, boolean includePackages, boolean includeCU) throws JavaModelException {
+ super();
+ this.includePackages = includePackages;
+ this.includeCU = includeCU;
+
+ // Add each treeSelection item into the list
+ addAll(treeSelection);
+ }
+
+ /**
+ *
+ * @param selection
+ * @throws JavaModelException
+ */
+ private void addAll(TreeSelection selection) throws JavaModelException {
+ Iterator<IJavaElement> selectionIterator = selection.iterator();
+ while (selectionIterator.hasNext()) {
+ IJavaElement item = selectionIterator.next();
+ scanJavaElement(item);
+ }
+ }
+
+ /**
+ * Scan a Compilation Unit item
+ * Just add it if it's necessary
+ *
+ * @param item
+ * a selection compilation unit
+ */
+ private void scanCU(ICompilationUnit item) {
+ if (includeCU) {
+ add(item);
+ }
+ }
+
+ /**
+ * Scan a package.
+ * add it if it's necessary and cross its childs to display all sub-packages (and recursively)
+ *
+ * @param item
+ * the package to scan
+ * @throws JavaModelException
+ */
+ private void scanPackage(IPackageFragment item) throws JavaModelException {
+ if (includePackages) {
+ add(item);
+ }
+
+ // Recursive search in tree
+ for (IJavaElement child : item.getChildren()) {
+ scanJavaElement(child);
+ }
+ }
+
+ /**
+ * Scan a source folder.
+ * add its childs (and recursively) by calling scanJavaElement on each child
+ *
+ * @param item
+ * the folder to scan
+ * @throws JavaModelException
+ */
+ private void scanFolder(IPackageFragmentRoot item) throws JavaModelException {
+ // Recursive search in tree
+ for (IJavaElement child : item.getChildren()) {
+ scanJavaElement(child);
+ }
+ }
+
+ /**
+ * scan and add a JavaElement by delegates to scan{typeOfJavaElement}
+ *
+ * @param item
+ * the item to display
+ * @throws JavaModelException
+ */
+ private void scanJavaElement(IJavaElement item) throws JavaModelException {
+ switch (item.getElementType()) {
+ case IJavaElement.PACKAGE_FRAGMENT_ROOT:
+ scanFolder((IPackageFragmentRoot) item);
+ break;
+ case IJavaElement.PACKAGE_FRAGMENT:
+ scanPackage((IPackageFragment) item);
+ break;
+ case IJavaElement.COMPILATION_UNIT:
+ scanCU((ICompilationUnit) item);
+ break;
+ }
+ }
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/DndReverseCodeDialog.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/DndReverseCodeDialog.java
new file mode 100644
index 00000000000..05180af829d
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/DndReverseCodeDialog.java
@@ -0,0 +1,93 @@
+package org.eclipse.papyrus.java.reverse.ui.dialog;
+
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.papyrus.java.reverse.ui.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class DndReverseCodeDialog extends ReverseCodeDialog {
+
+ private static final String DISPLAY_MODEL_UID = ":DISPLAY_MODEL"; //$NON-NLS-1$
+ private static final String DISPLAY_PACKAGES_UID = ":DISPLAY_PACKAGES"; //$NON-NLS-1$
+ private static final String DISPLAY_CU_UID = ":DISPLAY_CU"; //$NON-NLS-1$
+ private Button displayModelCheckbox;
+ private Button displayPackagesCheckbox;
+ private Button displayCUCheckbox;
+
+ private boolean displayModel;
+ private boolean displayPackages;
+ private boolean displayCU;
+
+ public DndReverseCodeDialog(Shell parentShell, String modelUid, String initialValue, List<String> searchPathsInitialValues) {
+ super(parentShell, modelUid, initialValue, searchPathsInitialValues);
+
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ // Create button to display or not the model
+ displayModelCheckbox = new Button(composite, SWT.CHECK);
+ displayModelCheckbox.setText("Display reversed Model into diagram");
+ displayModelCheckbox.setSelection(settings.getBoolean(MODEL_UID + DISPLAY_MODEL_UID));
+
+ // Create button to display or not package
+ displayPackagesCheckbox = new Button(composite, SWT.CHECK);
+ displayPackagesCheckbox.setText("Display reversed UML::packages into diagram");
+ displayPackagesCheckbox.setSelection(settings.getBoolean(MODEL_UID + DISPLAY_PACKAGES_UID));
+
+ // Create button to display or not CompilationUnit
+ displayCUCheckbox = new Button(composite, SWT.CHECK);
+ displayCUCheckbox.setText("Display UML::classes, UML::interfaces, UML::enumerations into diagram");
+ displayCUCheckbox.setSelection(settings.getBoolean(MODEL_UID + DISPLAY_CU_UID));
+
+ return composite;
+ }
+
+ @Override
+ protected void okPressed() {
+ // add selection into fields to prevent dialog disposing
+ displayModel = displayModelCheckbox.getSelection();
+ displayPackages = displayPackagesCheckbox.getSelection();
+ displayCU = displayCUCheckbox.getSelection();
+
+ // save selection into settings
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ settings.put(MODEL_UID + DISPLAY_MODEL_UID, displayModel);
+ settings.put(MODEL_UID + DISPLAY_PACKAGES_UID, displayPackages);
+ settings.put(MODEL_UID + DISPLAY_CU_UID, displayCU);
+ super.okPressed();
+ }
+
+ /**
+ *
+ * @return true if displayModelCheckbox is checked
+ */
+ public boolean displayModel() {
+ return displayModel;
+ }
+
+ /**
+ *
+ * @return true if displayPackagesCheckbox is checked
+ */
+ public boolean displayPackages() {
+ return displayPackages;
+ }
+
+ /**
+ *
+ * @return true if displayCUCheckbox is checked
+ */
+ public boolean displayCU() {
+ return displayCU;
+ }
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java
new file mode 100644
index 00000000000..f8c4fd0a58e
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java
@@ -0,0 +1,332 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui.dialog;
+
+import java.util.List;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author dumoulin
+ *
+ */
+public class InputListDialog {
+
+ /** Message to be show */
+ private String message;
+
+ /** Message to be show */
+ private String tooltips;
+
+ /** List of fields to show */
+ private List<String> fieldList;
+
+ /**
+ * Input text widget.
+ */
+ private Text addToListText;
+
+ private org.eclipse.swt.widgets.List listWidget;
+
+ /**
+ * Constructor.
+ *
+ * @param msg
+ * @param list
+ */
+ public InputListDialog(String msg, List<String> list) {
+ this.message = msg;
+ this.fieldList = list;
+ }
+
+
+
+ /**
+ * @param tooltips
+ * the tooltips to set
+ */
+ public void setTooltips(String tooltips) {
+ this.tooltips = tooltips;
+ }
+
+
+ /**
+ * Return the selected list.
+ *
+ * @return
+ */
+ public String[] getList() {
+ return listWidget.getItems();
+ }
+
+ /**
+ *
+ * @param parent
+ * @return
+ */
+ public Control createDialogArea(Composite parent) {
+ // create composite
+ Composite composite = parent;
+ // create message
+ if (message != null) {
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText(message);
+ GridData data = new GridData(GridData.GRAB_HORIZONTAL
+ /* | GridData.GRAB_VERTICAL */| GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_CENTER);
+ // data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+ setToolTip(label, tooltips);
+ ;
+ }
+
+ // button
+ createButtonBar(composite);
+
+ // list
+ listWidget = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE);
+
+ GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
+
+ listData.heightHint = 100;
+ listWidget.setLayoutData(listData);
+ setToolTip(listWidget, tooltips);
+ if (fieldList != null) {
+ for (String item : fieldList) {
+ listWidget.add(item);
+ }
+ }
+
+ // applyDialogFont(composite);
+ return composite;
+ }
+
+
+ /**
+ * Set the tooltips if not null.
+ *
+ * @param parent
+ * @param tooltips
+ */
+ private void setToolTip(Control parent, String tooltips) {
+ if (tooltips != null) {
+ parent.setToolTipText(tooltips);
+ }
+ }
+
+ /**
+ * Returns the style bits that should be used for the input text field.
+ * Defaults to a single line entry. Subclasses may override.
+ *
+ * @return the integer style bits that should be used when creating the
+ * input text
+ *
+ * @since 3.4
+ */
+ protected int getInputTextStyle() {
+ return SWT.SINGLE | SWT.BORDER;
+ }
+
+ /**
+ * Creates and returns the contents of this dialog's button bar.
+ * <p>
+ * The <code>Dialog</code> implementation of this framework method lays out a button bar and calls the <code>createButtonsForButtonBar</code> framework method to populate it. Subclasses may override.
+ * </p>
+ * <p>
+ * The returned control's layout data must be an instance of <code>GridData</code>.
+ * </p>
+ *
+ * @param parent
+ * the parent composite to contain the button bar
+ * @return the button bar control
+ */
+ protected Control createButtonBar(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ // create a layout with spacing and margins appropriate for the font
+ // size.
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 0; // this is incremented by createButton
+ layout.makeColumnsEqualWidth = false;
+ // layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ // layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ // layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ // layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ composite.setLayout(layout);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL
+ | GridData.VERTICAL_ALIGN_CENTER);
+ composite.setLayoutData(data);
+ composite.setFont(parent.getFont());
+
+ // Add the buttons to the button bar.
+ createButtonsForButtonBar(composite);
+ return composite;
+ }
+
+ /**
+ * Adds buttons to this dialog's button bar.
+ * <p>
+ * The <code>Dialog</code> implementation of this framework method adds standard ok and cancel buttons using the <code>createButton</code> framework method. These standard buttons will be accessible from <code>getCancelButton</code>, and
+ * <code>getOKButton</code>. Subclasses may override.
+ * </p>
+ *
+ * @param parent
+ * the button bar composite
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ // create OK and Cancel buttons by default
+ // Create input text
+ // input text
+ ((GridLayout) parent.getLayout()).numColumns++;
+ addToListText = new Text(parent, getInputTextStyle());
+ setButtonLayoutData(addToListText);
+ addToListText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
+ | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
+
+ // Create a Button
+ ((GridLayout) parent.getLayout()).numColumns++;
+ Button button = new Button(parent, SWT.PUSH);
+ button.setText("add");
+ button.setFont(JFaceResources.getDialogFont());
+ button.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ addPressed();
+ }
+ });
+ setButtonLayoutData(button);
+
+ // remove
+ ((GridLayout) parent.getLayout()).numColumns++;
+ button = new Button(parent, SWT.PUSH);
+ button.setText("-");
+ button.setFont(JFaceResources.getDialogFont());
+ button.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ removedPressed();
+ }
+ });
+ setButtonLayoutData(button);
+
+ // up
+ ((GridLayout) parent.getLayout()).numColumns++;
+ button = new Button(parent, SWT.PUSH);
+ button.setText("^");
+ button.setFont(JFaceResources.getDialogFont());
+ button.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ upPressed();
+ }
+ });
+ setButtonLayoutData(button);
+
+ // down
+ ((GridLayout) parent.getLayout()).numColumns++;
+ button = new Button(parent, SWT.PUSH);
+ button.setText("v");
+ button.setFont(JFaceResources.getDialogFont());
+ button.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ downPressed();
+ }
+ });
+ setButtonLayoutData(button);
+
+
+ }
+
+ /**
+ * Called when add button is pressed.
+ */
+ protected void addPressed() {
+ System.out.println("add pressed " + addToListText.getText());
+ String msg = addToListText.getText();
+ if (msg.length() == 0) {
+ return;
+ }
+
+ msg.trim();
+ listWidget.add(msg);
+ // listWidget.pack(true);
+ }
+
+ protected void upPressed() {
+ System.out.println("up pressed");
+ int selectionIndex = listWidget.getSelectionIndex();
+
+ if (selectionIndex > 0) {
+ swapItems(selectionIndex - 1, selectionIndex);
+ listWidget.setSelection(selectionIndex - 1);
+ }
+ }
+
+ /**
+ * Swap items in the list
+ *
+ * @param down
+ * @param up
+ */
+ private void swapItems(int down, int up) {
+ String tmp = listWidget.getItem(down);
+ listWidget.setItem(down, listWidget.getItem(up));
+ listWidget.setItem(up, tmp);
+ }
+
+ protected void downPressed() {
+ System.out.println("down pressed");
+ int selectionIndex = listWidget.getSelectionIndex();
+
+ if (selectionIndex < listWidget.getItemCount() - 1) {
+ swapItems(selectionIndex, selectionIndex + 1);
+ listWidget.setSelection(selectionIndex + 1);
+ }
+ }
+
+
+ protected void removedPressed() {
+ System.out.println("removed pressed");
+ int selectionIndex = listWidget.getSelectionIndex();
+
+ String old = listWidget.getItem(selectionIndex);
+ listWidget.remove(selectionIndex);
+ addToListText.setText(old);
+ }
+
+
+ /**
+ * Set the layout data of the button to a GridData with appropriate heights
+ * and widths.
+ *
+ * @param button
+ */
+ protected void setButtonLayoutData(Control button) {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ // int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
+ Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ // data.widthHint = Math.max(widthHint, minSize.x);
+ data.widthHint = minSize.x;
+ button.setLayoutData(data);
+ }
+
+
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java
new file mode 100644
index 00000000000..d21b20de12d
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java
@@ -0,0 +1,281 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui.dialog;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javagen.umlparser.CreationPackageCatalog;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.papyrus.java.reverse.ui.Activator;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author dumoulin
+ *
+ */
+public class ReverseCodeDialog extends InputDialog {
+
+ /** Internal dialog to show list of searchpaths */
+ private InputListDialog listDialog;
+
+ /** Internal dialog to show list of creation paths */
+ private InputListDialog creationPathsDialog;
+
+ /** Returned searchpaths */
+ private String[] searchPath;
+ /** creationPaths read by the list. One line pattern by element */
+ private String[] creationPaths;
+ /** splitted creationPaths. pattern lines are splitted in small path */
+ private List<String> splittedCreationPaths;
+
+ private String SEARCHPATHS_UID = ":searchpaths";
+ private String CREATIONPATHS_UID = ":creationpaths";
+ private static String DEFAULT_PACKAGE_NAME_UID = ":defaultpackagename";
+ protected String MODEL_UID = "nomodeluid";
+
+ private static String textMsg = "Default creation package.";
+ @SuppressWarnings("unused")
+ private static String creationPackageTooltips = "The default creation package is used when no matching creation package are found.";
+
+
+ private static String dialogTitle = "Reverse Code";
+
+ private static String listMsg = "search paths - list of model packages used to search for already existing classes (ex: p1/p2)";
+ private static String listTooltips = "search paths - list of model packages used to search for already existing classes (ex: p1/p2)";
+
+ private static String creationPathMsg = "creation paths \n"
+ + "pattern: includePath ; excludePath ; destination (use ';' as separator)\n";
+
+ private static String creationPathTooltips = "creation paths - list of path describing the models inside which reversed classes will be generated.\n"
+ + "pattern: includeJavaPackage ; excludeJavaPackage ; destinationPath (use ';' as separator)\n"
+ + "includeJavaPackage: the java package that should be mapped. Can contain a '*'.\n"
+ + "excludeJavaPackage: the java package that should be excluded. Can contain a '*'.\n"
+ + "destinationPath: the uml model inside which matching java packages will be created. Can contain a '*'.\n"
+ + "if destinationPath contains a '*', it will be replaced by the partname found at the place of '*'\n"
+ + "in the includeJavaPackage\n"
+ + "\n"
+ + "ex: eclipse.org.* ; eclipse.org.papyrus ; *";
+
+
+ /**
+ * @param parentShell
+ * @param dialogTitle
+ * @param dialogMessage
+ * @param initialValue
+ * @param validator
+ */
+ public ReverseCodeDialog(Shell parentShell, String modelUid, String initialValue, List<String> searchPathsInitialValues) {
+ super(parentShell, dialogTitle, textMsg, getInitialValue(modelUid, initialValue), null);
+ // TODO Auto-generated constructor stub
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ MODEL_UID = modelUid;
+
+ // Look for generationPackageName if none is provided.
+ // if(initialValue == null)
+ // {
+ // String generationPackageName = settings.get("generationPackageName");
+ // getText().setText(generationPackageName);
+ //
+ // }
+ // Look for saved searchpaths if none is provided.
+ if (searchPathsInitialValues == null) {
+ String[] savedSearchPath = settings.getArray(MODEL_UID + SEARCHPATHS_UID);
+ if (savedSearchPath != null) {
+ searchPathsInitialValues = Arrays.asList(savedSearchPath);
+ } else
+ {
+ searchPathsInitialValues = CreationPackageCatalog.getDefaultSearchPath();
+ }
+ }
+
+ // Look for saved creationPaths if none is provided.
+ if (creationPaths == null) {
+ String[] savedSearchPath = settings.getArray(MODEL_UID + CREATIONPATHS_UID);
+ if (savedSearchPath != null) {
+ creationPaths = savedSearchPath;
+ } else {
+ creationPaths = CreationPackageCatalog.getDefaultPackageCreationPatterns(" ; ");
+ }
+ }
+
+ listDialog = new InputListDialog(listMsg, searchPathsInitialValues);
+ listDialog.setTooltips(listTooltips);
+ creationPathsDialog = new InputListDialog(creationPathMsg, Arrays.asList(creationPaths));
+ creationPathsDialog.setTooltips(creationPathTooltips);
+ }
+
+ /**
+ *
+ * @param modelUid
+ * @param initialValue
+ * @return
+ */
+ private static String getInitialValue(String modelUid, String initialValue) {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ // Look for generationPackageName if none is provided.
+ if (initialValue == null) {
+ // String generationPackageName = settings.get(MODEL_UID + SEARCHPATH_UID);
+ String generationPackageName = settings.get(modelUid + DEFAULT_PACKAGE_NAME_UID);
+ return generationPackageName;
+
+ }
+ return initialValue;
+ }
+
+ /**
+ * Allows resizing.
+ */
+ @Override
+ protected boolean isResizable() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ /**
+ * Get the returned searchpaths.
+ *
+ * @return
+ */
+ public String[] getSearchPath() {
+ return searchPath;
+ }
+
+ /**
+ * Get the returned creationPaths, one pattern for each entry, separated by ';'.
+ *
+ * @return
+ */
+ public List<String> getCreationPaths() {
+
+ return splittedCreationPaths;
+ }
+
+
+ /**
+ * Create additional list of searchpaths.
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // create composite
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ listDialog.createDialogArea(composite);
+ creationPathsDialog.createDialogArea(composite);
+ return composite;
+ }
+
+ /**
+ * Save the searchpath after the button is pressed.
+ */
+ @Override
+ protected void okPressed() {
+ // Save the list before the control is disposed
+ searchPath = listDialog.getList();
+ creationPaths = creationPathsDialog.getList();
+ String defaultCreationPath = getValue();
+ if (defaultCreationPath == null || defaultCreationPath.length() == 0) {
+ defaultCreationPath = CreationPackageCatalog.getDefaultCreationPath();
+ }
+
+ // Check inputs
+ try {
+ // Check paths
+ splittedCreationPaths = computeCreationPaths(creationPaths);
+ CreationPackageCatalog.validateCreationPath(splittedCreationPaths);
+ // add default searchPaths
+ searchPath = addDefaultSearchPaths(Arrays.asList(searchPath), splittedCreationPaths).toArray(new String[0]);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ showError(e.getMessage());
+ return;
+ }
+
+
+ // save values
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ settings.put(MODEL_UID + SEARCHPATHS_UID, searchPath);
+ settings.put(MODEL_UID + CREATIONPATHS_UID, creationPaths);
+ settings.put(MODEL_UID + DEFAULT_PACKAGE_NAME_UID, getValue());
+
+
+ super.okPressed();
+ }
+
+
+ /**
+ * Add the defaultSearchPath extracted from the splittedCreationPath to the searchPath.
+ *
+ * @param splittedCreationPaths2
+ */
+ private List<String> addDefaultSearchPaths(List<String> searchPath, List<String> splittedCreationPaths) {
+
+
+ List<String> result = new ArrayList<String>(searchPath.size() + splittedCreationPaths.size());
+ result.addAll(searchPath);
+
+ List<String> additionalPaths = CreationPackageCatalog.extractCreationPaths(splittedCreationPaths.toArray(new String[0]));
+ for (String toAdd : additionalPaths) {
+ if (!result.contains(toAdd)) {
+ result.add(toAdd);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Show an error message
+ *
+ * @param message
+ */
+ private void showError(String message) {
+ System.err.println("Error: " + message);
+
+ }
+
+
+ /**
+ * Compute and check the creationsPaths
+ *
+ * @param creationPaths
+ * An array with one creationPattern by element
+ * @return An array with one path by elements
+ * @throws Exception
+ */
+ private List<String> computeCreationPaths(String[] creationPaths) throws Exception {
+
+ List<String> result = new ArrayList<String>();
+
+ // Iterate line by line
+ // For each line, separate the 3 patterns
+ // If a pattern is empty, put a null
+ for (String line : creationPaths) {
+ String[] eles = line.split(";");
+ if (eles.length != 3) {
+ throw new Exception("A line must contains 3 pattern separated by ';' :" + line);
+ }
+ for (String ele : eles)
+ {
+ ele = ele.trim();
+ if (ele.length() == 0) {
+ ele = null;
+ }
+ // add ele
+ result.add(ele);
+ }
+ }
+ return result;
+ }
+
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java
new file mode 100755
index 00000000000..9fdb9fb8505
--- /dev/null
+++ b/extraplugins/qompass/codegen/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.DndReverseCodeHandler;
+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() {
+ DndReverseCodeHandler reverse = new DndReverseCodeHandler();
+ 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/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java
new file mode 100755
index 00000000000..a302a6d3418
--- /dev/null
+++ b/extraplugins/qompass/codegen/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/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/Messages.java
new file mode 100644
index 00000000000..3253c5eb40a
--- /dev/null
+++ b/extraplugins/qompass/codegen/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/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties
new file mode 100644
index 00000000000..753937a59b2
--- /dev/null
+++ b/extraplugins/qompass/codegen/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
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/handlers/CreateAssociationFromPropertyHandler.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/handlers/CreateAssociationFromPropertyHandler.java
new file mode 100644
index 00000000000..848f5ea6cbc
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/handlers/CreateAssociationFromPropertyHandler.java
@@ -0,0 +1,286 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.java.reverse.utils.TypeOperationsEnhanced;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+
+/**
+ * An handler getting the selected element and reporting them in console.
+ *
+ * @author Cedric dumoulin
+ *
+ */
+public class CreateAssociationFromPropertyHandler extends AbstractHandler implements IHandler {
+
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * @param event
+ * @return
+ * @throws ExecutionException
+ *
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ List<Object> objects = lookupSelectedElements();
+ List<Property> selectedProperties = getAllSelectionOfType(event, Property.class);
+ if (objects == null) {
+
+ showErrorDialog(event, "No object selected", "Can't create association. Please select a Property First.");
+ return null;
+ }
+
+ // Try creation
+ try {
+ doExecute(selectedProperties);
+ } catch (ServiceException e) {
+ showErrorDialog(event, "Can't get TransactionalEditingDomain", e.getMessage());
+ e.printStackTrace();
+ } catch (Exception e) {
+ showErrorDialog(event, "Can't Create Association", e.getMessage());
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /**
+ * Get all selected element of the specified type.
+ *
+ * @param expectedType
+ * @return
+ * @throws ExecutionException
+ */
+ private <T> List<T> getAllSelectionOfType(ExecutionEvent event, Class<T> expectedType) throws ExecutionException {
+
+ ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
+ // IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ // ISelection selection = page.getSelection();
+ System.out.println("check " + selection);
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ return getAllElementOfType(structuredSelection.toList(), expectedType);
+ }
+ else if (selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection) selection;
+ return getAllElementOfType(treeSelection.toList(), expectedType);
+
+ }
+ return null;
+ }
+
+ /**
+ * Filter the list, and only retain objects that can be adapted to the specified type
+ *
+ * @param objects
+ * @param class1
+ * @return
+ */
+ private <T> List<T> getAllElementOfType(List<Object> list, Class<T> expectedClassType) {
+
+ List<T> res = new ArrayList<T>();
+
+ for (Object cur : list) {
+
+ T adapted = adapt(cur, expectedClassType);
+ if (adapted != null) {
+ res.add(adapted);
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Adapt the specified object to the requested type, if possible.
+ * Return null if the object can't be adapted.
+ *
+ * @param object
+ * @param expectedClassType
+ * @return The adapted object, or null.
+ */
+ private <T> T adapt(Object object, Class<T> expectedClassType) {
+
+ if (object instanceof IAdaptable) {
+ @SuppressWarnings("unchecked")
+ T ele = (T) ((IAdaptable) object).getAdapter(expectedClassType);
+ if (ele != null) {
+ return ele;
+ }
+ // Try as EObject if the expectedClasType is sub-type of EObject.
+ if (EObject.class.isAssignableFrom(expectedClassType)) {
+ // to EObject
+ EObject eobject = (EObject) ((IAdaptable) object).getAdapter(EObject.class);
+
+ if (eobject != null && expectedClassType.isInstance(eobject)) {
+ return (T) eobject;
+ }
+ }
+ }
+
+ // Try global mechanism
+ {
+ @SuppressWarnings("unchecked")
+ T ele = (T) Platform.getAdapterManager().getAdapter(object, expectedClassType);
+ if (ele != null) {
+ return ele;
+ }
+ // Try as EObject if the expectedClasType is sub-type of EObject.
+ if (EObject.class.isAssignableFrom(expectedClassType)) {
+ // to EObject
+ EObject eobject = (EObject) Platform.getAdapterManager().getAdapter(object, EObject.class);
+
+ if (eobject != null && expectedClassType.isInstance(eobject)) {
+
+ return (T) eobject;
+ }
+ }
+ }
+ // Can't be adapted
+ return null;
+
+ }
+
+ /**
+ *
+ * @param event
+ * @param errorMessage
+ * @throws ExecutionException
+ */
+ private void showErrorDialog(ExecutionEvent event, String title, String errorMessage) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ MessageDialog.openError(
+ window.getShell(),
+ title,
+ errorMessage);
+ }
+
+
+ /**
+ * Get the name used in the {@link RecordingCommand}. This name will be visible in
+ * undo/redo.
+ *
+ * @return The command name to show.
+ */
+ public String getCommandName() {
+ return "Create Association";
+ }
+
+ /**
+ * Do the execution of the command.
+ *
+ * @param objects
+ * List of object to generate Java code from.
+ * @throws ServiceException
+ */
+ protected void doExecute(final List<?> objects) throws ServiceException {
+
+ // Execute the reverse with provided paramters
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ RecordingCommand command = new RecordingCommand(editingDomain, getCommandName()) {
+
+ @Override
+ protected void doExecute() {
+ System.out.println(" Selections:");
+
+ for (Object obj : objects) {
+
+ System.out.println("found '" + obj + "'.");
+ createAssociationFromProperty((Property) obj);
+ }
+ }
+
+ };
+
+ editingDomain.getCommandStack().execute(command);
+
+
+ }
+
+
+ /**
+ * Create an association from the specified Property. The association is created
+ * in the property's nearest package.
+ *
+ * @param p
+ * The property to use to create an association.
+ */
+ protected void createAssociationFromProperty(Property p) {
+
+ Element owner = p.getOwner();
+
+ if (owner instanceof Type) {
+
+ Type classOwner = (Type) owner;
+
+ // Compute other end name
+ String name = classOwner.getName();
+ String newname = name.substring(0, 1).toLowerCase() + name.substring(1);
+ // Create
+ TypeOperationsEnhanced.createAssociationFromProperty(p, true, AggregationKind.COMPOSITE_LITERAL,
+ false, AggregationKind.NONE_LITERAL, newname, 0, 1);
+ }
+ }
+
+ /**
+ * Lookup selected objects in UI.
+ *
+ * @return
+ */
+ private List<Object> lookupSelectedElements() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+ System.out.println("check " + selection);
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ return structuredSelection.toList();
+ }
+ else if (selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection) selection;
+ return treeSelection.toList();
+
+ }
+ return null;
+ }
+
+ /**
+ * Get the main editing doamin.
+ *
+ * @return
+ * @throws ServiceException
+ */
+ protected TransactionalEditingDomain getEditingDomain() throws ServiceException {
+ return ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties
new file mode 100644
index 00000000000..a754ab7df2a
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties
@@ -0,0 +1,2 @@
+ReverseCodeHandler_NoModelError_Message=No model selected for Reverse. Please open a model where you want to add the reverse result.
+ReverseCodeHandler_NoModelError_Title=No model selected

Back to the top