4 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
6 import java
.text
.Collator
;
7 import java
.util
.Comparator
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.core
.runtime
.CoreException
;
13 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
14 import org
.eclipse
.core
.runtime
.IStatus
;
15 import org
.eclipse
.core
.runtime
.Status
;
16 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
17 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
18 import org
.eclipse
.jface
.viewers
.LabelProvider
;
19 import org
.eclipse
.jface
.window
.Window
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.ui
.dialogs
.FilteredItemsSelectionDialog
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
33 //public class FilteredTaxonSelectionDialog extends FilteredCdmResourceSelectionDialog {
38 public class FilteredTaxonSelectionDialog
extends FilteredItemsSelectionDialog
{
40 private static final Logger logger
= Logger
41 .getLogger(FilteredTaxonSelectionDialog
.class);
43 public static final String SETTINGS
= FilteredTaxonSelectionDialog
.class.getCanonicalName();
49 public static Taxon
getTaxon(Shell shell
, Taxon excludeTaxon
) {
50 FilteredTaxonSelectionDialog dialog
= new FilteredTaxonSelectionDialog(shell
,
51 "Choose a taxon", false);
52 if (dialog
.open() == Window
.CANCEL
) {
55 return dialog
.getTaxon();
59 private Map
<UUID
, String
> allTaxonBases
;
65 public FilteredTaxonSelectionDialog(Shell shell
, String title
, boolean multi
) {
70 ILabelProvider labelProvider
= new LabelProvider() {
71 public String
getText(Object element
) {
72 if (element
== null) {
75 return ((TaxonUuidAndTitleCache
) element
).getTitleCache();
78 setListLabelProvider(labelProvider
);
79 setDetailsLabelProvider(labelProvider
);
81 allTaxonBases
= CdmStore
.getTaxonService().getUuidAndTitleCacheOfAcceptedTaxa();
85 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor)
88 protected void fillContentProvider(AbstractContentProvider contentProvider
,
89 ItemsFilter itemsFilter
, IProgressMonitor progressMonitor
)
90 throws CoreException
{
91 progressMonitor
.beginTask("Looking for taxa", 1000); // Why no progres monitor?
92 for (UUID uuid
: allTaxonBases
.keySet()) {
93 TaxonUuidAndTitleCache taxon
= new TaxonUuidAndTitleCache(uuid
, allTaxonBases
.get(uuid
));
94 contentProvider
.add(taxon
, itemsFilter
);
101 private Taxon
getTaxon() {
102 Object
[] result
= getResult();
103 return result
[0] == null ?
null : (Taxon
) result
[0];
107 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
110 protected Control
createExtendedContentArea(Composite parent
) {
111 // TODO Auto-generated method stub
116 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
119 protected ItemsFilter
createFilter() {
120 return new ItemsFilter() {
123 public boolean isConsistentItem(Object item
) {
128 public boolean matchItem(Object item
) {
129 return matches(((TaxonUuidAndTitleCache
) item
).titleCache
);
136 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getDialogSettings()
139 protected IDialogSettings
getDialogSettings() {
140 IDialogSettings settings
= TaxeditorStorePlugin
.getDefault().getDialogSettings().getSection(getSettings());
142 if (settings
== null) {
143 settings
= TaxeditorStorePlugin
.getDefault().getDialogSettings().addNewSection(getSettings());
149 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getElementName(java.lang.Object)
152 public String
getElementName(Object item
) {
153 return ((TaxonUuidAndTitleCache
) item
).getTitleCache();
157 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getItemsComparator()
160 protected Comparator
getItemsComparator() {
161 return new Comparator
<TaxonUuidAndTitleCache
>() {
162 public int compare(TaxonUuidAndTitleCache entity1
,
163 TaxonUuidAndTitleCache entity2
) {
164 Collator collator
= Collator
.getInstance();
165 return collator
.compare(entity1
.getTitleCache(), entity2
.getTitleCache());
171 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#validateItem(java.lang.Object)
174 protected IStatus
validateItem(Object item
) {
175 return Status
.OK_STATUS
;
178 protected void restoreDialog(IDialogSettings settings
) {
182 public String
getSettings() {
183 if(SETTINGS
== null){
184 throw new IllegalStateException("No SETTINGS set.");
189 class TaxonUuidAndTitleCache
{
194 TaxonUuidAndTitleCache(UUID uuid
, String titleCache
) {
196 this.titleCache
= titleCache
;
200 * @return the titleCache
202 public String
getTitleCache() {
209 public UUID
getUuid() {