Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcdumoulin2010-01-27 21:28:19 +0000
committercdumoulin2010-01-27 21:28:19 +0000
commit02b2d3576da18dee818ee2275384edd451f64345 (patch)
treef31f49e2ab9a6cc4b120d13e20b748c136c600ab /extraplugins/java
parent2022a43d37438d32a37769d7d75717a765f8f3e8 (diff)
downloadorg.eclipse.papyrus-02b2d3576da18dee818ee2275384edd451f64345.tar.gz
org.eclipse.papyrus-02b2d3576da18dee818ee2275384edd451f64345.tar.xz
org.eclipse.papyrus-02b2d3576da18dee818ee2275384edd451f64345.zip
NEW - bug 300048: [General] Move extra plugins in more appropriate directory
https://bugs.eclipse.org/bugs/show_bug.cgi?id=300048 Move java plugins
Diffstat (limited to 'extraplugins/java')
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.classpath7
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.project28
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF17
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/build.properties6
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/icons/javaReverse.gifbin0 -> 152 bytes
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml47
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java52
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java118
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java194
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java304
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java121
11 files changed, 894 insertions, 0 deletions
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.classpath b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.classpath
new file mode 100644
index 00000000000..16d067f284a
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.project b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.project
new file mode 100644
index 00000000000..6456ba27df1
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.java.reverse.ui</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/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..3694420376b
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Ui Plug-in
+Bundle-SymbolicName: org.eclipse.papyrus.java.reverse.ui;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.java.reverse.ui.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.expressions,
+ org.eclipse.emf.transaction;bundle-version="1.2.0",
+ org.eclipse.gef;bundle-version="3.4.0",
+ org.eclipse.jdt;bundle-version="3.4.0",
+ org.eclipse.jdt.core;bundle-version="3.4.0",
+ org.eclipse.papyrus.core,
+ org.eclipse.papyrus.java.reverse;bundle-version="0.7.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/build.properties b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/build.properties
new file mode 100644
index 00000000000..285b8bf47b6
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/icons/javaReverse.gif b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/icons/javaReverse.gif
new file mode 100644
index 00000000000..68d40f7e2d5
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/icons/javaReverse.gif
Binary files differ
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml
new file mode 100644
index 00000000000..eba5c9f7a7d
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.java.reverse.ui.ReverseCodeHandler"
+ commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="toolbar:org.eclipse.ui.main.toolbar">
+ <toolbar
+ id="org.eclipse.papyrus.java.ui.toolbar">
+ <command
+ commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand"
+ icon="icons/javaReverse.gif"
+ label="Java Reverse"
+ style="push"
+ tooltip="Reverse Java code into current model">
+ </command>
+ </toolbar>
+ </menuContribution>
+ <menuContribution
+ locationURI="menu:org.eclipse.papyrus.ui.menu">
+ <menu
+ id="org.eclipse.papyrus.java.ui.menu"
+ label="java">
+ <command
+ commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand"
+ style="push">
+ </command>
+ </menu>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ description="Reverse Java code into current model"
+ id="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand"
+ name="Java Reverse">
+ </command>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java
new file mode 100644
index 00000000000..1a4ce66c08a
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Activator.java
@@ -0,0 +1,52 @@
+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)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java
new file mode 100644
index 00000000000..f89b28f4417
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/JavaCodeReverse.java
@@ -0,0 +1,118 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui;
+
+import java.util.List;
+
+import javagen.umlparser.CompilationUnitAnalyser;
+import japa.parser.JavaParser;
+import japa.parser.ParseException;
+import japa.parser.ast.CompilationUnit;
+
+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.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);
+ }
+
+
+}
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java
new file mode 100644
index 00000000000..8f87ead18d1
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java
@@ -0,0 +1,194 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui;
+
+import japa.parser.ParseException;
+
+import java.util.Arrays;
+import java.util.Iterator;
+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.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.java.reverse.ui.dialog.ReverseCodeDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Package;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class ReverseCodeHandler extends AbstractHandler implements IHandler {
+
+ private static String DefaultGenerationPackageName = "generated";
+
+ /**
+ * Method called when button is pressed.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+
+
+ final Resource umlResource = getUmlResource();
+ // String rootModelName = getRootModelName(umlResource);
+
+ // Get reverse parameters from a dialog
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getShell();
+ // ReverseCodeDialog dialog = new ReverseCodeDialog(shell, DefaultGenerationPackageName, Arrays.asList("generated") );
+ ReverseCodeDialog dialog = new ReverseCodeDialog(shell, null, null);
+
+ int res = dialog.open();
+ // System.out.println("dialog result =" + res);
+ if(res == dialog.CANCEL) {
+ System.out.println("Canceled by user.");
+ return null;
+ }
+ // Get returned name
+ String generationPackageName = dialog.getValue();
+ if(generationPackageName == null || generationPackageName.length() == 0) {
+ generationPackageName = DefaultGenerationPackageName;
+ }
+
+ // Adjust name
+ // generationPackageName = rootModelName + "/" + generationPackageName;
+ // Create searchpaths. Add the rootmodelname as prefix.
+ final List<String> searchPaths = Arrays.asList(dialog.getSearchPath());
+ // final List<String> searchPaths = new ArrayList<String>();
+ // for(String path : dialog.getSearchPath())
+ // {
+ // searchPaths.add( rootModelName + "/" + path);
+ // }
+
+ // Create revers object
+
+
+ // Execute the reverse with provided paramters
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ final String pname = generationPackageName;
+ RecordingCommand command = new RecordingCommand(editingDomain, "Reverse Java Code") {
+
+ @Override
+ protected void doExecute() {
+ executeCodeReverse(umlResource, pname, searchPaths);
+ }
+
+ };
+
+ editingDomain.getCommandStack().execute(command);
+
+
+ return null;
+ }
+
+ /**
+ * Real Implementation of the command.
+ *
+ * @param generationPackageName
+ * @param searchPaths
+ */
+ private void executeCodeReverse(Resource umlResource, String generationPackageName, List<String> searchPaths) {
+ System.out.println("executeCodeReverse()");
+ JavaCodeReverse codeReverse = new JavaCodeReverse(getRootPackage(umlResource), generationPackageName, searchPaths);
+ // Get current selection
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+
+ TreeSelection treeSelection = (TreeSelection)selection;
+ // String filename = treeSelection.
+ 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 {
+ obj = u.getCorrespondingResource();
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ // System.out.println("obj=" + obj.getClass());
+ if(obj instanceof IResource) {
+ try {
+ codeReverse.reverseResource((IResource)obj);
+ } catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ }
+
+
+ /**
+ * Get the uml resource used by the model.
+ *
+ * @return
+ */
+ private Resource getUmlResource() {
+ Resource umlResource = EditorUtils.getDiResourceSet().getModelResource();
+ return umlResource;
+ }
+
+ /**
+ * Get the name of the root model.
+ *
+ * @return
+ */
+ private 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
+ */
+ protected TransactionalEditingDomain getEditingDomain() {
+ return EditorUtils.getTransactionalEditingDomain();
+ }
+
+}
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java
new file mode 100644
index 00000000000..807b77d6330
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/InputListDialog.java
@@ -0,0 +1,304 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui.dialog;
+
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+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;
+import org.w3c.dom.ls.LSInput;
+
+/**
+ * @author dumoulin
+ *
+ */
+public class InputListDialog {
+
+ /** Message to be show */
+ private String message;
+
+ /** 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;
+ }
+
+ /**
+ * 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());
+ }
+
+ // 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);
+ if(fieldList != null)
+ for(String item : fieldList) {
+ listWidget.add(item);
+ }
+
+ // applyDialogFont(composite);
+ return composite;
+ }
+
+
+ /**
+ * 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() {
+
+ 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() {
+
+ 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() {
+
+ 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() {
+
+ 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/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java
new file mode 100644
index 00000000000..5a5366f46c5
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java
@@ -0,0 +1,121 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.java.reverse.ui.dialog;
+
+import java.util.Arrays;
+import java.util.List;
+
+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;
+
+ /** Returned searchpaths */
+ private String[] searchPath;
+
+ private static String textMsg = "Name of the package where reversed classes will be generated (ex: p1/p2)";
+
+ 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)";
+
+
+ /**
+ * @param parentShell
+ * @param dialogTitle
+ * @param dialogMessage
+ * @param initialValue
+ * @param validator
+ */
+ public ReverseCodeDialog(Shell parentShell, String initialValue, List<String> searchPathsInitialValues) {
+ super(parentShell, dialogTitle, textMsg, getInitialValue(initialValue), null);
+ // TODO Auto-generated constructor stub
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ // 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("searchpaths");
+ if(savedSearchPath != null)
+ searchPathsInitialValues = Arrays.asList(savedSearchPath);
+ }
+
+ listDialog = new InputListDialog(listMsg, searchPathsInitialValues);
+
+ }
+
+ private static String getInitialValue(String initialValue) {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ // Look for generationPackageName if none is provided.
+ if(initialValue == null) {
+ String generationPackageName = settings.get("generationPackageName");
+ 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;
+ }
+
+ /**
+ * Create additional list of searchpaths.
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // create composite
+ Composite composite = (Composite)super.createDialogArea(parent);
+
+ listDialog.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();
+ // save values
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ settings.put("searchpaths", searchPath);
+ settings.put("generationPackageName", getValue());
+
+ super.okPressed();
+ }
+}

Back to the top