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
.navigator
.handler
;
11 import java
.util
.HashSet
;
12 import java
.util
.Iterator
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.ui
.IWorkbenchPage
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
31 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
34 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
35 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingDeleteTaxonNodeOperation
;
36 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
37 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.deleteConfigurator
.DeleteConfiguratorDialog
;
44 public class RemotingDeleteTaxonNodeHandler
extends RemotingCdmHandler
{
46 private TaxonDeletionConfigurator config
;
47 private Set
<ITaxonTreeNode
> treeNodes
;
49 public RemotingDeleteTaxonNodeHandler() {
50 super(TaxonNavigatorLabels
.DELETE_TAXON_NODE_LABEL
);
54 public IStatus
allowOperations(ExecutionEvent event
) {
55 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
57 Iterator
<?
> selectionIterator
= selection
.iterator();
58 treeNodes
= new HashSet
<ITaxonTreeNode
>();
60 while (selectionIterator
.hasNext()){
61 Object object
= selectionIterator
.next();
62 if(object
instanceof ITaxonTreeNode
) {
63 treeNodes
.add((ITaxonTreeNode
) object
);
66 boolean allEditorsClosed
= true;
67 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
68 for (ITaxonTreeNode treeNode
: treeNodes
) {
69 if(treeNode
instanceof TaxonNode
) {
70 allEditorsClosed
&= EditorUtil
.closeObsoleteEditor((TaxonNode
) treeNode
, activePage
);
73 if(!allEditorsClosed
) {
74 return new Status(IStatus
.WARNING
,
75 "unknown", //$NON-NLS-1$
76 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
79 config
= new TaxonDeletionConfigurator();
81 if (treeNodes
.size() == 1 ){
82 ITaxonTreeNode treeNode
= treeNodes
.iterator().next();
83 ITaxonTreeNode taxonNode
= treeNode
;
84 if (taxonNode
instanceof TaxonNode
&& !((TaxonNode
)taxonNode
).hasTaxon()){
85 taxonNode
= CdmApplicationState
.getCurrentAppConfig().getClassificationService().load(((TaxonNode
)taxonNode
).getClassification().getUuid());
87 taxonNode
= CdmApplicationState
.getCurrentAppConfig().getTaxonNodeService().load(taxonNode
.getUuid());
89 treeNodes
= new HashSet
<ITaxonTreeNode
>();
90 treeNodes
.add(taxonNode
);
91 if (taxonNode
== null){
92 MessagingUtils
.informationDialog(Messages
.RemotingDeleteTaxonNodeHandler_NODE_DELETED
, Messages
.RemotingDeleteTaxonNodeHandler_NODE_DELETED_MESSAGE
);
93 return Status
.CANCEL_STATUS
;
96 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
97 if (taxonNode
instanceof Classification
) {
99 if (taxonNode
.hasChildNodes()) {
100 message
= DeleteHandler
.DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION
+DeleteHandler
.THE_TREE_HAS_CHILDREN_THEY_WILL_BE_DELETED_TOO
;
102 message
= DeleteHandler
.DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION
;
104 if (!DeleteConfiguratorDialog
.openConfirm(
105 HandlerUtil
.getActiveShell(event
), DeleteHandler
.CONFIRM_DELETION
,
107 return Status
.CANCEL_STATUS
;
112 if (taxonNode
.hasChildNodes()){
113 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(
115 HandlerUtil
.getActiveShell(event
),
116 DeleteHandler
.CONFIRM_DELETION
,
118 DeleteHandler
.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S
+DeleteHandler
.THERE_ARE_CHILDNODES_WHICH_WILL_BE_DELETED_TOO
,
119 MessageDialog
.WARNING
, new String
[] { DeleteHandler
.DELETE_ALL_CHILDREN
,
120 DeleteHandler
.MOVE_CHILDREN_TO_PARENT_NODE
, DeleteHandler
.SKIP
}, 0);
121 int result
= dialog
.open();
124 //delete all children
125 configNodes
.setChildHandling(ChildHandling
.DELETE
);
126 config
.setTaxonNodeConfig(configNodes
);
127 } else if (result
== 1){
129 configNodes
.setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
130 config
.setTaxonNodeConfig(configNodes
);
131 } else if (result
== 2){
132 return Status
.CANCEL_STATUS
;
135 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(configNodes
, HandlerUtil
.getActiveShell(event
), DeleteHandler
.CONFIRM_DELETION
, DeleteHandler
.DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S
)){
136 return Status
.CANCEL_STATUS
;
138 config
.setTaxonNodeConfig(configNodes
);
142 return Status
.OK_STATUS
;
146 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
147 return new RemotingDeleteTaxonNodeOperation(event
.getTrigger(),
154 public void onComplete() {