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