summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan GEOFFROY2014-08-04 03:55:56 (EDT)
committerJonathan GEOFFROY2014-08-04 03:55:56 (EDT)
commit97b6477919ff0e9ab8dd98fc35ba2f6b5c802d2c (patch)
treed5eec3e2dd780af847e75e6df3d355c81ee5fe4f
parent04ca537a4f7f85fd2f86a2b7ca31d5ed1f89934d (diff)
downloadorg.eclipse.papyrus-97b6477919ff0e9ab8dd98fc35ba2f6b5c802d2c.zip
org.eclipse.papyrus-97b6477919ff0e9ab8dd98fc35ba2f6b5c802d2c.tar.gz
org.eclipse.papyrus-97b6477919ff0e9ab8dd98fc35ba2f6b5c802d2c.tar.bz2
Bug 438345 - [java reverse] Reverse shall display an explicit error whenrefs/changes/01/29101/2
user has not opened any model Add an ErrorMessage when there is no selected model. Change-Id: Ie02777ab0a29731576ce1d773090fe1effc3f5a9 Signed-off-by: Jonathan GEOFFROY <geoffroy.jonathan@gmail.com>
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs1
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java19
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/ReverseCodeHandler.java21
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties2
4 files changed, 38 insertions, 5 deletions
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs
index b8c742b..2697efe 100644
--- a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/.settings/org.eclipse.core.resources.prefs
@@ -1,2 +1,3 @@
eclipse.preferences.version=1
encoding//src/org/eclipse/papyrus/java/reverse/ui/dnd/messages.properties=ISO-8859-1
+encoding//src/org/eclipse/papyrus/java/reverse/ui/messages.properties=ISO-8859-1
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java
new file mode 100644
index 0000000..3857750
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/Messages.java
@@ -0,0 +1,19 @@
+package org.eclipse.papyrus.java.reverse.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.java.reverse.ui.messages"; //$NON-NLS-1$
+
+ public static String ReverseCodeHandler_NoModelError_Message;
+
+ public static String ReverseCodeHandler_NoModelError_Title;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/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
index 24c33ed..55aec76 100644
--- 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
@@ -10,9 +10,11 @@ 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.Status;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.services.ServiceException;
@@ -22,6 +24,7 @@ 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;
@@ -37,11 +40,19 @@ public class ReverseCodeHandler extends AbstractHandler implements IHandler {
* Method called when button is pressed.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
-
-
-
- final Resource umlResource = getUmlResource();
- // String rootModelName = getRootModelName(umlResource);
+ // 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(Status.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);
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties
new file mode 100644
index 0000000..a754ab7
--- /dev/null
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse.ui/src/org/eclipse/papyrus/java/reverse/ui/messages.properties
@@ -0,0 +1,2 @@
+ReverseCodeHandler_NoModelError_Message=No model selected for Reverse. Please open a model where you want to add the reverse result.
+ReverseCodeHandler_NoModelError_Title=No model selected