Project

General

Profile

Download (3.27 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.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.dialogs.MessageDialog;
21

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

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

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

    
45
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
46

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

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

    
73
        TermVocabulary vocabulary = null;
74

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

    
81
        if(vocabulary == null){
82
            return true;
83
        }
84

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

    
91
        return true;
92
    }
93
}
(3-3/4)