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