#5297 Integrate remoting monitor cancel functionality in ui
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / AbstractUtility.java
index 560fd61f04b8dc701883df406c8c9934b2940eb4..cdfbe19aea59b18123381aefb80ac70734f42dfb 100644 (file)
@@ -16,7 +16,10 @@ import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.TreeSet;
+import java.util.UUID;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.NotEnabledException;
 import org.eclipse.core.commands.NotHandledException;
@@ -31,6 +34,7 @@ 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.core.runtime.jobs.Job;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ColorRegistry;
@@ -51,16 +55,23 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
 import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.progress.IProgressConstants;
 import org.eclipse.ui.progress.IProgressService;
 import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
 import org.eclipse.ui.themes.ITheme;
 import org.eclipse.ui.themes.IThemeManager;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
+import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
 import eu.etaxonomy.cdm.model.common.IEnumTerm;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
 import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
 import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
 import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
@@ -76,587 +87,681 @@ import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
  */
 public abstract class AbstractUtility {
 
+    private static final Logger logger = Logger.getLogger(AbstractUtility.class);
+
     /** Constant <code>statusLineManager</code> */
     protected static IStatusLineManager statusLineManager;
 
 
-       /**
-        * <p>
-        * closeAll
-        * </p>
-        *
-        * @return a boolean.
-        */
-       public static boolean closeAll() {
-               return getActivePage().closeAllEditors(true);
-       }
-
-       /**
-        * Close the given editor.
-        *
-        * @param editor
-        *            The <tt>MultipageTaxonEditor</tt> to close.
-        * @return <tt>true</tt> on success
-        */
-       public static boolean close(EditorPart editor) {
-               return getActivePage().closeEditor(editor, true);
-       }
-
-       /**
-        * <p>
-        * getShell
-        * </p>
-        *
-        * @return a {@link org.eclipse.swt.widgets.Shell} object.
-        */
-       public static Shell getShell() {
-
-               return TaxeditorStorePlugin.getDefault().getWorkbench()
-                               .getActiveWorkbenchWindow().getShell();
-       }
-
-       /**
-        * <p>
-        * getActivePage
-        * </p>
-        *
-        * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
-        */
-       public static IWorkbenchPage getActivePage() {
-
-               return TaxeditorStorePlugin.getDefault().getWorkbench()
-                               .getActiveWorkbenchWindow().getActivePage();
-       }
-
-       /**
-        * <p>
-        * getActivePart
-        * </p>
-        *
-        * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
-        */
-       public static IWorkbenchPart getActivePart() {
-               return getActivePage() != null ? getActivePage().getActivePart() : null;
-       }
-
-       public static IWorkbench getWorkbench() {
-               return TaxeditorStorePlugin.getDefault().getWorkbench();
-       }
-
-       /**
-        * <p>
-        * getWorkbenchWindow
-        * </p>
-        *
-        * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
-        */
-       public static ApplicationWindow getWorkbenchWindow() {
-               if (getWorkbench().getWorkbenchWindowCount() > 1) {
-                       throw new IllegalStateException("More than one workbench window");
-               }
-               return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0];
-       }
-
-       /**
-        * <p>
-        * showView
-        * </p>
-        *
-        * @param id
-        *            a {@link java.lang.String} object.
-        * @return a {@link org.eclipse.ui.IViewPart} object.
-        */
-       public static IViewPart showView(String id) {
-               try {
-                       return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
-                                       .getActivePage()
-                                       .showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
-               } catch (PartInitException e) {
-                       MessagingUtils.messageDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
-                       return null;
-               }
-       }
-
-       /**
-        * <p>
-        * hideView
-        * </p>
-        *
-        * @param view
-        *            a {@link org.eclipse.ui.IViewPart} object.
-        */
-       public static void hideView(IViewPart view) {
-               PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
-                               .hideView(view);
-       }
-
-       /**
-        * <p>
-        * getView
-        * </p>
-        *
-        * @param id
-        *            a {@link java.lang.String} object.
-        * @param restore
-        *            a boolean.
-        * @return a {@link org.eclipse.ui.IViewPart} object.
-        */
-       public static IViewPart getView(String id, boolean restore) {
-               IViewReference[] references = PlatformUI.getWorkbench()
-                               .getActiveWorkbenchWindow().getActivePage().getViewReferences();
-               for (IViewReference reference : references) {
-                       if (reference.getId().equals(id)) {
-                               return reference.getView(restore);
-                       }
-               }
-               return null;
-       }
-
-       /**
-        * <p>
-        * getService
-        * </p>
-        *
-        * @param api
-        *            a {@link java.lang.Class} object.
-        * @return a {@link java.lang.Object} object.
-        */
-       public static Object getService(Class api) {
-               return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
-       }
-
-       /**
-        * <p>
-        * getCurrentTheme
-        * </p>
-        *
-        * @return a {@link org.eclipse.ui.themes.ITheme} object.
-        */
-       public static ITheme getCurrentTheme() {
-               IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
-                               .getWorkbench().getThemeManager();
-               return themeManager.getCurrentTheme();
-       }
-
-       /**
-        * Fonts registered to the plugin may be obtained with the Eclipse themeing
-        * functionality. Thus fonts are chooseable by the user via
-        * Preferences->General->Appearance->Colors and Fonts
-        *
-        * @return the FontRegistry for the current theme
-        */
-       public static FontRegistry getFontRegistry() {
-               return getCurrentTheme().getFontRegistry();
-       }
-
-       /**
-        * <p>
-        * getFont
-        * </p>
-        *
-        * @param symbolicName
-        *            a {@link java.lang.String} object.
-        * @return a {@link org.eclipse.swt.graphics.Font} object.
-        */
-       public static Font getFont(String symbolicName) {
-               return getFontRegistry().get(symbolicName);
-       }
-
-       /**
-        * Color registered to the plugin may be obtained with the Eclipse themeing
-        * functionality. Thus colors are editable by the user via
-        * Preferences->General->Appearance->Colors and Fonts
-        *
-        * @return the ColorRegistry for the current theme
-        */
-       public static ColorRegistry getColorRegistry() {
-               return getCurrentTheme().getColorRegistry();
-       }
-
-       /**
-        * <p>
-        * getColor
-        * </p>
-        *
-        * @param symbolicName
-        *            a {@link java.lang.String} object.
-        * @return a {@link org.eclipse.swt.graphics.Color} object.
-        */
-       public static Color getColor(String symbolicName) {
-               return getColorRegistry().get(symbolicName);
-       }
-
-       /**
-        * <p>
-        * executeOperation
-        * </p>
-        *
-        * @param operation
-        *            a
-        *            {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
-        *            object.
-        * @return a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static IStatus executeOperation(final AbstractPostOperation operation) {
-               if (getOperationHistory() == null) {
-                       throw new IllegalArgumentException(
-                                       "There is no operation history for this context");
-               }
-
-               final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
-                               .getUIInfoAdapter(getShell());
-
-               IRunnableWithProgress runnable = new IRunnableWithProgress() {
-
-                       @Override
+    /**
+     * <p>
+     * closeAll
+     * </p>
+     *
+     * @return a boolean.
+     */
+    public static boolean closeAll() {
+        return getActivePage().closeAllEditors(true);
+    }
+
+    /**
+     * Close the given editor.
+     *
+     * @param editor
+     *            The <tt>MultipageTaxonEditor</tt> to close.
+     * @return <tt>true</tt> on success
+     */
+    public static boolean close(EditorPart editor) {
+        return getActivePage().closeEditor(editor, true);
+    }
+
+    /**
+     * <p>
+     * getShell
+     * </p>
+     *
+     * @return a {@link org.eclipse.swt.widgets.Shell} object.
+     */
+    public static Shell getShell() {
+
+        return TaxeditorStorePlugin.getDefault().getWorkbench()
+                .getActiveWorkbenchWindow().getShell();
+    }
+
+    /**
+     * <p>
+     * getActivePage
+     * </p>
+     *
+     * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
+     */
+    public static IWorkbenchPage getActivePage() {
+
+        return TaxeditorStorePlugin.getDefault().getWorkbench()
+                .getActiveWorkbenchWindow().getActivePage();
+    }
+
+    /**
+     * <p>
+     * getActivePart
+     * </p>
+     *
+     * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
+     */
+    public static IWorkbenchPart getActivePart() {
+        return getActivePage() != null ? getActivePage().getActivePart() : null;
+    }
+
+    public static IWorkbench getWorkbench() {
+        return TaxeditorStorePlugin.getDefault().getWorkbench();
+    }
+
+    /**
+     * <p>
+     * getWorkbenchWindow
+     * </p>
+     *
+     * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
+     */
+    public static ApplicationWindow getWorkbenchWindow() {
+        if (getWorkbench().getWorkbenchWindowCount() > 1) {
+            throw new IllegalStateException("More than one workbench window");
+        }
+        return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0];
+    }
+
+    /**
+     * <p>
+     * showView
+     * </p>
+     *
+     * @param id
+     *            a {@link java.lang.String} object.
+     * @return a {@link org.eclipse.ui.IViewPart} object.
+     */
+    public static IViewPart showView(String id) {
+        try {
+            return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+                    .getActivePage()
+                    .showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
+        } catch (PartInitException e) {
+            MessagingUtils.messageDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
+            return null;
+        }
+    }
+
+    /**
+     * <p>
+     * hideView
+     * </p>
+     *
+     * @param view
+     *            a {@link org.eclipse.ui.IViewPart} object.
+     */
+    public static void hideView(IViewPart view) {
+        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+        .hideView(view);
+    }
+
+    /**
+     * <p>
+     * getView
+     * </p>
+     *
+     * @param id
+     *            a {@link java.lang.String} object.
+     * @param restore
+     *            a boolean.
+     * @return a {@link org.eclipse.ui.IViewPart} object.
+     */
+    public static IViewPart getView(String id, boolean restore) {
+        IViewReference[] references = PlatformUI.getWorkbench()
+                .getActiveWorkbenchWindow().getActivePage().getViewReferences();
+        for (IViewReference reference : references) {
+            if (reference.getId().equals(id)) {
+                return reference.getView(restore);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * <p>
+     * getService
+     * </p>
+     *
+     * @param api
+     *            a {@link java.lang.Class} object.
+     * @return a {@link java.lang.Object} object.
+     */
+    public static Object getService(Class api) {
+        return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
+    }
+
+    /**
+     * <p>
+     * getCurrentTheme
+     * </p>
+     *
+     * @return a {@link org.eclipse.ui.themes.ITheme} object.
+     */
+    public static ITheme getCurrentTheme() {
+        IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
+                .getWorkbench().getThemeManager();
+        return themeManager.getCurrentTheme();
+    }
+
+    /**
+     * Fonts registered to the plugin may be obtained with the Eclipse themeing
+     * functionality. Thus fonts are chooseable by the user via
+     * Preferences->General->Appearance->Colors and Fonts
+     *
+     * @return the FontRegistry for the current theme
+     */
+    public static FontRegistry getFontRegistry() {
+        return getCurrentTheme().getFontRegistry();
+    }
+
+    /**
+     * <p>
+     * getFont
+     * </p>
+     *
+     * @param symbolicName
+     *            a {@link java.lang.String} object.
+     * @return a {@link org.eclipse.swt.graphics.Font} object.
+     */
+    public static Font getFont(String symbolicName) {
+        return getFontRegistry().get(symbolicName);
+    }
+
+    /**
+     * Color registered to the plugin may be obtained with the Eclipse themeing
+     * functionality. Thus colors are editable by the user via
+     * Preferences->General->Appearance->Colors and Fonts
+     *
+     * @return the ColorRegistry for the current theme
+     */
+    public static ColorRegistry getColorRegistry() {
+        return getCurrentTheme().getColorRegistry();
+    }
+
+    /**
+     * <p>
+     * getColor
+     * </p>
+     *
+     * @param symbolicName
+     *            a {@link java.lang.String} object.
+     * @return a {@link org.eclipse.swt.graphics.Color} object.
+     */
+    public static Color getColor(String symbolicName) {
+        return getColorRegistry().get(symbolicName);
+    }
+
+    /**
+     * <p>
+     * executeOperation
+     * </p>
+     *
+     * @param operation
+     *            a
+     *            {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
+     *            object.
+     * @return a {@link org.eclipse.core.runtime.IStatus} object.
+     */
+    public static IStatus executeOperation(final AbstractPostOperation operation) {
+        if (getOperationHistory() == null) {
+            throw new IllegalArgumentException(
+                    "There is no operation history for this context");
+        }
+
+        final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
+                .getUIInfoAdapter(getShell());
+
+        IRunnableWithProgress runnable = new IRunnableWithProgress() {
+
+            @Override
             public void run(IProgressMonitor monitor)
-                                       throws InvocationTargetException, InterruptedException {
-                               String operationlabel = operation.getLabel();
+                    throws InvocationTargetException, InterruptedException {
+                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) {
-
-                                       MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
-
-                               } finally {
-                                       monitor.done();
-                               }
-
-                               String statusString = status.equals(Status.OK_STATUS) ? "completed"
-                                               : "cancelled";
-                               setStatusLine(operationlabel + " " + statusString + ".");
-
-                       }
-               };
-
-               try {
-                       runInUI(runnable, null);
-               } catch (Exception e) {
-                       MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
-               }
-
-               IPostOperationEnabled postOperationEnabled = operation
-                               .getPostOperationEnabled();
-               if (postOperationEnabled != null) {
-                       postOperationEnabled.onComplete();
-               }
-               return Status.OK_STATUS;
-       }
-
-          public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandler handler) {
-               if (getOperationHistory() == null) {
-                   throw new IllegalArgumentException(
-                           "There is no operation history for this context");
-               }
-
-               final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
-                       .getUIInfoAdapter(getShell());
-
-               IRunnableWithProgress runnable = new IRunnableWithProgress() {
-
-                   @Override
-                   public void run(IProgressMonitor monitor)
-                           throws InvocationTargetException, InterruptedException {
-                       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);
-                           if(handler != null) {
-                               handler.postOperation(status);
-                           }
-                       } catch (ExecutionException e) {
-                           MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
-                       } finally {
-                           monitor.done();
-                       }
-
-                       String statusString = status.equals(Status.OK_STATUS) ? "completed"
-                               : "cancelled";
-                       setStatusLine(operationlabel + " " + statusString + ".");
-
-                   }
-               };
-
-               try {
-                   runInUI(runnable, null);
-               } catch (Exception e) {
-                   MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
-               }
-
-               return Status.OK_STATUS;
-           }
-       /**
-        * <p>
-        * getOperationHistory
-        * </p>
-        *
-        * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
-        *         object.
-        */
-       public static IOperationHistory getOperationHistory() {
-               return getWorkbench().getOperationSupport().getOperationHistory();
-       }
-
-       /**
-        * <p>
-        * setStatusLine
-        * </p>
-        *
-        * @param message
-        *            a {@link java.lang.String} object.
-        */
-       public static void setStatusLine(final String message) {
-               Display.getDefault().asyncExec(new Runnable() {
-
-                       @Override
+                IStatus status = Status.CANCEL_STATUS;
+                try {
+                    operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
+                    status = getOperationHistory().execute(operation, monitor,
+                            uiInfoAdapter);
+                } catch (ExecutionException e) {
+
+                    MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
+
+                } finally {
+                    monitor.done();
+                }
+
+                String statusString = status.equals(Status.OK_STATUS) ? "completed"
+                        : "cancelled";
+                setStatusLine(operationlabel + " " + statusString + ".");
+
+            }
+        };
+
+        try {
+            runInUI(runnable, null);
+        } catch (Exception e) {
+            MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+        }
+
+        IPostOperationEnabled postOperationEnabled = operation
+                .getPostOperationEnabled();
+        if (postOperationEnabled != null) {
+            postOperationEnabled.onComplete();
+        }
+        return Status.OK_STATUS;
+    }
+
+    public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandler handler) {
+        if (getOperationHistory() == null) {
+            throw new IllegalArgumentException(
+                    "There is no operation history for this context");
+        }
+
+        final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
+                .getUIInfoAdapter(getShell());
+
+        IRunnableWithProgress runnable = new IRunnableWithProgress() {
+
+            @Override
+            public void run(IProgressMonitor monitor)
+                    throws InvocationTargetException, InterruptedException {
+                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);
+                    if(handler != null) {
+                        handler.postOperation(status);
+                    }
+                } catch (ExecutionException e) {
+                    MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
+                } finally {
+                    monitor.done();
+                }
+
+                String statusString = status.equals(Status.OK_STATUS) ? "completed"
+                        : "cancelled";
+                setStatusLine(operationlabel + " " + statusString + ".");
+
+            }
+        };
+
+        try {
+            runInUI(runnable, null);
+        } catch (Exception e) {
+            MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+        }
+
+        return Status.OK_STATUS;
+    }
+
+    /**
+     * Executes a remoting monitored operation
+     *
+     * @param label for the operation
+     * @param uuid of the remoting monitor already started on the server
+     * @param pollInterval in milliseconds
+     * @param cancelable flag which determines whether the operation can be cancelled
+     * @param postOp callback for running post operation logic
+     * @return
+     */
+    public static IStatus executeMoniteredOperation(final String label,
+            final UUID uuid,
+            final int pollInterval,
+            final boolean cancelable,
+            final IPostMoniteredOperationEnabled postOp) {
+
+        try {
+            // get the remoting monitor the first time to make sure that the
+            // operation is valid
+            final IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
+            final IRemotingProgressMonitor firstRemotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
+            if(firstRemotingMonitor == null) {
+                throw new IllegalStateException("Remoting progress monitor is null");
+            }
+
+            Job job = new Job(label) {
+
+
+                @Override
+                public IStatus run(IProgressMonitor monitor) {
+                    // run the monitor until the operation is finished
+                    IRemotingProgressMonitor remotingMonitor;
+                    try {
+                        remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label, uuid, pollInterval, postOp, monitor);
+                    } catch (InterruptedException ie) {
+                        return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ie);
+                    }
+                    final StringBuilder reportSb = new StringBuilder();
+                    // collect reports
+                    for(String report : remotingMonitor.getReports()) {
+                        reportSb.append(report);
+                    }
+                    if(!StringUtils.isBlank(reportSb.toString())) {
+                        Display.getDefault().asyncExec(new Runnable() {
+                            @Override
+                            public void run() {
+                                // display reports with possibility to save
+                                ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+                                dialog.setTitle(label + " Report");
+                                dialog.setReportText(reportSb.toString());
+                                dialog.open();
+                            }
+                        });
+                    }
+                    return Status.OK_STATUS;
+                }
+
+                @Override
+                protected void canceling() {
+                    CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
+                }
+            };
+
+//            job.addJobChangeListener(new JobChangeAdapter() {
+//                @Override
+//                public void done(IJobChangeEvent event) {
+//                    if(event.getJob().) {
+//                        logger.warn("in jobc change listener");
+//                    }
+//                }
+//            });
+
+            // configure the job
+            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+            job.setUser(true);
+            // schedule job
+            job.schedule();
+
+        } catch (Exception e) {
+            MessagingUtils.errorDialog("Error executing operation",
+                    AbstractUtility.class,
+                    "An error occured while executing " + label,
+                    TaxeditorStorePlugin.PLUGIN_ID,
+                    e,
+                    true);
+        }
+
+        return Status.OK_STATUS;
+    }
+
+
+    /**
+     * <p>
+     * getOperationHistory
+     * </p>
+     *
+     * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
+     *         object.
+     */
+    public static IOperationHistory getOperationHistory() {
+        return getWorkbench().getOperationSupport().getOperationHistory();
+    }
+
+    /**
+     * <p>
+     * setStatusLine
+     * </p>
+     *
+     * @param message
+     *            a {@link java.lang.String} object.
+     */
+    public static void setStatusLine(final String message) {
+        Display.getDefault().asyncExec(new Runnable() {
+
+            @Override
             public void run() {
-                               statusLineManager.setMessage(message);
-                       }
-
-               });
-
-       }
-
-       /**
-        * <p>
-        * getMonitor
-        * </p>
-        *
-        * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
-        */
-       public static IProgressMonitor getMonitor() {
-               statusLineManager.setCancelEnabled(false);
-               return statusLineManager.getProgressMonitor();
-       }
-
-       /**
-        * Starts either the given {@link IProgressMonitor} if it's not
-        * <code>null</code> or a new {@link NullProgressMonitor}.
-        *
-        * @param progressMonitor
-        *            The {@link IProgressMonitor} or <code>null</code> if no
-        *            progress should be reported.
-        * @param taskName
-        *            The name of the main task.
-        * @param steps
-        *            The number of steps this task is subdivided into.
-        * @return The {@link IProgressMonitor}.
-        */
-       public static IProgressMonitor startMainMonitor(
-                       IProgressMonitor progressMonitor, String taskName, int steps) {
-               IProgressMonitor newMonitor = progressMonitor;
-               if (newMonitor == null) {
-                       newMonitor = new NullProgressMonitor();
-               }
-               newMonitor.beginTask(taskName == null ? "" : taskName, steps);
-               newMonitor.subTask(" ");
-               return newMonitor;
-       }
-
-       /**
-        * Creates a {@link SubProgressMonitor} if the given
-        * {@link IProgressMonitor} is not <code>null</code> and not a
-        * {@link NullProgressMonitor}.
-        *
-        * @param progressMonitor
-        *            The parent {@link IProgressMonitor} of the
-        *            {@link SubProgressMonitor} to be created.
-        * @param ticks
-        *            The number of steps this subtask is subdivided into. Must be a
-        *            positive number and must not be
-        *            {@link IProgressMonitor#UNKNOWN}.
-        * @return The {@link IProgressMonitor}.
-        */
-       public static IProgressMonitor getSubProgressMonitor(
-                       IProgressMonitor progressMonitor, int ticks) {
-               if (progressMonitor == null) {
-                       return new NullProgressMonitor();
-               }
-               if (progressMonitor instanceof NullProgressMonitor) {
-                       return progressMonitor;
-               }
-
-               return new SubProgressMonitor(progressMonitor, ticks);
-       }
-
-       /**
-        * Checks whether the user canceled this operation. If not canceled, the
-        * given number of steps are declared as done.
-        *
-        * @param newMonitor
-        *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
-        * @param steps
-        *            a int.
-        */
-       public static void workedChecked(IProgressMonitor newMonitor, int steps) {
-               // In case the progress monitor was canceled throw an exception.
-               if (newMonitor.isCanceled()) {
-                       throw new OperationCanceledException();
-               }
-               // Otherwise declare this step as done.
-               newMonitor.worked(steps);
-       }
-
-       /**
-        * Present a progress dialog to the user. This dialog will block the UI
-        *
-        * @param runnable
-        *            an implementation of {@link IRunnableWithProgress}
-        * @throws java.lang.InterruptedException
-        *             if any.
-        * @throws java.lang.reflect.InvocationTargetException
-        *             if any.
-        */
-       public static void busyCursorWhile(IRunnableWithProgress runnable)
-                       throws InvocationTargetException, InterruptedException {
-               getProgressService().busyCursorWhile(runnable);
-       }
-
-       /**
-        * <p>
-        * runInUI
-        * </p>
-        *
-        * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
-        * @param runnable
-        *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
-        *            object.
-        * @param rule
-        *            a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
-        *            object.
-        * @throws java.lang.reflect.InvocationTargetException
-        *             if any.
-        * @throws java.lang.InterruptedException
-        *             if any.
-        */
-       public static void runInUI(IRunnableWithProgress runnable,
-                       ISchedulingRule rule) throws InvocationTargetException,
-                       InterruptedException {
-               getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
-       }
-
-       /**
-        * <p>
-        * run
-        * </p>
-        *
-        * @param fork
-        *            a boolean.
-        * @param cancelable
-        *            a boolean.
-        * @param runnable
-        *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
-        *            object.
-        * @throws java.lang.reflect.InvocationTargetException
-        *             if any.
-        * @throws java.lang.InterruptedException
-        *             if any.
-        */
-       public static void run(boolean fork, boolean cancelable,
-                       IRunnableWithProgress runnable) throws InvocationTargetException,
-                       InterruptedException {
-               getProgressService().run(fork, cancelable, runnable);
-       }
-
-       /**
-        * <p>
-        * getProgressService
-        * </p>
-        *
-        * @return a {@link org.eclipse.ui.progress.IProgressService} object.
-        */
-       public static IProgressService getProgressService() {
-               IWorkbench workbench = PlatformUI.getWorkbench();
-               return workbench.getProgressService();
-       }
-
-       /**
-        * <p>
-        * getProgressService2
-        * </p>
-        *
-        * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
-        *         object.
-        */
-       public static IWorkbenchSiteProgressService getProgressService2() {
-               return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
-       }
-
-       /**
-        * <p>
-        * getPluginId
-        * </p>
-        *
-        * @return a {@link java.lang.String} object.
-        */
-       public static String getPluginId() {
-               return "eu.taxeditor";
-       }
-
-       /**
-        * <p>
-        * getActiveEditor
-        * </p>
-        *
-        * @return a {@link org.eclipse.ui.IEditorPart} object.
-        */
-       public static IEditorPart getActiveEditor() {
-               return getActivePage() != null ? getActivePage().getActiveEditor()
-                               : null;
-       }
-
-       /**
-        * <p>
-        * getDetailsView
-        * </p>
-        *
-        * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
-        *         object.
-        */
-       public static DetailsViewPart getDetailsView() {
-               return (DetailsViewPart) getView(DetailsViewPart.ID, false);
-       }
-
-       /**
-        * <p>
-        * refreshDetailsViewer
-        * </p>
-        */
-       public static void refreshDetailsViewer() {
-               if (getDetailsView() != null) {
-                       ((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
-               }
-       }
-
-       /**
-        * <p>
-        * reflowDetailsViewer
-        * </p>
-        */
-       public static void reflowDetailsViewer() {
-               if (getDetailsView() != null) {
-                       ((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
-               }
-       }
-
-       public static SupplementalDataViewPart getSupplementalDataView() {
-               return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID,
-                               false);
-       }
-
-       public static void reflowSupplementalViewer() {
-               if (getSupplementalDataView() != null) {
-                       ((AbstractCdmDataViewer) getSupplementalDataView().getViewer())
-                                       .reflow();
-               }
-       }
+                statusLineManager.setMessage(message);
+            }
+
+        });
+
+    }
+
+    /**
+     * <p>
+     * getMonitor
+     * </p>
+     *
+     * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
+     */
+    public static IProgressMonitor getMonitor() {
+        statusLineManager.setCancelEnabled(false);
+        return statusLineManager.getProgressMonitor();
+    }
+
+    /**
+     * Starts either the given {@link IProgressMonitor} if it's not
+     * <code>null</code> or a new {@link NullProgressMonitor}.
+     *
+     * @param progressMonitor
+     *            The {@link IProgressMonitor} or <code>null</code> if no
+     *            progress should be reported.
+     * @param taskName
+     *            The name of the main task.
+     * @param steps
+     *            The number of steps this task is subdivided into.
+     * @return The {@link IProgressMonitor}.
+     */
+    public static IProgressMonitor startMainMonitor(
+            IProgressMonitor progressMonitor, String taskName, int steps) {
+        IProgressMonitor newMonitor = progressMonitor;
+        if (newMonitor == null) {
+            newMonitor = new NullProgressMonitor();
+        }
+        newMonitor.beginTask(taskName == null ? "" : taskName, steps);
+        newMonitor.subTask(" ");
+        return newMonitor;
+    }
+
+    /**
+     * Creates a {@link SubProgressMonitor} if the given
+     * {@link IProgressMonitor} is not <code>null</code> and not a
+     * {@link NullProgressMonitor}.
+     *
+     * @param progressMonitor
+     *            The parent {@link IProgressMonitor} of the
+     *            {@link SubProgressMonitor} to be created.
+     * @param ticks
+     *            The number of steps this subtask is subdivided into. Must be a
+     *            positive number and must not be
+     *            {@link IProgressMonitor#UNKNOWN}.
+     * @return The {@link IProgressMonitor}.
+     */
+    public static IProgressMonitor getSubProgressMonitor(
+            IProgressMonitor progressMonitor, int ticks) {
+        if (progressMonitor == null) {
+            return new NullProgressMonitor();
+        }
+        if (progressMonitor instanceof NullProgressMonitor) {
+            return progressMonitor;
+        }
+
+        return new SubProgressMonitor(progressMonitor, ticks);
+    }
+
+    /**
+     * Checks whether the user canceled this operation. If not canceled, the
+     * given number of steps are declared as done.
+     *
+     * @param newMonitor
+     *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
+     * @param steps
+     *            a int.
+     */
+    public static void workedChecked(IProgressMonitor newMonitor, int steps) {
+        // In case the progress monitor was canceled throw an exception.
+        if (newMonitor.isCanceled()) {
+            throw new OperationCanceledException();
+        }
+        // Otherwise declare this step as done.
+        newMonitor.worked(steps);
+    }
+
+    /**
+     * Present a progress dialog to the user. This dialog will block the UI
+     *
+     * @param runnable
+     *            an implementation of {@link IRunnableWithProgress}
+     * @throws java.lang.InterruptedException
+     *             if any.
+     * @throws java.lang.reflect.InvocationTargetException
+     *             if any.
+     */
+    public static void busyCursorWhile(IRunnableWithProgress runnable)
+            throws InvocationTargetException, InterruptedException {
+        getProgressService().busyCursorWhile(runnable);
+    }
+
+    /**
+     * <p>
+     * runInUI
+     * </p>
+     *
+     * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
+     * @param runnable
+     *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
+     *            object.
+     * @param rule
+     *            a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
+     *            object.
+     * @throws java.lang.reflect.InvocationTargetException
+     *             if any.
+     * @throws java.lang.InterruptedException
+     *             if any.
+     */
+    public static void runInUI(IRunnableWithProgress runnable,
+            ISchedulingRule rule) throws InvocationTargetException,
+            InterruptedException {
+        getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
+    }
+
+    /**
+     * <p>
+     * run
+     * </p>
+     *
+     * @param fork
+     *            a boolean.
+     * @param cancelable
+     *            a boolean.
+     * @param runnable
+     *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
+     *            object.
+     * @throws java.lang.reflect.InvocationTargetException
+     *             if any.
+     * @throws java.lang.InterruptedException
+     *             if any.
+     */
+    public static void run(boolean fork, boolean cancelable,
+            IRunnableWithProgress runnable) throws InvocationTargetException,
+            InterruptedException {
+        getProgressService().run(fork, cancelable, runnable);
+    }
+
+    /**
+     * <p>
+     * getProgressService
+     * </p>
+     *
+     * @return a {@link org.eclipse.ui.progress.IProgressService} object.
+     */
+    public static IProgressService getProgressService() {
+        IWorkbench workbench = PlatformUI.getWorkbench();
+        return workbench.getProgressService();
+    }
+
+    /**
+     * <p>
+     * getProgressService2
+     * </p>
+     *
+     * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
+     *         object.
+     */
+    public static IWorkbenchSiteProgressService getProgressService2() {
+        return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
+    }
+
+    /**
+     * <p>
+     * getPluginId
+     * </p>
+     *
+     * @return a {@link java.lang.String} object.
+     */
+    public static String getPluginId() {
+        return "eu.taxeditor";
+    }
+
+    /**
+     * <p>
+     * getActiveEditor
+     * </p>
+     *
+     * @return a {@link org.eclipse.ui.IEditorPart} object.
+     */
+    public static IEditorPart getActiveEditor() {
+        return getActivePage() != null ? getActivePage().getActiveEditor()
+                : null;
+    }
+
+    /**
+     * <p>
+     * getDetailsView
+     * </p>
+     *
+     * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
+     *         object.
+     */
+    public static DetailsViewPart getDetailsView() {
+        return (DetailsViewPart) getView(DetailsViewPart.ID, false);
+    }
+
+    /**
+     * <p>
+     * refreshDetailsViewer
+     * </p>
+     */
+    public static void refreshDetailsViewer() {
+        if (getDetailsView() != null) {
+            ((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
+        }
+    }
+
+    /**
+     * <p>
+     * reflowDetailsViewer
+     * </p>
+     */
+    public static void reflowDetailsViewer() {
+        if (getDetailsView() != null) {
+            ((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
+        }
+    }
+
+    public static SupplementalDataViewPart getSupplementalDataView() {
+        return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID,
+                false);
+    }
+
+    public static void reflowSupplementalViewer() {
+        if (getSupplementalDataView() != null) {
+            ((AbstractCdmDataViewer) getSupplementalDataView().getViewer())
+            .reflow();
+        }
+    }
 
 
     /**