2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
;
11 import java
.util
.ArrayList
;
12 import java
.util
.HashSet
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import javax
.annotation
.PostConstruct
;
18 import javax
.annotation
.PreDestroy
;
19 import javax
.inject
.Inject
;
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
;
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
;
104 public class TaxonEditor
105 implements IDirtyMarkable
, IPartContentHasDetails
,
106 IPartContentHasSupplementalData
, IPartContentHasMedia
, IPartContentHasFactualData
, IPartChangeListener
,
107 ISelectionListener
, ISecuredEditor
, IE4SavablePart
, ITaxonEditor
, IDropTargetable
{
111 private ManagedForm managedForm
;
112 private ScrolledForm scrolledForm
;
113 private Composite parent
;
115 private EModelService modelService
;
118 private EPartService partService
;
119 private TaxonBase
<?
> selection
;
121 private AcceptedGroup acceptedGroup
;
122 private List
<HomotypicalSynonymGroup
> heterotypicSynonymGroups
= new ArrayList
<>();
123 private MisappliedGroup misappliedGroup
;
125 private DropTarget target
;
128 private UISynchronize sync
;
130 private TaxonBase
<?
> objectAffectedByLastOperation
;
133 private EMenuService menuService
;
136 private ESelectionService selService
;
139 private IEclipseContext context
;
142 private MDirtyable dirty
;
145 private MApplication application
;
147 private MPart thisPart
;
149 private TaxonEditorInput input
;
151 private UndoContext undoContext
;
154 private IEventBroker eventBroker
;
157 public TaxonEditor() {
158 undoContext
= new UndoContext();
162 public void createPartControl(Composite parent
, MPart thisPart
) {
163 this.thisPart
= thisPart
;
165 createManagedForm(parent
);
167 TaxeditorPartService
.getInstance().addListener(TaxeditorPartService
.PART_ACTIVATED
, this);
170 protected void createManagedForm(Composite composite
) {
172 managedForm
= new ManagedForm(composite
) {
175 public void dirtyStateChanged() {
176 dirty
.setDirty(true);
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
));
188 } else if (input
== null) {
190 selService
.setSelection(new StructuredSelection());
193 return super.setInput(input
);
197 scrolledForm
= managedForm
.getForm();
198 parent
= scrolledForm
.getBody();
200 parent
.setData(taxon
);
202 TableWrapLayout layout
= new TableWrapLayout();
203 layout
.leftMargin
= 0;
204 layout
.rightMargin
= 0;
205 layout
.topMargin
= 0;
206 layout
.bottomMargin
= 0;
208 layout
.verticalSpacing
= 0;
209 layout
.horizontalSpacing
= 0;
211 parent
.setLayout(layout
);
212 parent
.setBackground(AbstractUtility
.getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
215 public void createOrUpdateNameComposites(boolean accepted
, boolean heterotypicGroups
, boolean misappliedNames
) {
218 ContainerFactory
.createOrUpdateAcceptedTaxonsHomotypicGroup(this);
220 if (heterotypicGroups
) {
221 ContainerFactory
.createOrUpdateHeterotypicSynonymyGroups(this);
223 if (misappliedNames
) {
224 ContainerFactory
.createOrUpdateMisapplicationsGroup(this);
226 ContainerFactory
.setMenuToAllContainers(this);
230 managedForm
.refresh();
231 managedForm
.reflow(true);
235 public Taxon
getTaxon() {
236 return HibernateProxyHelper
.deproxy(taxon
);
240 public void addOperation(AbstractPostOperation operation
) {
241 input
.addOperation(operation
);
244 public void setDirty() {
245 managedForm
.dirtyStateChanged();
249 public void setFocus() {
250 // make sure to bind again if maybe in another view the conversation was
253 eventBroker
.post(WorkbenchEventConstants
.CURRENT_ACTIVE_EDITOR
, this);
255 if (EditorUtil
.isFactsVisible()){
256 EditorUtil
.showFacts(modelService
, partService
);
257 EditorUtil
.setFactsVisible(false);
259 if (EditorUtil
.isMediaVisible()){
260 EditorUtil
.showMedia(modelService
, partService
);
261 EditorUtil
.setMediaVisible(false);
264 if (getSelectedContainer() == null) {
265 throw new IllegalStateException(Messages
.TaxonNameEditor_THERE_SHOULD_ALWAYS_BE
);
268 if (input
.getCdmEntitySession() != null && !input
.getCdmEntitySession().isActive()) {
275 boolean doEnable
= permissionsSatisfied();
276 managedForm
.getForm().setEnabled(doEnable
);
280 public boolean permissionsSatisfied() {
281 boolean doEnable
= false;
283 TaxonNode taxonNode
= input
.getTaxonNode();
284 doEnable
= CdmStore
.currentAuthentiationHasPermission(taxonNode
,
285 RequiredPermissions
.TAXON_EDIT
);
291 * Redraws this editor return true on success
295 public boolean redraw() {
296 return redraw(true, true, true, true);
302 * Redraws the editor controls
304 public boolean redraw(boolean focus
, boolean accepted
, boolean heterotypic
, boolean misappliedNames
) {
306 createOrUpdateNameComposites(accepted
, heterotypic
, misappliedNames
);
316 public boolean postOperation(Object objectAffectedByOperation
) {
317 if (objectAffectedByOperation
instanceof TaxonBase
) {
318 objectAffectedByLastOperation
= (TaxonBase
<?
>) objectAffectedByOperation
;
320 redraw(true, true, true, true);
321 changed(objectAffectedByOperation
);
323 getContainer(objectAffectedByLastOperation
).setFocus();
327 public ManagedForm
getManagedForm() {
336 * @return true if there are empty names
338 public boolean checkForEmptyNames() {
339 for (AbstractGroupedContainer
<?
> container
: getGroupedContainers()) {
340 if (container
!= null
341 && (container
.getName() == null || StringUtils
.isEmpty(container
.getName().getTitleCache()))) {
348 public Set
<AbstractGroupedContainer
> getEmptyContainers() {
349 Set
<AbstractGroupedContainer
> containersWithEmptyNames
= new HashSet
<>();
351 for (AbstractGroupedContainer
<?
> container
: getGroupedContainers()) {
352 if (container
.getName() == null || StringUtils
.isEmpty(container
.getName().getTitleCache())) {
353 containersWithEmptyNames
.add(container
);
357 return containersWithEmptyNames
;
362 public void save(IProgressMonitor monitor
) {
364 monitor
.beginTask(Messages
.TaxonNameEditor_SAVING_NAMES
, getGroupedContainers().size());
366 this.getEditorInput().getCdmEntitySession().load(this.taxon
, true);
367 //this.getDirtyNames().forEach(container -> container.refresh());
368 // check for empty names
369 if (checkForEmptyNames()) {
370 MessageDialog
.openWarning(AbstractUtility
.getShell(), Messages
.MultiPageTaxonEditor_NO_NAME_SPECIFIED
,
371 Messages
.MultiPageTaxonEditor_NO_NAME_SPECIFIED_MESSAGE
);
374 for (AbstractGroupedContainer
<?
> container
: getGroupedContainers()) {
376 monitor
.subTask(Messages
.TaxonNameEditor_SAVING_COMPOSITES
+ container
.getTaxonBase().getTitleCache());
377 container
.persistName();
378 // because of missing cascading the concepts need to be saved
380 if (container
instanceof ConceptContainer
) {
381 input
.addToSaveConcept((Taxon
) container
.getData());
383 // In case the progress monitor was canceled throw an exception.
384 if (monitor
.isCanceled()) {
385 throw new OperationCanceledException();
388 // Otherwise declare this step as done.
395 dirty
.setDirty(false);
397 if (input
.getTaxonNode().getParent() != null) {
398 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAVIGATOR
, new TaxonNodeDto(input
.getTaxonNode().getParent()));
400 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAVIGATOR
, new TaxonNodeDto(input
.getTaxonNode()));
402 EventUtility
.postEvent(WorkbenchEventConstants
.SAVE_TAXON
, true);
403 EventUtility
.postAsyncEvent(WorkbenchEventConstants
.REFRESH_DETAILS
, true);
404 // EventUtility.postAsyncEvent(WorkbenchEventConstants.NEED_REFRESH_DETAILS, false);
405 // Stop the progress monitor.
409 public void init(TaxonEditorInput input
) {
410 if (this.input
!= null) {
411 this.input
.dispose();
412 // this.acceptedGroup = null;
413 // this.heterotypicSynonymGroups.clear();
414 // this.misappliedGroup = null;
416 eventBroker
.post(WorkbenchEventConstants
.CURRENT_ACTIVE_EDITOR
, this);
417 if (!(input
!= null)) {
418 MessagingUtils
.error(this.getClass(), new Exception(Messages
.TaxonNameEditor_INVALID_INPUT
));
422 if (input
.getAdapter(Taxon
.class) != null) {
423 taxon
= CdmBase
.deproxy(input
.getAdapter(Taxon
.class), Taxon
.class);
425 MessagingUtils
.error(this.getClass(), new Exception(Messages
.TaxonNameEditor_INVALID_INPUT_TAXON_NULL
));
430 createOrUpdateNameComposites(true, true, true);
435 // set initial selection
436 TaxonBase
<?
> initiallySelectedTaxonBase
= input
.getInitiallySelectedTaxonBase();
437 if (initiallySelectedTaxonBase
!= null) {
438 selService
.setSelection(new StructuredSelection(initiallySelectedTaxonBase
));
440 if (getContainer(initiallySelectedTaxonBase
)!= null) {
441 getContainer(initiallySelectedTaxonBase
).setSelected();
447 private void createDragSupport() {
448 // Listen for names being dragged outside of existing homotypic groups -
449 // user wants to create a new group
450 Transfer
[] types
= new Transfer
[] { CdmDataTransfer
.getInstance() };
451 int operations
= DND
.DROP_MOVE
;
452 if (target
== null) {
453 target
= new DropTarget(parent
, operations
);
454 target
.setTransfer(types
);
455 target
.addDropListener(new NameEditorDropTargetListener(this));
459 public AcceptedNameContainerE4
getAcceptedNameContainer() {
460 return getAcceptedGroup().getAcceptedNameContainer();
463 public HomotypicalSynonymGroup
getHomotypicalGroupContainer(HomotypicalGroup homotypicalGroup
) {
464 for (HomotypicalSynonymGroup group
: getHeterotypicSynonymGroups()) {
465 if (group
.getGroup().equals(homotypicalGroup
)) {
478 * @return a Set containing all composites that have been edited
480 public Set
<AbstractGroupedContainer
> getDirtyNames() {
481 Set
<AbstractGroupedContainer
> dirtyNames
= new HashSet
<>();
483 for (AbstractGroupedContainer
<?
> composite
: getGroupedContainers()) {
484 if (composite
.isDirty()) {
485 dirtyNames
.add(composite
);
492 public List
<AbstractGroupedContainer
> getGroupedContainers() {
493 List
<AbstractGroupedContainer
> groupedComposites
= new ArrayList
<>();
495 for (AbstractGroup group
: getAllGroups()) {
497 groupedComposites
.addAll(group
.getGroupedContainers());
501 return groupedComposites
;
504 public List
<AbstractGroup
> getAllGroups() {
505 List
<AbstractGroup
> allGroups
= new ArrayList
<>();
507 allGroups
.add(getAcceptedGroup());
509 heterotypicSynonymGroups
= getHeterotypicSynonymGroups();
511 if (heterotypicSynonymGroups
!= null) {
512 allGroups
.addAll(heterotypicSynonymGroups
);
515 if (misappliedGroup
!= null) {
516 allGroups
.add(misappliedGroup
);
523 public IEclipseContext
getContext() {
528 public boolean isDirty() {
529 return dirty
.isDirty();
533 public void dispose() {
537 dirty
.setDirty(false);
538 eventBroker
.post(WorkbenchEventConstants
.CURRENT_ACTIVE_EDITOR
, null);
542 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
546 public AbstractGroupedContainer
getSelectedContainer() {
547 if (selection
== null && input
!= null){
548 selection
= this.input
.getTaxon();
550 return (selection
!= null) ?
getContainer(selection
) : getAcceptedNameContainer();
554 public void dragEntered() {
556 getControl().setBackground(AbstractUtility
.getColor(Resources
.COLOR_DRAG_ENTER
));
560 public void dragLeft() {
561 getControl().setBackground(AbstractUtility
.getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
564 public void setMisapplicationsGroup(MisappliedGroup misappliedGroup
) {
565 this.misappliedGroup
= misappliedGroup
;
568 public FormToolkit
getToolkit() {
569 return managedForm
.getToolkit();
572 public List
<HomotypicalSynonymGroup
> getHeterotypicSynonymGroups() {
573 return heterotypicSynonymGroups
;
576 public void addHeterotypicSynonymGroup(HomotypicalSynonymGroup group
) {
577 heterotypicSynonymGroups
.add(group
);
580 public AcceptedGroup
getAcceptedGroup() {
581 return acceptedGroup
;
584 public void setAcceptedGroup(AcceptedGroup acceptedGroup
) {
585 this.acceptedGroup
= acceptedGroup
;
588 public MisappliedGroup
getMisappliedGroup() {
589 return misappliedGroup
;
592 public boolean isActive() {
593 return this.equals(AbstractUtility
.getActivePart());
597 public boolean onComplete() {
598 if (objectAffectedByLastOperation
!= null && getContainer(objectAffectedByLastOperation
) != null) {
599 getContainer(objectAffectedByLastOperation
).setSelected();
605 public void partChanged(Integer eventType
, IWorkbenchPartReference partRef
) {
606 if (!partRef
.getPart(false).equals(this)) {
612 public void removeGroup(AbstractGroup group
) {
616 // if (heterotypicSynonymGroups != null) {
617 heterotypicSynonymGroups
.remove(group
);
622 public AbstractGroupedContainer
<?
> getContainer(TaxonBase taxonBase
) {
623 @SuppressWarnings("rawtypes")
624 List
<AbstractGroupedContainer
> groupedContainers
= getGroupedContainers();
625 for (AbstractGroupedContainer
<?
> container
: groupedContainers
) {
626 if (container
.getData().equals(taxonBase
) && container
.getNameViewer().getTextWidget() != null) {
630 return getAcceptedNameContainer();
633 public void setOnError() {
634 Color disabledColor
= AbstractUtility
.getColor(Resources
.COLOR_EDITOR_ERROR
);
635 setEnabled(false, disabledColor
);
638 public void setDisabled() {
639 Color disabledColor
= AbstractUtility
.getColor(Resources
.COLOR_TEXT_DISABLED_BACKGROUND
);
640 setEnabled(false, disabledColor
);
643 protected void setEnabled(boolean enabled
, Color background
) {
645 for (AbstractGroupedContainer
<?
> groupedContainer
: getGroupedContainers()) {
646 groupedContainer
.setEnabled(enabled
);
649 // send an empty selection to the current provider - TODO only on error
652 getManagedForm().setInput(null);
654 for (AbstractGroupedContainer
<?
> groupedContainer
: getGroupedContainers()) {
655 groupedContainer
.setBackground(background
);
658 getControl().setBackground(background
);
662 public void changed(Object element
) {
664 // if the attribute is null then do not set the dirty flag -> hotfix for
665 // the problem that for tasks done in service methods the changes are
666 // saved automatically
667 if (element
!= null) {
668 dirty
.setDirty(true);
669 // refresh part title
670 // TODO: refresh taxon node in taxon navigator
674 if (element
instanceof TaxonBase
) {
675 AbstractGroupedContainer
<?
> container
= getContainer((TaxonBase
<?
>) element
);
676 if (container
!= null) {
678 container
.setDirty(false);
682 if (element
instanceof TaxonRelationship
) {
683 AbstractGroupedContainer container
= getContainer(((TaxonRelationship
) element
).getFromTaxon());
684 if (container
!= null) {
686 container
.setDirty(false);
691 public void setPartName() {
692 // FIXME: temporary fix for #6437 to avoid outdated title caches
693 thisPart
.setLabel(this.taxon
.getName().generateFullTitle());
694 // thisPart.setLabel(this.taxon.getName().getFullTitleCache());
698 public void forceDirty() {
702 public IUndoContext
getUndoContext() {
707 public Composite
getControl() {
708 return managedForm
.getForm().getBody();
711 public EMenuService
getMenuService() {
715 public ESelectionService
getSelectionService() {
720 public boolean canAttachMedia() {
724 public TaxonEditorInput
getEditorInput() {
729 public TaxonEditor
getEditor() {
735 private void updateView(@UIEventTopic(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
) CdmBase cdmbase
) {
737 if(this.taxon
!= null && (this.taxon
.equals(cdmbase
)
738 || (this.taxon
.getName() != null && this.taxon
.getName().equals(cdmbase
)))) {
739 this.redraw(false, true, true, true);
741 if (cdmbase
instanceof TaxonBase
) {
742 this.selection
= (TaxonBase
<?
>) cdmbase
;
749 private void updateView(@UIEventTopic(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
) List
<CdmBase
> cdmBases
) {
751 if (cdmBases
== null){
754 for (CdmBase cdmBase
: cdmBases
){
755 if (cdmBase
instanceof Taxon
|| cdmBase
instanceof TaxonName
){
756 if (this.taxon
!= null && (this.taxon
.equals(cdmBase
)
757 || (this.taxon
.getName() != null && this.taxon
.getName().equals(cdmBase
)))) {
766 private void updateView(@UIEventTopic(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
) UUID cdmbaseUuid
) {
767 if (this.taxon
.getUuid().equals(cdmbaseUuid
)) {
768 TaxonEditorInput input
= TaxonEditorInput
.NewInstanceFromTaxonBase(cdmbaseUuid
);
775 private void updatefromDelete(@UIEventTopic(WorkbenchEventConstants
.DELETE_DERIVATIVE
) DeleteResult result
) {
776 if (taxon
.getName() == null) {
779 Set
<DerivedUnit
> typeDesignationSpecimens
= new HashSet
<>();
780 this.taxon
.getName().getSpecimenTypeDesignations()
781 .forEach(designation
-> typeDesignationSpecimens
.add(designation
.getTypeSpecimen()));
782 // check if any deleted object was a type specimen
783 if (result
.getUpdatedObjects().stream()
784 // filter only DerivedUnits
785 .filter(cdmBase
-> cdmBase
.isInstanceOf(DerivedUnit
.class))
786 // deproxy from CdmBase to DerivedUnit
787 .map(unit
-> HibernateProxyHelper
.deproxy(unit
, DerivedUnit
.class))
788 // check for match in type designations
789 .anyMatch(unit
-> typeDesignationSpecimens
.contains(unit
))) {
790 EditorUtil
.updateEditor(this.input
.getTaxonNode(), this);
795 public void update() {
796 EPartService partService
= TaxeditorEditorPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService
.class);
797 EModelService modelService
= TaxeditorEditorPlugin
.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EModelService
.class);
798 EditorUtil
.openTaxonBaseE4(this.getTaxon().getUuid(), modelService
, partService
, application
);
802 public TaxonNode
getTaxonNode() {
803 return input
.getTaxonNode();