diff options
author | Cedric Dumoulin | 2016-03-15 16:21:43 +0000 |
---|---|---|
committer | Cedric Dumoulin | 2016-03-17 10:06:54 +0000 |
commit | b31846ff391f55d1a0014a450ec8e9f485d7730a (patch) | |
tree | 9b97b8019fc3ed060756ada4def7d7774cfd6d6d | |
parent | 33d2e42a924931931af3737fff8db22c6b19017d (diff) | |
download | org.eclipse.papyrus-b31846ff391f55d1a0014a450ec8e9f485d7730a.tar.gz org.eclipse.papyrus-b31846ff391f55d1a0014a450ec8e9f485d7730a.tar.xz org.eclipse.papyrus-b31846ff391f55d1a0014a450ec8e9f485d7730a.zip |
Bug 441179: [java code reverse] Reverse plugin shall provide eclipse
preferences for search path & creation path values.
Merge manually gerrit review 31044
https://git.eclipse.org/r/#/c/31044/
11 files changed, 1107 insertions, 654 deletions
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF index 831105a95fd..1252ef20a54 100644 --- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/META-INF/MANIFEST.MF @@ -1,22 +1,23 @@ -Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui,
- org.eclipse.emf.transaction;bundle-version="1.2.0",
- org.eclipse.gef;bundle-version="3.4.0",
- org.eclipse.jdt.core;bundle-version="3.4.0",
- org.eclipse.papyrus.java.reverse;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.tools;bundle-version="1.2.0",
- org.eclipse.gmf.runtime.diagram.core,
- org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.emf.diagram.common;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.diagram.common;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.ui;bundle-version="1.2.0"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.2.0.qualifier
-Bundle-Localization: plugin
-Bundle-Name: %pluginName
-Bundle-Activator: org.eclipse.papyrus.java.reverse.ui.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.java.reverse.ui;singleton:=true
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Manifest-Version: 1.0 +Require-Bundle: org.eclipse.ui, + org.eclipse.emf.transaction;bundle-version="1.2.0", + org.eclipse.gef;bundle-version="3.4.0", + org.eclipse.jdt.core;bundle-version="3.4.0", + org.eclipse.papyrus.java.reverse;bundle-version="1.2.0", + org.eclipse.papyrus.infra.core;bundle-version="1.2.0", + org.eclipse.papyrus.uml.tools;bundle-version="1.2.0", + org.eclipse.gmf.runtime.diagram.core, + org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="1.2.0", + org.eclipse.jdt.ui, + org.eclipse.papyrus.infra.emf.diagram.common;bundle-version="1.2.0", + org.eclipse.papyrus.uml.diagram.common;bundle-version="1.2.0", + org.eclipse.papyrus.infra.ui;bundle-version="1.2.0" +Bundle-Vendor: %providerName +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.2.0.qualifier +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-Activator: org.eclipse.papyrus.java.reverse.ui.Activator +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.papyrus.java.reverse.ui;singleton:=true +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml index 6e744e206e8..3f9e8386914 100644 --- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/plugin.xml @@ -1,154 +1,169 @@ -<?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">
- <enabledWhen>
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.papyrus.infra.core.papyrusEditor">
- </equals>
- </with>
- </enabledWhen>
- </handler>
- <handler
- class="org.eclipse.papyrus.java.reverse.ui.handlers.CreateAssociationFromPropertyHandler"
- commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand">
- </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>
- <command
- commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand"
- icon="icons/associationFromProperty.gif"
- label="Create Association From Property"
- style="push">
- </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>
- <menu
- id="org.eclipse.papyrus.ui.menu.misc"
- label="Utils">
- <command
- commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand"
- icon="icons/associationFromProperty.gif"
- label="Create Association From Property"
- style="push">
- </command>
- </menu>
- </menuContribution>
- <menuContribution
- locationURI="popup:org.eclipse.sash.ui.folder">
- <menu
- id="org.eclipse.papyrus.java.ui.sash.menu"
- label="Java">
- <command
- commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand"
- style="push">
- </command>
- </menu>
- </menuContribution>
- <menuContribution
- locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup">
- <menu
- id="org.eclipse.papyrus.ui.popupmenu.modelexplorer.misc"
- label="Utils">
- <command
- commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand"
- icon="icons/associationFromProperty.gif"
- label="Create Association From Property"
- style="push">
- </command>
- </menu>
- </menuContribution>
- <menuContribution
- locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
- <menu
- id="org.eclipse.papyrus.ui.popupmenu.diagram.misc"
- label="Utils">
- <command
- commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand"
- icon="icons/associationFromProperty.gif"
- label="Create Association From Property"
- style="push">
- </command>
- </menu>
- </menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="popup:org.eclipse.ui.popup.any">
- <menu
- id="org.eclipse.papyrus.java.reverse.ui.javaMenu"
- label="Java">
- <command
- commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand"
- style="push">
- <visibleWhen
- checkEnabled="false">
- <with
- variable="activeMenuSelection">
- <iterate
- ifEmpty="false"
- operator="or">
- <adapt
- type="org.eclipse.jdt.core.IJavaElement">
- <and>
- <not>
- <adapt
- type="org.eclipse.jdt.core.IJavaProject">
- </adapt>
- </not>
- </and>
- </adapt>
- </iterate>
- </with>
- </visibleWhen>
- </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>
- <command
- description="Create a New association from the Property."
- id="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand"
- name="Create Association From Property">
- </command>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy">
- <strategy
- strategy="org.eclipse.papyrus.java.reverse.ui.dnd.DropReverseStrategy">
- </strategy>
- </extension>
-</plugin>
+<?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"> + <enabledWhen> + <with + variable="activeEditorId"> + <equals + value="org.eclipse.papyrus.infra.core.papyrusEditor"> + </equals> + </with> + </enabledWhen> + </handler> + <handler + class="org.eclipse.papyrus.java.reverse.ui.handlers.CreateAssociationFromPropertyHandler" + commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand"> + </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> + <command + commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand" + icon="icons/associationFromProperty.gif" + label="Create Association From Property" + style="push"> + </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> + <menu + id="org.eclipse.papyrus.ui.menu.misc" + label="Utils"> + <command + commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand" + icon="icons/associationFromProperty.gif" + label="Create Association From Property" + style="push"> + </command> + </menu> + </menuContribution> + <menuContribution + locationURI="popup:org.eclipse.sash.ui.folder"> + <menu + id="org.eclipse.papyrus.java.ui.sash.menu" + label="Java"> + <command + commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand" + style="push"> + </command> + </menu> + </menuContribution> + <menuContribution + locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup"> + <menu + id="org.eclipse.papyrus.ui.popupmenu.modelexplorer.misc" + label="Utils"> + <command + commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand" + icon="icons/associationFromProperty.gif" + label="Create Association From Property" + style="push"> + </command> + </menu> + </menuContribution> + <menuContribution + locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu"> + <menu + id="org.eclipse.papyrus.ui.popupmenu.diagram.misc" + label="Utils"> + <command + commandId="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand" + icon="icons/associationFromProperty.gif" + label="Create Association From Property" + style="push"> + </command> + </menu> + </menuContribution> + <menuContribution + allPopups="false" + locationURI="popup:org.eclipse.ui.popup.any"> + <menu + id="org.eclipse.papyrus.java.reverse.ui.javaMenu" + label="Java"> + <command + commandId="org.eclipse.papyrus.java.reverse.ui.reverseCodeCommand" + style="push"> + <visibleWhen + checkEnabled="false"> + <with + variable="activeMenuSelection"> + <iterate + ifEmpty="false" + operator="or"> + <adapt + type="org.eclipse.jdt.core.IJavaElement"> + <and> + <not> + <adapt + type="org.eclipse.jdt.core.IJavaProject"> + </adapt> + </not> + </and> + </adapt> + </iterate> + </with> + </visibleWhen> + </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> + <command + description="Create a New association from the Property." + id="org.eclipse.papyrus.java.reverse.ui.commands.CreateAssociationFromPropertyCommand" + name="Create Association From Property"> + </command> + </extension> + <extension + point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy"> + <strategy + strategy="org.eclipse.papyrus.java.reverse.ui.dnd.DropReverseStrategy"> + </strategy> + </extension> + <extension + point="org.eclipse.ui.preferencePages"> + <page + category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory" + class="org.eclipse.papyrus.java.reverse.ui.preference.PreferencePage" + id="org.eclipse.papyrus.java.reverse.ui.preference.PreferencePage" + name="Java Code Reverse"> + </page> + </extension> + <extension + point="org.eclipse.core.runtime.preferences"> + <initializer + class="org.eclipse.papyrus.java.reverse.ui.preference.PreferenceInitializer"> + </initializer> + </extension> +</plugin> 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 index 491ddc1c18a..4dca0015470 100644 --- 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 @@ -125,7 +125,7 @@ public class DndReverseCodeHandler extends ReverseCodeHandler { @Override protected ReverseCodeDialog getDialog(Shell shell, String modelUid) { - return new DndReverseCodeDialog(shell, modelUid, null, null); + return new DndReverseCodeDialog(shell, modelUid, getSelectedProjectName(), null); } /** 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 index 6bd5d992149..cf6b83a6033 100644 --- 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 @@ -1,196 +1,216 @@ -/**
- *
- */
-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.services.ServiceException;
-import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.ui.util.EditorUtils;
-import org.eclipse.papyrus.infra.ui.util.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();
- }
-
-}
+/** + * + */ +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.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor; +import org.eclipse.papyrus.infra.ui.util.EditorUtils; +import org.eclipse.papyrus.infra.ui.util.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.IWorkbenchPage; +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, getSelectedProjectName(), null); + } + + /** + * + * @return the name of the selected project into explorer + */ + protected String getSelectedProjectName() { + // Get current selection + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + final ISelection selection = page.getSelection(); + + TreeSelection treeSelection = (TreeSelection)selection; + IJavaElement selectionElement = (IJavaElement)treeSelection.getFirstElement(); + String name = selectionElement.getAncestor(IJavaProject.JAVA_PROJECT).getElementName(); + return name; + } + + /** + * 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/dialog/ReverseCodeDialog.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dialog/ReverseCodeDialog.java index d21b20de12d..43289f2953b 100644 --- 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 @@ -1,281 +1,340 @@ -/**
- *
- */
-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;
- }
-
-
-}
+/** + * + */ +package org.eclipse.papyrus.java.reverse.ui.dialog; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +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.papyrus.java.reverse.ui.preference.ReversePreference; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +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.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 final String STEREOTYPERADIO_UID = ":stereotypeRadioButton"; + private static final String PROJECTNAME_UID = ":projectName"; + + protected String MODEL_UID = "nomodeluid"; + + /** + * then name of the selected project + */ + private String projectName; + + 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 projectName + * @param validator + */ + public ReverseCodeDialog(Shell parentShell, String modelUid, String projectName, List<String> searchPathsInitialValues) { + super(parentShell, dialogTitle, textMsg, getInitialValue(modelUid, projectName), null); + // TODO Auto-generated constructor stub + IDialogSettings settings = Activator.getDefault().getDialogSettings(); + + MODEL_UID = modelUid; + this.projectName = projectName; + + // Look for generationPackageName if none is provided. + // if(initialValue == null) + // { + // String generationPackageName = settings.get("generationPackageName"); + // getText().setText(generationPackageName); + // + // } + + // Find default values for search path and creation path + ReversePreference preference = new ReversePreference(); + + if (searchPathsInitialValues == null) { + String[] savedSearchPath = settings.getArray( getRootSettingKey() + SEARCHPATHS_UID); + if(savedSearchPath != null) + searchPathsInitialValues = Arrays.asList(savedSearchPath); + else + { + searchPathsInitialValues = getDefaultSearchPath(preference); + } + } + + // Look for saved creationPaths if none is provided. + if (creationPaths == null) { + String[] savedSearchPath = settings.getArray( getRootSettingKey() + CREATIONPATHS_UID); + if(savedSearchPath != null) + creationPaths = savedSearchPath; + else + creationPaths = getDefaultCreationPath(preference); + } + + // Look for saved creationPaths if none is provided. + if(creationPaths == null ) { + String[] savedSearchPath = settings.getArray( getRootSettingKey() + 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); + } + + /** + * + * @return the root of the setting key + */ + private String getRootSettingKey() { + return MODEL_UID + projectName; + } + + /** + * + * @param preference + * the eclipse preferences + * @return default values of SearchPath from eclipse preferences + */ + private List<String> getDefaultSearchPath(ReversePreference preference) { + String[] defaultSearchPath = preference.getSearchPath(); + LinkedList<String> listSearchPath = new LinkedList<String>(); + for(String path : defaultSearchPath) { + listSearchPath.add(path); + } + return listSearchPath; + } + + /** + * + * @param preference + * the eclipse preferences + * @return default values of CreationPath from eclipse preferences + */ + private String[] getDefaultCreationPath(ReversePreference preference) { + String[] defaultCreationPath = preference.getCreationPath(); + return defaultCreationPath; + } + + /** + * + * @param modelUid + * @param projectName + * the name of the reversed project + * @return initialValue contained into setting, or <code>projectName</code> if it doesn't exists + */ + private static String getInitialValue(String modelUid, String projectName) { + IDialogSettings settings = Activator.getDefault().getDialogSettings(); + + // Look for generationPackageName + String generationPackageName = settings.get(modelUid + projectName + PROJECTNAME_UID); + if(generationPackageName != null) { + return generationPackageName; + + } + return projectName; + } + + /** + * 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(getRootSettingKey() + SEARCHPATHS_UID, searchPath); + settings.put(getRootSettingKey() + CREATIONPATHS_UID, creationPaths); + settings.put(getRootSettingKey() + PROJECTNAME_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/preference/CreationPathListEditor.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/CreationPathListEditor.java new file mode 100644 index 00000000000..979e042496d --- /dev/null +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/CreationPathListEditor.java @@ -0,0 +1,93 @@ +/***************************************************************************** + * 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.preference; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.preference.ListEditor; +import org.eclipse.swt.widgets.Composite; + +/** + * A ListEditor implementation. When user push "add" button, open a dialog box which can validate/invalidate the input value for Creation Path. <br> + * Used to add a Creation Path value into Eclipse preferences + * + * @author Jonathan Geoffroy + * + */ +public class CreationPathListEditor extends ListEditor { + + public static final String SPLIT_STRING = ":"; + + /** + * Constructor. + * + * @param name + * @param labelText + * @param parent + */ + public CreationPathListEditor(String name, String labelText, Composite parent) { + super(name, labelText, parent); + } + + @Override + protected String createList(String[] items) { + StringBuffer str = new StringBuffer(); + for(String item : items) + str.append(item + SPLIT_STRING); + return str.toString(); + } + + @Override + protected String getNewInputObject() { + InputDialog dialog = new InputDialog(getShell(), "add creation path", "add creation path", "", new CreationPathValidator()); + dialog.open(); + + // If user clicked on "cancel" button, return null to NOT add empty value + if(dialog.getReturnCode() == InputDialog.CANCEL) { + return null; + } + return dialog.getValue(); + } + + @Override + protected String[] parseString(String stringList) { + return stringList.split(SPLIT_STRING); + } + + /** + * Validator for creation path value + * + * @author Jonathan Geoffroy + * + */ + private class CreationPathValidator implements IInputValidator { + + @Override + /** + * Validate the input value if it contains 3 parts, separated by ';' character + * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String) + * + * @param newText + * @return + */ + public String isValid(String newText) { + String[] splittedText = newText.split(";"); + if(! (splittedText.length == 3 || (splittedText.length == 2 && newText.charAt(newText.length() - 1) == ';'))) { + return "pattern: includePath ; excludePath ; destination (use ';' as separator)"; + } + return null; + } + + } +} diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferenceConstants.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferenceConstants.java new file mode 100644 index 00000000000..7340837ae0b --- /dev/null +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferenceConstants.java @@ -0,0 +1,29 @@ +/***************************************************************************** + * 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.preference; + +/** + * Provide constant identifiers for reverse eclipse preferences. + * + * @author Jonathan Geoffroy + * + */ +public class PreferenceConstants { + + public static final String P_PREFERENCE_ID = "org.eclipse.papyrus.java.reverse.ui.preference.PreferencePage"; + + public static final String P_SEARCH_PATH = P_PREFERENCE_ID + "searchPath"; + + public static final String P_CREATION_PATH = P_PREFERENCE_ID + "creationPath"; +} diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferenceInitializer.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferenceInitializer.java new file mode 100644 index 00000000000..5cd34e0399e --- /dev/null +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferenceInitializer.java @@ -0,0 +1,39 @@ +/***************************************************************************** + * 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.preference; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.java.reverse.ui.Activator; + +/** + * Initialize reverse eclipse preference by default values. + * + * @author Jonathan Geoffroy + * + */ +public class PreferenceInitializer extends AbstractPreferenceInitializer { + + public PreferenceInitializer() { + // TODO Auto-generated constructor stub + } + + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + store.setDefault(PreferenceConstants.P_SEARCH_PATH, "java;*;osgi.*;datatype"); + store.setDefault(PreferenceConstants.P_CREATION_PATH, "java.* ; ; java" + CreationPathListEditor.SPLIT_STRING + "org.eclipse.papyrus.* ; ; *" + CreationPathListEditor.SPLIT_STRING + "org.eclipse.* ; org.eclipse.papyrus.* ; *" + CreationPathListEditor.SPLIT_STRING + " org.osgi.* ; ; osgi.*" + CreationPathListEditor.SPLIT_STRING + " datatype.* ; ; datatype"); + } +} diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferencePage.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferencePage.java new file mode 100644 index 00000000000..6654b90445c --- /dev/null +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/PreferencePage.java @@ -0,0 +1,62 @@ +/***************************************************************************** + * 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.preference; + +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.papyrus.java.reverse.ui.Activator; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * Define a new section into eclipse preferences. Create a page for reverse eclipse preferences. + * + * @author Jonathan Geoffroy + * + */ +public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + public PreferencePage() { + super(GRID); + } + + public PreferencePage(int style) { + super(style); + } + + public PreferencePage(String title, int style) { + super(title, style); + } + + public PreferencePage(String title, ImageDescriptor image, int style) { + super(title, image, style); + } + + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setDescription("Edit your preferences to reverse java project into papyrus model"); + } + + @Override + protected void createFieldEditors() { + // Search path field + addField(new SearchPathListEditor(PreferenceConstants.P_SEARCH_PATH, "default search path", getFieldEditorParent())); + + // Creation path field + addField(new CreationPathListEditor(PreferenceConstants.P_CREATION_PATH, "default creation path", getFieldEditorParent())); + + } + +} diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/ReversePreference.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/ReversePreference.java new file mode 100644 index 00000000000..32faf62cd5e --- /dev/null +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/ReversePreference.java @@ -0,0 +1,50 @@ +/***************************************************************************** + * 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.preference; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.java.reverse.ui.Activator; + +/** + * Provide reverse eclipse preferences values + * + * @author Jonathan Geoffroy + * + */ +public class ReversePreference { + + /** + * allow to gather default value + */ + private IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + /** + * + * @return an array containing each search path values + */ + public String[] getSearchPath() { + String searchPath = store.getString(PreferenceConstants.P_SEARCH_PATH); + return searchPath.split(";"); + } + + /** + * + * @return an array containing each creation path values + */ + public String[] getCreationPath() { + String creationPath = store.getString(PreferenceConstants.P_CREATION_PATH); + return creationPath.split(CreationPathListEditor.SPLIT_STRING); + } +} diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/SearchPathListEditor.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/SearchPathListEditor.java new file mode 100644 index 00000000000..92d02d3a829 --- /dev/null +++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/preference/SearchPathListEditor.java @@ -0,0 +1,85 @@ +/***************************************************************************** + * 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.preference; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.jdt.internal.ui.preferences.TypeFilterInputDialog; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.preference.ListEditor; +import org.eclipse.swt.widgets.Composite; + +/** + * A ListEditor implementation. When user push "add" button, open a dialog box which can validate/invalidate the input value for Search Path. <br> + * Used to add a Search Path value into Eclipse preferences + * + * @author Jonathan Geoffroy + * + */ +public class SearchPathListEditor extends ListEditor { + + /** + * Constructor. + * + * @param name + * @param labelText + * @param parent + */ + public SearchPathListEditor(String name, String labelText, Composite parent) { + super(name, labelText, parent); + } + + @SuppressWarnings("restriction") + @Override + /** + * Functionality for New button. + * Shows a browser dialog to select a file and returns that file. + */ + protected String getNewInputObject() { + //Dialog p = new JDialog(); + List<String> l = new LinkedList<String>(); + + + TypeFilterInputDialog dialog = new TypeFilterInputDialog(getShell(), l); + dialog.open(); + // If user clicked on "cancel" button, return null to NOT add empty value + if(dialog.getReturnCode() == InputDialog.CANCEL) { + return null; + } + Object pack = dialog.getResult(); + + return pack.toString(); + } + + @Override + protected String createList(String[] items) { + StringBuffer str = new StringBuffer(); + for(String item : items) + str.append(item + ";"); + return str.toString(); + } + + /* + * (non-Javadoc) + * initialize list of items + * + * @see org.eclipse.jface.preference.ListEditor#parseString(java.lang.String) + */ + @Override + protected String[] parseString(String stringList) { + return stringList.split(";"); + } + +} |