Merge branch 'develop' into featureTreeEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / MultiPageTaxonEditor.java
index 6887838ddd4b127ed75a2d088b99913fd4aacbbd..e07239987cc8d24647173229e426ec8d6909dadf 100644 (file)
@@ -29,11 +29,13 @@ import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
@@ -58,10 +60,10 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  */
 public class MultiPageTaxonEditor extends FormEditor implements
 IPartContentHasFactualData, IConversationEnabled, IPostOperationEnabled,
-IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
+IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia, ITaxonEditor {
 
     /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.taxon"{trunked}</code> */
-    public static final String ID = "eu.etaxonomy.taxeditor.editor.taxon";
+    public static final String ID = "eu.etaxonomy.taxeditor.editor.taxon"; //$NON-NLS-1$
 
     private boolean dirty;
 
@@ -121,10 +123,21 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void pageChange(int newPageIndex) {
+        if(getCurrentPage()==-1){
+            return;
+        }
+        super.pageChange(newPageIndex);
+    }
+
     /** {@inheritDoc} */
     @Override
     public void doSave(IProgressMonitor monitor) {
-        monitor.beginTask("Saving Editor", 4);
+        monitor.beginTask(Messages.MultiPageTaxonEditor_SAVING_EDITOR, 4);
         try {
             if (!conversation.isBound()) {
                 conversation.bind();
@@ -134,9 +147,8 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
             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.");
+                        MessageDialog.openWarning(AbstractUtility.getShell(), Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED,
+                                Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED_MESSAGE);
                         return;
                     }
                 }
@@ -148,7 +160,7 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
             // commit the conversation and start a new transaction immediately
 
             input.merge();
-            
+
             conversation.commit(true);
             CdmApplicationState.getCurrentDataChangeService()
             .fireChangeEvent(new CdmChangeEvent(Action.Update, input.getTaxonNode() , MultiPageTaxonEditor.class), true);
@@ -158,7 +170,7 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
             monitor.worked(1);
         } catch (Exception e) {
             setFocus();
-            MessagingUtils.operationDialog(this, e, TaxeditorEditorPlugin.PLUGIN_ID,"saving a taxon", " Please close and reopen the taxon again.");
+            MessagingUtils.operationDialog(this, e, TaxeditorEditorPlugin.PLUGIN_ID,Messages.MultiPageTaxonEditor_SAVING_TAXON, Messages.MultiPageTaxonEditor_SAVING_TAXON_MESSAGE);
             disableEditor(true);
         } finally {
             monitor.done();
@@ -252,7 +264,7 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
 
         if (!(input instanceof TaxonEditorInput)) {
             throw new PartInitException(
-                    "Invalid Input: Must be TaxonEditorInput");
+                    Messages.MultiPageTaxonEditor_INVALID_INPUT);
         }
 
         this.input = (TaxonEditorInput) input;
@@ -288,14 +300,14 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
     protected void setPartName() {
 
         String partName = null;
-        TaxonNameBase<?, ?> name = getTaxon().getName();
+        TaxonName name = getTaxon().getName();
 
         if (name != null) {
             partName = name.getTitleCache();
         }
 
-        if (partName == null || partName.equals("")) {
-            partName = ("New taxon");
+        if (partName == null || partName.equals("")) { //$NON-NLS-1$
+            partName = (Messages.MultiPageTaxonEditor_NEW_TAXON);
         }
 
         setPartName(partName);
@@ -323,6 +335,13 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
                 container.refresh();
             }
         }
+        if (element instanceof TaxonRelationship) {
+            TaxonNameEditor page = (TaxonNameEditor) getPage(Page.NAME);
+            AbstractGroupedContainer container = page.getContainer(((TaxonRelationship) element).getFromTaxon());
+            if (container != null) {
+                container.refresh();
+            }
+        }
         //refresh part title
         //TODO: refresh taxon node in taxon navigator
         setPartName();
@@ -447,10 +466,10 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
             if (editor instanceof IPostOperationEnabled) {
                 ((IPostOperationEnabled) editor).postOperation(objectAffectedByOperation);
             } else {
-                MessagingUtils.warn(getClass(), "postOperation not enabled for editor " + editor);
+                MessagingUtils.warn(getClass(), Messages.MultiPageTaxonEditor_POST_OP_NOT_ENABLED + editor);
             }
         }
-        MessagingUtils.warn(getClass(), "postOperation called on MultiPageTaxonEditor. Can you make it more specific?");
+        MessagingUtils.warn(getClass(), Messages.MultiPageTaxonEditor_POST_OP_CALLED);
 
         return false;
     }
@@ -530,10 +549,7 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
      */
     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");
+            MessagingUtils.warningDialog(Messages.MultiPageTaxonEditor_UNSAVED_DATA, getClass(), Messages.MultiPageTaxonEditor_UNSAVED_DATA_MESSAGE);
         } else {
             TaxonEditorInput input = (TaxonEditorInput) getEditorInput();
 
@@ -548,14 +564,14 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
                     editorPart.redraw();
                 }
             } catch (Exception e) {
-                MessagingUtils.messageDialog("Error refreshing editor", getClass(), "Could not refresh this editor", e);
+                MessagingUtils.messageDialog(Messages.MultiPageTaxonEditor_REFRESH_ERROR, getClass(), Messages.MultiPageTaxonEditor_REFRESH_ERROR_MESSAGE, e);
             }
         }
     }
 
     @Override
     public String toString() {
-        return String.format("%s[%s]", this.getClass().getSimpleName(), getEditorInput());
+        return String.format("%s[%s]", this.getClass().getSimpleName(), getEditorInput()); //$NON-NLS-1$
     }
 
     @Override