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 java.util.UUID;
|
12
|
|
13
|
import javax.inject.Named;
|
14
|
|
15
|
import org.eclipse.core.commands.operations.IUndoContext;
|
16
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
17
|
import org.eclipse.e4.core.di.annotations.Execute;
|
18
|
import org.eclipse.e4.ui.di.UISynchronize;
|
19
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
20
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
21
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
|
22
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
23
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
24
|
|
25
|
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
|
26
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
27
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
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
|
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
|
45
|
UISynchronize sync) {
|
46
|
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
|
47
|
if(StoreUtil.promptCheckIsDirty(termEditor)){
|
48
|
return;
|
49
|
}
|
50
|
if(!StoreUtil.confirmDelete()){
|
51
|
return;
|
52
|
}
|
53
|
|
54
|
String label = menuItem.getLocalizedLabel();
|
55
|
IUndoContext undoContext = StoreUtil.getUndoContext();
|
56
|
AbstractPostOperation operation =
|
57
|
new DeleteTermBaseOperation(label,
|
58
|
undoContext,
|
59
|
(AbstractTermDto) selection.getFirstElement(),
|
60
|
termEditor.getDefinedTermEditorInput(),
|
61
|
termEditor);
|
62
|
AbstractUtility.executeOperation(operation, sync);
|
63
|
}
|
64
|
|
65
|
@CanExecute
|
66
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
|
67
|
MHandledMenuItem menuItem){
|
68
|
boolean canExecute = false;
|
69
|
Object firstElement = selection.getFirstElement();
|
70
|
canExecute = selection.size()==1
|
71
|
&& (firstElement instanceof AbstractTermDto);
|
72
|
UUID vocabularyUuid = null;
|
73
|
if(firstElement instanceof TermDto){
|
74
|
vocabularyUuid = ((TermDto) firstElement).getVocabularyUuid();
|
75
|
}else if(firstElement instanceof TermVocabularyDto){
|
76
|
vocabularyUuid = ((TermVocabularyDto) firstElement).getUuid();
|
77
|
}
|
78
|
canExecute &= vocabularyUuid!=null;
|
79
|
menuItem.setVisible(canExecute);
|
80
|
return canExecute;
|
81
|
}
|
82
|
}
|