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
;
25 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
28 * <p>ChooseClassificationWizard class.</p>
34 public class ChooseFromMultipleTaxonNodesDialog
extends ListDialog
{
36 public static TaxonNode
choose(Set
<TaxonNode
> taxonNodes
){
37 ChooseFromMultipleTaxonNodesDialog dialog
= new ChooseFromMultipleTaxonNodesDialog(EditorUtil
.getShell());
38 dialog
.setInput(taxonNodes
);
39 int result
= dialog
.open();
41 if(result
== IStatus
.OK
){
42 Classification selectedClassification
= (Classification
) dialog
.getResult()[0];
44 for(TaxonNode taxonNode
: taxonNodes
){
45 if(taxonNode
.getClassification().equals(selectedClassification
)){
53 public ChooseFromMultipleTaxonNodesDialog(Shell parent
) {
55 setTitle(Messages
.ChooseFromMultipleTaxonNodesDialog_CHOOSE_CLASSIFICATION
);
56 setMessage(Messages
.ChooseFromMultipleTaxonNodesDialog_CHOOSE_CLASSIFICATION_MESSAGE
);
57 setContentProvider(new ClassificationContentProvider());
58 setLabelProvider(new ClassificationLabelProvider());
61 private class ClassificationLabelProvider
extends LabelProvider
{
63 public String
getText(Object element
) {
64 return super.getText(((Classification
) element
).getTitleCache());
68 private class ClassificationContentProvider
implements IStructuredContentProvider
{
71 public Object
[] getElements(Object inputElement
) {
72 Set
<TaxonNode
> taxonNodes
= (Set
<TaxonNode
>) inputElement
;
74 List
<Classification
> classifications
= new ArrayList
<Classification
>();
76 for(TaxonNode node
: taxonNodes
){
77 classifications
.add(node
.getClassification());
80 return classifications
.toArray();
84 public void dispose() {
89 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {