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.
9 package eu
.etaxonomy
.taxeditor
.editor
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
17 import org
.eclipse
.jface
.viewers
.LabelProvider
;
18 import org
.eclipse
.jface
.viewers
.Viewer
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.ui
.dialogs
.ListDialog
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
24 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
27 * <p>ChooseClassificationWizard class.</p>
32 public class ChooseFromMultipleTaxonNodesDialog
extends ListDialog
{
34 public static TaxonNode
choose(Set
<TaxonNode
> taxonNodes
){
35 ChooseFromMultipleTaxonNodesDialog dialog
= new ChooseFromMultipleTaxonNodesDialog(EditorUtil
.getShell());
36 dialog
.setInput(taxonNodes
);
37 int result
= dialog
.open();
39 if(result
== IStatus
.OK
){
40 Classification selectedClassification
= (Classification
) dialog
.getResult()[0];
42 for(TaxonNode taxonNode
: taxonNodes
){
43 if(taxonNode
.getClassification().equals(selectedClassification
)){
51 public ChooseFromMultipleTaxonNodesDialog(Shell parent
) {
53 setTitle(Messages
.ChooseFromMultipleTaxonNodesDialog_CHOOSE_CLASSIFICATION
);
54 setMessage(Messages
.ChooseFromMultipleTaxonNodesDialog_CHOOSE_CLASSIFICATION_MESSAGE
);
55 setContentProvider(new ClassificationContentProvider());
56 setLabelProvider(new ClassificationLabelProvider());
59 private class ClassificationLabelProvider
extends LabelProvider
{
61 public String
getText(Object element
) {
62 return super.getText(((Classification
) element
).getTitleCache());
66 private class ClassificationContentProvider
implements IStructuredContentProvider
{
69 public Object
[] getElements(Object inputElement
) {
70 Set
<TaxonNode
> taxonNodes
= (Set
<TaxonNode
>) inputElement
;
72 List
<Classification
> classifications
= new ArrayList
<>();
74 for(TaxonNode node
: taxonNodes
){
75 classifications
.add(node
.getClassification());
78 return classifications
.toArray();
82 public void dispose() {
87 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {