Taxa that are part of multiple classifications can now be edited.
authorn.hoffmann <n.hoffmann@localhost>
Thu, 7 Jul 2011 16:13:30 +0000 (16:13 +0000)
committern.hoffmann <n.hoffmann@localhost>
Thu, 7 Jul 2011 16:13:30 +0000 (16:13 +0000)
.gitattributes
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java

index a3ec94c29306aa403c90eb539561afab126d0060..ba44754d2f55f3f58bac2aa4528da98e5c9a6a8a 100644 (file)
@@ -319,6 +319,7 @@ eu.etaxonomy.taxeditor.editor/plugin.properties -text
 eu.etaxonomy.taxeditor.editor/plugin.xml -text
 eu.etaxonomy.taxeditor.editor/pom.xml -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorStateManager.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/IDropTargetable.java -text
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java
new file mode 100644 (file)
index 0000000..dd5a512
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+* Copyright (C) 2007 EDIT
+* 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.
+*/
+
+package eu.etaxonomy.taxeditor.editor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ListDialog;
+
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+
+/**
+ * <p>ChooseClassificationWizard class.</p>
+ *
+ * @author n.hoffmann
+ * @created 19.03.2009
+ * @version 1.0
+ */
+public class ChooseFromMultipleTaxonNodesDialog extends ListDialog {
+
+       public static TaxonNode choose(Set<TaxonNode> taxonNodes){
+               ChooseFromMultipleTaxonNodesDialog dialog = new ChooseFromMultipleTaxonNodesDialog(EditorUtil.getShell());
+               dialog.setInput(taxonNodes);
+               int result = dialog.open();
+               
+               if(result == IStatus.OK){
+                       Classification selectedClassification = (Classification) dialog.getResult()[0];
+                       
+                       for(TaxonNode taxonNode : taxonNodes){
+                               if(taxonNode.getClassification().equals(selectedClassification)){
+                                       return taxonNode;
+                               }
+                       }
+               }
+               return null;
+       }
+       
+       public ChooseFromMultipleTaxonNodesDialog(Shell parent) {
+               super(parent);
+               setTitle("Choose Classification");
+               setMessage("The taxon is part of multiple classification. Please choose the one you want to open.");
+               setContentProvider(new ClassificationContentProvider());
+               setLabelProvider(new ClassificationLabelProvider());
+       }
+       
+       private class ClassificationLabelProvider extends LabelProvider{
+               @Override
+               public String getText(Object element) {
+                       return super.getText(((Classification) element).getTitleCache());
+               }
+       }
+       
+       private class ClassificationContentProvider implements IStructuredContentProvider{
+
+               @Override
+               public Object[] getElements(Object inputElement) {
+                       Set<TaxonNode> taxonNodes = (Set<TaxonNode>) inputElement;
+                               
+                               List<Classification> classifications = new ArrayList<Classification>(); 
+                               
+                               for(TaxonNode node : taxonNodes){
+                                       classifications.add(node.getClassification());
+                               }
+                               
+                               return classifications.toArray();
+               }
+               
+               @Override
+               public void dispose() {
+                       
+               }
+
+               @Override
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+                       
+               }               
+       }
+}
index 99eb505c45139adda824fbc0794286bd3016903d..c9af4f016d9a0a556ba60703ce5c09887ea3793e 100644 (file)
@@ -138,21 +138,19 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe
        
        return input;
     }
-
-
-
-
+    
        private static TaxonEditorInput getInputForMultipleNodes(ConversationHolder conversation, Set<TaxonNode> taxonNodes){
        if(taxonNodes.size() == 1){
                TaxonNode taxonNode = taxonNodes.iterator().next();
                return NewInstance(taxonNode.getUuid(), conversation);
        }else if(taxonNodes.size() > 1){
-                       // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
-                       EditorUtil.warningDialog("Not implemented yet", TaxonEditorInput.class, "The accepted taxon is in multiple taxonomic trees. We currently do not know which one you want to open." +
-                                       " This case is not handled yet by the software.");
+                       TaxonNode taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(taxonNodes);
+                       if(taxonNode != null){
+                               return NewInstance(taxonNode.getUuid(), conversation);                  
+                       }
                }else if(taxonNodes.size() == 0){
                        // this is an undesired state
-                       EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not in a taxonomic view. This should not have happened.");
+                       EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
                }
        return null;
     }