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.common.NotDefinedException;
|
14
|
import org.eclipse.core.commands.operations.IUndoContext;
|
15
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
16
|
import org.eclipse.e4.core.di.annotations.Execute;
|
17
|
import org.eclipse.e4.core.di.annotations.Optional;
|
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) throws NotDefinedException {
|
45
|
|
46
|
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
|
47
|
|
48
|
if (termEditor.isDirty()){
|
49
|
boolean proceed = MessageDialog.openQuestion(null,
|
50
|
"Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
|
51
|
if (proceed) {
|
52
|
termEditor.doSave();
|
53
|
} else {
|
54
|
return;
|
55
|
}
|
56
|
}
|
57
|
String label = menuItem.getLocalizedLabel();
|
58
|
IUndoContext undoContext = StoreUtil.getUndoContext();
|
59
|
AbstractPostOperation operation =
|
60
|
new DeleteTermBaseOperation(label,
|
61
|
undoContext,
|
62
|
termBase,
|
63
|
termEditor.getDefinedTermEditorInput(),
|
64
|
termEditor);
|
65
|
AbstractUtility.executeOperation(operation);
|
66
|
}
|
67
|
|
68
|
@CanExecute
|
69
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
|
70
|
if (termBase == null){
|
71
|
return true;
|
72
|
}
|
73
|
|
74
|
TermVocabulary vocabulary = null;
|
75
|
|
76
|
if(termBase instanceof DefinedTermBase){
|
77
|
vocabulary = ((DefinedTermBase) termBase).getVocabulary();
|
78
|
}else if(termBase instanceof TermVocabulary){
|
79
|
vocabulary = (TermVocabulary) termBase;
|
80
|
}
|
81
|
|
82
|
if(vocabulary == null){
|
83
|
return true;
|
84
|
}
|
85
|
|
86
|
for(Marker vocabularyMarker : vocabulary.getMarkers()){
|
87
|
if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
|
88
|
return vocabularyMarker.getValue();
|
89
|
}
|
90
|
}
|
91
|
|
92
|
return true;
|
93
|
}
|
94
|
}
|