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
.Button
;
20 import org
.eclipse
.swt
.widgets
.Combo
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Control
;
23 import org
.eclipse
.swt
.widgets
.Label
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
30 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
31 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
33 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 public class TaxonNodeSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNode
> implements SelectionListener
{
41 public static TaxonNode
select(Shell shell
,
42 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
) {
43 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
49 classificationUUID
, allowSelectClassification
, false);
50 return getSelectionFromDialog(dialog
);
52 public static TaxonNode
select(Shell shell
,
53 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
54 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
61 return getSelectionFromDialog(dialog
);
64 public static TaxonNodeAndBoolean
select(Shell shell
,
65 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
, boolean allowClassification
, boolean showDefaultDescription
) {
66 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
72 classificationUUID
, allowClassification
, showDefaultDescription
);
73 TaxonNode nodeResult
= getSelectionFromDialog(dialog
);
74 TaxonNodeAndBoolean result
= new TaxonNodeAndBoolean(nodeResult
,dialog
.useDefaultDescription
);
79 public static UuidAndTitleCache
<TaxonNode
> selectUuidAndTitleCache(Shell shell
,
80 String title
, Set
<UUID
> excludeTaxa
, TaxonNode node
, UUID classificationUUID
) {
81 TaxonNodeSelectionDialog dialog
= new TaxonNodeSelectionDialog(shell
,
87 classificationUUID
, false, false);
88 return getUuidAndTitleCacheSelectionFromDialog(dialog
);
91 private Combo classificationSelectionCombo
;
93 private List
<Classification
> classifications
;
95 private Classification selectedClassification
;
96 private UUID selectedUuid
;
97 // private final Set<UUID> excludeTaxa;
98 private boolean allowClassificationSelection
= false;
100 private boolean useDefaultDescription
= false;
102 Button checkDefaultDescription
;
103 private boolean showDefaultDescriptionCheck
= false;
105 protected TaxonNodeSelectionDialog(Shell shell
,
106 String title
, Set
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
, boolean allowSelectClassification
, boolean showDefaultDescription
) {
107 super(shell
, //conversation,
108 title
, multi
, TaxonNodeSelectionDialog
.class.getCanonicalName(), node
);
110 ILabelProvider labelProvider
= new FilteredCdmResourceLabelProvider();
112 setListLabelProvider(labelProvider
);
113 // setDetailsLabelProvider(labelProvider);
114 this.cdmBaseToBeFiltered
= excludeTaxa
;
115 if(classificationUUID
!= null){
116 selectedUuid
= classificationUUID
;
119 fillClassifications();
120 this.allowClassificationSelection
= allowSelectClassification
;
121 this.showDefaultDescriptionCheck
= showDefaultDescription
;
123 //createClassificationSelectionCombo(shell);
125 protected TaxonNodeSelectionDialog(Shell shell
,
126 String title
, Set
<UUID
> excludeTaxa
, boolean multi
, TaxonNode node
, UUID classificationUUID
) {
127 this(shell
, title
, excludeTaxa
, multi
, node
, classificationUUID
, false, false);
132 protected Control
createDialogArea(Composite parent
) {
133 Composite container
= (Composite
) super.createDialogArea(parent
);
135 return createClassificationSelectionCombo(container
);
139 * currently disabled tree selection composite
141 private Control
createClassificationSelectionCombo(Composite parent
){
142 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
144 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
145 classificationSelection
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, true, false));
148 GridLayout layout
= new GridLayout();
149 classificationSelection
.setLayout(layout
);
150 layout
.numColumns
= 2;
152 if (showDefaultDescriptionCheck
) {
154 Label labelDefault
= new Label(classificationSelection
, SWT
.NULL
);
155 labelDefault
.setText(Messages
.TaxonNodeSelectionDialog_0
);
156 GridData labelDefaultLayout
= new GridData(SWT
.LEFT
, SWT
.TOP
, false, false,1,1);
157 labelDefault
.setLayoutData(labelDefaultLayout
);
158 checkDefaultDescription
= new Button(classificationSelection
, SWT
.CHECK
);
159 checkDefaultDescription
.addSelectionListener(new SelectionListener() {
162 public void widgetSelected(SelectionEvent e
) {
163 useDefaultDescription
= checkDefaultDescription
.getSelection();
167 public void widgetDefaultSelected(SelectionEvent e
) {
168 // TODO Auto-generated method stub
175 Label label
= new Label(classificationSelection
, SWT
.NULL
);
176 // TODO not working is not really true but leave it here to remind everyone that this is under construction
177 label
.setText(Messages
.TaxonNodeSelectionDialog_1
);
178 GridData labelLayout
= new GridData(SWT
.LEFT
, SWT
.TOP
, true, false,2,1);
179 label
.setLayoutData(labelLayout
);
180 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
181 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
183 for(Classification tree
: classifications
){
184 classificationSelectionCombo
.add(tree
.getTitleCache(), classifications
.indexOf(tree
));
185 if (tree
.getUuid().equals(selectedUuid
)){
186 selectedClassification
= tree
;
191 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
193 // TODO remember last selection
194 classificationSelectionCombo
.addSelectionListener(this);
198 return classificationSelection
;
202 protected String
getTitle(TaxonNode taxonNode
) {
203 if(taxonNode
!= null && taxonNode
.getTaxon() != null){
204 return taxonNode
.getTaxon().getTitleCache();
207 return ""; //$NON-NLS-1$
211 protected SelectionListener
getNewWizardButtonSelectionListener(){
212 return new SelectionAdapter() {
215 public void widgetSelected(SelectionEvent e
) {
216 Classification tree
= selectedClassification
;
217 setPattern(tree
.getRootNode());
224 protected TaxonNode
getPersistentObject(UUID uuid
) {
225 return CdmStore
.getService(ITaxonNodeService
.class).find(uuid
);
229 protected void callService(String pattern
) {
230 model
= CdmStore
.getService(IClassificationService
.class)
231 .getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(
232 selectedClassification
.getUuid(), limitOfInitialElements
, pattern
, allowClassificationSelection
, true);
236 protected void sort() {
237 if(!PreferencesUtil
.isSortTaxaByRankAndName()){
238 Collections
.sort(model
, getItemsComparator());
240 // otherwise result is already sorted
243 private void fillClassifications() {
244 if(classifications
== null){
245 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
246 Collections
.sort(classifications
, new Comparator
<Classification
>() {
249 public int compare(Classification o1
, Classification o2
) {
253 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
255 return o1
.getUuid().compareTo(o2
.getUuid());
260 if (selectedClassification
== null){
261 // if (this.cdmBaseToBeFiltered.isEmpty()){
262 selectedClassification
= classifications
.iterator().next();
265 // selectedClassification = this.cdmBaseToBeFiltered.getClassification();
272 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
277 protected String
[] getNewWizardText() {
282 public void widgetSelected(SelectionEvent e
) {
283 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
286 if (getSearchField().getText() != null){
292 public void widgetDefaultSelected(SelectionEvent e
) {}