Fixes #2235
authorl.morris <l.morris@localhost>
Tue, 31 Jan 2012 15:37:08 +0000 (15:37 +0000)
committerl.morris <l.morris@localhost>
Tue, 31 Jan 2012 15:37:08 +0000 (15:37 +0000)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineEditor.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/ContainerFactory.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/SwapSynonymAndAcceptedHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/IPostOperationEnabled.java

index 86806573103a966ed9fa4e8997b6439a47da0598..dd461e780bf7c76c185069310cbb05b019a5cfd1 100644 (file)
@@ -303,4 +303,5 @@ public class AnnotatedLineEditor extends TextEditor implements IConversationEnab
                // TODO Auto-generated method stub
                return false;
        }
+
 }
index f1758c8214856224cfac3634a61e5438f5091780..222bf2c60890352ea1fd390835eceeafa3645e9a 100644 (file)
@@ -272,7 +272,8 @@ public class EditorUtil extends AbstractUtility {
 
                        boolean doSave = MessageDialog
                                        .openConfirm(shell, "Confirm save",
-                                                       "The current editor must be saved before this action can be executed.");
+                                                       "Warning - this operation will save the editor. This will also save all other unsaved changes " +
+                                                       "in your working editor to the database. Please 'Cancel' if you are not ready to do this.");
 
                        if (!doSave) {
                                return false;
index c2a91c9e773d2a08e846132decd8ed4da7fcb380..951dbcae6df3b417bec14bf5ec71835cd20b3b9a 100644 (file)
@@ -21,7 +21,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.SWT;
@@ -64,7 +63,6 @@ import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup;
 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
 import eu.etaxonomy.taxeditor.editor.name.container.AcceptedGroup;
 import eu.etaxonomy.taxeditor.editor.name.container.AcceptedNameContainer;
-import eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup;
 import eu.etaxonomy.taxeditor.editor.name.container.ContainerFactory;
 import eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup;
 import eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup;
@@ -107,21 +105,16 @@ public class TaxonNameEditor extends EditorPart implements
        private final ConversationHolder conversation;
 
        private MenuManager menuManager;
-
        private Menu menu;
 
+       private AcceptedGroup acceptedGroup;
+       private List<HomotypicalSynonymGroup> heterotypicSynonymGroups = new ArrayList<HomotypicalSynonymGroup>();
        private MisappliedGroup misappliedGroup;
 
-       private ConceptGroup conceptGroup;
-
-       private final List<HomotypicalSynonymGroup> heterotypicSynonymGroups = new ArrayList<HomotypicalSynonymGroup>();
-
        private DropTarget target;
 
        private ISelectionService selectionService;
 
-       private AcceptedGroup acceptedGroup;
-
        private TaxonBase objectAffectedByLastOperation;
 
        /**
@@ -242,7 +235,6 @@ public class TaxonNameEditor extends EditorPart implements
                ContainerFactory.createOrUpdateAcceptedTaxonsHomotypicGroup(this);
                ContainerFactory.createOrUpdateHeterotypicSynonymyGroups(this);
                ContainerFactory.createOrUpdateMisapplicationsGroup(this);
-               ContainerFactory.createOrUpdateConceptGroup(this);
 
                // Redraw composite
                managedForm.reflow(true);
@@ -368,7 +360,7 @@ public class TaxonNameEditor extends EditorPart implements
        public boolean postOperation(CdmBase objectAffectedByOperation) {
 
                editor.changed(objectAffectedByOperation);
-
+               
                redraw(false);
 
                if (objectAffectedByOperation instanceof TaxonBase) {
@@ -552,19 +544,6 @@ public class TaxonNameEditor extends EditorPart implements
                return null;
        }
 
-       /**
-        * <p>
-        * Getter for the field <code>conceptGroup</code>.
-        * </p>
-        * 
-        * @return a
-        *         {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup}
-        *         object.
-        */
-       public ConceptGroup getConceptGroup() {
-               return conceptGroup;
-       }
-
        /**
         * <p>
         * getDirtyNames
@@ -613,16 +592,18 @@ public class TaxonNameEditor extends EditorPart implements
 
                allGroups.add(getAcceptedGroup());
 
-               allGroups.addAll(getHeterotypicSynonymGroups());
+               List<HomotypicalSynonymGroup> grps = getHeterotypicSynonymGroups();
+               
+               heterotypicSynonymGroups = getHeterotypicSynonymGroups();
+               
+               if (heterotypicSynonymGroups != null) {
+                       allGroups.addAll(heterotypicSynonymGroups);
+               }
 
                if (misappliedGroup != null) {
                        allGroups.add(misappliedGroup);
                }
 
-               if (conceptGroup != null) {
-                       allGroups.add(conceptGroup);
-               }
-
                return allGroups;
        }
 
@@ -729,19 +710,6 @@ public class TaxonNameEditor extends EditorPart implements
                                EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
        }
 
-       /**
-        * <p>
-        * Setter for the field <code>conceptGroup</code>.
-        * </p>
-        * 
-        * @param conceptGroup
-        *            a
-        *            {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup}
-        *            object.
-        */
-       public void setConceptGroup(ConceptGroup conceptGroup) {
-               this.conceptGroup = conceptGroup;
-       }
 
        /**
         * <p>
@@ -882,7 +850,10 @@ public class TaxonNameEditor extends EditorPart implements
        public void removeGroup(AbstractGroup group) {
                if (group != null) {
                        group.dispose();
-                       getHeterotypicSynonymGroups().remove(group);
+                       
+                       //if (heterotypicSynonymGroups != null) {
+                       heterotypicSynonymGroups.remove(group);
+                       //}
                }
        }
 
index 7672265680a8d913ee33d2ec737cb767c6c1f409..1634b7dcc860ac92238988c8800e382237447ca6 100644 (file)
@@ -43,8 +43,13 @@ public class ContainerFactory {
                        TaxonNameEditor taxonNameEditor) {
                List<HomotypicalSynonymGroup> retainedGroups = new ArrayList<HomotypicalSynonymGroup>();
                
-               for(HomotypicalSynonymGroup group : taxonNameEditor.getHeterotypicSynonymGroups()){
-                       retainedGroups.add(group);
+               List<HomotypicalSynonymGroup> heterotypicSynonymGroups = taxonNameEditor.getHeterotypicSynonymGroups();
+               
+               if (heterotypicSynonymGroups != null) {
+               
+                       for(HomotypicalSynonymGroup group : heterotypicSynonymGroups){
+                               retainedGroups.add(group);
+                       }
                }
                
                for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
@@ -96,23 +101,4 @@ public class ContainerFactory {
                
        }
 
-       /**
-        * @param taxonNameEditor
-        */
-       public static void createOrUpdateConceptGroup(
-                       TaxonNameEditor taxonNameEditor) {
-               Set<TaxonRelationship> filteredTaxonRelations = new HashSet<TaxonRelationship>();
-               
-               for (TaxonRelationship relationship : taxonNameEditor.getTaxon().getTaxonRelations()) {
-                       if (! relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
-                                        relationship.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
-                               filteredTaxonRelations.add(relationship);
-                       }
-               }
-               
-               if(! filteredTaxonRelations.isEmpty()){
-                       taxonNameEditor.setConceptGroup(new ConceptGroup(taxonNameEditor));
-               }
-       }
-
 }
index 879ec5fa72bb9e65ed9cc83732f7b3b77bc6bdca..507d44cf7748c8ee5f137be80c1983f156a40819 100644 (file)
@@ -16,13 +16,20 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.IHandler;
 import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
-import eu.etaxonomy.taxeditor.editor.Page;
-import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 
 /**
  * <p>SwapSynonymAndAcceptedHandler class.</p>
@@ -32,27 +39,31 @@ import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperat
  * @version 1.0
  */
 public class SwapSynonymAndAcceptedHandler extends AbstractHandler implements
-               IHandler {
+               IHandler, IPostOperationEnabled {
        private static final Logger logger = Logger
                        .getLogger(SwapSynonymAndAcceptedHandler.class);
+       private MultiPageTaxonEditor editor;
+       private Taxon taxon;
 
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               MultiPageTaxonEditor multiEditor = EditorUtil.getActiveMultiPageTaxonEditor();
-
-               TaxonNameEditor editor = (TaxonNameEditor) multiEditor.getPage(Page.NAME);
-               
+               editor = EditorUtil.getActiveMultiPageTaxonEditor();
+               Shell shell = HandlerUtil.getActiveShell(event);
                Synonym synonym = (Synonym) EditorUtil.getSelection(event).getFirstElement();
                
-               
-               SwapSynonymAndAcceptedOperation operation;
+
+               // Force user to save taxon - not really necessary though, is it?
+               if (!EditorUtil.forceUserSave(editor, shell)) {
+                       return null;
+               }
                
                try {
-                       operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(), editor.getUndoContext(),
-                                                               editor.getTaxon(), synonym, editor);
+                       SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(), editor.getUndoContext(),
+                                                               editor.getTaxon(), synonym, this);
+                       
                        EditorUtil.executeOperation(operation);
                        
                } catch (NotDefinedException e) {
@@ -61,4 +72,44 @@ public class SwapSynonymAndAcceptedHandler extends AbstractHandler implements
 
                return null;
        }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
+        */
+       @Override
+       public boolean postOperation(CdmBase objectAffectedByOperation) {
+               // Redraw existing editor
+               //((IPostOperationEnabled) editor).postOperation(null);
+               
+               editor.doSave(EditorUtil.getMonitor());
+               editor.close(true);
+               
+               if (objectAffectedByOperation instanceof Taxon) {
+               
+                       taxon = (Taxon) objectAffectedByOperation;
+                                       
+                       
+               }
+               return true;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
+        */
+       @Override
+       public boolean onComplete() {
+               Display display = Display.getCurrent();
+               display.asyncExec(new Runnable() {
+                       public void run() {
+                               try {
+                                       EditorUtil.openTaxonBase(taxon.getUuid());
+                                       
+                               } catch (Exception e) {
+                                       EditorUtil.warningDialog("Could not open editor for taxon", this, e.getMessage());
+                               }
+                               
+                       }
+               });
+               return true;
+       }
 }
index 4926128addfa6dcdeb7bfe2492c02d5f493a8bda..0758a17b23e00c66a70d9cf04cba6bcde4d4e9d6 100644 (file)
@@ -15,11 +15,14 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 
 import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -61,7 +64,7 @@ public class SwapSynonymAndAcceptedOperation extends AbstractPostOperation {
        @Override
        public IStatus execute(IProgressMonitor monitor, IAdaptable info)
                        throws ExecutionException {
-
+               
                monitor.worked(20);
                
                CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym, taxon);
index e9bd3b1344af6897ffe22bc2204fbf09a2103a16..40e533a0ff457cc3e5291601ed3f1ee276241aa8 100644 (file)
@@ -37,7 +37,7 @@ public interface IPostOperationEnabled {
         *         might not be what you want.
         */
        public boolean postOperation(CdmBase objectAffectedByOperation);
-
+       
        /**
         * This method will get called after the execution took place and occasional
         * cleanups were performed. This is typically the last thing to happen.
@@ -45,4 +45,5 @@ public interface IPostOperationEnabled {
         * @return a boolean.
         */
        public boolean onComplete();
+       
 }