2 * Copyright (C) 2018 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
.descriptiveDataSet
.matrix
.handler
;
11 import javax
.inject
.Named
;
13 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
14 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
15 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
18 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.cdm
.api
.service
.config
.RemoveDescriptionsFromDescriptiveDataSetConfigurator
;
23 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
24 import eu
.etaxonomy
.cdm
.api
.service
.dto
.SpecimenRowWrapperDTO
;
25 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
27 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.SpecimenNodeWrapper
;
30 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
31 import eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.CharacterMatrixPart
;
32 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
33 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
40 public class DeleteDescriptionHandler
{
43 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
44 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
46 CharacterMatrixPart matrixPart
= (CharacterMatrixPart
) activePart
.getObject();
47 // if(StoreUtil.promptCheckIsDirty(matrixPart)){
50 DescriptiveDataSet descriptiveDataSet
= matrixPart
.getDescriptiveDataSet();
51 RowWrapperDTO wrapper
= (RowWrapperDTO
) matrixPart
.getSelection().getFirstElement();
52 DescriptionBase description
= wrapper
.getDescription().getDescription();
53 RemoveDescriptionsFromDescriptiveDataSetConfigurator deleteConfig
= new RemoveDescriptionsFromDescriptiveDataSetConfigurator();
55 if (!DeleteConfiguratorDialog
.openConfirmWithConfigurator(deleteConfig
, shell
, Messages
.DeleteDescriptiveDataSetHandler_DELETE_TITLE
, Messages
.CharacterMatrix_DELETE_DESCRIPTION
)){
58 boolean ok
= matrixPart
.getMatrix().getDescriptions().remove(wrapper
);
59 matrixPart
.getMatrix().addDescriptionToDelete(description
.getUuid(), deleteConfig
);
60 if (description
instanceof SpecimenDescription
){
61 UuidAndTitleCache
<SpecimenOrObservationBase
> uuidAndTitleCache
= new UuidAndTitleCache
<>(((SpecimenRowWrapperDTO
)wrapper
).getSpecimen().getUuid(), ((SpecimenRowWrapperDTO
)wrapper
).getSpecimen().getId(), ((SpecimenRowWrapperDTO
)wrapper
).getSpecimen().getLabel());
62 SpecimenNodeWrapper nodeWrapper
= new SpecimenNodeWrapper(uuidAndTitleCache
,
63 ((SpecimenRowWrapperDTO
)wrapper
).getType(),
64 wrapper
.getTaxonNode());
67 if (matrixPart
.getMatrix().getSpecimenCache()!= null){
68 matrixPart
.getMatrix().getSpecimenCache().add(nodeWrapper
);
71 matrixPart
.getMatrix().update();
73 matrixPart
.setDirty();
78 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
79 MHandledMenuItem menuItem
){
81 CharacterMatrixPart matrixPart
= (CharacterMatrixPart
) activePart
.getObject();
82 DescriptiveDataSet descriptiveDataSet
= matrixPart
.getDescriptiveDataSet();
83 IStructuredSelection selection
= ((CharacterMatrixPart
)activePart
.getObject()).getSelection();
85 boolean canExecute
= selection
.size()==1
86 && selection
.getFirstElement() instanceof RowWrapperDTO
;
87 menuItem
.setVisible(canExecute
);