Project

General

Profile

Download (4.25 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.descriptiveDataSet.matrix.handler;
10

    
11
import javax.inject.Named;
12

    
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;
21

    
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;
34

    
35
/**
36
 *  @author k.luther
37
 *  @since May 8, 2020
38
 *
39
 */
40
public class DeleteDescriptionHandler{
41

    
42
    @Execute
43
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
44
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
45
            UISynchronize sync) {
46
        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
47
//        if(StoreUtil.promptCheckIsDirty(matrixPart)){
48
//            return;
49
//        }
50
        DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
51
        RowWrapperDTO wrapper = (RowWrapperDTO) matrixPart.getSelection().getFirstElement();
52
        DescriptionBase description = wrapper.getDescription().getDescription();
53
        RemoveDescriptionsFromDescriptiveDataSetConfigurator deleteConfig = new RemoveDescriptionsFromDescriptiveDataSetConfigurator();
54

    
55
        if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfig, shell, Messages.DeleteDescriptiveDataSetHandler_DELETE_TITLE,  Messages.CharacterMatrix_DELETE_DESCRIPTION)){
56
            return;
57
        }
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());
65

    
66

    
67
            if (matrixPart.getMatrix().getSpecimenCache()!= null){
68
                matrixPart.getMatrix().getSpecimenCache().add(nodeWrapper);
69
            }
70
        }
71
        matrixPart.getMatrix().update();
72
        if (ok){
73
            matrixPart.getMatrix().redraw();
74
            matrixPart.setDirty();
75
        }
76
    }
77

    
78
    @CanExecute
79
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
80
            MHandledMenuItem menuItem){
81

    
82
            CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
83
            DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
84
            IStructuredSelection selection = ((CharacterMatrixPart)activePart.getObject()).getSelection();
85

    
86
            boolean canExecute = selection.size()==1
87
                    && selection.getFirstElement() instanceof RowWrapperDTO;
88
            menuItem.setVisible(canExecute);
89
            return canExecute;
90

    
91
    }
92
}
(6-6/7)