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
.SelectionAdapter
;
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
;
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
.cdm
.persistence
.dto
.UuidAndTitleCache
;
28 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
38 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
39 String title
, List
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
40 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
46 classificationUUID
, allowSelectClassification
);
47 return getSelectionFromDialog(dialog
);
49 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
50 String title
, List
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
51 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
58 return getSelectionFromDialog(dialog
);
61 public static UuidAndTitleCache
<TaxonNode
> selectUuidAndTitleCache(Shell shell
, //ConversationHolder conversation,
62 String title
, List
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
63 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
69 classificationUUID
, false);
70 return getUuidAndTitleCacheSelectionFromDialog(dialog
);
73 private Combo classificationSelectionCombo
;
75 private List
<Classification
> classifications
;
77 private Classification selectedClassification
;
78 private UUID selectedUuid
;
79 private final List
<UUID
> excludeTaxa
;
80 private boolean allowClassificationSelection
= false;
82 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
83 String title
, List
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
84 super(shell
, //conversation,
85 title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
87 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
89 setListLabelProvider(labelProvider
);
90 // setDetailsLabelProvider(labelProvider);
91 this.excludeTaxa
= excludeTaxa
;
92 if(classificationUUID
!= null){
93 selectedUuid
= classificationUUID
;
96 fillClassifications();
97 this.allowClassificationSelection
= allowSelectClassification
;
99 createClassificationSelectionCombo(shell
);
101 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
102 String title
, List
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
) {
103 this(shell
, title
, excludeTaxa
, multi
, node
, classificationUUID
, false);
108 protected Control
createDialogArea(Composite parent
) {
109 Composite container
= (Composite
) super.createDialogArea(parent
);
110 return createClassificationSelectionCombo(container
);
114 * currently disabled tree selection composite
116 private Control
createClassificationSelectionCombo(Composite parent
){
117 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
119 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
120 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
122 GridLayout layout
= new GridLayout();
123 classificationSelection
.setLayout(layout
);
125 Label label
= new Label(classificationSelection
, SWT
.NULL
);
126 // TODO not working is not really true but leave it here to remind everyone that this is under construction
127 label
.setText("Select Classification");
128 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
129 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
131 for(Classification tree
: classifications
){
132 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
133 if (tree
.getUuid().equals(selectedUuid
)){
134 selectedClassification
= tree
;
139 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
141 // TODO remember last selection
142 classificationSelectionCombo
.addSelectionListener(this);
146 return classificationSelection
;
151 protected String
getTitle(TaxonNode taxonNode
) {
152 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
153 return taxonNode
.getTaxon().getTitleCache();
160 protected SelectionListener
getNewWizardButtonSelectionListener(){
161 return new SelectionAdapter() {
164 public void widgetSelected(SelectionEvent e
) {
165 Classification tree
= selectedClassification
;
166 setPattern(tree
.getRootNode());
175 protected TaxonNode
getPersistentObject(UUID uuid
) {
176 return CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(uuid
);
181 protected void callService(String pattern
) {
182 model
= CdmStore
.getService(IClassificationService
.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification
.getUuid(), limitOfInitialElements
, pattern
, allowClassificationSelection
);
185 protected void sort() {
186 if(!PreferencesUtil
.isSortTaxaByRankAndName()){
187 Collections
.sort(model
, getItemsComparator());
189 // otherwise result is already sorted
192 private void fillClassifications() {
193 if(classifications
== null){
194 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
195 Collections
.sort(classifications
, new Comparator
<Classification
>() {
198 public int compare(Classification o1
, Classification o2
) {
202 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
204 return o1
.getUuid().compareTo(o2
.getUuid());
209 if (selectedClassification
== null){
210 if (this.cdmBaseToBeFiltered
== null){
211 selectedClassification
= classifications
.iterator().next();
213 selectedClassification
= this.cdmBaseToBeFiltered
.getClassification();
221 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
227 protected String
[] getNewWizardText() {
233 public void widgetSelected(SelectionEvent e
) {
234 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
237 if (getSearchField().getText() != null){
244 public void widgetDefaultSelected(SelectionEvent e
) {}