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.editor.name.e4;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import javax.annotation.PostConstruct;
|
18
|
import javax.annotation.PreDestroy;
|
19
|
import javax.inject.Inject;
|
20
|
|
21
|
import org.apache.commons.lang3.StringUtils;
|
22
|
import org.eclipse.core.commands.operations.IUndoContext;
|
23
|
import org.eclipse.core.commands.operations.UndoContext;
|
24
|
import org.eclipse.core.runtime.IProgressMonitor;
|
25
|
import org.eclipse.core.runtime.OperationCanceledException;
|
26
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
27
|
import org.eclipse.e4.core.di.annotations.Optional;
|
28
|
import org.eclipse.e4.core.services.events.IEventBroker;
|
29
|
import org.eclipse.e4.ui.di.Focus;
|
30
|
import org.eclipse.e4.ui.di.Persist;
|
31
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
32
|
import org.eclipse.e4.ui.di.UISynchronize;
|
33
|
import org.eclipse.e4.ui.model.application.MApplication;
|
34
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
35
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
36
|
import org.eclipse.e4.ui.services.EMenuService;
|
37
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
38
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
39
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
40
|
import org.eclipse.jface.dialogs.MessageDialog;
|
41
|
import org.eclipse.jface.viewers.ISelection;
|
42
|
import org.eclipse.jface.viewers.StructuredSelection;
|
43
|
import org.eclipse.swt.dnd.DND;
|
44
|
import org.eclipse.swt.dnd.DropTarget;
|
45
|
import org.eclipse.swt.dnd.Transfer;
|
46
|
import org.eclipse.swt.graphics.Color;
|
47
|
import org.eclipse.swt.widgets.Composite;
|
48
|
import org.eclipse.ui.ISelectionListener;
|
49
|
import org.eclipse.ui.IWorkbenchPart;
|
50
|
import org.eclipse.ui.IWorkbenchPartReference;
|
51
|
import org.eclipse.ui.forms.ManagedForm;
|
52
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
53
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
54
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
55
|
|
56
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
57
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
58
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
59
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
60
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
61
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
62
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
63
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
64
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
65
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
66
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
67
|
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
|
68
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
69
|
import eu.etaxonomy.taxeditor.editor.ISecuredEditor;
|
70
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
71
|
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInput;
|
72
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
73
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
74
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroup;
|
75
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupedContainer;
|
76
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedGroup;
|
77
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedNameContainerE4;
|
78
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.ConceptContainer;
|
79
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.ContainerFactory;
|
80
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.HomotypicalSynonymGroup;
|
81
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroup;
|
82
|
import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDropTargetListener;
|
83
|
import eu.etaxonomy.taxeditor.event.EventUtility;
|
84
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
85
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
86
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
87
|
import eu.etaxonomy.taxeditor.model.IPartChangeListener;
|
88
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
89
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
90
|
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
|
91
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
92
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
93
|
import eu.etaxonomy.taxeditor.model.TaxeditorPartService;
|
94
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
95
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
96
|
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
|
97
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
98
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
99
|
|
100
|
/**
|
101
|
* @author pplitzner
|
102
|
* @date Aug 24, 2017
|
103
|
*/
|
104
|
public class TaxonEditor
|
105
|
implements IDirtyMarkable, IPartContentHasDetails,
|
106
|
IPartContentHasSupplementalData, IPartContentHasMedia, IPartContentHasFactualData, IPartChangeListener,
|
107
|
ISelectionListener, ISecuredEditor, IE4SavablePart, ITaxonEditor, IDropTargetable {
|
108
|
|
109
|
private Taxon taxon;
|
110
|
|
111
|
private ManagedForm managedForm;
|
112
|
private ScrolledForm scrolledForm;
|
113
|
private Composite parent;
|
114
|
@Inject
|
115
|
private EModelService modelService;
|
116
|
|
117
|
@Inject
|
118
|
private EPartService partService;
|
119
|
private TaxonBase<?> selection;
|
120
|
|
121
|
private AcceptedGroup acceptedGroup;
|
122
|
private List<HomotypicalSynonymGroup> heterotypicSynonymGroups = new ArrayList<>();
|
123
|
private MisappliedGroup misappliedGroup;
|
124
|
|
125
|
private DropTarget target;
|
126
|
|
127
|
@Inject
|
128
|
private UISynchronize sync;
|
129
|
|
130
|
private TaxonBase<?> objectAffectedByLastOperation;
|
131
|
|
132
|
@Inject
|
133
|
private EMenuService menuService;
|
134
|
|
135
|
@Inject
|
136
|
private ESelectionService selService;
|
137
|
|
138
|
@Inject
|
139
|
private IEclipseContext context;
|
140
|
|
141
|
@Inject
|
142
|
private MDirtyable dirty;
|
143
|
|
144
|
@Inject
|
145
|
private MApplication application;
|
146
|
|
147
|
private MPart thisPart;
|
148
|
|
149
|
private TaxonEditorInput input;
|
150
|
|
151
|
private UndoContext undoContext;
|
152
|
|
153
|
@Inject
|
154
|
private IEventBroker eventBroker;
|
155
|
|
156
|
@Inject
|
157
|
public TaxonEditor() {
|
158
|
undoContext = new UndoContext();
|
159
|
}
|
160
|
|
161
|
@PostConstruct
|
162
|
public void createPartControl(Composite parent, MPart thisPart) {
|
163
|
this.thisPart = thisPart;
|
164
|
|
165
|
createManagedForm(parent);
|
166
|
|
167
|
TaxeditorPartService.getInstance().addListener(TaxeditorPartService.PART_ACTIVATED, this);
|
168
|
}
|
169
|
|
170
|
protected void createManagedForm(Composite composite) {
|
171
|
|
172
|
managedForm = new ManagedForm(composite) {
|
173
|
|
174
|
@Override
|
175
|
public void dirtyStateChanged() {
|
176
|
dirty.setDirty(true);
|
177
|
}
|
178
|
|
179
|
@Override
|
180
|
public boolean setInput(Object input) {
|
181
|
if (input instanceof AbstractGroupedContainer) {
|
182
|
TaxonBase<?> newSelection = ((AbstractGroupedContainer<?>) input).getData();
|
183
|
if (selection != newSelection || TaxonEditor.this.isDirty()) {
|
184
|
selection = newSelection;
|
185
|
selService.setSelection(new StructuredSelection(selection));
|
186
|
|
187
|
}
|
188
|
} else if (input == null) {
|
189
|
selection = null;
|
190
|
selService.setSelection(new StructuredSelection());
|
191
|
}
|
192
|
|
193
|
return super.setInput(input);
|
194
|
}
|
195
|
};
|
196
|
|
197
|
scrolledForm = managedForm.getForm();
|
198
|
parent = scrolledForm.getBody();
|
199
|
|
200
|
parent.setData(taxon);
|
201
|
|
202
|
TableWrapLayout layout = new TableWrapLayout();
|
203
|
layout.leftMargin = 0;
|
204
|
layout.rightMargin = 0;
|
205
|
layout.topMargin = 0;
|
206
|
layout.bottomMargin = 0;
|
207
|
|
208
|
layout.verticalSpacing = 0;
|
209
|
layout.horizontalSpacing = 0;
|
210
|
|
211
|
parent.setLayout(layout);
|
212
|
parent.setBackground(AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
213
|
}
|
214
|
|
215
|
public void createOrUpdateNameComposites(boolean accepted, boolean heterotypicGroups, boolean misappliedNames) {
|
216
|
|
217
|
if (accepted) {
|
218
|
ContainerFactory.createOrUpdateAcceptedTaxonsHomotypicGroup(this);
|
219
|
}
|
220
|
if (heterotypicGroups) {
|
221
|
ContainerFactory.createOrUpdateHeterotypicSynonymyGroups(this);
|
222
|
}
|
223
|
if (misappliedNames) {
|
224
|
ContainerFactory.createOrUpdateMisapplicationsGroup(this);
|
225
|
}
|
226
|
ContainerFactory.setMenuToAllContainers(this);
|
227
|
|
228
|
// Redraw composite
|
229
|
parent.pack();
|
230
|
managedForm.refresh();
|
231
|
managedForm.reflow(true);
|
232
|
}
|
233
|
|
234
|
@Override
|
235
|
public Taxon getTaxon() {
|
236
|
return HibernateProxyHelper.deproxy(taxon);
|
237
|
}
|
238
|
|
239
|
@Override
|
240
|
public void addOperation(AbstractPostOperation operation) {
|
241
|
input.addOperation(operation);
|
242
|
}
|
243
|
|
244
|
public void setDirty() {
|
245
|
managedForm.dirtyStateChanged();
|
246
|
}
|
247
|
|
248
|
@Focus
|
249
|
public void setFocus() {
|
250
|
// make sure to bind again if maybe in another view the conversation was
|
251
|
// unbound
|
252
|
|
253
|
eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, this);
|
254
|
|
255
|
if (EditorUtil.isFactsVisible()){
|
256
|
EditorUtil.showFacts(modelService, partService);
|
257
|
EditorUtil.setFactsVisible(false);
|
258
|
}
|
259
|
if (EditorUtil.isMediaVisible()){
|
260
|
EditorUtil.showMedia(modelService, partService);
|
261
|
EditorUtil.setMediaVisible(false);
|
262
|
}
|
263
|
if (input != null) {
|
264
|
if (getSelectedContainer() == null) {
|
265
|
throw new IllegalStateException(Messages.TaxonNameEditor_THERE_SHOULD_ALWAYS_BE);
|
266
|
}
|
267
|
|
268
|
if (input.getCdmEntitySession() != null && !input.getCdmEntitySession().isActive()) {
|
269
|
input.bind();
|
270
|
}
|
271
|
|
272
|
}
|
273
|
|
274
|
// check permissions
|
275
|
boolean doEnable = permissionsSatisfied();
|
276
|
managedForm.getForm().setEnabled(doEnable);
|
277
|
}
|
278
|
|
279
|
@Override
|
280
|
public boolean permissionsSatisfied() {
|
281
|
boolean doEnable = false;
|
282
|
if (input != null){
|
283
|
TaxonNode taxonNode = input.getTaxonNode();
|
284
|
doEnable = CdmStore.currentAuthentiationHasPermission(taxonNode,
|
285
|
RequiredPermissions.TAXON_EDIT);
|
286
|
}
|
287
|
return doEnable;
|
288
|
}
|
289
|
|
290
|
/**
|
291
|
* Redraws this editor return true on success
|
292
|
*
|
293
|
* @return a boolean.
|
294
|
*/
|
295
|
public boolean redraw() {
|
296
|
return redraw(true, true, true, true);
|
297
|
}
|
298
|
|
299
|
/**
|
300
|
* {@inheritDoc}
|
301
|
*
|
302
|
* Redraws the editor controls
|
303
|
*/
|
304
|
public boolean redraw(boolean focus, boolean accepted, boolean heterotypic, boolean misappliedNames) {
|
305
|
|
306
|
createOrUpdateNameComposites(accepted, heterotypic, misappliedNames);
|
307
|
|
308
|
if (focus) {
|
309
|
setFocus();
|
310
|
}
|
311
|
|
312
|
return true;
|
313
|
}
|
314
|
|
315
|
@Override
|
316
|
public boolean postOperation(Object objectAffectedByOperation) {
|
317
|
if (objectAffectedByOperation instanceof TaxonBase) {
|
318
|
objectAffectedByLastOperation = (TaxonBase<?>) objectAffectedByOperation;
|
319
|
}
|
320
|
redraw(true, true, true, true);
|
321
|
changed(objectAffectedByOperation);
|
322
|
onComplete();
|
323
|
getContainer(objectAffectedByLastOperation).setFocus();
|
324
|
return true;
|
325
|
}
|
326
|
|
327
|
public ManagedForm getManagedForm() {
|
328
|
return managedForm;
|
329
|
}
|
330
|
|
331
|
/**
|
332
|
* <p>
|
333
|
* checkForEmptyNames
|
334
|
* </p>
|
335
|
*
|
336
|
* @return true if there are empty names
|
337
|
*/
|
338
|
public boolean checkForEmptyNames() {
|
339
|
for (AbstractGroupedContainer<?> container : getGroupedContainers()) {
|
340
|
if (container != null
|
341
|
&& (container.getName() == null || StringUtils.isEmpty(container.getName().getTitleCache()))) {
|
342
|
return true;
|
343
|
}
|
344
|
}
|
345
|
return false;
|
346
|
}
|
347
|
|
348
|
public Set<AbstractGroupedContainer> getEmptyContainers() {
|
349
|
Set<AbstractGroupedContainer> containersWithEmptyNames = new HashSet<>();
|
350
|
|
351
|
for (AbstractGroupedContainer<?> container : getGroupedContainers()) {
|
352
|
if (container.getName() == null || StringUtils.isEmpty(container.getName().getTitleCache())) {
|
353
|
containersWithEmptyNames.add(container);
|
354
|
}
|
355
|
}
|
356
|
|
357
|
return containersWithEmptyNames;
|
358
|
}
|
359
|
|
360
|
@Override
|
361
|
@Persist
|
362
|
public void save(IProgressMonitor monitor) {
|
363
|
|
364
|
monitor.beginTask(Messages.TaxonNameEditor_SAVING_NAMES, getGroupedContainers().size());
|
365
|
monitor.worked(1);
|
366
|
//this.getDirtyNames().forEach(container -> container.refresh());
|
367
|
// check for empty names
|
368
|
if (checkForEmptyNames()) {
|
369
|
MessageDialog.openWarning(AbstractUtility.getShell(), Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED,
|
370
|
Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED_MESSAGE);
|
371
|
return;
|
372
|
}
|
373
|
for (AbstractGroupedContainer<?> container : getGroupedContainers()) {
|
374
|
|
375
|
monitor.subTask(Messages.TaxonNameEditor_SAVING_COMPOSITES + container.getTaxonBase().getTitleCache());
|
376
|
container.persistName();
|
377
|
// because of missing cascading the concepts need to be saved
|
378
|
// separately
|
379
|
if (container instanceof ConceptContainer) {
|
380
|
input.addToSaveConcept((Taxon) container.getData());
|
381
|
}
|
382
|
// In case the progress monitor was canceled throw an exception.
|
383
|
if (monitor.isCanceled()) {
|
384
|
throw new OperationCanceledException();
|
385
|
}
|
386
|
|
387
|
// Otherwise declare this step as done.
|
388
|
monitor.worked(1);
|
389
|
}
|
390
|
|
391
|
input.setSync(sync);
|
392
|
input.merge();
|
393
|
|
394
|
dirty.setDirty(false);
|
395
|
|
396
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, new TaxonNodeDto(input.getTaxonNode().getParent()));
|
397
|
EventUtility.postEvent(WorkbenchEventConstants.SAVE_TAXON, true);
|
398
|
EventUtility.postAsyncEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
|
399
|
// EventUtility.postAsyncEvent(WorkbenchEventConstants.NEED_REFRESH_DETAILS, false);
|
400
|
// Stop the progress monitor.
|
401
|
monitor.done();
|
402
|
}
|
403
|
|
404
|
public void init(TaxonEditorInput input) {
|
405
|
if (this.input != null) {
|
406
|
this.input.dispose();
|
407
|
// this.acceptedGroup = null;
|
408
|
// this.heterotypicSynonymGroups.clear();
|
409
|
// this.misappliedGroup = null;
|
410
|
}
|
411
|
eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, this);
|
412
|
if (!(input != null)) {
|
413
|
MessagingUtils.error(this.getClass(), new Exception(Messages.TaxonNameEditor_INVALID_INPUT));
|
414
|
return;
|
415
|
}
|
416
|
|
417
|
if (input.getAdapter(Taxon.class) != null) {
|
418
|
taxon = CdmBase.deproxy(input.getAdapter(Taxon.class), Taxon.class);
|
419
|
} else {
|
420
|
MessagingUtils.error(this.getClass(), new Exception(Messages.TaxonNameEditor_INVALID_INPUT_TAXON_NULL));
|
421
|
return;
|
422
|
}
|
423
|
|
424
|
this.input = input;
|
425
|
createOrUpdateNameComposites(true, true, true);
|
426
|
|
427
|
createDragSupport();
|
428
|
|
429
|
setPartName();
|
430
|
// this.setFocus();
|
431
|
// set initial selection
|
432
|
TaxonBase<?> initiallySelectedTaxonBase = input.getInitiallySelectedTaxonBase();
|
433
|
if (initiallySelectedTaxonBase != null) {
|
434
|
selService.setSelection(new StructuredSelection(initiallySelectedTaxonBase));
|
435
|
getContainer(initiallySelectedTaxonBase).setSelected();
|
436
|
}
|
437
|
}
|
438
|
|
439
|
private void createDragSupport() {
|
440
|
// Listen for names being dragged outside of existing homotypic groups -
|
441
|
// user wants to create a new group
|
442
|
Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
|
443
|
int operations = DND.DROP_MOVE;
|
444
|
if (target == null) {
|
445
|
target = new DropTarget(parent, operations);
|
446
|
target.setTransfer(types);
|
447
|
target.addDropListener(new NameEditorDropTargetListener(this));
|
448
|
}
|
449
|
}
|
450
|
|
451
|
public AcceptedNameContainerE4 getAcceptedNameContainer() {
|
452
|
return getAcceptedGroup().getAcceptedNameContainer();
|
453
|
}
|
454
|
|
455
|
public HomotypicalSynonymGroup getHomotypicalGroupContainer(HomotypicalGroup homotypicalGroup) {
|
456
|
for (HomotypicalSynonymGroup group : getHeterotypicSynonymGroups()) {
|
457
|
if (group.getGroup().equals(homotypicalGroup)) {
|
458
|
return group;
|
459
|
}
|
460
|
}
|
461
|
|
462
|
return null;
|
463
|
}
|
464
|
|
465
|
/**
|
466
|
* <p>
|
467
|
* getDirtyNames
|
468
|
* </p>
|
469
|
*
|
470
|
* @return a Set containing all composites that have been edited
|
471
|
*/
|
472
|
public Set<AbstractGroupedContainer> getDirtyNames() {
|
473
|
Set<AbstractGroupedContainer> dirtyNames = new HashSet<>();
|
474
|
|
475
|
for (AbstractGroupedContainer<?> composite : getGroupedContainers()) {
|
476
|
if (composite.isDirty()) {
|
477
|
dirtyNames.add(composite);
|
478
|
}
|
479
|
}
|
480
|
|
481
|
return dirtyNames;
|
482
|
}
|
483
|
|
484
|
public List<AbstractGroupedContainer> getGroupedContainers() {
|
485
|
List<AbstractGroupedContainer> groupedComposites = new ArrayList<>();
|
486
|
|
487
|
for (AbstractGroup group : getAllGroups()) {
|
488
|
if (group != null) {
|
489
|
groupedComposites.addAll(group.getGroupedContainers());
|
490
|
}
|
491
|
}
|
492
|
|
493
|
return groupedComposites;
|
494
|
}
|
495
|
|
496
|
public List<AbstractGroup> getAllGroups() {
|
497
|
List<AbstractGroup> allGroups = new ArrayList<>();
|
498
|
|
499
|
allGroups.add(getAcceptedGroup());
|
500
|
|
501
|
heterotypicSynonymGroups = getHeterotypicSynonymGroups();
|
502
|
|
503
|
if (heterotypicSynonymGroups != null) {
|
504
|
allGroups.addAll(heterotypicSynonymGroups);
|
505
|
}
|
506
|
|
507
|
if (misappliedGroup != null) {
|
508
|
allGroups.add(misappliedGroup);
|
509
|
}
|
510
|
|
511
|
return allGroups;
|
512
|
}
|
513
|
|
514
|
@Override
|
515
|
public IEclipseContext getContext() {
|
516
|
return context;
|
517
|
}
|
518
|
|
519
|
@Override
|
520
|
public boolean isDirty() {
|
521
|
return dirty.isDirty();
|
522
|
}
|
523
|
|
524
|
@PreDestroy
|
525
|
public void dispose() {
|
526
|
if (input != null) {
|
527
|
input.dispose();
|
528
|
}
|
529
|
dirty.setDirty(false);
|
530
|
eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, null);
|
531
|
}
|
532
|
|
533
|
@Override
|
534
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
535
|
|
536
|
}
|
537
|
|
538
|
public AbstractGroupedContainer getSelectedContainer() {
|
539
|
if (selection == null && input != null){
|
540
|
selection = this.input.getTaxon();
|
541
|
}
|
542
|
return (selection != null) ? getContainer(selection) : getAcceptedNameContainer();
|
543
|
}
|
544
|
|
545
|
@Override
|
546
|
public void dragEntered() {
|
547
|
// TODO change this
|
548
|
getControl().setBackground(AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
|
549
|
}
|
550
|
|
551
|
@Override
|
552
|
public void dragLeft() {
|
553
|
getControl().setBackground(AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
554
|
}
|
555
|
|
556
|
public void setMisapplicationsGroup(MisappliedGroup misappliedGroup) {
|
557
|
this.misappliedGroup = misappliedGroup;
|
558
|
}
|
559
|
|
560
|
public FormToolkit getToolkit() {
|
561
|
return managedForm.getToolkit();
|
562
|
}
|
563
|
|
564
|
public List<HomotypicalSynonymGroup> getHeterotypicSynonymGroups() {
|
565
|
return heterotypicSynonymGroups;
|
566
|
}
|
567
|
|
568
|
public void addHeterotypicSynonymGroup(HomotypicalSynonymGroup group) {
|
569
|
heterotypicSynonymGroups.add(group);
|
570
|
}
|
571
|
|
572
|
public AcceptedGroup getAcceptedGroup() {
|
573
|
return acceptedGroup;
|
574
|
}
|
575
|
|
576
|
public void setAcceptedGroup(AcceptedGroup acceptedGroup) {
|
577
|
this.acceptedGroup = acceptedGroup;
|
578
|
}
|
579
|
|
580
|
public MisappliedGroup getMisappliedGroup() {
|
581
|
return misappliedGroup;
|
582
|
}
|
583
|
|
584
|
public boolean isActive() {
|
585
|
return this.equals(AbstractUtility.getActivePart());
|
586
|
}
|
587
|
|
588
|
@Override
|
589
|
public boolean onComplete() {
|
590
|
getContainer(objectAffectedByLastOperation).setSelected();
|
591
|
return true;
|
592
|
}
|
593
|
|
594
|
@Override
|
595
|
public void partChanged(Integer eventType, IWorkbenchPartReference partRef) {
|
596
|
if (!partRef.getPart(false).equals(this)) {
|
597
|
|
598
|
|
599
|
}
|
600
|
}
|
601
|
|
602
|
public void removeGroup(AbstractGroup group) {
|
603
|
if (group != null) {
|
604
|
group.dispose();
|
605
|
|
606
|
// if (heterotypicSynonymGroups != null) {
|
607
|
heterotypicSynonymGroups.remove(group);
|
608
|
// }
|
609
|
}
|
610
|
}
|
611
|
|
612
|
public AbstractGroupedContainer getContainer(TaxonBase taxonBase) {
|
613
|
@SuppressWarnings("rawtypes")
|
614
|
List<AbstractGroupedContainer> groupedContainers = getGroupedContainers();
|
615
|
for (AbstractGroupedContainer<?> container : groupedContainers) {
|
616
|
if (container.getData().equals(taxonBase) && container.getNameViewer().getTextWidget() != null) {
|
617
|
return container;
|
618
|
}
|
619
|
}
|
620
|
return getAcceptedNameContainer();
|
621
|
}
|
622
|
|
623
|
public void setOnError() {
|
624
|
Color disabledColor = AbstractUtility.getColor(Resources.COLOR_EDITOR_ERROR);
|
625
|
setEnabled(false, disabledColor);
|
626
|
}
|
627
|
|
628
|
public void setDisabled() {
|
629
|
Color disabledColor = AbstractUtility.getColor(Resources.COLOR_TEXT_DISABLED_BACKGROUND);
|
630
|
setEnabled(false, disabledColor);
|
631
|
}
|
632
|
|
633
|
protected void setEnabled(boolean enabled, Color background) {
|
634
|
|
635
|
for (AbstractGroupedContainer<?> groupedContainer : getGroupedContainers()) {
|
636
|
groupedContainer.setEnabled(enabled);
|
637
|
}
|
638
|
|
639
|
// send an empty selection to the current provider - TODO only on error
|
640
|
// ???
|
641
|
if (!enabled) {
|
642
|
getManagedForm().setInput(null);
|
643
|
|
644
|
for (AbstractGroupedContainer<?> groupedContainer : getGroupedContainers()) {
|
645
|
groupedContainer.setBackground(background);
|
646
|
}
|
647
|
}
|
648
|
getControl().setBackground(background);
|
649
|
}
|
650
|
|
651
|
@Override
|
652
|
public void changed(Object element) {
|
653
|
// setDirty(true);
|
654
|
// if the attribute is null then do not set the dirty flag -> hotfix for
|
655
|
// the problem that for tasks done in service methods the changes are
|
656
|
// saved automatically
|
657
|
if (element != null) {
|
658
|
dirty.setDirty(true);
|
659
|
// refresh part title
|
660
|
// TODO: refresh taxon node in taxon navigator
|
661
|
setPartName();
|
662
|
}
|
663
|
|
664
|
if (element instanceof TaxonBase) {
|
665
|
AbstractGroupedContainer<?> container = getContainer((TaxonBase<?>) element);
|
666
|
if (container != null) {
|
667
|
container.refresh();
|
668
|
container.setDirty(false);
|
669
|
}
|
670
|
}
|
671
|
|
672
|
if (element instanceof TaxonRelationship) {
|
673
|
AbstractGroupedContainer container = getContainer(((TaxonRelationship) element).getFromTaxon());
|
674
|
if (container != null) {
|
675
|
container.refresh();
|
676
|
container.setDirty(false);
|
677
|
}
|
678
|
}
|
679
|
}
|
680
|
|
681
|
public void setPartName() {
|
682
|
// FIXME: temporary fix for #6437 to avoid outdated title caches
|
683
|
thisPart.setLabel(this.taxon.getName().generateFullTitle());
|
684
|
// thisPart.setLabel(this.taxon.getName().getFullTitleCache());
|
685
|
}
|
686
|
|
687
|
@Override
|
688
|
public void forceDirty() {
|
689
|
setDirty();
|
690
|
}
|
691
|
|
692
|
public IUndoContext getUndoContext() {
|
693
|
return undoContext;
|
694
|
}
|
695
|
|
696
|
@Override
|
697
|
public Composite getControl() {
|
698
|
return managedForm.getForm().getBody();
|
699
|
}
|
700
|
|
701
|
public EMenuService getMenuService() {
|
702
|
return menuService;
|
703
|
}
|
704
|
|
705
|
public ESelectionService getSelectionService() {
|
706
|
return selService;
|
707
|
}
|
708
|
|
709
|
@Override
|
710
|
public boolean canAttachMedia() {
|
711
|
return true;
|
712
|
}
|
713
|
|
714
|
public TaxonEditorInput getEditorInput() {
|
715
|
return input;
|
716
|
}
|
717
|
|
718
|
@Override
|
719
|
public TaxonEditor getEditor() {
|
720
|
return this;
|
721
|
}
|
722
|
|
723
|
@Inject
|
724
|
@Optional
|
725
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAME_EDITOR) CdmBase cdmbase) {
|
726
|
|
727
|
if(this.taxon != null && (this.taxon.equals(cdmbase)
|
728
|
|| (this.taxon.getName() != null && this.taxon.getName().equals(cdmbase)))) {
|
729
|
this.redraw(false, true, true, true);
|
730
|
this.setDirty();
|
731
|
if (cdmbase instanceof TaxonBase) {
|
732
|
this.selection = (TaxonBase<?>) cdmbase;
|
733
|
}
|
734
|
}
|
735
|
}
|
736
|
|
737
|
@Inject
|
738
|
@Optional
|
739
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAME_EDITOR) List<CdmBase> cdmBases) {
|
740
|
|
741
|
if (cdmBases == null){
|
742
|
return;
|
743
|
}
|
744
|
for (CdmBase cdmBase: cdmBases){
|
745
|
if (cdmBase instanceof Taxon || cdmBase instanceof TaxonName){
|
746
|
if (this.taxon != null && (this.taxon.equals(cdmBase)
|
747
|
|| (this.taxon.getName() != null && this.taxon.getName().equals(cdmBase)))) {
|
748
|
update();
|
749
|
}
|
750
|
}
|
751
|
}
|
752
|
}
|
753
|
|
754
|
@Inject
|
755
|
@Optional
|
756
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAME_EDITOR) UUID cdmbaseUuid) {
|
757
|
if (this.taxon.getUuid().equals(cdmbaseUuid)) {
|
758
|
TaxonEditorInput input = TaxonEditorInput.NewInstanceFromTaxonBase(cdmbaseUuid);
|
759
|
init(input);
|
760
|
}
|
761
|
}
|
762
|
|
763
|
@Inject
|
764
|
@Optional
|
765
|
private void updatefromDelete(@UIEventTopic(WorkbenchEventConstants.DELETE_DERIVATIVE) DeleteResult result) {
|
766
|
if (taxon.getName() == null) {
|
767
|
return;
|
768
|
}
|
769
|
Set<DerivedUnit> typeDesignationSpecimens = new HashSet<>();
|
770
|
this.taxon.getName().getSpecimenTypeDesignations()
|
771
|
.forEach(designation -> typeDesignationSpecimens.add(designation.getTypeSpecimen()));
|
772
|
// check if any deleted object was a type specimen
|
773
|
if (result.getUpdatedObjects().stream()
|
774
|
// filter only DerivedUnits
|
775
|
.filter(cdmBase -> cdmBase.isInstanceOf(DerivedUnit.class))
|
776
|
// deproxy from CdmBase to DerivedUnit
|
777
|
.map(unit -> HibernateProxyHelper.deproxy(unit, DerivedUnit.class))
|
778
|
// check for match in type designations
|
779
|
.anyMatch(unit -> typeDesignationSpecimens.contains(unit))) {
|
780
|
EditorUtil.updateEditor(this.input.getTaxonNode(), this);
|
781
|
}
|
782
|
}
|
783
|
|
784
|
@Override
|
785
|
public void update() {
|
786
|
EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
|
787
|
EModelService modelService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EModelService.class);
|
788
|
EditorUtil.openTaxonBaseE4(this.getTaxon().getUuid(), modelService, partService, application);
|
789
|
}
|
790
|
|
791
|
@Override
|
792
|
public TaxonNode getTaxonNode() {
|
793
|
return input.getTaxonNode();
|
794
|
}
|
795
|
|
796
|
|
797
|
}
|