4 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
6 import java
.util
.Collections
;
7 import java
.util
.Comparator
;
11 import org
.eclipse
.core
.runtime
.CoreException
;
12 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Combo
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Control
;
21 import org
.eclipse
.swt
.widgets
.Label
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.swt
.widgets
.Text
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
37 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
38 String title
, List
<UUID
> excludeTaxa
, TaxonNode node
, Classification classification
) {
39 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
46 return getSelectionFromDialog(dialog
);
49 private Combo classificationSelectionCombo
;
51 private List
<Classification
> classifications
;
53 private Classification selectedClassification
;
54 private final List
<UUID
> excludeTaxa
;
56 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
57 String title
, List
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, Classification classification
) {
58 super(shell
, //conversation,
59 title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
61 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
63 setListLabelProvider(labelProvider
);
64 // setDetailsLabelProvider(labelProvider);
65 this.excludeTaxa
= excludeTaxa
;
66 if(classification
!= null){
67 selectedClassification
= classification
;
70 fillClassifications();
71 createClassificationSelectionCombo(shell
);
76 protected Control
createDialogArea(Composite parent
) {
77 Composite container
= (Composite
) super.createDialogArea(parent
);
78 return createClassificationSelectionCombo(container
);
82 * currently disabled tree selection composite
84 private Control
createClassificationSelectionCombo(Composite parent
){
85 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
87 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
88 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
90 GridLayout layout
= new GridLayout();
91 classificationSelection
.setLayout(layout
);
93 Label label
= new Label(classificationSelection
, SWT
.NULL
);
94 // TODO not working is not really true but leave it here to remind everyone that this is under construction
95 label
.setText("Select Classification");
96 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
97 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
99 for(Classification tree
: classifications
){
100 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
104 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
106 // TODO remember last selection
107 classificationSelectionCombo
.addSelectionListener(this);
111 return classificationSelection
;
116 protected String
getTitle(TaxonNode taxonNode
) {
117 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
118 return taxonNode
.getTaxon().getTitleCache();
126 protected TaxonNode
getPersistentObject(UUID uuid
) {
127 return CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(uuid
);
132 protected void search() {
133 // default to first tree
134 // TODO this will be problematic and can only be seen as workaround
136 Control control
=getSearchField();
137 String pattern
= null;
138 if (control
!= null){
139 pattern
= ((Text
)control
).getText();
143 // fillClassifications();
144 if (pattern
== null || pattern
.equals("?")){
145 model
= CdmStore
.getService(IClassificationService
.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification
.getUuid(), null, null);
147 model
= CdmStore
.getService(IClassificationService
.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification
.getUuid(), limitOfInitialElements
, pattern
);
150 fillContentProvider(null);
151 } catch (CoreException e
) {
152 // TODO Auto-generated catch block
157 private void fillClassifications() {
158 if(classifications
== null){
159 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
160 Collections
.sort(classifications
, new Comparator
<Classification
>() {
163 public int compare(Classification o1
, Classification o2
) {
167 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
169 return o1
.getUuid().compareTo(o2
.getUuid());
174 if (this.cdmBaseToBeFiltered
== null){
175 selectedClassification
= classifications
.iterator().next();
177 selectedClassification
= this.cdmBaseToBeFiltered
.getClassification();
184 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
190 protected String
[] getNewWizardText() {
196 public void widgetSelected(SelectionEvent e
) {
197 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
200 if (getSearchField().getText() != null){
207 public void widgetDefaultSelected(SelectionEvent e
) {}