Project

General

Profile

Download (2.52 KB) Statistics
| Branch: | Tag: | Revision:
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
}
(2-2/18)