Project

General

Profile

Download (3.35 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2009 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.definedterm.e4.handler;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.e4.core.di.annotations.CanExecute;
15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.core.di.annotations.Optional;
17
import org.eclipse.e4.ui.di.UISynchronize;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.jface.dialogs.MessageDialog;
22

    
23
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
24
import eu.etaxonomy.cdm.model.common.Marker;
25
import eu.etaxonomy.cdm.model.common.MarkerType;
26
import eu.etaxonomy.cdm.model.common.TermBase;
27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
29
import eu.etaxonomy.taxeditor.editor.definedterm.operation.DeleteTermBaseOperation;
30
import eu.etaxonomy.taxeditor.model.AbstractUtility;
31
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
32
import eu.etaxonomy.taxeditor.store.StoreUtil;
33

    
34
/**
35
 *
36
 * @author pplitzner
37
 * @since Aug 22, 2017
38
 *
39
 */
40
public class DeleteTermBaseHandlerE4 {
41

    
42
    @Execute
43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
44
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MMenuItem menuItem,
45
            UISynchronize sync) {
46

    
47
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
48

    
49
        if (termEditor.isDirty()){
50
            boolean proceed = MessageDialog.openQuestion(null,
51
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
52
            if (proceed) {
53
                termEditor.save(null);
54
            } else {
55
                return;
56
            }
57
        }
58
        String label = menuItem.getLocalizedLabel();
59
        IUndoContext undoContext = StoreUtil.getUndoContext();
60
        AbstractPostOperation operation =
61
                new DeleteTermBaseOperation(label,
62
                        undoContext,
63
                        termBase,
64
                        termEditor.getDefinedTermEditorInput(),
65
                        termEditor);
66
        AbstractUtility.executeOperation(operation, sync);
67
    }
68

    
69
    @CanExecute
70
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
71
        if (termBase == null){
72
            return true;
73
        }
74

    
75
        TermVocabulary vocabulary = null;
76

    
77
        if(termBase instanceof DefinedTermBase){
78
            vocabulary = ((DefinedTermBase) termBase).getVocabulary();
79
        }else if(termBase instanceof TermVocabulary){
80
            vocabulary = (TermVocabulary) termBase;
81
        }
82

    
83
        if(vocabulary == null){
84
            return true;
85
        }
86

    
87
        for(Marker vocabularyMarker : vocabulary.getMarkers()){
88
            if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
89
                return vocabularyMarker.getValue();
90
            }
91
        }
92

    
93
        return true;
94
    }
95
}
(3-3/4)