Project

General

Profile

Download (2.57 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

    
21
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
22
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
23
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
24
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

    
27
/**
28
 * @author pplitzner
29
 * @since Sep 7, 2018
30
 *
31
 */
32
public class DeleteDescriptionHandler{
33

    
34
    @Execute
35
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
36
        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
37
        if(StoreUtil.promptCheckIsDirty(matrixPart)){
38
            return;
39
        }
40
        DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
41
        SpecimenRowWrapperDTO wrapper = (SpecimenRowWrapperDTO) matrixPart.getSelection().getFirstElement();
42
        SpecimenDescription description = wrapper.getDescription();
43

    
44
        boolean ok = matrixPart.getMatrix().getDescriptions().remove(wrapper);
45
        matrixPart.getMatrix().putDescriptionToDelete(description.getUuid());
46
        matrixPart.getMatrix().update();
47
        if (ok){
48
            matrixPart.setDirty();
49
        }
50
    }
51

    
52
    @CanExecute
53
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
54
            MHandledMenuItem menuItem){
55

    
56
            CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
57
            DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
58
            IStructuredSelection selection = ((CharacterMatrixPart)activePart.getObject()).getSelection();
59

    
60
            boolean canExecute = selection.size()==1
61
                    && selection.getFirstElement() instanceof SpecimenRowWrapperDTO;
62
            menuItem.setVisible(canExecute);
63
            return canExecute;
64

    
65
    }
66
}
(4-4/4)