2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 * <p>ChooseClassificationWizard class.</p>
33 public class ChooseFromMultipleTaxonNodesDialog
extends ListDialog
{
35 public static TaxonNode
choose(Set
<TaxonNode
> taxonNodes
){
36 ChooseFromMultipleTaxonNodesDialog dialog
= new ChooseFromMultipleTaxonNodesDialog(EditorUtil
.getShell());
37 dialog
.setInput(taxonNodes
);
38 int result
= dialog
.open();
40 if(result
== IStatus
.OK
){
41 Classification selectedClassification
= (Classification
) dialog
.getResult()[0];
43 for(TaxonNode taxonNode
: taxonNodes
){
44 if(taxonNode
.getClassification().equals(selectedClassification
)){
52 public ChooseFromMultipleTaxonNodesDialog(Shell 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());
60 private class ClassificationLabelProvider
extends LabelProvider
{
62 public String
getText(Object element
) {
63 return super.getText(((Classification
) element
).getTitleCache());
67 private class ClassificationContentProvider
implements IStructuredContentProvider
{
70 public Object
[] getElements(Object inputElement
) {
71 Set
<TaxonNode
> taxonNodes
= (Set
<TaxonNode
>) inputElement
;
73 List
<Classification
> classifications
= new ArrayList
<Classification
>();
75 for(TaxonNode node
: taxonNodes
){
76 classifications
.add(node
.getClassification());
79 return classifications
.toArray();
83 public void dispose() {
88 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {