3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.dialogs
.filteredSelection
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
15 import java
.util
.HashSet
;
17 import java
.util
.UUID
;
19 import org
.eclipse
.jface
.action
.Action
;
20 import org
.eclipse
.jface
.action
.IAction
;
21 import org
.eclipse
.jface
.action
.IMenuManager
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Control
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
26 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
28 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
29 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
31 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
32 import eu
.etaxonomy
.cdm
.model
.common
.VocabularyEnum
;
33 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
34 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 * <p>FilteredNamedAreaSelectionDialog class.</p>
41 * @created May 11, 2010
44 public class NamedAreaSelectionDialog
extends
45 AbstractFilteredCdmResourceSelectionDialog
<NamedArea
> {
47 private class IncludeTdwgAreaAction
extends Action
{
49 * Creates a new instance of the class.
51 public IncludeTdwgAreaAction() {
52 super("TDWG Areas", IAction
.AS_CHECK_BOX
);
57 selectedVocabularies
.add(VocabularyEnum
.TdwgArea
);
59 selectedVocabularies
.remove(VocabularyEnum
.TdwgArea
);
66 private class IncludeWaterbodyOrCountryAction
extends Action
{
68 * Creates a new instance of the class.
70 public IncludeWaterbodyOrCountryAction() {
71 super("Waterbody Or Country", IAction
.AS_CHECK_BOX
);
76 selectedVocabularies
.add(VocabularyEnum
.WaterbodyOrCountry
);
78 selectedVocabularies
.remove(VocabularyEnum
.WaterbodyOrCountry
);
85 private class IncludeContinentAction
extends Action
{
87 * Creates a new instance of the class.
89 public IncludeContinentAction() {
90 super("Continent", IAction
.AS_CHECK_BOX
);
95 selectedVocabularies
.add(VocabularyEnum
.Continent
);
97 selectedVocabularies
.remove(VocabularyEnum
.Continent
);
104 private Collection
<VocabularyEnum
> selectedVocabularies
;
106 private IncludeTdwgAreaAction includeTdwgAreaAction
;
107 private IncludeWaterbodyOrCountryAction includeWaterbodyOrCountryAction
;
108 private IncludeContinentAction includeContinentAction
;
111 * Creates a filtered selection dialog to select a named area.
114 * The shell for displaying this widget
116 * A namedArea that should be selected when the dialog opens
117 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
118 * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
120 public static NamedArea
select(Shell shell
, ConversationHolder conversation
, NamedArea namedArea
) {
121 NamedAreaSelectionDialog dialog
= new NamedAreaSelectionDialog(shell
, conversation
,
122 "Choose an area", false, namedArea
);
123 return getSelectionFromDialog(dialog
);
127 * <p>Constructor for FilteredNamedAreaSelectionDialog.</p>
129 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
130 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
131 * @param title a {@link java.lang.String} object.
132 * @param multi a boolean.
133 * @param namedArea a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
135 protected NamedAreaSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, NamedArea namedArea
) {
136 super(shell
, conversation
, title
, multi
, NamedAreaSelectionDialog
.class.getCanonicalName(), namedArea
);
141 protected void fillViewMenu(IMenuManager menuManager
) {
143 super.fillViewMenu(menuManager
);
145 includeTdwgAreaAction
= new IncludeTdwgAreaAction();
146 menuManager
.add(includeTdwgAreaAction
);
147 includeTdwgAreaAction
.setChecked(true);
149 includeWaterbodyOrCountryAction
= new IncludeWaterbodyOrCountryAction();
150 menuManager
.add(includeWaterbodyOrCountryAction
);
151 includeWaterbodyOrCountryAction
.setChecked(true);
153 includeContinentAction
= new IncludeContinentAction();
154 menuManager
.add(includeContinentAction
);
155 includeContinentAction
.setChecked(true);
161 protected NamedArea
getPersistentObject(UUID uuid
) {
162 for(VocabularyEnum selectedVocabulary
: selectedVocabularies
){
163 TermVocabulary vocabulary
= CdmStore
.getService(IVocabularyService
.class).getVocabulary(selectedVocabulary
);
164 for(Object object
: vocabulary
.getTerms()){
165 CdmBase cdmBaseObject
= (CdmBase
) object
;
166 if(uuid
.equals(cdmBaseObject
.getUuid())){
167 return (NamedArea
) cdmBaseObject
;
176 protected void init() {
178 selectedVocabularies
= new HashSet
<VocabularyEnum
>();
179 selectedVocabularies
.add(VocabularyEnum
.TdwgArea
);
180 selectedVocabularies
.add(VocabularyEnum
.WaterbodyOrCountry
);
181 selectedVocabularies
.add(VocabularyEnum
.Continent
);
186 protected void initModel() {
188 Set
<NamedArea
> terms
= new HashSet
<NamedArea
>();
189 for(VocabularyEnum vocabularyEnum
: selectedVocabularies
){
190 TermVocabulary vocabulary
= (TermVocabulary
) HibernateProxyHelper
.deproxy(CdmStore
.getService(IVocabularyService
.class).getVocabulary(vocabularyEnum
));
191 terms
.addAll(vocabulary
.getTermsOrderedByLabels(CdmStore
.getDefaultLanguage()));
195 model
= new ArrayList
<UuidAndTitleCache
<NamedArea
>>();
198 for(Object areaObject
: terms
){
199 NamedArea area
= (NamedArea
) HibernateProxyHelper
.deproxy(areaObject
);
200 UuidAndTitleCache
<NamedArea
> element
= new UuidAndTitleCache
<NamedArea
>(NamedArea
.class, area
.getUuid(), getTitle(area
));
207 protected Control
createExtendedContentArea(Composite parent
) {
213 protected String
getTitle(NamedArea namedArea
) {
214 return NamedArea
.labelWithLevel(namedArea
, CdmStore
.getDefaultLanguage());
219 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
225 protected String
getNewWizardLinkText() {