solving #4056 (taxeditor responds with nicer dialogue in case a user executes a prohi...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 11 Feb 2014 16:20:34 +0000 (16:20 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 11 Feb 2014 16:20:34 +0000 (16:20 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/UpdateDataSourceHandler.java

index e335480a8e2e36e7c27b8e75f65ad902ced113ca..70d4ba028f39302bf9ebe680fbfb156836087b90 100644 (file)
@@ -10,6 +10,9 @@
 
 package eu.etaxonomy.taxeditor.model;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -24,12 +27,14 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.ILog;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ColorRegistry;
@@ -54,7 +59,9 @@ 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;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
@@ -416,16 +423,16 @@ 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() {
 
                        @Override
             public void run() {
-                               MessageDialog.openError(getShell(), title, status.getMessage());
+                               ErrorDialog.openError(getShell(), title, null, status);
                                Class<? extends Object> clazz = source != null ? source
                                                .getClass() : this.getClass();
-                               error(clazz, status.getMessage(), status.getException());
+                               error(clazz, status);
                        }
                });
        }
@@ -477,7 +484,31 @@ public abstract class AbstractUtility {
                                        status = getOperationHistory().execute(operation, monitor,
                                                        uiInfoAdapter);
                                } catch (ExecutionException e) {
-                                       errorDialog("Error executing operation", getClass(), String.format("An error occured while executing %s.", operation.getLabel()), 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);
+                                       
                                } finally {
                                        monitor.done();
                                }
index 154dc12b923f49b450759a692ee94939534b5550..0d51b22e19d7049d6f244e5f67e7e5076deba6ae 100644 (file)
@@ -76,7 +76,7 @@ public class UpdateDataSourceHandler extends AbstractDataSourceHandler {
                                        }
                                }catch(Exception e){
                                        status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
-                                       StoreUtil.errorDialog("Could not run updater", getClass(), status);
+                                       StoreUtil.errorDialog("Could not run updater", getClass(), status.getMessage());
                                }