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
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.Comparator;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Observable;
|
19
|
import java.util.Observer;
|
20
|
import java.util.Set;
|
21
|
import java.util.UUID;
|
22
|
|
23
|
import javax.annotation.PostConstruct;
|
24
|
import javax.annotation.PreDestroy;
|
25
|
import javax.inject.Inject;
|
26
|
|
27
|
import org.eclipse.core.commands.operations.UndoContext;
|
28
|
import org.eclipse.core.runtime.IAdaptable;
|
29
|
import org.eclipse.core.runtime.IProgressMonitor;
|
30
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
31
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
32
|
import org.eclipse.e4.core.di.annotations.Optional;
|
33
|
import org.eclipse.e4.ui.di.Focus;
|
34
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
35
|
import org.eclipse.e4.ui.di.UISynchronize;
|
36
|
import org.eclipse.e4.ui.model.application.MApplication;
|
37
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
38
|
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
|
39
|
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
|
40
|
import org.eclipse.e4.ui.model.application.ui.menu.impl.HandledToolItemImpl;
|
41
|
import org.eclipse.e4.ui.services.EMenuService;
|
42
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
43
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
44
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
45
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
46
|
import org.eclipse.jface.viewers.IElementComparer;
|
47
|
import org.eclipse.jface.viewers.ISelection;
|
48
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
49
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
50
|
import org.eclipse.jface.viewers.StructuredSelection;
|
51
|
import org.eclipse.jface.viewers.TreePath;
|
52
|
import org.eclipse.jface.viewers.TreeViewer;
|
53
|
import org.eclipse.swt.SWT;
|
54
|
import org.eclipse.swt.dnd.DND;
|
55
|
import org.eclipse.swt.dnd.Transfer;
|
56
|
import org.eclipse.swt.layout.FillLayout;
|
57
|
import org.eclipse.swt.widgets.Composite;
|
58
|
import org.eclipse.swt.widgets.Tree;
|
59
|
import org.eclipse.ui.IMemento;
|
60
|
|
61
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
62
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
|
63
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
64
|
import eu.etaxonomy.cdm.api.application.ICdmChangeListener;
|
65
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
66
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
67
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
68
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
69
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
70
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
71
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
72
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
73
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
74
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByNameComparator;
|
75
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator;
|
76
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoNaturalComparator;
|
77
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
78
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
79
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
80
|
import eu.etaxonomy.taxeditor.event.EventUtility;
|
81
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
82
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
83
|
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
|
84
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
85
|
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
|
86
|
import eu.etaxonomy.taxeditor.navigation.AppModelId;
|
87
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
88
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
89
|
import eu.etaxonomy.taxeditor.navigation.navigator.EmptyRoot;
|
90
|
import eu.etaxonomy.taxeditor.navigation.navigator.Root;
|
91
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodeNavigatorComparator;
|
92
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
93
|
import eu.etaxonomy.taxeditor.preference.NavigatorOrderEnum;
|
94
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
95
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
96
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
97
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
98
|
import eu.etaxonomy.taxeditor.store.LoginManager;
|
99
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
100
|
import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
|
101
|
|
102
|
/**
|
103
|
* @author pplitzner
|
104
|
* @since Sep 7, 2017
|
105
|
*/
|
106
|
public class TaxonNavigatorE4 implements
|
107
|
IPostOperationEnabled, IConversationEnabled, Observer,
|
108
|
ICdmEntitySessionEnabled, ICdmChangeListener, IContextListener,
|
109
|
ICollapsableExpandable {
|
110
|
|
111
|
private static final String RESTORING_TAXON_NAVIGATOR = Messages.TaxonNavigator_RESTORE;
|
112
|
|
113
|
private static final String TREE_PATH = "treepath"; //$NON-NLS-1$
|
114
|
|
115
|
private static final String TREE_PATHS = "treepaths"; //$NON-NLS-1$
|
116
|
|
117
|
private final int dndOperations = DND.DROP_MOVE;
|
118
|
|
119
|
private ConversationHolder conversation;
|
120
|
|
121
|
private ICdmEntitySession cdmEntitySession;
|
122
|
|
123
|
private IDataChangeBehavior dataChangeBehavior;
|
124
|
|
125
|
private Root root;
|
126
|
|
127
|
private TreeViewer viewer;
|
128
|
|
129
|
@Inject
|
130
|
private ESelectionService selService;
|
131
|
|
132
|
@Inject
|
133
|
private UISynchronize sync;
|
134
|
|
135
|
private ISelectionChangedListener selectionChangedListener;
|
136
|
|
137
|
private UndoContext undoContext;
|
138
|
|
139
|
@Inject
|
140
|
private MApplication application;
|
141
|
|
142
|
@Inject
|
143
|
private EModelService modelService;
|
144
|
|
145
|
@Inject
|
146
|
private EPartService partService;
|
147
|
|
148
|
private boolean linkWithTaxon = false;
|
149
|
|
150
|
@Inject
|
151
|
public TaxonNavigatorE4() {
|
152
|
undoContext = new UndoContext();
|
153
|
CdmStore.getContextManager().addContextListener(this);
|
154
|
}
|
155
|
|
156
|
@PostConstruct
|
157
|
private void create(Composite parent, EMenuService menuService, IEclipseContext context){
|
158
|
FillLayout layout = new FillLayout();
|
159
|
layout.marginHeight = 0;
|
160
|
layout.marginWidth = 0;
|
161
|
layout.type = SWT.VERTICAL;
|
162
|
|
163
|
parent.setLayout(layout);
|
164
|
viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
|
165
|
viewer.getControl().setLayoutData(LayoutConstants.FILL());
|
166
|
|
167
|
viewer.setContentProvider(new TaxonNavigatorContentProviderE4());
|
168
|
viewer.setLabelProvider(new TaxonNavigatorLabelProviderE4());
|
169
|
viewer.addDoubleClickListener(event->{
|
170
|
ISelection selection = event.getSelection();
|
171
|
if(selection instanceof IStructuredSelection){
|
172
|
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
|
173
|
if(firstElement instanceof ICdmBase){
|
174
|
NavigationUtil.openEditor((ICdmBase) firstElement, viewer.getControl().getShell(), modelService, partService, application);
|
175
|
}
|
176
|
if(firstElement instanceof TaxonNodeDto){
|
177
|
NavigationUtil.openEditor((TaxonNodeDto) firstElement, viewer.getControl().getShell(), modelService, partService, application);
|
178
|
}
|
179
|
}
|
180
|
});
|
181
|
|
182
|
//propagate selection
|
183
|
selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
|
184
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
185
|
|
186
|
//create context menu
|
187
|
menuService.registerContextMenu(viewer.getControl(), AppModelId.POPUPMENU_EU_ETAXONOMY_TAXEDITOR_NAVIGATOR_POPUPMENU_TAXONNAVIGATOR );
|
188
|
|
189
|
//add drag'n'drop support
|
190
|
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer()};
|
191
|
viewer.addDragSupport(dndOperations, transfers, new TreeNodeDragListenerE4(viewer));
|
192
|
TreeNodeDropAdapterE4 dropAdapter = new TreeNodeDropAdapterE4(this);
|
193
|
ContextInjectionFactory.inject(dropAdapter, context);
|
194
|
viewer.addDropSupport(dndOperations, transfers, dropAdapter);
|
195
|
|
196
|
updateSyncButton();
|
197
|
|
198
|
|
199
|
|
200
|
init();
|
201
|
}
|
202
|
|
203
|
protected void updateSyncButton() {
|
204
|
MPart viewPart = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_NAVIGATION_NAVIGATOR);
|
205
|
if(viewPart!=null){
|
206
|
MToolBar toolBar = viewPart.getToolbar();
|
207
|
|
208
|
List<MToolBarElement> toolBarElements = toolBar.getChildren();
|
209
|
|
210
|
MToolBarElement upperHandledMenuItem = toolBarElements.get(1);
|
211
|
if (upperHandledMenuItem instanceof HandledToolItemImpl){
|
212
|
((HandledToolItemImpl)upperHandledMenuItem).setSelected(linkWithTaxon);
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
|
217
|
/** {@inheritDoc} */
|
218
|
protected IAdaptable getInitialInput() {
|
219
|
Comparator<TaxonNodeDto> comparator;
|
220
|
NavigatorOrderEnum orderValue = NavigatorOrderEnum.RankAndNameOrder;
|
221
|
try{
|
222
|
orderValue = PreferencesUtil.getSortNodes();
|
223
|
}catch(IllegalArgumentException e){
|
224
|
|
225
|
}
|
226
|
|
227
|
if (orderValue.equals(NavigatorOrderEnum.NaturalOrder)){
|
228
|
comparator = new TaxonNodeDtoNaturalComparator();
|
229
|
} else if (orderValue.equals(NavigatorOrderEnum.AlphabeticalOrder)){
|
230
|
comparator = new TaxonNodeDtoByNameComparator();
|
231
|
}else {
|
232
|
comparator = new TaxonNodeDtoByRankAndNameComparator();
|
233
|
}
|
234
|
|
235
|
TaxonNodeNavigatorComparator viewerComparator = new TaxonNodeNavigatorComparator(comparator);
|
236
|
viewer.setComparator(viewerComparator);
|
237
|
viewer.setComparer(new IElementComparer() {
|
238
|
|
239
|
@Override
|
240
|
public int hashCode(Object element) {
|
241
|
if (element instanceof TaxonNodeDto){
|
242
|
TaxonNodeDto nodeDto = (TaxonNodeDto)element;
|
243
|
|
244
|
String s = nodeDto.getUuid().toString();
|
245
|
if (s != null) {
|
246
|
return s.hashCode();
|
247
|
}
|
248
|
return element.hashCode();
|
249
|
}else{
|
250
|
return element.toString().hashCode();
|
251
|
}
|
252
|
}
|
253
|
|
254
|
@Override
|
255
|
public boolean equals(Object element1, Object element2) {
|
256
|
if (element1 instanceof TaxonNodeDto && element2 instanceof TaxonNodeDto){
|
257
|
TaxonNodeDto node1 = (TaxonNodeDto)element1;
|
258
|
TaxonNodeDto node2 = (TaxonNodeDto)element2;
|
259
|
return (node1.getUuid().equals(node2.getUuid()));
|
260
|
}else {
|
261
|
return element1.equals(element2);
|
262
|
}
|
263
|
}
|
264
|
}
|
265
|
);
|
266
|
|
267
|
if (CdmStore.isActive()) {
|
268
|
|
269
|
// TODO when closing and reopening the taxon navigator
|
270
|
// we do not preserve state. Closing the view, in contrary to
|
271
|
// closing the whole application
|
272
|
// should be handled by the state manager too
|
273
|
root = new Root(conversation);
|
274
|
|
275
|
return root;
|
276
|
}
|
277
|
return new EmptyRoot();
|
278
|
}
|
279
|
|
280
|
public void init() {
|
281
|
if (CdmStore.isActive() && conversation == null) {
|
282
|
conversation = CdmStore.createConversation();
|
283
|
conversation.registerForDataStoreChanges(TaxonNavigatorE4.this);
|
284
|
}
|
285
|
if (CdmStore.isActive()) {
|
286
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
287
|
CdmApplicationState.getCurrentDataChangeService().register(this);
|
288
|
viewer.setInput(getInitialInput());
|
289
|
}
|
290
|
CdmStore.getLoginManager().addObserver(this);
|
291
|
|
292
|
}
|
293
|
|
294
|
//Link with taxon selection
|
295
|
@Inject
|
296
|
@Optional
|
297
|
public void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
|
298
|
if(linkWithTaxon && editor!=null){
|
299
|
viewer.refresh();
|
300
|
TaxonNodeDto taxonNode = null;
|
301
|
if(editor.getTaxon()!=null && editor.getTaxon().getTaxonNodes()!=null){
|
302
|
if (editor instanceof TaxonNameEditorE4){
|
303
|
taxonNode = new TaxonNodeDto( ((TaxonNameEditorE4)editor).getEditorInput().getTaxonNode());
|
304
|
}else{
|
305
|
if (editor.getTaxon().getTaxonNodes() != null && !editor.getTaxon().getTaxonNodes().isEmpty()){
|
306
|
taxonNode = new TaxonNodeDto(editor.getTaxon().getTaxonNodes().iterator().next());
|
307
|
}
|
308
|
}
|
309
|
if (taxonNode != null){
|
310
|
viewer.reveal(taxonNode);
|
311
|
viewer.setSelection(new StructuredSelection(taxonNode));
|
312
|
}else{
|
313
|
//TODO: show message in status bar
|
314
|
}
|
315
|
|
316
|
}
|
317
|
}
|
318
|
}
|
319
|
|
320
|
@Inject
|
321
|
@Optional
|
322
|
public void updateLinkWithTaxon(@UIEventTopic(WorkbenchEventConstants.UPDATE_LINK_WITH_TAXON) boolean isLinkWithTaxon){
|
323
|
this.linkWithTaxon = !linkWithTaxon;
|
324
|
|
325
|
if(this.isLinkWithTaxon()){
|
326
|
this.updateCurrentTaxon(EventUtility.getTaxonEditor());
|
327
|
}
|
328
|
}
|
329
|
|
330
|
public void setLinkWithTaxon(boolean linkWithTaxon) {
|
331
|
this.linkWithTaxon = linkWithTaxon;
|
332
|
}
|
333
|
|
334
|
public boolean isLinkWithTaxon() {
|
335
|
return linkWithTaxon;
|
336
|
}
|
337
|
|
338
|
/**
|
339
|
* Refresh this navigators viewer
|
340
|
*/
|
341
|
public void refresh() {
|
342
|
if(getConversationHolder() != null){
|
343
|
getConversationHolder().bind();
|
344
|
//FIXME : Need to make sure this is a stable fix (ticket 3822)
|
345
|
if(!getConversationHolder().isCompleted()){
|
346
|
getConversationHolder().commit();
|
347
|
}
|
348
|
}
|
349
|
if(!viewer.getTree().isDisposed()){
|
350
|
if (CdmStore.isActive()){
|
351
|
viewer.setInput(getInitialInput());
|
352
|
}
|
353
|
viewer.refresh();
|
354
|
}
|
355
|
|
356
|
updateSyncButton();
|
357
|
}
|
358
|
|
359
|
/**
|
360
|
* Refresh this navigators viewer
|
361
|
*/
|
362
|
public void refresh(Set<?> objects) {
|
363
|
for(Object obj : objects) {
|
364
|
viewer.refresh(obj);
|
365
|
}
|
366
|
updateSyncButton();
|
367
|
}
|
368
|
|
369
|
/**
|
370
|
* Refresh this navigators viewer
|
371
|
*/
|
372
|
public void refresh(Object object) {
|
373
|
viewer.refresh(object);
|
374
|
updateSyncButton();
|
375
|
}
|
376
|
|
377
|
/**
|
378
|
* Removes all content
|
379
|
*/
|
380
|
public void clear() {
|
381
|
viewer.setInput(new EmptyRoot());
|
382
|
}
|
383
|
|
384
|
private void restore(IMemento memento, IProgressMonitor monitor) {
|
385
|
root = new Root(conversation);
|
386
|
if (memento == null) {
|
387
|
viewer.setInput(root);
|
388
|
return;
|
389
|
}
|
390
|
int mementoWork = 0;
|
391
|
Set<TreePath> treePaths = new HashSet<TreePath>();
|
392
|
IMemento[] treePathMementos = null;
|
393
|
|
394
|
IMemento treePathsMemento = memento.getChild(TREE_PATHS);
|
395
|
|
396
|
if (treePathsMemento != null) {
|
397
|
treePathMementos = treePathsMemento.getChildren(TREE_PATH);
|
398
|
mementoWork = treePathMementos.length;
|
399
|
}
|
400
|
// begin the monitor with steps for all tree paths and steps for
|
401
|
// creating
|
402
|
// conversation s.o., refreshing the tree and setting the paths
|
403
|
IProgressMonitor subProgressMonitor = AbstractUtility
|
404
|
.getSubProgressMonitor(monitor, 1);
|
405
|
|
406
|
subProgressMonitor.beginTask(RESTORING_TAXON_NAVIGATOR,
|
407
|
1 + mementoWork + 5);
|
408
|
subProgressMonitor.subTask(RESTORING_TAXON_NAVIGATOR);
|
409
|
subProgressMonitor.worked(1);
|
410
|
|
411
|
conversation = CdmStore.createConversation();
|
412
|
subProgressMonitor.worked(1);
|
413
|
conversation.registerForDataStoreChanges(TaxonNavigatorE4.this);
|
414
|
subProgressMonitor.worked(1);
|
415
|
viewer.setInput(root);
|
416
|
subProgressMonitor.worked(1);
|
417
|
viewer.refresh();
|
418
|
subProgressMonitor.worked(1);
|
419
|
|
420
|
if (treePathMementos != null && treePathMementos.length > 0) {
|
421
|
for (IMemento treePathMemento : treePathMementos) {
|
422
|
TreePath treePath = createTreePathFromString(treePathMemento
|
423
|
.getID());
|
424
|
if (!subProgressMonitor.isCanceled() && treePath != null) {
|
425
|
treePaths.add(treePath);
|
426
|
subProgressMonitor.worked(1);
|
427
|
}
|
428
|
}
|
429
|
}
|
430
|
if (treePaths.size() > 0) {
|
431
|
TaxonNavigatorE4.this.viewer.setExpandedTreePaths(
|
432
|
treePaths.toArray(new TreePath[0]));
|
433
|
subProgressMonitor.worked(1);
|
434
|
}
|
435
|
subProgressMonitor.done();
|
436
|
}
|
437
|
|
438
|
private TreePath createTreePathFromString(String string) {
|
439
|
|
440
|
List<CdmBase> pathList = new ArrayList<CdmBase>();
|
441
|
|
442
|
if (string.length() == 0) {
|
443
|
return null;
|
444
|
}
|
445
|
|
446
|
for (String uuid : string.split(" ")) { //$NON-NLS-1$
|
447
|
CdmBase cdmBaseObject = CdmStore.getService(
|
448
|
ITaxonNodeService.class).find(
|
449
|
UUID.fromString(uuid));
|
450
|
if (cdmBaseObject == null) {
|
451
|
// is this a tree uuid?
|
452
|
cdmBaseObject = CdmStore.getService(
|
453
|
IClassificationService.class).load(
|
454
|
UUID.fromString(uuid));
|
455
|
|
456
|
if (cdmBaseObject == null) {
|
457
|
return null;
|
458
|
}
|
459
|
}
|
460
|
pathList.add(cdmBaseObject);
|
461
|
}
|
462
|
return new TreePath(pathList.toArray());
|
463
|
}
|
464
|
|
465
|
/**
|
466
|
* {@inheritDoc}
|
467
|
*/
|
468
|
@Override
|
469
|
public void collapse() {
|
470
|
viewer.collapseAll();
|
471
|
}
|
472
|
|
473
|
/**
|
474
|
* {@inheritDoc}
|
475
|
*/
|
476
|
@Override
|
477
|
public void expand() {
|
478
|
viewer.expandAll();
|
479
|
}
|
480
|
|
481
|
@Override
|
482
|
public ConversationHolder getConversationHolder() {
|
483
|
return conversation;
|
484
|
}
|
485
|
|
486
|
/** {@inheritDoc} */
|
487
|
@PreDestroy
|
488
|
public void dispose() {
|
489
|
dataChangeBehavior = null;
|
490
|
if (conversation != null) {
|
491
|
conversation.unregisterForDataStoreChanges(this);
|
492
|
conversation.close();
|
493
|
}
|
494
|
if(cdmEntitySession != null) {
|
495
|
cdmEntitySession.dispose();
|
496
|
cdmEntitySession = null;
|
497
|
}
|
498
|
if(CdmApplicationState.getCurrentDataChangeService() != null) {
|
499
|
CdmApplicationState.getCurrentDataChangeService().unregister(this);
|
500
|
}
|
501
|
}
|
502
|
|
503
|
/** {@inheritDoc} */
|
504
|
@Focus
|
505
|
public void setFocus() {
|
506
|
if (getConversationHolder() != null) {
|
507
|
getConversationHolder().bind();
|
508
|
}
|
509
|
if(cdmEntitySession != null) {
|
510
|
cdmEntitySession.bind();
|
511
|
}
|
512
|
}
|
513
|
|
514
|
public UISynchronize getSync() {
|
515
|
return sync;
|
516
|
}
|
517
|
|
518
|
public TreeViewer getViewer() {
|
519
|
return viewer;
|
520
|
}
|
521
|
|
522
|
public UndoContext getUndoContext() {
|
523
|
return undoContext;
|
524
|
}
|
525
|
|
526
|
/** {@inheritDoc} */
|
527
|
@Override
|
528
|
public boolean postOperation(Object objectAffectedByOperation) {
|
529
|
viewer.refresh();
|
530
|
return true;
|
531
|
}
|
532
|
|
533
|
@Override
|
534
|
public boolean onComplete() {
|
535
|
return true;
|
536
|
}
|
537
|
|
538
|
@Override
|
539
|
public void update(Observable o, Object arg) {
|
540
|
if(o instanceof LoginManager){
|
541
|
refresh();
|
542
|
}
|
543
|
|
544
|
}
|
545
|
/** {@inheritDoc} */
|
546
|
@Override
|
547
|
public void update(CdmDataChangeMap changeEvents) {
|
548
|
if (dataChangeBehavior == null) {
|
549
|
dataChangeBehavior = new TaxonNavigatorDataChangeBehaviorE4(this);
|
550
|
}
|
551
|
|
552
|
DataChangeBridge.handleDataChange(changeEvents, dataChangeBehavior);
|
553
|
updateSyncButton();
|
554
|
|
555
|
}
|
556
|
|
557
|
@Override
|
558
|
public ICdmEntitySession getCdmEntitySession() {
|
559
|
return cdmEntitySession;
|
560
|
}
|
561
|
|
562
|
@Override
|
563
|
public List<TaxonNodeDto> getRootEntities() {
|
564
|
if(root != null) {
|
565
|
return root.getParentBeans();
|
566
|
}
|
567
|
return null;
|
568
|
}
|
569
|
|
570
|
@Override
|
571
|
public void onChange(CdmChangeEvent event) {
|
572
|
Object[] expandedElements = viewer.getExpandedElements();
|
573
|
refresh();
|
574
|
for(CdmBase cb : event.getChangedObjects()) {
|
575
|
if(cb instanceof TaxonNode) {
|
576
|
TaxonNode tn = (TaxonNode)cb;
|
577
|
if(tn.getTaxon() == null) {
|
578
|
viewer.refresh(tn.getClassification());
|
579
|
} else {
|
580
|
viewer.refresh(cb);
|
581
|
}
|
582
|
} else if (cb instanceof Classification) {
|
583
|
if ( event.getAction().equals(Action.Create)){
|
584
|
root.addRootNode((Classification)cb);
|
585
|
} else if ( event.getAction().equals(Action.Delete)){
|
586
|
root.removeRootNode((Classification)cb);
|
587
|
}
|
588
|
viewer.refresh();
|
589
|
}
|
590
|
}
|
591
|
viewer.setExpandedElements(expandedElements);
|
592
|
}
|
593
|
|
594
|
@Override
|
595
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
596
|
Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
|
597
|
List<String> taxonNodePropertyPaths = Arrays.asList(new String[] {
|
598
|
"taxon.name" //$NON-NLS-1$
|
599
|
});
|
600
|
propertyPathsMap.put("childNodes", taxonNodePropertyPaths); //$NON-NLS-1$
|
601
|
return propertyPathsMap;
|
602
|
}
|
603
|
|
604
|
@Override
|
605
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
606
|
// TODO Auto-generated method stub
|
607
|
|
608
|
}
|
609
|
|
610
|
@Override
|
611
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
612
|
}
|
613
|
|
614
|
@Override
|
615
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
616
|
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
|
617
|
init();
|
618
|
}
|
619
|
}
|
620
|
|
621
|
@Override
|
622
|
public void contextRefresh(IProgressMonitor monitor) {
|
623
|
// viewer.refresh();
|
624
|
}
|
625
|
|
626
|
@Override
|
627
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
628
|
}
|
629
|
|
630
|
@Inject
|
631
|
@Optional
|
632
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAVIGATOR)TaxonNodeDto dto){
|
633
|
if(dto!= null){
|
634
|
Object[] expandedElements = viewer.getExpandedElements();
|
635
|
|
636
|
refresh();
|
637
|
viewer.setExpandedElements(expandedElements);
|
638
|
viewer.reveal(dto);
|
639
|
viewer.setSelection(new StructuredSelection(dto));
|
640
|
|
641
|
}
|
642
|
}
|
643
|
|
644
|
@Inject
|
645
|
@Optional
|
646
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAVIGATOR)boolean refresh){
|
647
|
if(refresh){
|
648
|
Object[] expandedElements = viewer.getExpandedElements();
|
649
|
refresh();
|
650
|
viewer.setExpandedElements(expandedElements);
|
651
|
|
652
|
}
|
653
|
}
|
654
|
}
|