4 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
6 import java
.util
.Collections
;
7 import java
.util
.Comparator
;
11 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Combo
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Label
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
36 public static TaxonNode
select(Shell shell
, ConversationHolder conversation
, String title
, List
<UUID
> excludeTaxa
, TaxonNode node
, Classification classification
) {
37 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
44 return getSelectionFromDialog(dialog
);
47 private Combo classificationSelectionCombo
;
49 private List
<Classification
> classifications
;
51 private Classification selectedClassification
;
53 protected TaxonNodeSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, List
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, Classification classification
) {
54 super(shell
, conversation
, title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
56 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
58 setListLabelProvider(labelProvider
);
59 setDetailsLabelProvider(labelProvider
);
61 if(classification
!= null){
62 selectedClassification
= classification
;
68 protected Control
createExtendedContentArea(Composite parent
) {
69 return createClassificationSelectionCombo(parent
);
73 * currently disabled tree selection composite
75 private Control
createClassificationSelectionCombo(Composite parent
){
76 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
78 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
79 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
81 GridLayout layout
= new GridLayout();
82 classificationSelection
.setLayout(layout
);
84 Label label
= new Label(classificationSelection
, SWT
.NULL
);
85 // TODO not working is not really true but leave it here to remind everyone that this is under construction
86 label
.setText("Select Classification");
87 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
88 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
90 for(Classification tree
: classifications
){
91 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
95 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
97 // TODO remember last selection
98 classificationSelectionCombo
.addSelectionListener(this);
102 return classificationSelection
;
107 protected String
getTitle(TaxonNode taxonNode
) {
108 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
109 return taxonNode
.getTaxon().getTitleCache();
117 protected TaxonNode
getPersistentObject(UUID uuid
) {
118 return CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(uuid
);
123 protected void initModel() {
124 // default to first tree
125 // TODO this will be problematic and can only be seen as workaround
128 if(classifications
== null){
129 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
130 Collections
.sort(classifications
, new Comparator
<Classification
>() {
133 public int compare(Classification o1
, Classification o2
) {
134 return o1
.getTitleCache().compareTo(o2
.getTitleCache());
137 selectedClassification
= classifications
.iterator().next();
140 model
= CdmStore
.getService(IClassificationService
.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification
);
145 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
151 protected String
getNewWizardLinkText() {
157 public void widgetSelected(SelectionEvent e
) {
158 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
166 public void widgetDefaultSelected(SelectionEvent e
) {}