fixing: #4110 (imlement nicer warning dialogue in Taxon Editor for permission denied...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 10 Mar 2014 11:43:47 +0000 (11:43 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 10 Mar 2014 11:43:47 +0000 (11:43 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java

index 2f49284d4d95d3d7de60b2cc8bd2bc566bc1f6dd..4c79beba15d2496ae841f3829d5a3e4c2bc97d9c 100644 (file)
@@ -145,8 +145,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
             monitor.worked(1);
         } catch (Exception e) {
             setFocus();
-            AbstractUtility.errorDialog("An error occurred while saving", getClass(),
-                    "An error occurred while saving the editor. Please close and reopen the taxon again.", e);
+            AbstractUtility.dialogForAbortedOperation(e, this, "saving a taxon", " Please close and reopen the taxon again.");
             disableEditor(true);
         } finally {
             monitor.done();
index 70d4ba028f39302bf9ebe680fbfb156836087b90..9a1e0e16a742a370bf8c13489915bba7f1418bac 100644 (file)
@@ -59,7 +59,6 @@ import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
 import org.eclipse.ui.themes.ITheme;
 import org.eclipse.ui.themes.IThemeManager;
 
-import eu.etaxonomy.cdm.database.PermissionDeniedException;
 import eu.etaxonomy.cdm.model.common.IEnumTerm;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.SecurityExceptionUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
@@ -423,7 +422,7 @@ public abstract class AbstractUtility {
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
-       public static void errorDialog(final String title, final Object source, 
+       public static void errorDialog(final String title, final Object source,
                        final IStatus status) {
                Display.getDefault().asyncExec(new Runnable() {
 
@@ -477,45 +476,24 @@ public abstract class AbstractUtility {
                        @Override
             public void run(IProgressMonitor monitor)
                                        throws InvocationTargetException, InterruptedException {
-                               monitor.beginTask(operation.getLabel(), 100);
+                               String operationlabel = operation.getLabel();
+                monitor.beginTask(operationlabel, 100);
                                IStatus status = Status.CANCEL_STATUS;
                                try {
                                        operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
                                        status = getOperationHistory().execute(operation, monitor,
                                                        uiInfoAdapter);
                                } catch (ExecutionException e) {
-                                       MultiStatus info = null;
-                                       String title = null;
-
-                                       // FIXME cannot access TaxonomicEditorPlugin.PLUGIN_ID from here 
-                                       // String PID = TaxonomicEditorPlugin.PLUGIN_ID;
-                                       String PID = "eu.etaxonomy.taxeditor.application";
-                                       
-                                       RuntimeException securityRuntimeException = SecurityExceptionUtils.findSecurityRuntimeException(e);
-                                       
-                                       if(securityRuntimeException != null){
-                                               title = "Your changes could not be saved!";
-                                               info = new MultiStatus(PID, 1, String.format("You are missing sufficient permissions for the operation \"%s\".", operation.getLabel()), null);
-                                               info.add(new Status(IStatus.WARNING, PID, 1, securityRuntimeException.getMessage(), null));
-                                               
-                                       } else {
-                                               title = "Error executing operation";
-                                               info = new MultiStatus(PID, 1, String.format("An error occured while executing %s.", operation.getLabel()), null);
-                                               Writer writer = new StringWriter();
-                                           PrintWriter printWriter = new PrintWriter(writer);
-                                           e.printStackTrace(printWriter);
-                                               info.add(new Status(IStatus.ERROR, PID, 1, writer.toString(), null));
-                                       }
-                               
-                                       errorDialog(title, getClass(), info);
-                                       
+
+                                       dialogForAbortedOperation(e, this, operationlabel, null);
+
                                } finally {
                                        monitor.done();
                                }
 
                                String statusString = status.equals(Status.OK_STATUS) ? "completed"
                                                : "cancelled";
-                               setStatusLine(operation.getLabel() + " " + statusString + ".");
+                               setStatusLine(operationlabel + " " + statusString + ".");
 
                        }
                };
@@ -1043,6 +1021,33 @@ public abstract class AbstractUtility {
         }
     }
 
+    public static void dialogForAbortedOperation(Exception e, final Object source,  String operationlabel, String hint) {
+        MultiStatus info = null;
+        String title = null;
+
+        // FIXME cannot access TaxonomicEditorPlugin.PLUGIN_ID from here
+        // String PID = TaxonomicEditorPlugin.PLUGIN_ID;
+        String PID = "eu.etaxonomy.taxeditor.application";
+
+        RuntimeException securityRuntimeException = SecurityExceptionUtils.findSecurityRuntimeException(e);
+
+        if(securityRuntimeException != null){
+               title = "Your changes could not be saved!";
+               info = new MultiStatus(PID, 1, String.format("You are missing sufficient permissions for the operation \"%s\". %s", operationlabel, hint), null);
+               info.add(new Status(IStatus.WARNING, PID, 1, securityRuntimeException.getMessage(), null));
+
+        } else {
+               title = "Error executing operation";
+               info = new MultiStatus(PID, 1, String.format("An error occured while executing %s. %s", operationlabel, hint), null);
+               Writer writer = new StringWriter();
+            PrintWriter printWriter = new PrintWriter(writer);
+            e.printStackTrace(printWriter);
+               info.add(new Status(IStatus.ERROR, PID, 1, writer.toString(), null));
+        }
+
+        errorDialog(title, source, info);
+    }
+
     private static class TermNode<T extends IEnumTerm<T>> implements Comparable<TermNode<T>>{
         private final T term;
         private final TreeSet<TermNode<T>> children;