Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2016-03-16 13:19:17 +0000
committerCedric Dumoulin2016-03-17 10:07:09 +0000
commite7b03a7a14a8d2100c42c274e7f7609a4d6809fc (patch)
tree22fc87358f6bdfd1c8fd2afc74d6a52342a7a1a0 /extraplugins/qompass
parentccb038548f57bfcdbb25262ca42a88864bbfd651 (diff)
downloadorg.eclipse.papyrus-e7b03a7a14a8d2100c42c274e7f7609a4d6809fc.tar.gz
org.eclipse.papyrus-e7b03a7a14a8d2100c42c274e7f7609a4d6809fc.tar.xz
org.eclipse.papyrus-e7b03a7a14a8d2100c42c274e7f7609a4d6809fc.zip
438640: [java reverse code] should allow a drag & drop way to run the
reverse https://bugs.eclipse.org/bugs/show_bug.cgi?id=438640 Reenable drag and drop from Package explorer to Class diagram. The reverse is performed, but classes are still not shown.
Diffstat (limited to 'extraplugins/qompass')
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/DndReverseCodeHandler.java79
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java8
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java106
-rwxr-xr-xextraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseCommand.java7
-rwxr-xr-xextraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/dnd/DropReverseStrategy.java2
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties7
6 files changed, 130 insertions, 79 deletions
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 cade8f285c0..1f735dca23c 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
@@ -18,25 +18,26 @@ import java.util.List;
import java.util.ListIterator;
import java.util.TreeSet;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
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.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.infra.core.Activator;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.ui.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;
@@ -71,7 +72,7 @@ public class DndReverseCodeHandler extends ReverseCodeHandler {
* 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
+ * @param dialog The dialog previuosly used to get data from user. This dialog has already been called by execute().
*/
protected void doExecute(ReverseCodeDialog dialog) {
// Get user preferences on dialog
@@ -81,33 +82,25 @@ public class DndReverseCodeHandler extends ReverseCodeHandler {
displayCU = dndDialog.displayCU();
// get current selection
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- ISelection selection = page.getSelection();
+ ISelection selection = getCurrentSelection();
TreeSelection treeSelection = (TreeSelection) selection;
+
+ // Run the reverse
+ super.doExecute(dialog);
- // 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);
+ // Try to insert result into current diagram
+ try {
+ // Find active papyrus diagram
+ Diagram diagram = null;
+ IEditorPart activeEditor = getNestedActiveIEditorPart();
+ if (activeEditor != null) {
+ diagram = activeEditor.getAdapter(Diagram.class);
}
- }
- // Remove items already in diagram from selection
- List<IJavaElement> listSelection;
- try {
+ // Remove items already in diagram from selection
+ List<IJavaElement> listSelection;
listSelection = selectionMinusAlreadyInDiagram(treeSelection, diagram);
- } catch (JavaModelException e1) {
- e1.printStackTrace();
- return;
- }
- // Run the reverse
- super.doExecute(dialog);
-
-
- try {
// Find model to display
Model model = null;
if (displayModel) {
@@ -119,11 +112,16 @@ public class DndReverseCodeHandler extends ReverseCodeHandler {
DisplayReverse displayReverse = new DisplayReverse(listSelection, diagram, getUmlResource(), model);
displayReverse.execute();
} catch (JavaModelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // Can't get a Papyrus ServiceRegistry.
+ Shell shell = getShell();
+ Status errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DndReverseCodeHandler_CantDisplayResult_Title);
+ ErrorDialog.openError(shell, "", Messages.DndReverseCodeHandler_CantDisplayResult_Message, errorStatus);
+
} catch (ServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // Can't get a Papyrus ServiceRegistry.
+ Shell shell = getShell();
+ Status errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DndReverseCodeHandler_CantFindService_Title );
+ ErrorDialog.openError(shell, "", Messages.DndReverseCodeHandler_CantFindService_Message+ " - " + e.getMessage(), errorStatus);
}
}
@@ -145,12 +143,13 @@ public class DndReverseCodeHandler extends ReverseCodeHandler {
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;
+ @SuppressWarnings("unchecked")
+ List<View> diagramList = diagram.getChildren();
+ Iterator<View> diagramIt = diagramList.iterator();
+ Shape item;
NamedElement e;
while (diagramIt.hasNext()) {
- item = (ShapeImpl) diagramIt.next();
+ item = (Shape) diagramIt.next();
e = (NamedElement) (item.getElement());
alreadyExists.add(e.getName());
}
@@ -239,15 +238,17 @@ public class DndReverseCodeHandler extends ReverseCodeHandler {
* @return true if model is in diagram
*/
private boolean isInDiagram(Diagram diagram, Model model) {
- EList diagramList = diagram.getChildren();
- Iterator diagramIt = diagramList.iterator();
- ShapeImpl item;
+ @SuppressWarnings("unchecked")
+ EList<View> diagramList = diagram.getChildren();
+ Iterator<View> diagramIt = diagramList.iterator();
+ Shape item;
while (diagramIt.hasNext()) {
- item = (ShapeImpl) diagramIt.next();
+ item = (Shape) 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/Messages.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java
index 96060e9d1dd..1ccc7715fcd 100644
--- 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
@@ -14,6 +14,14 @@ public class Messages extends NLS {
public static String ReverseCodeHandler_NoPapyrusEditor_Message;
+ public static String DndReverseCodeHandler_CantDisplayResult_Title;
+
+ public static String DndReverseCodeHandler_CantDisplayResult_Message;
+
+ public static String DndReverseCodeHandler_CantFindService_Title;
+
+ public static String DndReverseCodeHandler_CantFindService_Message;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
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 0903515ecaf..718f4f9ddc6 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
@@ -23,16 +23,16 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.services.spi.IContextualServiceRegistryTracker;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.ui.util.EditorUtils;
import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
import org.eclipse.papyrus.java.reverse.ui.dialog.ReverseCodeDialog;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
@@ -63,45 +63,30 @@ public class ReverseCodeHandler extends AbstractHandler implements IHandler {
// Store the event in order to be able to use it from utility methods.
this.event = event;
- // Lookup ServiceRegistry
- try {
- registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
- } catch (ServiceException e1) {
- try {
- registry = getContextualServiceRegistry();
- } catch (ServiceException e) {
- // Can't get a Papyrus ServiceRegistry.
- Shell shell = HandlerUtil.getActiveShell(event);
- Status errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ReverseCodeHandler_NoPapyrusEditor_Title);
- ErrorDialog.openError(shell, "", Messages.ReverseCodeHandler_NoPapyrusEditor_Message, errorStatus);
-
- // Stop the handler execution.
- return null;
- }
- }
-
- System.err.println("ServiceRegistry = " + registry);
// Try to find uml resource
final Resource umlResource;
try {
+ // Lookup ServiceRegistry
+ registry = lookupServiceRegistry(event);
+
+ System.err.println("ServiceRegistry = " + registry);
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);
+ Shell shell = getShell();
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;
} catch (ServiceException 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);
+ // Can't get a Papyrus ServiceRegistry.
+ Shell shell = getShell();
+ Status errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ReverseCodeHandler_NoPapyrusEditor_Title);
+ ErrorDialog.openError(shell, "", Messages.ReverseCodeHandler_NoPapyrusEditor_Message, errorStatus);
- e.printStackTrace();
- // Stop the reverse execution.
+ // Stop the handler execution.
return null;
}
;
@@ -109,7 +94,7 @@ public class ReverseCodeHandler extends AbstractHandler implements IHandler {
String modelUid = getModelUid(umlResource);
// Get reverse parameters from a dialog
- Shell shell = HandlerUtil.getActiveShell(event);
+ Shell shell = getShell();
// ReverseCodeDialog dialog = new ReverseCodeDialog(shell, DefaultGenerationPackageName, Arrays.asList("generated") );
final ReverseCodeDialog dialog = getDialog(shell, modelUid);
@@ -145,6 +130,40 @@ public class ReverseCodeHandler extends AbstractHandler implements IHandler {
}
/**
+ * Get the active shell from the event, or from the active page if event is null.
+ *
+ * @param event
+ * @return
+ */
+ protected Shell getShell() {
+
+ if(event != null ) {
+ return HandlerUtil.getActiveShell(event);
+ }
+ else {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getShell();
+
+ }
+ }
+
+ /**
+ * @param event
+ * @return
+ */
+ protected ServicesRegistry lookupServiceRegistry(ExecutionEvent event) throws ServiceException {
+
+ ServicesRegistry registry;
+
+ try {
+ // This utility accept null event.
+ registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event);
+ } catch (ServiceException e1) {
+ registry = getContextualServiceRegistry();
+ }
+ return registry;
+ }
+
+ /**
* Find the modelUid name contains into umlResource taken in parameter
*
* @param umlResource
@@ -216,14 +235,17 @@ public class ReverseCodeHandler extends AbstractHandler implements IHandler {
*/
protected ISelection getCurrentSelection() {
ISelection selection=null;
- Object context = event.getApplicationContext();
- if (context instanceof IEvaluationContext) {
- IEvaluationContext evaluationContext = (IEvaluationContext) context;
- selection = (ISelection)evaluationContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
+ if (event != null) {
+ // Try to get selection from context
+ Object context = event.getApplicationContext();
+ if ( context instanceof IEvaluationContext) {
+ IEvaluationContext evaluationContext = (IEvaluationContext) context;
+ selection = (ISelection)evaluationContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
+ }
}
if( selection == null) {
- // Get current selection
+ // Try to get selection from ActivePage
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
selection = page.getSelection();
}
@@ -270,15 +292,27 @@ public class ReverseCodeHandler extends AbstractHandler implements IHandler {
}
/**
- * Get the current MultiDiagramEditor.
+ * Gets the {@link IEditorPart} of the currently nested active editor.
*
+ * @param from
* @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
*/
- protected IMultiDiagramEditor getMultiDiagramEditor() {
- return EditorUtils.getMultiDiagramEditor();
+ public IEditorPart getNestedActiveIEditorPart() throws ServiceException {
+ return ServiceUtils.getInstance().getService(ISashWindowsContainer.class, registry).getActiveEditor();
}
/**
+ * Get the current MultiDiagramEditor.
+ *
+ * @return
+ */
+// protected IMultiDiagramEditor getMultiDiagramEditor() {
+// return EditorUtils.getMultiDiagramEditor();
+// }
+
+ /**
* Get the main editing doamin.
*
* @return
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
index 9fdb9fb8505..b78f05e39c6 100755
--- 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
@@ -18,6 +18,7 @@ import java.util.List;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.jdt.core.IJavaElement;
@@ -56,7 +57,7 @@ public class DropReverseCommand extends Command {
@Override
public boolean canExecute() {
// Find the type of each selected file (CompilationUnit, packages ...)
- List selected; // The selected files from JDT
+ List<?> selected; // The selected files from JDT
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection selection = page.getSelection();
@@ -80,6 +81,7 @@ public class DropReverseCommand extends Command {
public void execute() {
DndReverseCodeHandler reverse = new DndReverseCodeHandler();
try {
+
reverse.execute(null);
} catch (ExecutionException e) {
e.printStackTrace();
@@ -89,11 +91,12 @@ public class DropReverseCommand extends Command {
/**
* return a singleton of this command
* Change the request if it differ from the previous calling
+ * @param targetEditPart
*
*
* @return a singleton of this command
*/
- public static DropReverseCommand getInstance(Request request) {
+ public static DropReverseCommand getInstance(Request request, EditPart targetEditPart) {
if (instance == null) {
instance = new DropReverseCommand();
}
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
index a302a6d3418..4cc990969c8 100755
--- 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
@@ -48,7 +48,7 @@ public class DropReverseStrategy implements DropStrategy {
@Override
public Command getCommand(final Request request, final EditPart targetEditPart) {
- return DropReverseCommand.getInstance(request);
+ return DropReverseCommand.getInstance(request, targetEditPart);
}
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
index 91fed190265..92a5ca789b8 100644
--- 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
@@ -1,4 +1,9 @@
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
ReverseCodeHandler_NoPapyrusEditor_Title=No Papyrus Editor selected
-ReverseCodeHandler_NoPapyrusEditor_Message=No Papyrus Editor selected for Reverse. Please open and select a Papyrus Editor, then select java classes to reverse. \ No newline at end of file
+ReverseCodeHandler_NoPapyrusEditor_Message=No Papyrus Editor selected for Reverse. Please open and select a Papyrus Editor, then select java classes to reverse.
+
+DndReverseCodeHandler_CantDisplayResult_Title=Can't display reversed element in diagram
+DndReverseCodeHandler_CantDisplayResult_Message=Can't display reversed element in diagram
+DndReverseCodeHandler_CantFindService_Title=Can't display reversed element in diagram
+DndReverseCodeHandler_CantFindService_Message=Can't display reversed element in diagram

Back to the top