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