1
|
/**
|
2
|
* Copyright (C) 2015 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.navigation.key.polytomous.e4.handler;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.core.runtime.Status;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
20
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
21
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
22
|
import org.eclipse.swt.widgets.Shell;
|
23
|
|
24
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4;
|
25
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
26
|
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
|
27
|
import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RemotingDeletePolytomousKeyOperation;
|
28
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
29
|
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
|
30
|
import eu.etaxonomy.taxeditor.util.OperationsUtil;
|
31
|
|
32
|
/**
|
33
|
* @author cmathew
|
34
|
* @date 25 Jun 2015
|
35
|
*
|
36
|
*/
|
37
|
public class RemotingDeletePolytomousKeyHandlerE4 extends RemotingCdmHandlerE4 {
|
38
|
|
39
|
List<UUID> keysToDelete;
|
40
|
public static final String CONFIRM = Messages.DeleteHandler_CONFIRM;
|
41
|
public static final String CONFIRM_MESSAGE = Messages.DeleteHandler_CONFIRM_MESSAGE;
|
42
|
|
43
|
public RemotingDeletePolytomousKeyHandlerE4() {
|
44
|
super(PolytomousKeyViewLabels.DELETE_POLYTOMOUS_KEY_LABEL);
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public IStatus allowOperations(IStructuredSelection selection, Shell shell, MPart activePart,
|
49
|
MHandledMenuItem menuItem) {
|
50
|
|
51
|
keysToDelete = OperationsUtil.convertToUuidList(selection.toList());
|
52
|
|
53
|
if(keysToDelete.isEmpty()){
|
54
|
return Status.CANCEL_STATUS;
|
55
|
}
|
56
|
|
57
|
boolean confirmation = MessagingUtils.confirmDialog(CONFIRM, CONFIRM_MESSAGE);
|
58
|
|
59
|
if(!confirmation) {
|
60
|
return Status.CANCEL_STATUS;
|
61
|
}
|
62
|
closeObsoleteEditor(partService);
|
63
|
return Status.OK_STATUS;
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public AbstractOperation prepareOperation(IStructuredSelection selection, Shell shell, MPart activePart,
|
68
|
MHandledMenuItem menuItem) {
|
69
|
return new RemotingDeletePolytomousKeyOperation(getTrigger(),
|
70
|
false,
|
71
|
keysToDelete);
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public void onComplete() {
|
76
|
}
|
77
|
|
78
|
protected void closeObsoleteEditor(EPartService partService){
|
79
|
Collection<MPart> parts = partService.getParts();
|
80
|
for (MPart part : parts) {
|
81
|
if(part.getElementId().equals("eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4")){
|
82
|
PolytomousKeyListEditorE4 keyListEditor = (PolytomousKeyListEditorE4) part.getObject();
|
83
|
UUID uuidForKey = keyListEditor.getEditorInput().getKey().getUuid();
|
84
|
for (UUID keyUuid :keysToDelete) {
|
85
|
if(uuidForKey.equals(keyUuid)){
|
86
|
partService.hidePart(part, true);
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* {@inheritDoc}
|
95
|
*/
|
96
|
@Override
|
97
|
protected Object getTrigger() {
|
98
|
return this;
|
99
|
}
|
100
|
}
|