2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
.handler
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
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
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.ui
.IEditorInput
;
20 import org
.eclipse
.ui
.IEditorReference
;
21 import org
.eclipse
.ui
.IWorkbenchPage
;
22 import org
.eclipse
.ui
.PartInitException
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyEditorInput
;
26 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
27 import eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
.PolytomousKeyViewLabels
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
.operation
.RemotingDeletePolytomousKeyOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
30 import eu
.etaxonomy
.taxeditor
.util
.OperationsUtil
;
37 public class RemotingDeletePolytomousKeyHandler
extends RemotingCdmHandler
{
39 List
<UUID
> keysToDelete
;
43 public RemotingDeletePolytomousKeyHandler() {
44 super(PolytomousKeyViewLabels
.DELETE_POLYTOMOUS_KEY_LABEL
);
48 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
51 public IStatus
allowOperations(ExecutionEvent event
) {
52 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
54 keysToDelete
= OperationsUtil
.convertToUuidList(selection
.toList());
56 if(keysToDelete
.isEmpty()){
57 return Status
.CANCEL_STATUS
;
60 boolean confirmation
= MessagingUtils
.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keysToDelete
.size() == 1 ?
"" : "s") + "?");
63 return Status
.CANCEL_STATUS
;
65 closeObsoleteEditor(event
);
66 return Status
.OK_STATUS
;
70 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
73 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
74 return new RemotingDeletePolytomousKeyOperation(event
.getTrigger(),
80 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
83 public void onComplete() {
84 // TODO Auto-generated method stub
87 protected boolean closeObsoleteEditor(ExecutionEvent event
){
88 boolean result
= true;
89 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
91 for (IEditorReference ref
: activePage
.getEditorReferences()) {
93 IEditorInput input
= ref
.getEditorInput();
94 if (input
instanceof PolytomousKeyEditorInput
) {
95 UUID uuidForKey
= ((PolytomousKeyEditorInput
) input
).getKey().getUuid();
96 for (UUID keyUuid
:keysToDelete
) {
97 if( uuidForKey
.equals(keyUuid
)){
98 result
&= activePage
.closeEditor(ref
.getEditor(false), false);
103 } catch (PartInitException e
) {