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.common.DefinedTermBase;
|
29
|
import eu.etaxonomy.cdm.model.common.TermType;
|
30
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
31
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
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.IPreferenceKeys;
|
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.getPreferenceStore().setValue(getPrefKey(vocabulary), !isChecked());
|
66
|
search();
|
67
|
}
|
68
|
}
|
69
|
|
70
|
protected List<TermVocabulary> selectedVocabularies;
|
71
|
protected ArrayList<TermVocabulary> preselectedVocabularies;
|
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
|
preselectedVocabularies = new ArrayList<TermVocabulary>();
|
101
|
if (preselectedVocabularyUuids == null || preselectedVocabularyUuids.length == 0){
|
102
|
preselectedVocabularyUuids = createVocabularyUuidList();
|
103
|
}
|
104
|
for(int i=0;i<preselectedVocabularyUuids.length;i++){
|
105
|
TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
|
106
|
preselectedVocabularies.add(preselectedVocabulary);
|
107
|
}
|
108
|
|
109
|
|
110
|
selectedVocabularies = createSelectedVocabularies();
|
111
|
|
112
|
}
|
113
|
|
114
|
protected List<TermVocabulary> createSelectedVocabularies() {
|
115
|
List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
|
116
|
for(TermVocabulary vocabulary:selectedVocabularies){
|
117
|
if(preselectedVocabularies.contains(vocabulary)
|
118
|
|| !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
|
119
|
tempSelectedVocabularies.add(vocabulary);
|
120
|
}
|
121
|
}
|
122
|
return tempSelectedVocabularies;
|
123
|
}
|
124
|
|
125
|
private static UUID[] createVocabularyUuidList() {
|
126
|
String preselectedVocString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.DISTRIBUTION_VOCABULARIES);
|
127
|
String[] preselectedVocArray = preselectedVocString.split(";");
|
128
|
UUID[] uuidList = new UUID[preselectedVocArray.length];
|
129
|
int i = 0;
|
130
|
for (String uuidString: preselectedVocArray){
|
131
|
uuidList[i]= UUID.fromString(uuidString);
|
132
|
i++;
|
133
|
}
|
134
|
return uuidList;
|
135
|
}
|
136
|
|
137
|
|
138
|
private String getPrefKey(TermVocabulary vocabulary){
|
139
|
return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID;
|
140
|
}
|
141
|
|
142
|
/** {@inheritDoc} */
|
143
|
@Override
|
144
|
protected NamedArea getPersistentObject(UUID uuid) {
|
145
|
|
146
|
DefinedTermBase area = CdmStore.getService(ITermService.class).find(uuid);
|
147
|
if (area instanceof NamedArea){
|
148
|
return (NamedArea) area;
|
149
|
}
|
150
|
|
151
|
return null;
|
152
|
}
|
153
|
|
154
|
/** {@inheritDoc} */
|
155
|
@Override
|
156
|
protected void init() {
|
157
|
selectedVocabularies = getAvailableVocabularies();
|
158
|
}
|
159
|
|
160
|
private List<TermVocabulary> getAvailableVocabularies(){
|
161
|
List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
|
162
|
return vocabularies;
|
163
|
}
|
164
|
|
165
|
// /** {@inheritDoc} */
|
166
|
// @Override
|
167
|
// protected void search() {
|
168
|
// Control control =getSearchField();
|
169
|
// String pattern = null;
|
170
|
// if (control != null){
|
171
|
// pattern = ((Text)control).getText();
|
172
|
// }
|
173
|
//
|
174
|
// if (pattern == null || pattern.equals("?")){
|
175
|
// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, null, PreferencesUtil.getGlobalLanguage());
|
176
|
// }else{
|
177
|
// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
|
178
|
// }
|
179
|
// }
|
180
|
|
181
|
// /** {@inheritDoc} */
|
182
|
// @Override
|
183
|
// protected Control createExtendedContentArea(Composite parent) {
|
184
|
// return null;
|
185
|
// }
|
186
|
|
187
|
/** {@inheritDoc} */
|
188
|
@Override
|
189
|
protected String getTitle(NamedArea namedArea) {
|
190
|
try {
|
191
|
String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage());
|
192
|
return result;
|
193
|
} catch (Exception e) {
|
194
|
MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e);
|
195
|
return namedArea.getTitleCache();
|
196
|
}
|
197
|
}
|
198
|
|
199
|
/** {@inheritDoc} */
|
200
|
@Override
|
201
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
202
|
return null;
|
203
|
}
|
204
|
|
205
|
/** {@inheritDoc} */
|
206
|
@Override
|
207
|
protected String[] getNewWizardText() {
|
208
|
return null;
|
209
|
}
|
210
|
|
211
|
@Override
|
212
|
void createFilterButton(Composite searchAndFilter)
|
213
|
{
|
214
|
filterButton = new Button(searchAndFilter, SWT.NONE);
|
215
|
// filterButton.setText("Filter");
|
216
|
filterButton.setImage(ImageResources.getImage(ImageResources.FUNNEL_ICON));
|
217
|
// SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this);
|
218
|
filterButton.addSelectionListener(new SelectionListener(){
|
219
|
@Override
|
220
|
public void widgetSelected(SelectionEvent e) {
|
221
|
|
222
|
Object source = e.getSource();
|
223
|
String text = null;
|
224
|
if (source instanceof Button){
|
225
|
Shell shell = ((Button)source).getShell();
|
226
|
Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies);
|
227
|
if(dialog!=null){
|
228
|
dialog.open();
|
229
|
}
|
230
|
createSelectedVocabularies();
|
231
|
search();
|
232
|
}
|
233
|
|
234
|
|
235
|
|
236
|
|
237
|
}
|
238
|
|
239
|
@Override
|
240
|
public void widgetDefaultSelected(SelectionEvent e) {
|
241
|
// TODO Auto-generated method stub
|
242
|
|
243
|
}
|
244
|
|
245
|
|
246
|
});
|
247
|
|
248
|
}
|
249
|
|
250
|
/**
|
251
|
*
|
252
|
*/
|
253
|
public void setSelectedVocabularies() {
|
254
|
// TODO Auto-generated method stub
|
255
|
|
256
|
}
|
257
|
|
258
|
/* (non-Javadoc)
|
259
|
* @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
|
260
|
*/
|
261
|
@Override
|
262
|
void callService(String pattern) {
|
263
|
model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
|
264
|
}
|
265
|
|
266
|
}
|