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.editor.view.checklist;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.Collections;
|
15
|
import java.util.HashMap;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.SortedSet;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.eclipse.core.runtime.IProgressMonitor;
|
22
|
import org.eclipse.core.runtime.IStatus;
|
23
|
import org.eclipse.core.runtime.Status;
|
24
|
import org.eclipse.core.runtime.jobs.Job;
|
25
|
import org.eclipse.jface.viewers.ISelection;
|
26
|
import org.eclipse.jface.viewers.StructuredViewer;
|
27
|
import org.eclipse.jface.viewers.TableViewer;
|
28
|
import org.eclipse.jface.viewers.TableViewerColumn;
|
29
|
import org.eclipse.swt.SWT;
|
30
|
import org.eclipse.swt.events.ModifyListener;
|
31
|
import org.eclipse.swt.events.SelectionAdapter;
|
32
|
import org.eclipse.swt.events.SelectionEvent;
|
33
|
import org.eclipse.swt.layout.GridData;
|
34
|
import org.eclipse.swt.layout.GridLayout;
|
35
|
import org.eclipse.swt.widgets.Composite;
|
36
|
import org.eclipse.swt.widgets.Display;
|
37
|
import org.eclipse.swt.widgets.Label;
|
38
|
import org.eclipse.swt.widgets.Menu;
|
39
|
import org.eclipse.swt.widgets.MenuItem;
|
40
|
import org.eclipse.swt.widgets.Table;
|
41
|
import org.eclipse.swt.widgets.TableColumn;
|
42
|
import org.eclipse.swt.widgets.Text;
|
43
|
import org.eclipse.swt.widgets.ToolBar;
|
44
|
import org.eclipse.swt.widgets.ToolItem;
|
45
|
import org.eclipse.ui.IEditorInput;
|
46
|
import org.eclipse.ui.IEditorSite;
|
47
|
import org.eclipse.ui.IMemento;
|
48
|
import org.eclipse.ui.ISelectionListener;
|
49
|
import org.eclipse.ui.ISelectionService;
|
50
|
import org.eclipse.ui.IWorkbenchPart;
|
51
|
import org.eclipse.ui.PartInitException;
|
52
|
import org.eclipse.ui.part.EditorPart;
|
53
|
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
|
54
|
|
55
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
56
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
57
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
58
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
59
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
60
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
61
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
62
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
63
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
64
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
65
|
import eu.etaxonomy.taxeditor.editor.SimpleSelectionProvider;
|
66
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
67
|
import eu.etaxonomy.taxeditor.editor.view.checklist.edit.DistributionEditingSupport;
|
68
|
import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
|
69
|
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistDropdownSelectionListener;
|
70
|
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistFocusListener;
|
71
|
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistModifyListener;
|
72
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
73
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
74
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
75
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
76
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
77
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
78
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
79
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
80
|
|
81
|
/**
|
82
|
* <p>
|
83
|
* ChecklistViewPart class.
|
84
|
* </p>
|
85
|
*
|
86
|
* @author a.oppermann
|
87
|
* @created 30.04.2014
|
88
|
* @version 1.0
|
89
|
*/
|
90
|
public class ChecklistEditor extends EditorPart implements ISelectionListener, IPartContentHasFactualData, IConversationEnabled,
|
91
|
IContextListener, IDirtyMarkable, IPartContentHasDetails{
|
92
|
|
93
|
private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
|
94
|
private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
|
95
|
private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
|
96
|
public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
|
97
|
|
98
|
private static final Logger logger = Logger.getLogger(ChecklistEditor.class);
|
99
|
|
100
|
|
101
|
private class ChecklistJob extends Job {
|
102
|
|
103
|
private List<TaxonNode> taxonNodes;
|
104
|
|
105
|
/**
|
106
|
* @param name
|
107
|
*/
|
108
|
public ChecklistJob(String title, List<TaxonNode> listTaxonNodes) {
|
109
|
super(title);
|
110
|
this.taxonNodes = listTaxonNodes;
|
111
|
|
112
|
|
113
|
}
|
114
|
|
115
|
/*
|
116
|
* (non-Javadoc)
|
117
|
*
|
118
|
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
|
119
|
* IProgressMonitor)
|
120
|
*/
|
121
|
@Override
|
122
|
public IStatus run(final IProgressMonitor monitor) {
|
123
|
try {
|
124
|
logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
|
125
|
monitor.beginTask(Messages.ChecklistEditor_RETRIEVE_NODES, taxonNodes.size() + 1);
|
126
|
|
127
|
final List<Taxon> taxonList = new ArrayList<Taxon>();
|
128
|
|
129
|
for (TaxonNode taxonNode : taxonNodes) {
|
130
|
HibernateProxyHelper hh = new HibernateProxyHelper();
|
131
|
Taxon taxon = hh.deproxy(taxonNode.getTaxon(), Taxon.class);
|
132
|
taxonList.add(taxon);
|
133
|
}
|
134
|
// set View input
|
135
|
Display.getDefault().asyncExec(new Runnable() {
|
136
|
|
137
|
@Override
|
138
|
public void run() {
|
139
|
viewer.setInput(taxonList);
|
140
|
}
|
141
|
});
|
142
|
monitor.worked(1);
|
143
|
|
144
|
} finally {
|
145
|
monitor.done();
|
146
|
taxonNodes = null;
|
147
|
}
|
148
|
return Status.OK_STATUS;
|
149
|
}
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* Constant
|
154
|
* <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
|
155
|
*/
|
156
|
public static String ID = "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor"; //$NON-NLS-1$
|
157
|
|
158
|
private TableViewer viewer;
|
159
|
|
160
|
private String partNameCache;
|
161
|
|
162
|
private IWorkbenchSiteProgressService service;
|
163
|
|
164
|
private ITaxonNodeService taxonNodeService;
|
165
|
|
166
|
private ChecklistEditorComparator comparator;
|
167
|
|
168
|
private ChecklistEditorInput checklistEditorInput;
|
169
|
|
170
|
private SimpleSelectionProvider simpleSelectionProvider;
|
171
|
|
172
|
private ISelectionService selectionService;
|
173
|
|
174
|
private ConversationHolder conversation;
|
175
|
|
176
|
private Integer countNodes;
|
177
|
|
178
|
private List<TaxonNode> selectedTaxonNodes;
|
179
|
|
180
|
private boolean dirty;
|
181
|
|
182
|
private ChecklistEditorFilter filter;
|
183
|
|
184
|
private Menu headerMenu;
|
185
|
|
186
|
private Label statusLabel;
|
187
|
|
188
|
// private ICdmEntitySession cdmEntitySession;
|
189
|
|
190
|
private ChecklistLabelProvider labelProvider;
|
191
|
|
192
|
private SortedSet<DefinedTermBase> terms = null;
|
193
|
private ToolItem toolItem;
|
194
|
private ChecklistDropdownSelectionListener dropListener;
|
195
|
|
196
|
/**
|
197
|
* @return the selectedTaxonNodes
|
198
|
*/
|
199
|
public List<TaxonNode> getSelectedTaxonNodes() {
|
200
|
return selectedTaxonNodes;
|
201
|
}
|
202
|
|
203
|
/**
|
204
|
* @param selectedTaxonNodes
|
205
|
* the selectedTaxonNodes to set
|
206
|
*/
|
207
|
public void setSelectedTaxonNodes(List<TaxonNode> selectedTaxonNodes) {
|
208
|
this.selectedTaxonNodes = selectedTaxonNodes;
|
209
|
}
|
210
|
|
211
|
/**
|
212
|
* <p>
|
213
|
* Constructor for CdmDataSourceViewPart.
|
214
|
* </p>
|
215
|
*/
|
216
|
public ChecklistEditor() {
|
217
|
//cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
218
|
|
219
|
}
|
220
|
|
221
|
/** {@inheritDoc} */
|
222
|
@Override
|
223
|
public void createPartControl(Composite parent) {
|
224
|
service = getSite().getAdapter(IWorkbenchSiteProgressService.class);
|
225
|
taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
|
226
|
selectionService = getSite().getWorkbenchWindow().getSelectionService();
|
227
|
selectionService.addSelectionListener(this);
|
228
|
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
229
|
|
230
|
// viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
231
|
// @Override
|
232
|
// public void selectionChanged(SelectionChangedEvent event) {
|
233
|
// IStructuredSelection selection = viewer.getStructuredSelection();
|
234
|
// Object firstElement = selection.getFirstElement();
|
235
|
// // do something with it
|
236
|
// }
|
237
|
//
|
238
|
//
|
239
|
// });
|
240
|
labelProvider = new ChecklistLabelProvider(this.viewer);
|
241
|
|
242
|
terms = labelProvider.getNamedAreas(false);
|
243
|
if (terms == null){
|
244
|
MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
|
245
|
this.dispose();
|
246
|
return;
|
247
|
}
|
248
|
filter = new ChecklistEditorFilter();
|
249
|
createTopComposite(parent);
|
250
|
loadDataInput();
|
251
|
}
|
252
|
|
253
|
/**
|
254
|
* @param parent
|
255
|
*/
|
256
|
private void createTopComposite(Composite parent) {
|
257
|
GridLayout gridLayout = new GridLayout(3, false);
|
258
|
gridLayout.marginWidth = 0;
|
259
|
gridLayout.marginHeight = 0;
|
260
|
parent.setLayout(gridLayout);
|
261
|
|
262
|
final Text searchText = createSearchBar(parent);
|
263
|
createToolbar(parent);
|
264
|
|
265
|
// getSite().setSelectionProvider(viewer);
|
266
|
|
267
|
final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
|
268
|
|
269
|
searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
|
270
|
searchText.addModifyListener(modifyListener);
|
271
|
createGridDataForViewerLayout();
|
272
|
|
273
|
viewer.addFilter(filter);
|
274
|
createTable();
|
275
|
|
276
|
viewer.setContentProvider(new ChecklistContentProvider());
|
277
|
viewer.setLabelProvider(this.labelProvider);
|
278
|
comparator = new ChecklistEditorComparator();
|
279
|
viewer.setComparator(comparator);
|
280
|
|
281
|
createStatusBar(parent);
|
282
|
}
|
283
|
|
284
|
private void createGridDataForViewerLayout() {
|
285
|
GridData gridData = new GridData();
|
286
|
gridData.verticalAlignment = GridData.FILL;
|
287
|
gridData.horizontalSpan = 3;
|
288
|
gridData.grabExcessHorizontalSpace = true;
|
289
|
gridData.grabExcessVerticalSpace = true;
|
290
|
gridData.horizontalAlignment = GridData.FILL;
|
291
|
viewer.getControl().setLayoutData(gridData);
|
292
|
}
|
293
|
|
294
|
/**
|
295
|
* @param parent
|
296
|
* @return
|
297
|
*/
|
298
|
private Text createSearchBar(Composite parent) {
|
299
|
Label searchLabel = new Label(parent, SWT.NONE);
|
300
|
searchLabel.setText(Messages.ChecklistEditor_SEARCH);
|
301
|
final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
|
302
|
searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
|
303
|
searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
304
|
searchText.setText(TYPE_FILTER_TEXT);
|
305
|
return searchText;
|
306
|
}
|
307
|
|
308
|
/**
|
309
|
* @param parent
|
310
|
*/
|
311
|
private void createToolbar(Composite parent) {
|
312
|
ToolBar toolBar = new ToolBar(parent, SWT.NONE);
|
313
|
toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
|
314
|
toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
|
315
|
toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
|
316
|
createToolbarItems();
|
317
|
toolItem.addSelectionListener(dropListener);
|
318
|
toolBar.pack();
|
319
|
}
|
320
|
|
321
|
private void createToolbarItems() {
|
322
|
dropListener = new ChecklistDropdownSelectionListener(toolItem, this, terms);
|
323
|
|
324
|
for (DefinedTermBase<DefinedTermBase> term : terms) {
|
325
|
if(term!=null){
|
326
|
dropListener.add(term);
|
327
|
}
|
328
|
}
|
329
|
}
|
330
|
|
331
|
private void createStatusBar(Composite composite) {
|
332
|
GridData gridData = new GridData();
|
333
|
gridData.horizontalSpan = 3;
|
334
|
gridData.grabExcessHorizontalSpace = true;
|
335
|
gridData.horizontalAlignment = GridData.FILL;
|
336
|
|
337
|
statusLabel = new Label(composite, SWT.LEFT);
|
338
|
statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
|
339
|
statusLabel.setLayoutData(gridData);
|
340
|
}
|
341
|
|
342
|
private void createTable() {
|
343
|
Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
|
344
|
List<String> titles = new ArrayList<String>();
|
345
|
List<Integer> bounds = new ArrayList<Integer>();
|
346
|
if (PreferencesUtil.isShowRankInChecklistEditor()){
|
347
|
Collections.addAll(titles, Messages.ChecklistEditor_TAXON, Messages.ChecklistEditor_RANK);
|
348
|
Collections.addAll(bounds, 300, 200);
|
349
|
} else{
|
350
|
Collections.addAll(titles, Messages.ChecklistEditor_TAXON);
|
351
|
Collections.addAll(bounds, 300);
|
352
|
}
|
353
|
|
354
|
|
355
|
Map<Integer, Boolean> restoreValuesForColumnWidth = restoreValuesForColumnWidth(titles, bounds);
|
356
|
createInitalDistributionColumns(table, titles, bounds, restoreValuesForColumnWidth);
|
357
|
table.setSortDirection(SWT.DOWN);
|
358
|
table.setHeaderVisible(true);
|
359
|
table.setLinesVisible(true);
|
360
|
}
|
361
|
/**
|
362
|
* This method creates initially the distribution columns for a table. It should only be called for creation.<br>
|
363
|
*<p>
|
364
|
*
|
365
|
*<b>Notice:</b> If you want to add additional columns later please use <b>addTableViewerColumn()</b>
|
366
|
*
|
367
|
* @param table
|
368
|
* @param titles
|
369
|
* @param bounds
|
370
|
* @param restoreValuesForColumnWidth
|
371
|
*/
|
372
|
private void createInitalDistributionColumns(Table table,
|
373
|
List<String> titles, List<Integer> bounds, Map<Integer, Boolean> restoreValuesForColumnWidth) {
|
374
|
for (int columnIndex = 0; columnIndex < titles.size(); columnIndex++) {
|
375
|
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
|
376
|
column.getColumn().setText(titles.get(columnIndex));
|
377
|
column.getColumn().setWidth(bounds.get(columnIndex));
|
378
|
column.getColumn().setResizable(true);
|
379
|
column.getColumn().setMoveable(true);
|
380
|
column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn(), columnIndex));
|
381
|
if (columnIndex == 0) {
|
382
|
table.setSortColumn(column.getColumn());
|
383
|
}
|
384
|
if (columnIndex == 1 && PreferencesUtil.isShowRankInChecklistEditor()) {
|
385
|
/** uncommented it for now because no rank editing is wanted **/
|
386
|
// column.setEditingSupport(new RankEditingSupport(viewer, this));
|
387
|
}
|
388
|
if ((columnIndex == 1 && !PreferencesUtil.isShowRankInChecklistEditor()) || columnIndex >= 2 ) {
|
389
|
//read PrefrenceStore to setWidth according to last saved state
|
390
|
if(restoreValuesForColumnWidth.get(columnIndex)){
|
391
|
column.getColumn().setWidth(50);
|
392
|
}else{
|
393
|
column.getColumn().setWidth(50);
|
394
|
}
|
395
|
column.setEditingSupport(new DistributionEditingSupport(viewer, this, columnIndex));
|
396
|
}
|
397
|
}
|
398
|
}
|
399
|
|
400
|
/**
|
401
|
* This methods loads the last opened distribution columns for the table viewer from the prefrence store.<br>
|
402
|
*<p>
|
403
|
* <b>Notice:</b> It adds also the TitleCache to the titles list for the header of each column.<p>
|
404
|
*
|
405
|
* @param titles
|
406
|
* @param bounds
|
407
|
* @return Map<Integer, Boolean>
|
408
|
*/
|
409
|
private Map<Integer, Boolean> restoreValuesForColumnWidth(List<String> titles,
|
410
|
List<Integer> bounds) {
|
411
|
Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
|
412
|
if (terms != null) {
|
413
|
int columnIndex;
|
414
|
if (PreferencesUtil.isShowRankInChecklistEditor()){
|
415
|
columnIndex = 2;
|
416
|
} else{
|
417
|
columnIndex = 1;
|
418
|
}
|
419
|
for (DefinedTermBase<DefinedTermBase> term : terms) {
|
420
|
if(term != null){
|
421
|
restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
|
422
|
if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
|
423
|
if (term.getIdInVocabulary() != null){
|
424
|
titles.add(term.getIdInVocabulary());
|
425
|
} else{
|
426
|
titles.add(term.getTitleCache());
|
427
|
}
|
428
|
}else{
|
429
|
titles.add(term.getTitleCache());
|
430
|
}
|
431
|
bounds.add(200);
|
432
|
columnIndex++;
|
433
|
}
|
434
|
}
|
435
|
}
|
436
|
return restoreColumnWidth;
|
437
|
}
|
438
|
|
439
|
/**
|
440
|
* This method adds new DistributionColumns to an existing table.
|
441
|
*
|
442
|
* @param title
|
443
|
* @param bound
|
444
|
* @param colNumber
|
445
|
* @return
|
446
|
*/
|
447
|
private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber) {
|
448
|
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
|
449
|
final TableColumn column = viewerColumn.getColumn();
|
450
|
column.setText(title);
|
451
|
column.setWidth(200);
|
452
|
viewerColumn.setEditingSupport(new DistributionEditingSupport(viewer, this, colNumber));
|
453
|
column.setResizable(true);
|
454
|
column.setMoveable(true);
|
455
|
return viewerColumn;
|
456
|
}
|
457
|
|
458
|
|
459
|
|
460
|
/**
|
461
|
*
|
462
|
* pull data from database and set input for view
|
463
|
*
|
464
|
*/
|
465
|
private void loadDataInput() {
|
466
|
Classification classification = checklistEditorInput.getClassification();
|
467
|
TaxonNode taxonNode = checklistEditorInput.getTaxonNode();
|
468
|
if (classification != null && taxonNode == null) {
|
469
|
countNodes = taxonNodeService.countAllNodesForClassification(classification);
|
470
|
// statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
|
471
|
// This should not kill the view nor the editor if something goes
|
472
|
// wrong
|
473
|
// TODO: don't load the whole taxonNode Object but rather a small
|
474
|
// and simple Solution
|
475
|
// FIXME: May be don't open classification which are greater than
|
476
|
// 3000 Taxa
|
477
|
selectedTaxonNodes = taxonNodeService.listAllNodesForClassification(classification, 0, countNodes);
|
478
|
countNodes = selectedTaxonNodes.size();
|
479
|
statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
|
480
|
getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
|
481
|
}
|
482
|
if (taxonNode != null) {
|
483
|
selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
|
484
|
getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
|
485
|
countNodes = selectedTaxonNodes.size();
|
486
|
statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
|
487
|
}
|
488
|
}
|
489
|
|
490
|
/** {@inheritDoc} */
|
491
|
@Override
|
492
|
public void dispose() {
|
493
|
// this.checklistEditorInput.dispose();
|
494
|
super.dispose();
|
495
|
|
496
|
conversation.unregisterForDataStoreChanges(this);
|
497
|
conversation.unbind();
|
498
|
|
499
|
//conversation.close();
|
500
|
conversation = null;
|
501
|
}
|
502
|
|
503
|
/** {@inheritDoc} */
|
504
|
@Override
|
505
|
public void setFocus() {
|
506
|
|
507
|
viewer.getControl().setFocus();
|
508
|
}
|
509
|
|
510
|
/*
|
511
|
* (non-Javadoc)
|
512
|
*
|
513
|
* @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
|
514
|
*/
|
515
|
/** {@inheritDoc} */
|
516
|
@Override
|
517
|
public void showBusy(boolean busy) {
|
518
|
super.showBusy(busy);
|
519
|
// viewer.getTable().setEnabled(!busy);
|
520
|
if (busy) {
|
521
|
partNameCache = getPartName();
|
522
|
setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
|
523
|
} else {
|
524
|
if (partNameCache != null) {
|
525
|
setPartName(partNameCache);
|
526
|
}
|
527
|
}
|
528
|
}
|
529
|
|
530
|
/**
|
531
|
* <p>
|
532
|
* Getter for the field <code>viewer</code>.
|
533
|
* </p>
|
534
|
*
|
535
|
* @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
|
536
|
*/
|
537
|
public StructuredViewer getViewer() {
|
538
|
return viewer;
|
539
|
}
|
540
|
|
541
|
public void refresh() {
|
542
|
viewer.refresh();
|
543
|
}
|
544
|
|
545
|
/**
|
546
|
* This method should only be called for adding new Distribution columns and reloading the table.<br>
|
547
|
* It will hide the old distribution column and load the newly added columns.<br>
|
548
|
* <p>
|
549
|
* <b>Notice:</b> for data update please use <b>refresh()</b>
|
550
|
*
|
551
|
*/
|
552
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
553
|
public void reload(){
|
554
|
//create new Items for Dropdown menue
|
555
|
Table table = viewer.getTable();
|
556
|
table.setRedraw(false);
|
557
|
SortedSet<DefinedTermBase> oldTerms = terms;
|
558
|
|
559
|
// if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
|
560
|
//
|
561
|
// } else{
|
562
|
// terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
|
563
|
// }
|
564
|
SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas(true);
|
565
|
toolItem.removeSelectionListener(dropListener);
|
566
|
hideDistributionColumns(oldTerms);
|
567
|
createToolbarItems();
|
568
|
toolItem.addSelectionListener(dropListener);
|
569
|
for(DefinedTermBase term:newTerms){
|
570
|
int count = viewer.getTable().getColumnCount();
|
571
|
addTableViewerColumn(term.getTitleCache(), 200, count);
|
572
|
acitivateNewColumnInDropDownMenu(term);
|
573
|
}
|
574
|
viewer.setLabelProvider(labelProvider);
|
575
|
getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
|
576
|
table.setRedraw(true);
|
577
|
viewer.refresh();
|
578
|
}
|
579
|
|
580
|
private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
|
581
|
Menu menu = dropListener.getMenu();
|
582
|
MenuItem[] items = menu.getItems();
|
583
|
for(MenuItem item: items){
|
584
|
if(item.getText().equalsIgnoreCase(term.getTitleCache())){
|
585
|
item.setSelection(true);
|
586
|
PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
|
587
|
}
|
588
|
}
|
589
|
}
|
590
|
|
591
|
private void hideDistributionColumns(SortedSet<DefinedTermBase> oldTerms) {
|
592
|
TableColumn[] columns = viewer.getTable().getColumns();
|
593
|
for(int i=4; i<columns.length; i++){
|
594
|
//remove all columns
|
595
|
columns[i].dispose();
|
596
|
Menu menu = dropListener.getMenu();
|
597
|
int itemCount = menu.getItemCount();
|
598
|
MenuItem item = menu.getItem(i-3);
|
599
|
item.setSelection(false);
|
600
|
}
|
601
|
if(oldTerms != null){
|
602
|
for(DefinedTermBase term : oldTerms){
|
603
|
PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
|
604
|
}
|
605
|
}
|
606
|
}
|
607
|
|
608
|
/**
|
609
|
* <p>
|
610
|
* Getter for the field <code>service</code>.
|
611
|
* </p>
|
612
|
*
|
613
|
* @return the service
|
614
|
*/
|
615
|
public IWorkbenchSiteProgressService getService() {
|
616
|
return service;
|
617
|
}
|
618
|
|
619
|
private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
|
620
|
SelectionAdapter selectionAdapter = new SelectionAdapter() {
|
621
|
@Override
|
622
|
public void widgetSelected(SelectionEvent e) {
|
623
|
comparator.setColumn(index);
|
624
|
int dir = viewer.getTable().getSortDirection();
|
625
|
if (viewer.getTable().getSortColumn() == column) {
|
626
|
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
|
627
|
} else {
|
628
|
dir = SWT.DOWN;
|
629
|
}
|
630
|
viewer.getTable().setSortDirection(dir);
|
631
|
viewer.getTable().setSortColumn(column);
|
632
|
viewer.refresh();
|
633
|
}
|
634
|
};
|
635
|
return selectionAdapter;
|
636
|
}
|
637
|
|
638
|
@Override
|
639
|
public void doSave(IProgressMonitor monitor) {
|
640
|
try {
|
641
|
monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
|
642
|
if (!conversation.isBound()) {
|
643
|
conversation.bind();
|
644
|
}
|
645
|
CdmStore.getService(ITaxonNodeService.class).merge(selectedTaxonNodes, true);
|
646
|
//this.checklistEditorInput.merge();
|
647
|
conversation.commit(true);
|
648
|
setDirty(false);
|
649
|
monitor.worked(1);
|
650
|
} finally {
|
651
|
monitor.done();
|
652
|
}
|
653
|
|
654
|
}
|
655
|
|
656
|
@Override
|
657
|
public void doSaveAs() {
|
658
|
}
|
659
|
|
660
|
@Override
|
661
|
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
|
662
|
setSite(site);
|
663
|
setInput(input);
|
664
|
if (input instanceof ChecklistEditorInput) {
|
665
|
checklistEditorInput = (ChecklistEditorInput) input;
|
666
|
setPartName(getPartName() + ": " + checklistEditorInput.getName()); //$NON-NLS-1$
|
667
|
conversation = checklistEditorInput.getConversation();
|
668
|
conversation.registerForDataStoreChanges(this);
|
669
|
}
|
670
|
simpleSelectionProvider = new SimpleSelectionProvider();
|
671
|
getSite().setSelectionProvider(simpleSelectionProvider);
|
672
|
|
673
|
}
|
674
|
|
675
|
@Override
|
676
|
public boolean isSaveAsAllowed() {
|
677
|
return false;
|
678
|
}
|
679
|
|
680
|
/*
|
681
|
* (non-Javadoc)
|
682
|
*
|
683
|
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.
|
684
|
* IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
|
685
|
*/
|
686
|
@Override
|
687
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
688
|
// System.out.println(selection.getClass().getSimpleName());
|
689
|
// viewer.setSelection(selection, true);
|
690
|
}
|
691
|
|
692
|
|
693
|
|
694
|
|
695
|
|
696
|
/*
|
697
|
* (non-Javadoc)
|
698
|
*
|
699
|
* @see
|
700
|
* eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
|
701
|
* eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
702
|
*/
|
703
|
|
704
|
@Override
|
705
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
706
|
|
707
|
}
|
708
|
|
709
|
/*
|
710
|
* (non-Javadoc)
|
711
|
*
|
712
|
* @see
|
713
|
* eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse
|
714
|
* .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
715
|
*/
|
716
|
@Override
|
717
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
718
|
// IStructuredSelection sel = (IStructuredSelection) this.viewer.getSelection();
|
719
|
// if (sel.isEmpty()) {
|
720
|
// return;
|
721
|
// }
|
722
|
// memento = memento.createChild("tree-selections");
|
723
|
// Iterator iter = sel.iterator();
|
724
|
// while (iter.hasNext()) {
|
725
|
// String nodeName = (String) iter.next();
|
726
|
// memento.createChild("selected-nodes", nodeName);
|
727
|
// }
|
728
|
}
|
729
|
|
730
|
/*
|
731
|
* (non-Javadoc)
|
732
|
*
|
733
|
* @see
|
734
|
* eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse
|
735
|
* .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
736
|
*/
|
737
|
@Override
|
738
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
739
|
|
740
|
}
|
741
|
|
742
|
/*
|
743
|
* (non-Javadoc)
|
744
|
*
|
745
|
* @see
|
746
|
* eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse
|
747
|
* .core.runtime.IProgressMonitor)
|
748
|
*/
|
749
|
@Override
|
750
|
public void contextRefresh(IProgressMonitor monitor) {
|
751
|
}
|
752
|
|
753
|
/*
|
754
|
* (non-Javadoc)
|
755
|
*
|
756
|
* @see
|
757
|
* eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse
|
758
|
* .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
759
|
*/
|
760
|
@Override
|
761
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
762
|
conversation.clear();
|
763
|
conversation.close();
|
764
|
conversation = null;
|
765
|
}
|
766
|
|
767
|
private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
|
768
|
"descriptions.*", "description.state", "feature", "feature.*", "childNodes", "childNodes.taxon", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
769
|
"childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
770
|
"taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
771
|
"name.rank.representations", "name.status.type.representations", "stateData.$" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
772
|
|
773
|
/*
|
774
|
* (non-Javadoc)
|
775
|
*
|
776
|
* @see
|
777
|
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
|
778
|
* java.lang.Object)
|
779
|
*/
|
780
|
@Override
|
781
|
public void changed(Object element) {
|
782
|
if (element != null) {
|
783
|
viewer.update(element, null);
|
784
|
if (element instanceof Taxon){
|
785
|
checklistEditorInput.addTaxonToSave((Taxon)element);
|
786
|
}
|
787
|
setDirty(true);
|
788
|
firePropertyChange(PROP_DIRTY);
|
789
|
}
|
790
|
}
|
791
|
|
792
|
/* (non-Javadoc)
|
793
|
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
|
794
|
*/
|
795
|
@Override
|
796
|
public void forceDirty() {
|
797
|
changed(null);
|
798
|
}
|
799
|
|
800
|
public void setDirty(boolean dirty) {
|
801
|
this.dirty = dirty;
|
802
|
firePropertyChange(PROP_DIRTY);
|
803
|
}
|
804
|
|
805
|
/*
|
806
|
* (non-Javadoc)
|
807
|
*
|
808
|
* @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
|
809
|
*/
|
810
|
@Override
|
811
|
public boolean isDirty() {
|
812
|
return dirty;
|
813
|
}
|
814
|
|
815
|
/* (non-Javadoc)
|
816
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
|
817
|
*/
|
818
|
|
819
|
|
820
|
// /* (non-Javadoc)
|
821
|
// * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
822
|
// */
|
823
|
// @Override
|
824
|
// public <T extends CdmBase> Collection<T> getRootEntities() {
|
825
|
// // TODO Auto-generated method stub
|
826
|
// return null;
|
827
|
// }
|
828
|
//
|
829
|
// /* (non-Javadoc)
|
830
|
// * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
|
831
|
// */
|
832
|
// @Override
|
833
|
// public Map<Object, List<String>> getPropertyPathsMap() {
|
834
|
// // TODO Auto-generated method stub
|
835
|
// return null;
|
836
|
// }
|
837
|
|
838
|
/**
|
839
|
* @return the labelProvider
|
840
|
*/
|
841
|
public ChecklistLabelProvider getLabelProvider() {
|
842
|
return labelProvider;
|
843
|
}
|
844
|
|
845
|
/* (non-Javadoc)
|
846
|
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
847
|
*/
|
848
|
@Override
|
849
|
public void update(CdmDataChangeMap arg0) {
|
850
|
// TODO Auto-generated method stub
|
851
|
|
852
|
}
|
853
|
|
854
|
/* (non-Javadoc)
|
855
|
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
|
856
|
*/
|
857
|
@Override
|
858
|
public ConversationHolder getConversationHolder() {
|
859
|
|
860
|
return conversation;
|
861
|
}
|
862
|
|
863
|
|
864
|
}
|