4 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
6 import java
.util
.Collections
;
7 import java
.util
.Comparator
;
10 import java
.util
.UUID
;
12 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.SelectionAdapter
;
15 import org
.eclipse
.swt
.events
.SelectionEvent
;
16 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import org
.eclipse
.swt
.layout
.GridData
;
18 import org
.eclipse
.swt
.layout
.GridLayout
;
19 import org
.eclipse
.swt
.widgets
.Combo
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Label
;
23 import org
.eclipse
.swt
.widgets
.Shell
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
30 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
31 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
40 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
41 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
42 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
48 classificationUUID
, allowSelectClassification
);
49 return getSelectionFromDialog(dialog
);
51 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
52 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
53 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
60 return getSelectionFromDialog(dialog
);
63 public static UuidAndTitleCache
<TaxonNode
> selectUuidAndTitleCache(Shell shell
, //ConversationHolder conversation,
64 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
65 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
71 classificationUUID
, false);
72 return getUuidAndTitleCacheSelectionFromDialog(dialog
);
75 private Combo classificationSelectionCombo
;
77 private List
<Classification
> classifications
;
79 private Classification selectedClassification
;
80 private UUID selectedUuid
;
81 // private final Set<UUID> excludeTaxa;
82 private boolean allowClassificationSelection
= false;
84 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
85 String title
, Set
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
86 super(shell
, //conversation,
87 title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
89 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
91 setListLabelProvider(labelProvider
);
92 // setDetailsLabelProvider(labelProvider);
93 this.cdmBaseToBeFiltered
= excludeTaxa
;
94 if(classificationUUID
!= null){
95 selectedUuid
= classificationUUID
;
98 fillClassifications();
99 this.allowClassificationSelection
= allowSelectClassification
;
101 createClassificationSelectionCombo(shell
);
103 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
104 String title
, Set
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
) {
105 this(shell
, title
, excludeTaxa
, multi
, node
, classificationUUID
, false);
110 protected Control
createDialogArea(Composite parent
) {
111 Composite container
= (Composite
) super.createDialogArea(parent
);
112 return createClassificationSelectionCombo(container
);
116 * currently disabled tree selection composite
118 private Control
createClassificationSelectionCombo(Composite parent
){
119 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
121 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
122 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
124 GridLayout layout
= new GridLayout();
125 classificationSelection
.setLayout(layout
);
127 Label label
= new Label(classificationSelection
, SWT
.NULL
);
128 // TODO not working is not really true but leave it here to remind everyone that this is under construction
129 label
.setText("Select Classification");
130 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
131 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
133 for(Classification tree
: classifications
){
134 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
135 if (tree
.getUuid().equals(selectedUuid
)){
136 selectedClassification
= tree
;
141 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
143 // TODO remember last selection
144 classificationSelectionCombo
.addSelectionListener(this);
148 return classificationSelection
;
153 protected String
getTitle(TaxonNode taxonNode
) {
154 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
155 return taxonNode
.getTaxon().getTitleCache();
162 protected SelectionListener
getNewWizardButtonSelectionListener(){
163 return new SelectionAdapter() {
166 public void widgetSelected(SelectionEvent e
) {
167 Classification tree
= selectedClassification
;
168 setPattern(tree
.getRootNode());
177 protected TaxonNode
getPersistentObject(UUID uuid
) {
178 return CdmStore
.getService(ITaxonNodeService
.class).find(uuid
);
183 protected void callService(String pattern
) {
184 model
= CdmStore
.getService(IClassificationService
.class)
185 .getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(
186 selectedClassification
.getUuid(), limitOfInitialElements
, pattern
, allowClassificationSelection
);
190 protected void sort() {
191 if(!PreferencesUtil
.isSortTaxaByRankAndName()){
192 Collections
.sort(model
, getItemsComparator());
194 // otherwise result is already sorted
197 private void fillClassifications() {
198 if(classifications
== null){
199 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
200 Collections
.sort(classifications
, new Comparator
<Classification
>() {
203 public int compare(Classification o1
, Classification o2
) {
207 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
209 return o1
.getUuid().compareTo(o2
.getUuid());
214 if (selectedClassification
== null){
215 // if (this.cdmBaseToBeFiltered.isEmpty()){
216 selectedClassification
= classifications
.iterator().next();
219 // selectedClassification = this.cdmBaseToBeFiltered.getClassification();
227 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
233 protected String
[] getNewWizardText() {
239 public void widgetSelected(SelectionEvent e
) {
240 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
243 if (getSearchField().getText() != null){
250 public void widgetDefaultSelected(SelectionEvent e
) {}