DeleteResult handling in DeleteSynonymOperation
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / MultiPageTaxonEditor.java
index 669c354dc6d268f6a44b04402f8d47f805c64af5..a55a03de33824865111ca34a73e4c317c899628a 100644 (file)
@@ -1,8 +1,8 @@
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -32,24 +32,27 @@ import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.DataChangeBridge;
 import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
+import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 
 /**
- * 
+ *
  * Generates the tabbed editor with <code>TaxonNameEditor</code> on top and tabs
  * for "Descriptions", "Concepts", "Geography", etc.
- * 
+ *
  * @author p.ciardelli
  * @author n.hoffmann
  * @created 15.05.2008
  * @version 1.0
  */
 public class MultiPageTaxonEditor extends FormEditor implements
-               IConversationEnabled, IPostOperationEnabled,
+        IPartContentHasFactualData, IConversationEnabled, IPostOperationEnabled,
                IDirtyMarkableSelectionProvider, IPartContentHasDetails, ISecuredEditor {
 
        /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.taxon"{trunked}</code> */
@@ -83,7 +86,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
         */
        /** {@inheritDoc} */
@@ -107,7 +110,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
                        // EditorUtil.showPropertySheet();
 
                } catch (PartInitException e) {
-                       EditorUtil.error(getClass(), e);
+                       MessagingUtils.error(getClass(), e);
                }
        }
 
@@ -121,41 +124,33 @@ public class MultiPageTaxonEditor extends FormEditor implements
                        }
                        monitor.worked(1);
 
-                       for (IEditorPart editorPage : getPages()) {
-                               if (editorPage instanceof TaxonNameEditor) {
-                                       if (((TaxonNameEditor) editorPage).checkForEmptyNames()) {
-                                               MessageDialog
-                                                               .openWarning(
-                                                                               EditorUtil.getShell(),
-                                                                               "No Name Specified",
-                                                                               "An attempt was made to save a taxon or synonym with "
-                                                                                               + "an empty name. Operation was cancelled.");
-                                               return;
-                                       }
-                               }
-
-                               editorPage.doSave(monitor);
-                               monitor.worked(1);
-                       }
+            for (IEditorPart editorPage : getPages()) {
+                if (editorPage instanceof TaxonNameEditor) {
+                    if (((TaxonNameEditor) editorPage).checkForEmptyNames()) {
+                        MessageDialog.openWarning(AbstractUtility.getShell(), "No Name Specified",
+                                "An attempt was made to save a taxon or synonym with "
+                                        + "an empty name. Operation was cancelled.");
+                        return;
+                    }
+                }
+
+                editorPage.doSave(monitor);
+                monitor.worked(1);
+            }
 
                        // commit the conversation and start a new transaction immediately
                        conversation.commit(true);
                        monitor.worked(1);
 
-                       this.setDirty(false);
-                       monitor.worked(1);
-               } catch (Exception e) {
-                       setFocus();
-                       EditorUtil
-                                       .errorDialog(
-                                                       "An error occurred while saving",
-                                                       getClass(),
-                                                       "An error occurred while saving the editor. Please close and reopen the taxon again.",
-                                                       e);
-                       disableEditor(true);
-               } finally {
-                       monitor.done();
-               }
+            this.setDirty(false);
+            monitor.worked(1);            
+        } catch (Exception e) {
+            setFocus();
+            MessagingUtils.operationDialog(this, e, "saving a taxon", " Please close and reopen the taxon again.");
+            disableEditor(true);
+        } finally {
+            monitor.done();
+        }
        }
 
        private void disableEditor(boolean isOnError) {
@@ -163,7 +158,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
                        if(isOnError){
                                editorPage.setOnError();
                        }else {
-                               editorPage.setDisabled();                               
+                               editorPage.setDisabled();
                        }
                }
                conversation.unregisterForDataStoreChanges(this);
@@ -178,23 +173,24 @@ public class MultiPageTaxonEditor extends FormEditor implements
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty()
         */
        /**
         * <p>
         * isDirty
         * </p>
-        * 
+        *
         * @return a boolean.
         */
-       public boolean isDirty() {
+       @Override
+    public boolean isDirty() {
                return dirty;
        }
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
         */
        /** {@inheritDoc} */
@@ -206,7 +202,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
 
        /**
         * {@inheritDoc}
-        * 
+        *
         * Checks whether nested editors are calling
         * <code>firePropertyChange(PROP_DIRTY)</code> to signal an edit has taken
         * place before passing property change along to
@@ -214,10 +210,11 @@ public class MultiPageTaxonEditor extends FormEditor implements
         */
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int)
         */
-       protected void handlePropertyChange(int propertyId) {
+       @Override
+    protected void handlePropertyChange(int propertyId) {
                if (propertyId == PROP_DIRTY) {
                        setDirty(true);
                }
@@ -240,9 +237,10 @@ public class MultiPageTaxonEditor extends FormEditor implements
        public void init(IEditorSite site, IEditorInput input)
                        throws PartInitException {
 
-               if (!(input instanceof TaxonEditorInput))
-                       throw new PartInitException(
+               if (!(input instanceof TaxonEditorInput)) {
+            throw new PartInitException(
                                        "Invalid Input: Must be TaxonEditorInput");
+        }
 
                this.input = (TaxonEditorInput) input;
 
@@ -289,29 +287,29 @@ public class MultiPageTaxonEditor extends FormEditor implements
                setPartName(partName);
        }
 
-       /**
-        * {@inheritDoc}
-        * 
-        * Editor pages call this in their postOperation to notify the
-        * MultiPageTaxonEditor of unsaved changes
-        */
-       public void changed(Object element) {
-               // setDirty(true);
-               dirty = true;
-               super.editorDirtyStateChanged();
-               if (element instanceof TaxonBase) {
-                       TaxonNameEditor page = (TaxonNameEditor) getPage(Page.NAME);
-                       AbstractGroupedContainer container = page
-                                       .getContainer((TaxonBase) element);
-                       if (container != null) {
-                               container.refresh();
-                       }
-               }
-       }
+    /**
+     * {@inheritDoc}
+     *
+     * Editor pages call this in their postOperation to notify the
+     * MultiPageTaxonEditor of unsaved changes
+     */
+    @Override
+    public void changed(Object element) {
+        // setDirty(true);
+        dirty = true;
+        super.editorDirtyStateChanged();
+        if (element instanceof TaxonBase) {
+            TaxonNameEditor page = (TaxonNameEditor) getPage(Page.NAME);
+            AbstractGroupedContainer container = page.getContainer((TaxonBase) element);
+            if (container != null) {
+                container.refresh();
+            }
+        }
+    }
 
        /**
         * The accepted taxon that is the input for this editor
-        * 
+        *
         * @return the accepted taxon
         */
        public Taxon getTaxon() {
@@ -320,7 +318,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
         * ()
@@ -329,11 +327,12 @@ public class MultiPageTaxonEditor extends FormEditor implements
         * <p>
         * getConversationHolder
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
         *         object.
         */
-       public ConversationHolder getConversationHolder() {
+       @Override
+    public ConversationHolder getConversationHolder() {
                return conversation;
        }
 
@@ -341,7 +340,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
         * <p>
         * setConversationHolder
         * </p>
-        * 
+        *
         * @param conversation
         *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
         *            object.
@@ -354,7 +353,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
         * <p>
         * Getter for the field <code>undoContext</code>.
         * </p>
-        * 
+        *
         * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
         *         object.
         */
@@ -366,7 +365,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
         * <p>
         * Setter for the field <code>undoContext</code>.
         * </p>
-        * 
+        *
         * @param undoContext
         *            a {@link org.eclipse.core.commands.operations.IUndoContext}
         *            object.
@@ -385,53 +384,50 @@ public class MultiPageTaxonEditor extends FormEditor implements
                getActiveEditor().setFocus();
        }
 
-       /*
-        * (non-Javadoc)
-        * 
-        * @see
-        * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu
-        * .etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
-        */
-       /** {@inheritDoc} */
-       public void update(CdmDataChangeMap events) {
-               if (dataChangeBehavior == null) {
-                       dataChangeBehavior = new MultiPageTaxonEditorDataChangeBehaviour(
-                                       this);
-               }
-
-               DataChangeBridge.handleDataChange(events, dataChangeBehavior);
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see
-        * eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation
-        * ()
-        */
-       /** {@inheritDoc} */
-       public boolean postOperation(CdmBase objectAffectedByOperation) {
-               setDirty(true);
-
-               for (IEditorPart editor : this.getPages()) {
-                       if (editor instanceof IPostOperationEnabled) {
-                               ((IPostOperationEnabled) editor)
-                                               .postOperation(objectAffectedByOperation);
-                       } else {
-                               EditorUtil.warn(getClass(),
-                                               "postOperation not enabled for editor " + editor);
-                       }
-               }
-               EditorUtil
-                               .warn(getClass(),
-                                               "postOperation called on MultiPageTaxonEditor. Can you make it more specific?");
-
-               return false;
-       }
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu
+     * .etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void update(CdmDataChangeMap events) {
+        if (dataChangeBehavior == null) {
+            dataChangeBehavior = new MultiPageTaxonEditorDataChangeBehaviour(this);
+        }
+
+        DataChangeBridge.handleDataChange(events, dataChangeBehavior);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation
+     * ()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public boolean postOperation(CdmBase objectAffectedByOperation) {
+        setDirty(true);
+
+        for (IEditorPart editor : this.getPages()) {
+            if (editor instanceof IPostOperationEnabled) {
+                ((IPostOperationEnabled) editor).postOperation(objectAffectedByOperation);
+            } else {
+                MessagingUtils.warn(getClass(), "postOperation not enabled for editor " + editor);
+            }
+        }
+        MessagingUtils.warn(getClass(), "postOperation called on MultiPageTaxonEditor. Can you make it more specific?");
+
+        return false;
+    }
 
        /**
         * Returns an <code>IEditorPart</code> implementation by type
-        * 
+        *
         * @param page
         *            the page type
         * @return a {@link eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage}
@@ -449,7 +445,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
        /**
         * Return a list of <code>AbstractTaxonEditor</code>s registered with this
         * <code>MultiPageTaxonEditor</code>.
-        * 
+        *
         * @return a {@link java.util.List} object.
         */
        public List<IMultiPageTaxonEditorPage> getPages() {
@@ -463,7 +459,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
 
        /**
         * Refreshes a certain page of the MultipageTaxonEditor
-        * 
+        *
         * @param page
         *            a {@link eu.etaxonomy.taxeditor.editor.Page} object.
         * @return a boolean.
@@ -475,7 +471,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
        /**
         * Refreshes a certain page of the MultipageTaxonEditor and sets focus to
         * that page
-        * 
+        *
         * @param page
         *            a {@link eu.etaxonomy.taxeditor.editor.Page} object.
         * @param focus
@@ -491,46 +487,42 @@ public class MultiPageTaxonEditor extends FormEditor implements
         * <p>
         * onComplete
         * </p>
-        * 
+        *
         * @return a boolean.
         */
-       public boolean onComplete() {
+       @Override
+    public boolean onComplete() {
                return false;
        }
 
-       /**
-        * Reloads the data for this
-        */
-       public void reload() {
-               if (isDirty()) {
-                       EditorUtil
-                                       .warningDialog(
-                                                       "Editor has unsaved data",
-                                                       getClass(),
-                                                       "This editor can not be "
-                                                                       + "refreshed because it contains unsaved data. Refreshing "
-                                                                       + "this editor would discard the changes. Please save this editor, "
-                                                                       + "close and reopen it manually in order to get the latest content");
-               } else {
-                       TaxonEditorInput input = (TaxonEditorInput) getEditorInput();
-
-                       UUID uuid = input.getTaxonNode().getUuid();
-
-                       conversation.clear();
-
-                       try {
-                               TaxonEditorInput newInput = TaxonEditorInput.NewInstance(uuid);
-                               setInput(newInput);
-                               for (IMultiPageTaxonEditorPage editorPart : getPages()) {
-                                       editorPart.redraw();
-                               }
-                       } catch (Exception e) {
-                               EditorUtil.errorDialog("Error refreshing editor", getClass(),
-                                               "Could not refresh this editor", e);
-                       }
-               }
-       }
-       
+    /**
+     * Reloads the data for this
+     */
+    public void reload() {
+        if (isDirty()) {
+            MessagingUtils.warningDialog("Editor has unsaved data", getClass(), "This editor can not be "
+                    + "refreshed because it contains unsaved data. Refreshing "
+                    + "this editor would discard the changes. Please save this editor, "
+                    + "close and reopen it manually in order to get the latest content");
+        } else {
+            TaxonEditorInput input = (TaxonEditorInput) getEditorInput();
+
+            UUID uuid = input.getTaxonNode().getUuid();
+
+            conversation.clear();
+
+            try {
+                TaxonEditorInput newInput = TaxonEditorInput.NewInstance(uuid);
+                setInput(newInput);
+                for (IMultiPageTaxonEditorPage editorPart : getPages()) {
+                    editorPart.redraw();
+                }
+            } catch (Exception e) {
+                MessagingUtils.messageDialog("Error refreshing editor", getClass(), "Could not refresh this editor", e);
+            }
+        }
+    }
+
        @Override
        public String toString() {
                return String.format("%s[%s]", this.getClass().getSimpleName(), getEditorInput());