From 70264b7f3b6c20dd3a7dfc9e3bc2ed8a298bc7a8 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Thu, 7 Jul 2011 16:13:30 +0000 Subject: [PATCH] Taxa that are part of multiple classifications can now be edited. --- .gitattributes | 1 + .../ChooseFromMultipleTaxonNodesDialog.java | 92 +++++++++++++++++++ .../taxeditor/editor/TaxonEditorInput.java | 14 ++- 3 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java diff --git a/.gitattributes b/.gitattributes index a3ec94c29..ba44754d2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 index 000000000..dd5a51271 --- /dev/null +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java @@ -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; + +/** + *

ChooseClassificationWizard class.

+ * + * @author n.hoffmann + * @created 19.03.2009 + * @version 1.0 + */ +public class ChooseFromMultipleTaxonNodesDialog extends ListDialog { + + public static TaxonNode choose(Set 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 taxonNodes = (Set) inputElement; + + List classifications = new ArrayList(); + + 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) { + + } + } +} diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java index 99eb505c4..c9af4f016 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java @@ -138,21 +138,19 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe return input; } - - - - + private static TaxonEditorInput getInputForMultipleNodes(ConversationHolder conversation, Set 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; } -- 2.34.1