2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
12 import java
.util
.Collections
;
13 import java
.util
.HashSet
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.swt
.widgets
.Shell
;
18 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
22 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
23 import eu
.etaxonomy
.taxeditor
.newWizard
.NewTaxonWizard
;
24 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 * @created Sep 21, 2009
32 public class TaxonBaseSelectionDialog
<T
extends TaxonBase
> extends AbstractFilteredCdmResourceSelectionDialog
{
35 public static TaxonBase
selectTaxonBase(Shell shell
){//, ConversationHolder conversation) {
36 AbstractFilteredCdmResourceSelectionDialog
<TaxonBase
> dialog
= new TaxonBaseSelectionDialog(TaxonBase
.class, shell
, //conversation,
37 "Choose a taxon/synonym", false, null, null);
38 return getSelectionFromDialog(dialog
);
41 public static Taxon
selectTaxon(Shell shell
, //ConversationHolder conversation,
42 Taxon taxonToBeFiltered
) {
45 AbstractFilteredCdmResourceSelectionDialog
<TaxonBase
> dialog
= new TaxonBaseSelectionDialog(Taxon
.class, shell
, //conversation,
46 "Choose a taxon", false, null, taxonToBeFiltered
);
47 return (Taxon
) getSelectionFromDialog(dialog
);
50 public static Synonym
selectSynonym(Shell shell
){//, ConversationHolder conversation) {
51 AbstractFilteredCdmResourceSelectionDialog
<TaxonBase
> dialog
= new TaxonBaseSelectionDialog(Synonym
.class, shell
, //conversation,
52 "Choose a synonym", false, null, null);
53 return (Synonym
) getSelectionFromDialog(dialog
);
56 private final Class
<?
extends TaxonBase
> clazz
;
58 protected TaxonBaseSelectionDialog(Class
<?
extends TaxonBase
> clazz
, Shell shell
, //ConversationHolder conversation,
59 String title
, boolean multi
, TaxonBase taxon
, TaxonBase taxonToBeFiltered
) {
60 super(shell
, //conversation,
61 title
, multi
, TaxonBaseSelectionDialog
.class.getCanonicalName(), taxon
);
62 if (taxonToBeFiltered
!= null){
63 this.cdmBaseToBeFiltered
= new HashSet
<>();
64 this.cdmBaseToBeFiltered
.add(taxonToBeFiltered
.getUuid());
72 protected TaxonBase
getPersistentObject(UUID uuid
) {
73 return CdmStore
.getService(ITaxonService
.class).load(uuid
);
77 @SuppressWarnings({ "unchecked", "rawtypes" })
79 protected void callService(String pattern
) {
81 model
= CdmStore
.getService(ITaxonService
.class).getUuidAndTitleCache(limitOfInitialElements
, pattern
);
86 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
87 return new NewTaxonWizard();
92 protected String
[] getNewWizardText() {
93 return new String
[]{"New Taxon"};
97 protected void sort() {
98 if(!PreferencesUtil
.isSortTaxaByRankAndName()){
99 Collections
.sort(model
, getItemsComparator());
101 // otherwise result is already sorted