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
|
import org.eclipse.wb.swt.ResourceManager;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
28
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
29
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
30
|
import eu.etaxonomy.cdm.model.common.TermType;
|
31
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
32
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
33
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
34
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
35
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
36
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
37
|
|
38
|
/**
|
39
|
* @author n.hoffmann
|
40
|
* @created May 11, 2010
|
41
|
* @version 1.0
|
42
|
*/
|
43
|
public class NamedAreaSelectionDialog extends
|
44
|
AbstractFilteredCdmResourceSelectionDialog<NamedArea> {
|
45
|
|
46
|
private class IncludeNamedAreaVocabulary extends Action {
|
47
|
private final TermVocabulary<NamedArea> vocabulary;
|
48
|
|
49
|
/**
|
50
|
* Creates a new instance of the class.
|
51
|
*/
|
52
|
public IncludeNamedAreaVocabulary(TermVocabulary<NamedArea> vocabulary) {
|
53
|
super(vocabulary.getTitleCache(), IAction.AS_CHECK_BOX);
|
54
|
this.vocabulary = vocabulary;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public void run(){
|
59
|
if(isChecked()){
|
60
|
selectedVocabularies.add(vocabulary);
|
61
|
}else{
|
62
|
selectedVocabularies.remove(vocabulary);
|
63
|
}
|
64
|
PreferencesUtil.getPreferenceStore().setValue(getPrefKey(vocabulary), !isChecked());
|
65
|
search();
|
66
|
}
|
67
|
}
|
68
|
|
69
|
protected List<TermVocabulary> selectedVocabularies;
|
70
|
protected ArrayList<TermVocabulary> preselectedVocabularies;
|
71
|
|
72
|
|
73
|
|
74
|
/**
|
75
|
* Creates a filtered selection dialog to select a named area.
|
76
|
*
|
77
|
* @param shell
|
78
|
* The shell for displaying this widget
|
79
|
* @param namedArea
|
80
|
* A namedArea that should be selected when the dialog opens
|
81
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
82
|
* @param preferenceId a class which is used for generating the preference key so that every
|
83
|
* dialogs can be grouped to have their own preferences depending on this id
|
84
|
* @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
|
85
|
* @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
|
86
|
*/
|
87
|
public static NamedArea select(Shell shell, //ConversationHolder conversation,
|
88
|
NamedArea namedArea, String preferenceId, UUID... preselectedVocabularyUuids) {
|
89
|
NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, //conversation,
|
90
|
"Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids);
|
91
|
return getSelectionFromDialog(dialog);
|
92
|
}
|
93
|
|
94
|
protected NamedAreaSelectionDialog(Shell shell, //ConversationHolder conversation,
|
95
|
String title, boolean multi, NamedArea namedArea, Object preferenceId, UUID... preselectedVocabularyUuids) {
|
96
|
super(shell, //conversation,
|
97
|
title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea);
|
98
|
// this.preferenceID = preferenceId;
|
99
|
preselectedVocabularies = new ArrayList<TermVocabulary>();
|
100
|
for(int i=0;i<preselectedVocabularyUuids.length;i++){
|
101
|
TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
|
102
|
preselectedVocabularies.add(preselectedVocabulary);
|
103
|
}
|
104
|
|
105
|
|
106
|
selectedVocabularies = createSelectedVocabularies();;
|
107
|
// search;//re-init to consider pre-selected vocabularies
|
108
|
}
|
109
|
|
110
|
private List<TermVocabulary> createSelectedVocabularies() {
|
111
|
List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
|
112
|
for(TermVocabulary vocabulary:selectedVocabularies){
|
113
|
if(preselectedVocabularies.contains(vocabulary)
|
114
|
|| !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
|
115
|
tempSelectedVocabularies.add(vocabulary);
|
116
|
}
|
117
|
}
|
118
|
return tempSelectedVocabularies;
|
119
|
}
|
120
|
|
121
|
/** {@inheritDoc} */
|
122
|
// @Override
|
123
|
// protected void fillViewMenu(IMenuManager menuManager) {
|
124
|
//
|
125
|
//// super.fillViewMenu(menuManager);
|
126
|
//
|
127
|
// for(TermVocabulary<NamedArea> vocabulary : getAvailableVocabularies()){
|
128
|
// IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary);
|
129
|
// menuManager.add(action);
|
130
|
// if(preselectedVocabularies.contains(vocabulary)) {
|
131
|
// action.setChecked(true);
|
132
|
// }
|
133
|
// else{
|
134
|
// action.setChecked(!PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary)));
|
135
|
// }
|
136
|
// }
|
137
|
// }
|
138
|
|
139
|
private String getPrefKey(TermVocabulary vocabulary){
|
140
|
return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID;
|
141
|
}
|
142
|
|
143
|
/** {@inheritDoc} */
|
144
|
@Override
|
145
|
protected NamedArea getPersistentObject(UUID uuid) {
|
146
|
|
147
|
DefinedTermBase area = CdmStore.getService(ITermService.class).find(uuid);
|
148
|
if (area instanceof NamedArea){
|
149
|
return (NamedArea) area;
|
150
|
}
|
151
|
|
152
|
return null;
|
153
|
}
|
154
|
|
155
|
/** {@inheritDoc} */
|
156
|
@Override
|
157
|
protected void init() {
|
158
|
selectedVocabularies = getAvailableVocabularies();
|
159
|
}
|
160
|
|
161
|
private List<TermVocabulary> getAvailableVocabularies(){
|
162
|
List<TermVocabulary> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
|
163
|
return vocabularies;
|
164
|
}
|
165
|
|
166
|
// /** {@inheritDoc} */
|
167
|
// @Override
|
168
|
// protected void search() {
|
169
|
// Control control =getSearchField();
|
170
|
// String pattern = null;
|
171
|
// if (control != null){
|
172
|
// pattern = ((Text)control).getText();
|
173
|
// }
|
174
|
//
|
175
|
// if (pattern == null || pattern.equals("?")){
|
176
|
// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, null, PreferencesUtil.getGlobalLanguage());
|
177
|
// }else{
|
178
|
// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
|
179
|
// }
|
180
|
// }
|
181
|
|
182
|
// /** {@inheritDoc} */
|
183
|
// @Override
|
184
|
// protected Control createExtendedContentArea(Composite parent) {
|
185
|
// return null;
|
186
|
// }
|
187
|
|
188
|
/** {@inheritDoc} */
|
189
|
@Override
|
190
|
protected String getTitle(NamedArea namedArea) {
|
191
|
try {
|
192
|
String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage());
|
193
|
return result;
|
194
|
} catch (Exception e) {
|
195
|
MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e);
|
196
|
return namedArea.getTitleCache();
|
197
|
}
|
198
|
}
|
199
|
|
200
|
/** {@inheritDoc} */
|
201
|
@Override
|
202
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
203
|
return null;
|
204
|
}
|
205
|
|
206
|
/** {@inheritDoc} */
|
207
|
@Override
|
208
|
protected String[] getNewWizardText() {
|
209
|
return null;
|
210
|
}
|
211
|
|
212
|
@Override
|
213
|
void createFilterButton(Composite searchAndFilter)
|
214
|
{
|
215
|
filterButton = new Button(searchAndFilter, SWT.NONE);
|
216
|
// filterButton.setText("Filter");
|
217
|
filterButton.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/funnel-icon.png"));
|
218
|
// SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this);
|
219
|
filterButton.addSelectionListener(new SelectionListener(){
|
220
|
@Override
|
221
|
public void widgetSelected(SelectionEvent e) {
|
222
|
|
223
|
Object source = e.getSource();
|
224
|
String text = null;
|
225
|
if (source instanceof Button){
|
226
|
Shell shell = ((Button)source).getShell();
|
227
|
Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies);
|
228
|
if(dialog!=null){
|
229
|
dialog.open();
|
230
|
}
|
231
|
createSelectedVocabularies();
|
232
|
search();
|
233
|
}
|
234
|
|
235
|
|
236
|
|
237
|
|
238
|
}
|
239
|
|
240
|
@Override
|
241
|
public void widgetDefaultSelected(SelectionEvent e) {
|
242
|
// TODO Auto-generated method stub
|
243
|
|
244
|
}
|
245
|
|
246
|
|
247
|
});
|
248
|
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
*
|
253
|
*/
|
254
|
public void setSelectedVocabularies() {
|
255
|
// TODO Auto-generated method stub
|
256
|
|
257
|
}
|
258
|
|
259
|
/* (non-Javadoc)
|
260
|
* @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
|
261
|
*/
|
262
|
@Override
|
263
|
void callService(String pattern) {
|
264
|
model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage());
|
265
|
}
|
266
|
|
267
|
}
|