Revision 91d58d15
Added by Katja Luther almost 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/NomenclaturalStatusTypeAdminPreference.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2019 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.databaseAdmin.preferencePage; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
import java.util.UUID; |
|
14 |
|
|
15 |
import org.apache.commons.lang.StringUtils; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
18 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference; |
|
19 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
20 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
21 |
import eu.etaxonomy.taxeditor.preference.LocalOrDefaultEnum; |
|
22 |
import eu.etaxonomy.taxeditor.preference.NomenclaturalStatusTypePreferences; |
|
23 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
24 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author k.luther |
|
28 |
* @since 05.06.2019 |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class NomenclaturalStatusTypeAdminPreference extends NomenclaturalStatusTypePreferences { |
|
32 |
|
|
33 |
|
|
34 |
public NomenclaturalStatusTypeAdminPreference(){ |
|
35 |
super(); |
|
36 |
setLocalPref(false); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
@Override |
|
42 |
public boolean performOk() { |
|
43 |
if (!isApply()){ |
|
44 |
return true; |
|
45 |
} |
|
46 |
Object[] checkedElements = treeComposite.getViewer().getCheckedElements(); |
|
47 |
List<UUID> listUIIDChecked = new ArrayList<>(); |
|
48 |
List<DefinedTermBase> preferredTerms = new ArrayList<>(); |
|
49 |
for (Object o : checkedElements) { |
|
50 |
if(o instanceof TermDto){ |
|
51 |
TermDto termDto = (TermDto) o; |
|
52 |
listUIIDChecked.add(termDto.getUuid()); |
|
53 |
preferredTerms.add(CdmStore.getService(ITermService.class).load(termDto.getUuid())); |
|
54 |
} |
|
55 |
} |
|
56 |
String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$ |
|
57 |
if (StringUtils.isBlank(saveCheckedElements)){ |
|
58 |
saveCheckedElements = null; |
|
59 |
} |
|
60 |
CdmPreference savePref = CdmPreference.NewTaxEditorInstance(predicate, saveCheckedElements); |
|
61 |
String text = this.useLocalOrAdmin.getText(); |
|
62 |
if (text.equals(LocalOrDefaultEnum.Database.getLabel()) ){ |
|
63 |
savePref.setAllowOverride(false); |
|
64 |
}else if (text.equals(LocalOrDefaultEnum.AllowOverride.getLabel())){ |
|
65 |
savePref.setAllowOverride(true); |
|
66 |
} |
|
67 |
|
|
68 |
PreferencesUtil.setPreferenceToDB(savePref); |
|
69 |
PreferencesUtil.updateDBPreferences(); |
|
70 |
PreferencesUtil.firePreferencesChanged(this.getClass()); |
|
71 |
return true; |
|
72 |
|
|
73 |
} |
|
74 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/CommonNameNamedAreaSelectionDialog.java | ||
---|---|---|
16 | 16 |
import org.eclipse.swt.widgets.Shell; |
17 | 17 |
|
18 | 18 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
19 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
20 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
21 | 19 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
22 | 20 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference; |
21 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey; |
|
23 | 22 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; |
23 |
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject; |
|
24 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
25 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
24 | 26 |
import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache; |
25 | 27 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
26 | 28 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
48 | 50 |
} |
49 | 51 |
|
50 | 52 |
private static UUID[] createVocabularyUuidList() { |
51 |
String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.CommonNameAreaVocabularies.getKey()); |
|
53 |
String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.CommonNameAreaVocabularies.getKey(), false);
|
|
52 | 54 |
if (StringUtils.isBlank(preselectedVocString)){ |
53 | 55 |
return null; |
54 | 56 |
} |
... | ... | |
72 | 74 |
|
73 | 75 |
UUID[] preselectedVocabularyUuids = createVocabularyUuidList(); |
74 | 76 |
CdmPreferenceCache cache = CdmPreferenceCache.instance(); |
75 |
CdmPreference pref = cache.get(PreferencePredicate.CommonNameAreaVocabularies.getKey()); |
|
77 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.CommonNameAreaVocabularies); |
|
78 |
CdmPreference pref = cache.findBestMatching(key); |
|
79 |
if (preselectedVocabularyUuids != null){ |
|
80 |
for(int i=0;i<preselectedVocabularyUuids.length;i++){ |
|
81 |
TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]); |
|
82 |
vocabularies.add(preselectedVocabulary); |
|
83 |
} |
|
84 |
} |
|
76 | 85 |
if ((pref != null && !pref.isAllowOverride()) && preselectedVocabularyUuids!=null) { |
77 |
for(int i=0;i<preselectedVocabularyUuids.length;i++){ |
|
78 |
TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]); |
|
79 |
vocabularies.add(preselectedVocabulary); |
|
80 |
} |
|
86 |
return vocabularies; |
|
81 | 87 |
}else{ |
82 |
vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null); |
|
88 |
selectedVocabularies = vocabularies; |
|
89 |
|
|
90 |
return CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null); |
|
83 | 91 |
} |
84 | 92 |
|
85 |
return vocabularies; |
|
93 |
|
|
86 | 94 |
} |
87 | 95 |
|
88 | 96 |
/** |
... | ... | |
104 | 112 |
"Choose an area", false, namedArea, preferenceId); |
105 | 113 |
return getSelectionFromDialog(dialog); |
106 | 114 |
} |
115 |
|
|
116 |
|
|
107 | 117 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.ui.dialog.selection; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
import java.util.UUID; |
|
15 |
|
|
16 |
import org.eclipse.jface.action.Action; |
|
17 |
import org.eclipse.jface.action.IAction; |
|
18 |
import org.eclipse.jface.dialogs.Dialog; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.events.SelectionEvent; |
|
21 |
import org.eclipse.swt.events.SelectionListener; |
|
22 |
import org.eclipse.swt.widgets.Button; |
|
23 |
import org.eclipse.swt.widgets.Composite; |
|
24 |
import org.eclipse.swt.widgets.Shell; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
27 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
28 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
29 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
30 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
31 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
32 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
33 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
34 |
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard; |
|
35 |
import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache; |
|
36 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
37 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author n.hoffmann |
|
41 |
* @created May 11, 2010 |
|
42 |
* @version 1.0 |
|
43 |
*/ |
|
44 |
public class NamedAreaSelectionDialog extends |
|
45 |
AbstractFilteredCdmResourceSelectionDialog<NamedArea> { |
|
46 |
|
|
47 |
private class IncludeNamedAreaVocabulary extends Action { |
|
48 |
private final TermVocabulary<NamedArea> vocabulary; |
|
49 |
|
|
50 |
/** |
|
51 |
* Creates a new instance of the class. |
|
52 |
*/ |
|
53 |
public IncludeNamedAreaVocabulary(TermVocabulary<NamedArea> vocabulary) { |
|
54 |
super(vocabulary.getTitleCache(), IAction.AS_CHECK_BOX); |
|
55 |
this.vocabulary = vocabulary; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void run(){ |
|
60 |
if(isChecked()){ |
|
61 |
selectedVocabularies.add(vocabulary); |
|
62 |
}else{ |
|
63 |
selectedVocabularies.remove(vocabulary); |
|
64 |
} |
|
65 |
PreferencesUtil.setBooleanValue(getPrefKey(vocabulary), !isChecked()); |
|
66 |
search(); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
protected List<TermVocabulary> selectedVocabularies; |
|
71 |
protected List<TermVocabulary> vocabularies; |
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* Creates a filtered selection dialog to select a named area. |
|
77 |
* |
|
78 |
* @param shell |
|
79 |
* The shell for displaying this widget |
|
80 |
* @param namedArea |
|
81 |
* A namedArea that should be selected when the dialog opens |
|
82 |
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
83 |
* @param preferenceId a class which is used for generating the preference key so that every |
|
84 |
* dialogs can be grouped to have their own preferences depending on this id |
|
85 |
* @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies |
|
86 |
* @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object. |
|
87 |
*/ |
|
88 |
public static NamedArea select(Shell shell, //ConversationHolder conversation, |
|
89 |
NamedArea namedArea, String preferenceId, UUID... preselectedVocabularyUuids) { |
|
90 |
NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, //conversation, |
|
91 |
"Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids); |
|
92 |
return getSelectionFromDialog(dialog); |
|
93 |
} |
|
94 |
|
|
95 |
protected NamedAreaSelectionDialog(Shell shell, //ConversationHolder conversation, |
|
96 |
String title, boolean multi, NamedArea namedArea, Object preferenceId, UUID... preselectedVocabularyUuids) { |
|
97 |
super(shell, //conversation, |
|
98 |
title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea); |
|
99 |
|
|
100 |
selectedVocabularies = new ArrayList<TermVocabulary>(); |
|
101 |
this.preferenceID = preferenceId; |
|
102 |
|
|
103 |
if (preselectedVocabularyUuids != null && preselectedVocabularyUuids.length > 0){ |
|
104 |
for(int i=0;i<preselectedVocabularyUuids.length;i++){ |
|
105 |
TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]); |
|
106 |
selectedVocabularies.add(preselectedVocabulary); |
|
107 |
} |
|
108 |
}else{ |
|
109 |
selectedVocabularies = createSelectedVocabularies(); |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
protected List<TermVocabulary> createSelectedVocabularies() { |
|
115 |
List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>(); |
|
116 |
for(TermVocabulary vocabulary:vocabularies){ |
|
117 |
if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))) |
|
118 |
|| !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))){ |
|
119 |
tempSelectedVocabularies.add(vocabulary); |
|
120 |
} |
|
121 |
} |
|
122 |
return tempSelectedVocabularies; |
|
123 |
} |
|
124 |
|
|
125 |
// private static UUID[] createVocabularyUuidList() { |
|
126 |
// String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); |
|
127 |
// if (StringUtils.isBlank(preselectedVocString)){ |
|
128 |
// return null; |
|
129 |
// } |
|
130 |
// String[] preselectedVocArray = preselectedVocString.split(";"); |
|
131 |
// UUID[] uuidList = new UUID[preselectedVocArray.length]; |
|
132 |
// int i = 0; |
|
133 |
// for (String uuidString: preselectedVocArray){ |
|
134 |
// uuidList[i]= UUID.fromString(uuidString); |
|
135 |
// i++; |
|
136 |
// } |
|
137 |
// return uuidList; |
|
138 |
// } |
|
139 |
|
|
140 |
|
|
141 |
private String getPrefKey(TermVocabulary vocabulary){ |
|
142 |
return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID; |
|
143 |
} |
|
144 |
|
|
145 |
/** {@inheritDoc} */ |
|
146 |
@Override |
|
147 |
protected NamedArea getPersistentObject(UUID uuid) { |
|
148 |
|
|
149 |
DefinedTermBase area = CdmStore.getService(ITermService.class).find(uuid); |
|
150 |
if (area instanceof NamedArea){ |
|
151 |
return (NamedArea) area; |
|
152 |
} |
|
153 |
|
|
154 |
return null; |
|
155 |
} |
|
156 |
|
|
157 |
/** {@inheritDoc} */ |
|
158 |
@Override |
|
159 |
protected void init() { |
|
160 |
vocabularies = getAvailableVocabularies(); |
|
161 |
} |
|
162 |
|
|
163 |
private List<TermVocabulary> getAvailableVocabularies(){ |
|
164 |
vocabularies = new ArrayList(); |
|
165 |
CdmPreferenceCache cache = CdmPreferenceCache.instance(); |
|
166 |
// CdmPreference pref = cache.get(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); |
|
167 |
// if (pref != null && !pref.isAllowOverride()){ |
|
168 |
// UUID[] preselectedVocabularyUuids = createVocabularyUuidList(); |
|
169 |
// |
|
170 |
// for(int i=0;i<preselectedVocabularyUuids.length;i++){ |
|
171 |
// TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]); |
|
172 |
// vocabularies.add(preselectedVocabulary); |
|
173 |
// } |
|
174 |
// }else{ |
|
175 |
vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null); |
|
176 |
// } |
|
177 |
//List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null); |
|
178 |
return vocabularies; |
|
179 |
} |
|
180 |
|
|
181 |
// /** {@inheritDoc} */ |
|
182 |
// @Override |
|
183 |
// protected void search() { |
|
184 |
// Control control =getSearchField(); |
|
185 |
// String pattern = null; |
|
186 |
// if (control != null){ |
|
187 |
// pattern = ((Text)control).getText(); |
|
188 |
// } |
|
189 |
// |
|
190 |
// if (pattern == null || pattern.equals("?")){ |
|
191 |
// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, null, PreferencesUtil.getGlobalLanguage()); |
|
192 |
// }else{ |
|
193 |
// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); |
|
194 |
// } |
|
195 |
// } |
|
196 |
|
|
197 |
// /** {@inheritDoc} */ |
|
198 |
// @Override |
|
199 |
// protected Control createExtendedContentArea(Composite parent) { |
|
200 |
// return null; |
|
201 |
// } |
|
202 |
|
|
203 |
/** {@inheritDoc} */ |
|
204 |
@Override |
|
205 |
protected String getTitle(NamedArea namedArea) { |
|
206 |
try { |
|
207 |
String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage()); |
|
208 |
return result; |
|
209 |
} catch (Exception e) { |
|
210 |
MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e); |
|
211 |
return namedArea.getTitleCache(); |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
/** {@inheritDoc} */ |
|
216 |
@Override |
|
217 |
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) { |
|
218 |
return null; |
|
219 |
} |
|
220 |
|
|
221 |
/** {@inheritDoc} */ |
|
222 |
@Override |
|
223 |
protected String[] getNewWizardText() { |
|
224 |
return null; |
|
225 |
} |
|
226 |
|
|
227 |
@Override |
|
228 |
void createFilterButton(Composite searchAndFilter) |
|
229 |
{ |
|
230 |
filterButton = new Button(searchAndFilter, SWT.NONE); |
|
231 |
// filterButton.setText("Filter"); |
|
232 |
filterButton.setImage(ImageResources.getImage(ImageResources.FUNNEL_ICON)); |
|
233 |
// SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this); |
|
234 |
filterButton.addSelectionListener(new SelectionListener(){ |
|
235 |
@Override |
|
236 |
public void widgetSelected(SelectionEvent e) { |
|
237 |
|
|
238 |
Object source = e.getSource(); |
|
239 |
String text = null; |
|
240 |
if (source instanceof Button){ |
|
241 |
Shell shell = ((Button)source).getShell(); |
|
242 |
Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies); |
|
243 |
if(dialog!=null){ |
|
244 |
dialog.open(); |
|
245 |
} |
|
246 |
createSelectedVocabularies(); |
|
247 |
search(); |
|
248 |
} |
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
} |
|
254 |
|
|
255 |
@Override |
|
256 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
257 |
// TODO Auto-generated method stub |
|
258 |
|
|
259 |
} |
|
260 |
|
|
261 |
|
|
262 |
}); |
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
/* (non-Javadoc) |
|
269 |
* @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String) |
|
270 |
*/ |
|
271 |
@Override |
|
272 |
void callService(String pattern) { |
|
273 |
if (selectedVocabularies == null || selectedVocabularies.size() == 0){ |
|
274 |
model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); |
|
275 |
}else{ |
|
276 |
model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); |
|
277 |
} |
|
278 |
} |
|
279 |
|
|
280 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.ui.dialog.selection; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
import java.util.UUID; |
|
15 |
|
|
16 |
import org.eclipse.jface.action.Action; |
|
17 |
import org.eclipse.jface.action.IAction; |
|
18 |
import org.eclipse.jface.dialogs.Dialog; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.events.SelectionEvent; |
|
21 |
import org.eclipse.swt.events.SelectionListener; |
|
22 |
import org.eclipse.swt.widgets.Button; |
|
23 |
import org.eclipse.swt.widgets.Composite; |
|
24 |
import org.eclipse.swt.widgets.Shell; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
27 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
28 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
29 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
30 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
31 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
32 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
33 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
34 |
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard; |
|
35 |
import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache; |
|
36 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
37 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author n.hoffmann |
|
41 |
* @created May 11, 2010 |
|
42 |
* @version 1.0 |
|
43 |
*/ |
|
44 |
public class NamedAreaSelectionDialog extends |
|
45 |
AbstractFilteredCdmResourceSelectionDialog<NamedArea> { |
|
46 |
|
|
47 |
private class IncludeNamedAreaVocabulary extends Action { |
|
48 |
private final TermVocabulary<NamedArea> vocabulary; |
|
49 |
|
|
50 |
/** |
|
51 |
* Creates a new instance of the class. |
|
52 |
*/ |
|
53 |
public IncludeNamedAreaVocabulary(TermVocabulary<NamedArea> vocabulary) { |
|
54 |
super(vocabulary.getTitleCache(), IAction.AS_CHECK_BOX); |
|
55 |
this.vocabulary = vocabulary; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void run(){ |
|
60 |
if(isChecked()){ |
|
61 |
selectedVocabularies.add(vocabulary); |
|
62 |
}else{ |
|
63 |
selectedVocabularies.remove(vocabulary); |
|
64 |
} |
|
65 |
PreferencesUtil.setBooleanValue(getPrefKey(vocabulary), !isChecked()); |
|
66 |
search(); |
|
67 |
} |
|
68 |
} |
|
69 |
protected List<NamedArea> selectedAreas; |
|
70 |
protected List<TermVocabulary> selectedVocabularies; |
|
71 |
protected List<TermVocabulary> vocabularies; |
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* Creates a filtered selection dialog to select a named area. |
|
77 |
* |
|
78 |
* @param shell |
|
79 |
* The shell for displaying this widget |
|
80 |
* @param namedArea |
|
81 |
* A namedArea that should be selected when the dialog opens |
|
82 |
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
83 |
* @param preferenceId a class which is used for generating the preference key so that every |
|
84 |
* dialogs can be grouped to have their own preferences depending on this id |
|
85 |
* @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies |
|
86 |
* @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object. |
|
87 |
*/ |
|
88 |
public static NamedArea select(Shell shell, //ConversationHolder conversation, |
|
89 |
NamedArea namedArea, String preferenceId, UUID... preselectedVocabularyUuids) { |
|
90 |
NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, //conversation, |
|
91 |
"Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids); |
|
92 |
return getSelectionFromDialog(dialog); |
|
93 |
} |
|
94 |
|
|
95 |
protected NamedAreaSelectionDialog(Shell shell, //ConversationHolder conversation, |
|
96 |
String title, boolean multi, NamedArea namedArea, Object preferenceId, UUID... preselectedVocabularyUuids) { |
|
97 |
super(shell, //conversation, |
|
98 |
title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea); |
|
99 |
|
|
100 |
selectedVocabularies = new ArrayList<TermVocabulary>(); |
|
101 |
this.preferenceID = preferenceId; |
|
102 |
|
|
103 |
if (preselectedVocabularyUuids != null && preselectedVocabularyUuids.length > 0){ |
|
104 |
for(int i=0;i<preselectedVocabularyUuids.length;i++){ |
|
105 |
TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]); |
|
106 |
selectedVocabularies.add(preselectedVocabulary); |
|
107 |
} |
|
108 |
}else{ |
|
109 |
selectedVocabularies = createSelectedVocabularies(); |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
protected List<TermVocabulary> createSelectedVocabularies() { |
|
115 |
List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>(); |
|
116 |
for(TermVocabulary vocabulary:vocabularies){ |
|
117 |
if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))) |
|
118 |
|| !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))){ |
|
119 |
tempSelectedVocabularies.add(vocabulary); |
|
120 |
} |
|
121 |
} |
|
122 |
return tempSelectedVocabularies; |
|
123 |
} |
|
124 |
|
|
125 |
// private static UUID[] createVocabularyUuidList() { |
|
126 |
// String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); |
|
127 |
// if (StringUtils.isBlank(preselectedVocString)){ |
|
128 |
// return null; |
|
129 |
// } |
|
130 |
// String[] preselectedVocArray = preselectedVocString.split(";"); |
|
131 |
// UUID[] uuidList = new UUID[preselectedVocArray.length]; |
|
132 |
// int i = 0; |
|
133 |
// for (String uuidString: preselectedVocArray){ |
|
134 |
// uuidList[i]= UUID.fromString(uuidString); |
|
135 |
// i++; |
|
136 |
// } |
|
137 |
// return uuidList; |
|
138 |
// } |
|
139 |
|
|
140 |
|
|
141 |
private String getPrefKey(TermVocabulary vocabulary){ |
|
142 |
return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID; |
|
143 |
} |
|
144 |
|
|
145 |
/** {@inheritDoc} */ |
|
146 |
@Override |
|
147 |
protected NamedArea getPersistentObject(UUID uuid) { |
|
148 |
|
|
149 |
DefinedTermBase area = CdmStore.getService(ITermService.class).find(uuid); |
|
150 |
if (area instanceof NamedArea){ |
|
151 |
return (NamedArea) area; |
|
152 |
} |
|
153 |
|
|
154 |
return null; |
|
155 |
} |
|
156 |
|
|
157 |
/** {@inheritDoc} */ |
|
158 |
@Override |
|
159 |
protected void init() { |
|
160 |
vocabularies = getAvailableVocabularies(); |
|
161 |
} |
|
162 |
|
|
163 |
private List<TermVocabulary> getAvailableVocabularies(){ |
|
164 |
vocabularies = new ArrayList(); |
|
165 |
CdmPreferenceCache cache = CdmPreferenceCache.instance(); |
|
166 |
vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null); |
|
167 |
return vocabularies; |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
/** {@inheritDoc} */ |
|
173 |
@Override |
|
174 |
protected String getTitle(NamedArea namedArea) { |
|
175 |
try { |
|
176 |
String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage()); |
|
177 |
return result; |
|
178 |
} catch (Exception e) { |
|
179 |
MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e); |
|
180 |
return namedArea.getTitleCache(); |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
/** {@inheritDoc} */ |
|
185 |
@Override |
|
186 |
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) { |
|
187 |
return null; |
|
188 |
} |
|
189 |
|
|
190 |
/** {@inheritDoc} */ |
|
191 |
@Override |
|
192 |
protected String[] getNewWizardText() { |
|
193 |
return null; |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
void createFilterButton(Composite searchAndFilter) |
|
198 |
{ |
|
199 |
filterButton = new Button(searchAndFilter, SWT.NONE); |
|
200 |
// filterButton.setText("Filter"); |
|
201 |
filterButton.setImage(ImageResources.getImage(ImageResources.FUNNEL_ICON)); |
|
202 |
// SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this); |
|
203 |
filterButton.addSelectionListener(new SelectionListener(){ |
|
204 |
@Override |
|
205 |
public void widgetSelected(SelectionEvent e) { |
|
206 |
|
|
207 |
Object source = e.getSource(); |
|
208 |
String text = null; |
|
209 |
if (source instanceof Button){ |
|
210 |
Shell shell = ((Button)source).getShell(); |
|
211 |
Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies); |
|
212 |
if(dialog!=null){ |
|
213 |
dialog.open(); |
|
214 |
} |
|
215 |
createSelectedVocabularies(); |
|
216 |
search(); |
|
217 |
} |
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
226 |
// TODO Auto-generated method stub |
|
227 |
|
|
228 |
} |
|
229 |
|
|
230 |
|
|
231 |
}); |
|
232 |
|
|
233 |
} |
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
/* (non-Javadoc) |
|
238 |
* @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String) |
|
239 |
*/ |
|
240 |
@Override |
|
241 |
void callService(String pattern) { |
|
242 |
if (selectedVocabularies == null || selectedVocabularies.size() == 0){ |
|
243 |
model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); |
|
244 |
}else{ |
|
245 |
model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.dialog.selection; |
|
10 |
|
|
11 |
import org.eclipse.swt.widgets.Shell; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
|
14 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
|
15 |
import eu.etaxonomy.cdm.model.agent.Institution; |
|
16 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
17 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
18 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
19 |
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl; |
|
20 |
import eu.etaxonomy.cdm.model.common.Group; |
|
21 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
|
22 |
import eu.etaxonomy.cdm.model.common.User; |
|
23 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
24 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
|
25 |
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; |
|
26 |
import eu.etaxonomy.cdm.model.location.Country; |
|
27 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
28 |
import eu.etaxonomy.cdm.model.media.Media; |
|
29 |
import eu.etaxonomy.cdm.model.media.Rights; |
|
30 |
import eu.etaxonomy.cdm.model.molecular.Amplification; |
|
31 |
import eu.etaxonomy.cdm.model.molecular.Primer; |
|
32 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
33 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
|
34 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
35 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
36 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
37 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
38 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
39 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
40 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
41 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
42 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
43 |
import eu.etaxonomy.cdm.model.term.FeatureTree; |
|
44 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
45 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
46 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
|
47 |
import eu.etaxonomy.taxeditor.ui.element.IEntityElement; |
|
48 |
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement; |
|
49 |
import eu.etaxonomy.taxeditor.ui.section.description.CommonNameSourceElement; |
|
50 |
import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement; |
|
51 |
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement; |
|
52 |
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection; |
|
53 |
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement; |
|
54 |
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement; |
|
55 |
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement; |
|
56 |
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement; |
|
57 |
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection; |
|
58 |
|
|
59 |
/** |
|
60 |
* @author n.hoffmann |
|
61 |
* @date Jan 25, 2012 |
|
62 |
* |
|
63 |
*/ |
|
64 |
public class SelectionDialogFactory { |
|
65 |
|
|
66 |
public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation, |
|
67 |
T currentSelection){ |
|
68 |
return getSelectionFromDialog(clazz, shell, //conversation, |
|
69 |
currentSelection, null); |
|
70 |
} |
|
71 |
|
|
72 |
public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation, |
|
73 |
T currentSelection, ICdmFormElement parentElement){ |
|
74 |
|
|
75 |
if(clazz.equals(Taxon.class)){ |
|
76 |
return (T) TaxonSelectionDialog.selectTaxon(shell, //conversation, |
|
77 |
(Taxon) currentSelection); |
|
78 |
} |
|
79 |
if(clazz.equals(Synonym.class)){ |
|
80 |
return (T) TaxonBaseSelectionDialog.selectSynonym(shell );//,conversation); |
|
81 |
} |
|
82 |
if(clazz.equals(TaxonBase.class)){ |
|
83 |
return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell);//, conversation); |
|
84 |
} |
|
85 |
if(clazz.equals(Classification.class)){ |
|
86 |
return (T) ClassificationSelectionDialog.select(shell, //conversation, |
|
87 |
(Classification) currentSelection); |
|
88 |
} |
|
89 |
if(clazz.equals(TaxonNode.class)){ |
|
90 |
return (T) TaxonNodeSelectionDialog.select(shell, //conversation, |
|
91 |
null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid()); |
|
92 |
} |
|
93 |
if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){ |
|
94 |
return (T) NomenclaturalReferenceSelectionDialog.select(shell, //conversation, |
|
95 |
(Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship()); |
|
96 |
} |
|
97 |
if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){ |
|
98 |
return (T) CommonNameReferenceSelectionDialog.select(shell, //conversation, |
|
99 |
(Reference) currentSelection); |
|
100 |
} |
|
101 |
if(clazz.equals(Reference.class)){ |
|
102 |
if (parentElement instanceof ReferenceDetailElement){ |
|
103 |
return (T) ReferenceSelectionDialog.select(shell, //conversation, |
|
104 |
((ReferenceDetailElement) parentElement).getEntity(), true); |
|
105 |
} |
|
106 |
return (T) ReferenceSelectionDialog.select(shell, //conversation, |
|
107 |
(Reference) currentSelection); |
|
108 |
} |
|
109 |
|
|
110 |
if(clazz.equals(TaxonName.class)){ |
|
111 |
return (T) NameSelectionDialog.select(shell, //conversation, |
|
112 |
(TaxonName) currentSelection); |
|
113 |
} |
|
114 |
if(clazz.equals(Team.class)){ |
|
115 |
return (T) TeamSelectionDialog.select(shell, //conversation, |
|
116 |
(Team) currentSelection); |
|
117 |
} |
|
118 |
if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){ |
|
119 |
return (T) NomenclaturalAuthorSelectionDialog.select(shell, //conversation, |
|
120 |
(TeamOrPersonBase) currentSelection, false); |
|
121 |
}else if(clazz.equals(TeamOrPersonBase.class)){ |
|
122 |
//TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545) |
|
123 |
return (T) TeamOrPersonBaseSelectionDialog.select(shell, //conversation, |
|
124 |
(TeamOrPersonBase) currentSelection, false); |
|
125 |
} |
|
126 |
if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){ |
|
127 |
return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, //conversation, |
|
128 |
(TeamOrPersonBase) currentSelection, true); |
|
129 |
} |
|
130 |
if(clazz.equals(AgentBase.class)){ |
|
131 |
return (T) AgentSelectionDialog.select(shell, //conversation, |
|
132 |
(AgentBase) currentSelection, false); |
|
133 |
} |
|
134 |
if(clazz.equals(Feature.class)){ |
|
135 |
return (T) FeatureSelectionDialog.select(shell, //conversation, |
|
136 |
(Feature) currentSelection); |
|
137 |
} |
|
138 |
if(clazz.equals(FeatureTree.class)){ |
|
139 |
return (T) FeatureTreeSelectionDialog.select(shell, //conversation, |
|
140 |
(FeatureTree) currentSelection); |
|
141 |
} |
|
142 |
if(clazz.equals(PolytomousKey.class)){ |
|
143 |
return (T) PolytomousKeySelectionDialog.select(shell, //conversation, |
|
144 |
(PolytomousKey) currentSelection); |
|
145 |
} |
|
146 |
if(clazz.equals(PolytomousKeyNode.class)){ |
|
147 |
MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class, |
|
148 |
"This functionality is not implemented yet."); |
|
149 |
return null; |
|
150 |
} |
|
151 |
if(clazz.equals(DerivedUnit.class)){ |
|
152 |
return (T) DerivedUnitSelectionDialog.select(shell, //conversation, |
|
153 |
(DerivedUnit) currentSelection); |
|
154 |
} |
|
155 |
if(clazz.equals(FieldUnit.class)){ |
|
156 |
return (T) FieldUnitSelectionDialog.select(shell, //conversation, |
|
157 |
(FieldUnit) currentSelection); |
|
158 |
} |
|
159 |
if(clazz.equals(SpecimenOrObservationBase.class)){ |
|
160 |
return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, //conversation, |
|
161 |
(SpecimenOrObservationBase) currentSelection); |
|
162 |
} |
|
163 |
if(clazz.equals(NamedArea.class)){ |
|
164 |
if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){ |
|
165 |
return (T) NamedAreaSelectionDialog.select(shell, //conversation, |
|
166 |
(NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary); |
|
167 |
} |
|
168 |
else if(parentElement instanceof CommonNameDetailElement ){ |
|
169 |
return (T) CommonNameNamedAreaSelectionDialog.select(shell, //conversation, |
|
170 |
(NamedArea) currentSelection, parentElement.getClass().getCanonicalName()); |
|
171 |
} |
|
172 |
else{ |
|
173 |
return (T) NamedAreaSelectionDialog.select(shell, //conversation, |
|
174 |
(NamedArea) currentSelection, parentElement.getClass().getCanonicalName()); |
|
175 |
} |
|
176 |
} |
|
177 |
if(clazz.equals(Collection.class)){ |
|
178 |
return (T) CollectionSelectionDialog.select(shell, //conversation, |
|
179 |
(Collection) currentSelection); |
|
180 |
} |
|
181 |
if(clazz.equals(User.class) && parentElement instanceof MemberDetailElement){ |
|
182 |
MemberDetailSection section = (MemberDetailSection)((MemberDetailElement)parentElement).getParentElement(); |
|
183 |
return (T) UserSelectionDialog.select(shell, //conversation, |
|
184 |
(User) currentSelection, section.getEntity()); |
|
185 |
} |
|
186 |
if(clazz.equals(GrantedAuthorityImpl.class)){ |
|
187 |
return (T) GrantedAuthoritySelectionDialog.select(shell, //conversation, |
|
188 |
(GrantedAuthorityImpl) currentSelection); |
|
189 |
} |
|
190 |
if (clazz.equals(Person.class)){ |
|
191 |
return (T) PersonSelectionDialog.select(shell, //conversation, |
|
192 |
(Person) currentSelection); |
|
193 |
} |
|
194 |
if(clazz.equals(Group.class) && parentElement instanceof GroupsByUserDetailElement){ |
|
195 |
GroupsByUserDetailSection section =(GroupsByUserDetailSection)((GroupsByUserDetailElement)parentElement).getParentElement(); |
|
196 |
return (T) GroupSelectionDialog.select(shell, //conversation, |
|
197 |
(Group) currentSelection, section.getEntity()); |
|
198 |
} |
|
199 |
if(clazz.equals(Institution.class)){ |
|
200 |
return (T) InstitutionSelectionDialog.select(shell, //conversation, |
|
201 |
(Institution) currentSelection); |
|
202 |
} |
|
203 |
if(clazz.equals(Primer.class)){ |
|
204 |
return (T) PrimerSelectionDialog.select(shell, //conversation, |
|
205 |
(Primer) currentSelection); |
|
206 |
} |
|
207 |
if(clazz.equals(Amplification.class)){ |
|
208 |
return (T) AmplificationSelectionDialog.select(shell, //conversation, |
|
209 |
(Amplification) currentSelection); |
|
210 |
} |
|
211 |
if(clazz.equals(Media.class)){ |
|
212 |
return (T) MediaSelectionDialog.select(shell, //conversation, |
|
213 |
(Media) currentSelection); |
|
214 |
} |
|
215 |
if(clazz.equals(Rights.class)){ |
|
216 |
return (T) RightsSelectionDialog.select(shell, //conversation, |
|
217 |
(Rights) currentSelection); |
|
218 |
} |
|
219 |
|
|
220 |
return null; |
|
221 |
} |
|
222 |
|
|
223 |
public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation, |
|
224 |
ICdmFormElement parentElement){ |
|
225 |
return (T) ExtReferenceSelectionDialog.select(shell, //conversation, |
|
226 |
null); |
|
227 |
} |
|
228 |
|
|
229 |
|
|
230 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2009 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.dialog.selection; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.eclipse.swt.widgets.Shell; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
|
17 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
|
18 |
import eu.etaxonomy.cdm.model.agent.Institution; |
|
19 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
20 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
21 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
22 |
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl; |
|
23 |
import eu.etaxonomy.cdm.model.common.Group; |
|
24 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
|
25 |
import eu.etaxonomy.cdm.model.common.User; |
|
26 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
27 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
|
28 |
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; |
|
29 |
import eu.etaxonomy.cdm.model.location.Country; |
|
30 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
31 |
import eu.etaxonomy.cdm.model.media.Media; |
|
32 |
import eu.etaxonomy.cdm.model.media.Rights; |
|
33 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; |
|
34 |
import eu.etaxonomy.cdm.model.molecular.Amplification; |
|
35 |
import eu.etaxonomy.cdm.model.molecular.Primer; |
|
36 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
37 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
|
38 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
39 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
40 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
41 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
42 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
43 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
44 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
45 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
46 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
47 |
import eu.etaxonomy.cdm.model.term.FeatureTree; |
|
48 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
49 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
50 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
|
51 |
import eu.etaxonomy.taxeditor.ui.element.IEntityElement; |
|
52 |
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement; |
|
53 |
import eu.etaxonomy.taxeditor.ui.section.description.CommonNameSourceElement; |
|
54 |
import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement; |
|
55 |
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement; |
|
56 |
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection; |
|
57 |
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement; |
|
58 |
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement; |
|
59 |
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement; |
|
60 |
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement; |
|
61 |
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection; |
|
62 |
|
|
63 |
/** |
|
64 |
* @author n.hoffmann |
|
65 |
* @date Jan 25, 2012 |
|
66 |
* |
|
67 |
*/ |
|
68 |
public class SelectionDialogFactory { |
|
69 |
|
|
70 |
public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation, |
|
71 |
T currentSelection){ |
|
72 |
return getSelectionFromDialog(clazz, shell, //conversation, |
|
73 |
currentSelection, null); |
|
74 |
} |
|
75 |
|
|
76 |
public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation, |
|
77 |
T currentSelection, ICdmFormElement parentElement){ |
|
78 |
|
|
79 |
if(clazz.equals(Taxon.class)){ |
|
80 |
return (T) TaxonSelectionDialog.selectTaxon(shell, //conversation, |
|
81 |
(Taxon) currentSelection); |
|
82 |
} |
|
83 |
if(clazz.equals(Synonym.class)){ |
|
84 |
return (T) TaxonBaseSelectionDialog.selectSynonym(shell );//,conversation); |
|
85 |
} |
|
86 |
if(clazz.equals(TaxonBase.class)){ |
|
87 |
return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell);//, conversation); |
|
88 |
} |
|
89 |
if(clazz.equals(Classification.class)){ |
|
90 |
return (T) ClassificationSelectionDialog.select(shell, //conversation, |
|
91 |
(Classification) currentSelection); |
|
92 |
} |
|
93 |
if(clazz.equals(TaxonNode.class)){ |
|
94 |
return (T) TaxonNodeSelectionDialog.select(shell, //conversation, |
|
95 |
null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid()); |
|
96 |
} |
|
97 |
if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){ |
|
98 |
return (T) NomenclaturalReferenceSelectionDialog.select(shell, //conversation, |
|
99 |
(Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship()); |
|
100 |
} |
|
101 |
if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){ |
|
102 |
return (T) CommonNameReferenceSelectionDialog.select(shell, //conversation, |
|
103 |
(Reference) currentSelection); |
|
104 |
} |
|
105 |
if(clazz.equals(Reference.class)){ |
|
106 |
if (parentElement instanceof ReferenceDetailElement){ |
|
107 |
return (T) ReferenceSelectionDialog.select(shell, //conversation, |
|
108 |
((ReferenceDetailElement) parentElement).getEntity(), true); |
|
109 |
} |
|
110 |
return (T) ReferenceSelectionDialog.select(shell, //conversation, |
|
111 |
(Reference) currentSelection); |
|
112 |
} |
|
113 |
|
|
114 |
if(clazz.equals(TaxonName.class)){ |
|
115 |
return (T) NameSelectionDialog.select(shell, //conversation, |
|
116 |
(TaxonName) currentSelection); |
|
117 |
} |
|
118 |
if(clazz.equals(Team.class)){ |
|
119 |
return (T) TeamSelectionDialog.select(shell, //conversation, |
|
120 |
(Team) currentSelection); |
|
121 |
} |
|
122 |
if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){ |
|
123 |
return (T) NomenclaturalAuthorSelectionDialog.select(shell, //conversation, |
|
124 |
(TeamOrPersonBase) currentSelection, false); |
|
125 |
}else if(clazz.equals(TeamOrPersonBase.class)){ |
|
126 |
//TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545) |
|
127 |
return (T) TeamOrPersonBaseSelectionDialog.select(shell, //conversation, |
|
128 |
(TeamOrPersonBase) currentSelection, false); |
|
129 |
} |
|
130 |
if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){ |
|
131 |
return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, //conversation, |
|
132 |
(TeamOrPersonBase) currentSelection, true); |
|
133 |
} |
|
134 |
if(clazz.equals(AgentBase.class)){ |
|
135 |
return (T) AgentSelectionDialog.select(shell, //conversation, |
|
136 |
(AgentBase) currentSelection, false); |
|
137 |
} |
|
138 |
if(clazz.equals(Feature.class)){ |
|
139 |
return (T) FeatureSelectionDialog.select(shell, //conversation, |
|
140 |
(Feature) currentSelection); |
|
141 |
} |
|
142 |
if(clazz.equals(FeatureTree.class)){ |
|
143 |
return (T) FeatureTreeSelectionDialog.select(shell, //conversation, |
|
144 |
(FeatureTree) currentSelection); |
|
145 |
} |
|
146 |
if(clazz.equals(PolytomousKey.class)){ |
|
147 |
return (T) PolytomousKeySelectionDialog.select(shell, //conversation, |
|
148 |
(PolytomousKey) currentSelection); |
|
149 |
} |
|
150 |
if(clazz.equals(PolytomousKeyNode.class)){ |
|
151 |
MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class, |
|
152 |
"This functionality is not implemented yet."); |
|
153 |
return null; |
|
154 |
} |
|
155 |
if(clazz.equals(DerivedUnit.class)){ |
|
156 |
return (T) DerivedUnitSelectionDialog.select(shell, //conversation, |
|
157 |
(DerivedUnit) currentSelection); |
|
158 |
} |
|
159 |
if(clazz.equals(FieldUnit.class)){ |
|
160 |
return (T) FieldUnitSelectionDialog.select(shell, //conversation, |
|
161 |
(FieldUnit) currentSelection); |
|
162 |
} |
|
163 |
if(clazz.equals(SpecimenOrObservationBase.class)){ |
|
164 |
return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, //conversation, |
|
165 |
(SpecimenOrObservationBase) currentSelection); |
|
166 |
} |
|
167 |
if(clazz.equals(NamedArea.class)){ |
|
168 |
if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){ |
|
169 |
return (T) NamedAreaSelectionDialog.select(shell, //conversation, |
|
170 |
(NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary); |
|
171 |
} |
|
172 |
else if(parentElement instanceof CommonNameDetailElement ){ |
|
173 |
return (T) CommonNameNamedAreaSelectionDialog.select(shell, //conversation, |
|
174 |
(NamedArea) currentSelection, parentElement.getClass().getCanonicalName()); |
|
175 |
} |
|
176 |
else{ |
|
177 |
//if (parentElement == null){ |
|
178 |
List<UUID> uuidList = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); |
|
179 |
UUID[] uuidArray = new UUID[uuidList.size()]; |
|
180 |
uuidList.toArray(uuidArray); |
|
181 |
return (T)NamedAreaSelectionDialog.select(shell, (NamedArea) currentSelection, null, uuidArray); |
|
182 |
//} |
|
183 |
//return (T) NamedAreaSelectionDialog.select(shell, //conversation, |
|
184 |
// (NamedArea) currentSelection, parentElement.getClass().getCanonicalName()); |
|
185 |
} |
|
186 |
} |
|
187 |
if(clazz.equals(Collection.class)){ |
|
188 |
return (T) CollectionSelectionDialog.select(shell, //conversation, |
|
189 |
(Collection) currentSelection); |
|
190 |
} |
|
191 |
if(clazz.equals(User.class) && parentElement instanceof MemberDetailElement){ |
|
192 |
MemberDetailSection section = (MemberDetailSection)((MemberDetailElement)parentElement).getParentElement(); |
|
193 |
return (T) UserSelectionDialog.select(shell, //conversation, |
|
194 |
(User) currentSelection, section.getEntity()); |
|
195 |
} |
|
196 |
if(clazz.equals(GrantedAuthorityImpl.class)){ |
|
197 |
return (T) GrantedAuthoritySelectionDialog.select(shell, //conversation, |
|
198 |
(GrantedAuthorityImpl) currentSelection); |
|
199 |
} |
|
200 |
if (clazz.equals(Person.class)){ |
|
201 |
return (T) PersonSelectionDialog.select(shell, //conversation, |
|
202 |
(Person) currentSelection); |
|
203 |
} |
|
204 |
if(clazz.equals(Group.class) && parentElement instanceof GroupsByUserDetailElement){ |
|
205 |
GroupsByUserDetailSection section =(GroupsByUserDetailSection)((GroupsByUserDetailElement)parentElement).getParentElement(); |
|
206 |
return (T) GroupSelectionDialog.select(shell, //conversation, |
|
207 |
(Group) currentSelection, section.getEntity()); |
|
208 |
} |
|
209 |
if(clazz.equals(Institution.class)){ |
|
210 |
return (T) InstitutionSelectionDialog.select(shell, //conversation, |
|
211 |
(Institution) currentSelection); |
|
212 |
} |
|
213 |
if(clazz.equals(Primer.class)){ |
|
214 |
return (T) PrimerSelectionDialog.select(shell, //conversation, |
|
215 |
(Primer) currentSelection); |
|
216 |
} |
|
217 |
if(clazz.equals(Amplification.class)){ |
|
218 |
return (T) AmplificationSelectionDialog.select(shell, //conversation, |
|
219 |
(Amplification) currentSelection); |
|
220 |
} |
|
221 |
if(clazz.equals(Media.class)){ |
|
222 |
return (T) MediaSelectionDialog.select(shell, //conversation, |
|
223 |
(Media) currentSelection); |
|
224 |
} |
|
225 |
if(clazz.equals(Rights.class)){ |
|
226 |
return (T) RightsSelectionDialog.select(shell, //conversation, |
|
227 |
(Rights) currentSelection); |
|
228 |
} |
|
229 |
|
|
230 |
return null; |
|
231 |
} |
|
232 |
|
|
233 |
public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation, |
|
234 |
ICdmFormElement parentElement){ |
|
235 |
return (T) ExtReferenceSelectionDialog.select(shell, //conversation, |
|
236 |
null); |
|
237 |
} |
|
238 |
|
|
239 |
|
|
240 |
} |
Also available in: Unified diff
ref #8293: use distribution editor preference for area filter in details view