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
.model
.taxon
.Classification
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
29 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
30 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
39 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
40 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
41 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
47 classificationUUID
, allowSelectClassification
);
48 return getSelectionFromDialog(dialog
);
50 public static TaxonNode
select(Shell shell
, //ConversationHolder conversation,
51 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
52 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
59 return getSelectionFromDialog(dialog
);
62 public static UuidAndTitleCache
<TaxonNode
> selectUuidAndTitleCache(Shell shell
, //ConversationHolder conversation,
63 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
64 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
70 classificationUUID
, false);
71 return getUuidAndTitleCacheSelectionFromDialog(dialog
);
74 private Combo classificationSelectionCombo
;
76 private List
<Classification
> classifications
;
78 private Classification selectedClassification
;
79 private UUID selectedUuid
;
80 // private final Set<UUID> excludeTaxa;
81 private boolean allowClassificationSelection
= false;
83 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
84 String title
, Set
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
85 super(shell
, //conversation,
86 title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
88 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
90 setListLabelProvider(labelProvider
);
91 // setDetailsLabelProvider(labelProvider);
92 this.cdmBaseToBeFiltered
= excludeTaxa
;
93 if(classificationUUID
!= null){
94 selectedUuid
= classificationUUID
;
97 fillClassifications();
98 this.allowClassificationSelection
= allowSelectClassification
;
100 createClassificationSelectionCombo(shell
);
102 protected TaxonNodeSelectionDialog(Shell shell
, //ConversationHolder conversation,
103 String title
, Set
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
) {
104 this(shell
, title
, excludeTaxa
, multi
, node
, classificationUUID
, false);
109 protected Control
createDialogArea(Composite parent
) {
110 Composite container
= (Composite
) super.createDialogArea(parent
);
111 return createClassificationSelectionCombo(container
);
115 * currently disabled tree selection composite
117 private Control
createClassificationSelectionCombo(Composite parent
){
118 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
120 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
121 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
123 GridLayout layout
= new GridLayout();
124 classificationSelection
.setLayout(layout
);
126 Label label
= new Label(classificationSelection
, SWT
.NULL
);
127 // TODO not working is not really true but leave it here to remind everyone that this is under construction
128 label
.setText("Select Classification");
129 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
130 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
132 for(Classification tree
: classifications
){
133 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
134 if (tree
.getUuid().equals(selectedUuid
)){
135 selectedClassification
= tree
;
140 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
142 // TODO remember last selection
143 classificationSelectionCombo
.addSelectionListener(this);
147 return classificationSelection
;
152 protected String
getTitle(TaxonNode taxonNode
) {
153 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
154 return taxonNode
.getTaxon().getTitleCache();
161 protected SelectionListener
getNewWizardButtonSelectionListener(){
162 return new SelectionAdapter() {
165 public void widgetSelected(SelectionEvent e
) {
166 Classification tree
= selectedClassification
;
167 setPattern(tree
.getRootNode());
176 protected TaxonNode
getPersistentObject(UUID uuid
) {
177 return CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(uuid
);
182 protected void callService(String pattern
) {
183 model
= CdmStore
.getService(IClassificationService
.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification
.getUuid(), limitOfInitialElements
, pattern
, allowClassificationSelection
);
186 protected void sort() {
187 if(!PreferencesUtil
.isSortTaxaByRankAndName()){
188 Collections
.sort(model
, getItemsComparator());
190 // otherwise result is already sorted
193 private void fillClassifications() {
194 if(classifications
== null){
195 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
196 Collections
.sort(classifications
, new Comparator
<Classification
>() {
199 public int compare(Classification o1
, Classification o2
) {
203 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
205 return o1
.getUuid().compareTo(o2
.getUuid());
210 if (selectedClassification
== null){
211 // if (this.cdmBaseToBeFiltered.isEmpty()){
212 selectedClassification
= classifications
.iterator().next();
215 // selectedClassification = this.cdmBaseToBeFiltered.getClassification();
223 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
229 protected String
[] getNewWizardText() {
235 public void widgetSelected(SelectionEvent e
) {
236 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
239 if (getSearchField().getText() != null){
246 public void widgetDefaultSelected(SelectionEvent e
) {}