Project

General

Profile

« Previous | Next » 

Revision 70264b7f

Added by Niels Hoffmann almost 13 years ago

Taxa that are part of multiple classifications can now be edited.

View differences:

.gitattributes
319 319
eu.etaxonomy.taxeditor.editor/plugin.xml -text
320 320
eu.etaxonomy.taxeditor.editor/pom.xml -text
321 321
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java -text
322
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java -text
322 323
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorStateManager.java -text
323 324
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java -text
324 325
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/IDropTargetable.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/ChooseFromMultipleTaxonNodesDialog.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.editor;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.Set;
15

  
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.jface.viewers.IStructuredContentProvider;
18
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.jface.viewers.Viewer;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.ui.dialogs.ListDialog;
22

  
23
import eu.etaxonomy.cdm.model.taxon.Classification;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25

  
26
/**
27
 * <p>ChooseClassificationWizard class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created 19.03.2009
31
 * @version 1.0
32
 */
33
public class ChooseFromMultipleTaxonNodesDialog extends ListDialog {
34

  
35
	public static TaxonNode choose(Set<TaxonNode> taxonNodes){
36
		ChooseFromMultipleTaxonNodesDialog dialog = new ChooseFromMultipleTaxonNodesDialog(EditorUtil.getShell());
37
		dialog.setInput(taxonNodes);
38
		int result = dialog.open();
39
		
40
		if(result == IStatus.OK){
41
			Classification selectedClassification = (Classification) dialog.getResult()[0];
42
			
43
			for(TaxonNode taxonNode : taxonNodes){
44
				if(taxonNode.getClassification().equals(selectedClassification)){
45
					return taxonNode;
46
				}
47
			}
48
		}
49
		return null;
50
	}
51
	
52
	public ChooseFromMultipleTaxonNodesDialog(Shell parent) {
53
		super(parent);
54
		setTitle("Choose Classification");
55
		setMessage("The taxon is part of multiple classification. Please choose the one you want to open.");
56
		setContentProvider(new ClassificationContentProvider());
57
		setLabelProvider(new ClassificationLabelProvider());
58
	}
59
	
60
	private class ClassificationLabelProvider extends LabelProvider{
61
		@Override
62
		public String getText(Object element) {
63
			return super.getText(((Classification) element).getTitleCache());
64
		}
65
	}
66
	
67
	private class ClassificationContentProvider implements IStructuredContentProvider{
68

  
69
		@Override
70
		public Object[] getElements(Object inputElement) {
71
			Set<TaxonNode> taxonNodes = (Set<TaxonNode>) inputElement;
72
				
73
				List<Classification> classifications = new ArrayList<Classification>(); 
74
				
75
				for(TaxonNode node : taxonNodes){
76
					classifications.add(node.getClassification());
77
				}
78
				
79
				return classifications.toArray();
80
		}
81
		
82
		@Override
83
		public void dispose() {
84
			
85
		}
86

  
87
		@Override
88
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
89
			
90
		}		
91
	}
92
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java
138 138
    	
139 139
    	return input;
140 140
    }
141

  
142

  
143

  
144

  
141
    
145 142
	private static TaxonEditorInput getInputForMultipleNodes(ConversationHolder conversation, Set<TaxonNode> taxonNodes){
146 143
    	if(taxonNodes.size() == 1){
147 144
    		TaxonNode taxonNode = taxonNodes.iterator().next();
148 145
    		return NewInstance(taxonNode.getUuid(), conversation);
149 146
    	}else if(taxonNodes.size() > 1){
150
			// FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
151
			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." +
152
					" This case is not handled yet by the software.");
147
			TaxonNode taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(taxonNodes);
148
			if(taxonNode != null){
149
				return NewInstance(taxonNode.getUuid(), conversation);			
150
			}
153 151
		}else if(taxonNodes.size() == 0){
154 152
			// this is an undesired state
155
			EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not in a taxonomic view. This should not have happened.");
153
			EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
156 154
		}
157 155
    	return null;
158 156
    }

Also available in: Unified diff