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
.service
.IClassificationService
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
35 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
36 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
;
52 private final List
<UUID
> excludeTaxa
;
54 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
55 String title
, List
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, Classification classification
) {
56 super(shell
, //conversation,
57 title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
59 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
61 setListLabelProvider(labelProvider
);
62 // setDetailsLabelProvider(labelProvider);
63 this.excludeTaxa
= excludeTaxa
;
64 if(classification
!= null){
65 selectedClassification
= classification
;
68 fillClassifications();
69 createClassificationSelectionCombo(shell
);
74 protected Control
createDialogArea(Composite parent
) {
75 Composite container
= (Composite
) super.createDialogArea(parent
);
76 return createClassificationSelectionCombo(container
);
80 * currently disabled tree selection composite
82 private Control
createClassificationSelectionCombo(Composite parent
){
83 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
85 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
86 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
88 GridLayout layout
= new GridLayout();
89 classificationSelection
.setLayout(layout
);
91 Label label
= new Label(classificationSelection
, SWT
.NULL
);
92 // TODO not working is not really true but leave it here to remind everyone that this is under construction
93 label
.setText("Select Classification");
94 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
95 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
97 for(Classification tree
: classifications
){
98 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
102 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
104 // TODO remember last selection
105 classificationSelectionCombo
.addSelectionListener(this);
109 return classificationSelection
;
114 protected String
getTitle(TaxonNode taxonNode
) {
115 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
116 return taxonNode
.getTaxon().getTitleCache();
124 protected TaxonNode
getPersistentObject(UUID uuid
) {
125 return CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(uuid
);
130 protected void callService(String pattern
) {
131 model
= CdmStore
.getService(IClassificationService
.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification
.getUuid(), limitOfInitialElements
, pattern
);
134 private void fillClassifications() {
135 if(classifications
== null){
136 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
137 Collections
.sort(classifications
, new Comparator
<Classification
>() {
140 public int compare(Classification o1
, Classification o2
) {
144 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
146 return o1
.getUuid().compareTo(o2
.getUuid());
151 if (selectedClassification
== null){
152 if (this.cdmBaseToBeFiltered
== null){
153 selectedClassification
= classifications
.iterator().next();
155 selectedClassification
= this.cdmBaseToBeFiltered
.getClassification();
163 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
169 protected String
[] getNewWizardText() {
175 public void widgetSelected(SelectionEvent e
) {
176 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
179 if (getSearchField().getText() != null){
186 public void widgetDefaultSelected(SelectionEvent e
) {}