Revision 83a06467
Added by Katja Luther about 7 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingDeleteTaxonNodeHandler.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.navigation.navigator.handler; |
|
11 |
|
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.Iterator; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 |
import org.eclipse.core.commands.ExecutionEvent; |
|
17 |
import org.eclipse.core.commands.operations.AbstractOperation; |
|
18 |
import org.eclipse.core.runtime.IStatus; |
|
19 |
import org.eclipse.core.runtime.Status; |
|
20 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
21 |
import org.eclipse.jface.viewers.TreeSelection; |
|
22 |
import org.eclipse.ui.IWorkbenchPage; |
|
23 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
|
26 |
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator; |
|
27 |
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling; |
|
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.navigation.navigator.TaxonNavigatorLabels; |
|
33 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation; |
|
34 |
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler; |
|
35 |
import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog; |
|
36 |
|
|
37 |
/** |
|
38 |
* @author cmathew |
|
39 |
* @date 22 Jun 2015 |
|
40 |
* |
|
41 |
*/ |
|
42 |
public class RemotingDeleteTaxonNodeHandler extends RemotingCdmHandler { |
|
43 |
|
|
44 |
private TaxonDeletionConfigurator config; |
|
45 |
private Set<ITaxonTreeNode> treeNodes; |
|
46 |
|
|
47 |
/** |
|
48 |
* @param label |
|
49 |
*/ |
|
50 |
public RemotingDeleteTaxonNodeHandler() { |
|
51 |
super(TaxonNavigatorLabels.DELETE_TAXON_NODE_LABEL); |
|
52 |
} |
|
53 |
|
|
54 |
/* (non-Javadoc) |
|
55 |
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent) |
|
56 |
*/ |
|
57 |
@Override |
|
58 |
public IStatus allowOperations(ExecutionEvent event) { |
|
59 |
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); |
|
60 |
|
|
61 |
Iterator selectionIterator = selection.iterator(); |
|
62 |
treeNodes = new HashSet<ITaxonTreeNode>(); |
|
63 |
|
|
64 |
while (selectionIterator.hasNext()){ |
|
65 |
Object object = selectionIterator.next(); |
|
66 |
if(object instanceof ITaxonTreeNode) { |
|
67 |
treeNodes.add((ITaxonTreeNode) object); |
|
68 |
} |
|
69 |
} |
|
70 |
boolean allEditorsClosed = true; |
|
71 |
IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
|
72 |
for (ITaxonTreeNode treeNode : treeNodes) { |
|
73 |
if(treeNode instanceof TaxonNode) { |
|
74 |
allEditorsClosed &= EditorUtil.closeObsoleteEditor((TaxonNode) treeNode, activePage); |
|
75 |
} |
|
76 |
} |
|
77 |
if(!allEditorsClosed) { |
|
78 |
return new Status(IStatus.WARNING, |
|
79 |
"unknown", |
|
80 |
TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE); |
|
81 |
} |
|
82 |
|
|
83 |
config = new TaxonDeletionConfigurator(); |
|
84 |
|
|
85 |
if (treeNodes.size() == 1 ){ |
|
86 |
|
|
87 |
ITaxonTreeNode treeNode = treeNodes.iterator().next(); |
|
88 |
ITaxonTreeNode taxonNode = treeNode; |
|
89 |
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator(); |
|
90 |
if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){ |
|
91 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){ |
|
92 |
return Status.CANCEL_STATUS; |
|
93 |
} |
|
94 |
} else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){ |
|
95 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){ |
|
96 |
return Status.CANCEL_STATUS; |
|
97 |
} |
|
98 |
} else { |
|
99 |
|
|
100 |
if (taxonNode.hasChildNodes()){ |
|
101 |
DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog( |
|
102 |
config, |
|
103 |
HandlerUtil.getActiveShell(event), |
|
104 |
"Confirm Deletion", |
|
105 |
null, |
|
106 |
"Do you really want to delete the selected node? It has childnodes, they will be deleted, too.", |
|
107 |
MessageDialog.WARNING, new String[] { "Delete all children", |
|
108 |
"Move children to parent node", "Skip" }, 0); |
|
109 |
int result = dialog.open(); |
|
110 |
|
|
111 |
if (result == 0){ |
|
112 |
//delete all children |
|
113 |
configNodes.setChildHandling(ChildHandling.DELETE); |
|
114 |
config.setTaxonNodeConfig(configNodes); |
|
115 |
} else if (result == 1){ |
|
116 |
//move children |
|
117 |
configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT); |
|
118 |
config.setTaxonNodeConfig(configNodes); |
|
119 |
} else if (result == 2){ |
|
120 |
return Status.CANCEL_STATUS; |
|
121 |
} |
|
122 |
} else{ |
|
123 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){ |
|
124 |
return Status.CANCEL_STATUS; |
|
125 |
} |
|
126 |
config.setTaxonNodeConfig(configNodes); |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
return Status.OK_STATUS; |
|
131 |
} |
|
132 |
|
|
133 |
/* (non-Javadoc) |
|
134 |
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent) |
|
135 |
*/ |
|
136 |
@Override |
|
137 |
public AbstractOperation prepareOperation(ExecutionEvent event) { |
|
138 |
return new RemotingDeleteTaxonNodeOperation(event.getTrigger(), |
|
139 |
false, |
|
140 |
treeNodes, |
|
141 |
config); |
|
142 |
} |
|
143 |
|
|
144 |
/* (non-Javadoc) |
|
145 |
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete() |
|
146 |
*/ |
|
147 |
@Override |
|
148 |
public void onComplete() { |
|
149 |
// TODO Auto-generated method stub |
|
150 |
|
|
151 |
} |
|
152 |
|
|
153 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.navigation.navigator.handler; |
|
11 |
|
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.Iterator; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 |
import org.eclipse.core.commands.ExecutionEvent; |
|
17 |
import org.eclipse.core.commands.operations.AbstractOperation; |
|
18 |
import org.eclipse.core.runtime.IStatus; |
|
19 |
import org.eclipse.core.runtime.Status; |
|
20 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
21 |
import org.eclipse.jface.viewers.TreeSelection; |
|
22 |
import org.eclipse.ui.IWorkbenchPage; |
|
23 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
|
26 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
|
27 |
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator; |
|
28 |
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling; |
|
29 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
30 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
|
32 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
33 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
34 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
35 |
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels; |
|
36 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation; |
|
37 |
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler; |
|
38 |
import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog; |
|
39 |
|
|
40 |
/** |
|
41 |
* @author cmathew |
|
42 |
* @date 22 Jun 2015 |
|
43 |
* |
|
44 |
*/ |
|
45 |
public class RemotingDeleteTaxonNodeHandler extends RemotingCdmHandler { |
|
46 |
|
|
47 |
private TaxonDeletionConfigurator config; |
|
48 |
private Set<ITaxonTreeNode> treeNodes; |
|
49 |
|
|
50 |
/** |
|
51 |
* @param label |
|
52 |
*/ |
|
53 |
public RemotingDeleteTaxonNodeHandler() { |
|
54 |
super(TaxonNavigatorLabels.DELETE_TAXON_NODE_LABEL); |
|
55 |
} |
|
56 |
|
|
57 |
/* (non-Javadoc) |
|
58 |
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent) |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public IStatus allowOperations(ExecutionEvent event) { |
|
62 |
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); |
|
63 |
|
|
64 |
Iterator selectionIterator = selection.iterator(); |
|
65 |
treeNodes = new HashSet<ITaxonTreeNode>(); |
|
66 |
|
|
67 |
while (selectionIterator.hasNext()){ |
|
68 |
Object object = selectionIterator.next(); |
|
69 |
if(object instanceof ITaxonTreeNode) { |
|
70 |
treeNodes.add((ITaxonTreeNode) object); |
|
71 |
} |
|
72 |
} |
|
73 |
boolean allEditorsClosed = true; |
|
74 |
IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
|
75 |
for (ITaxonTreeNode treeNode : treeNodes) { |
|
76 |
if(treeNode instanceof TaxonNode) { |
|
77 |
allEditorsClosed &= EditorUtil.closeObsoleteEditor((TaxonNode) treeNode, activePage); |
|
78 |
} |
|
79 |
} |
|
80 |
if(!allEditorsClosed) { |
|
81 |
return new Status(IStatus.WARNING, |
|
82 |
"unknown", |
|
83 |
TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE); |
|
84 |
} |
|
85 |
|
|
86 |
config = new TaxonDeletionConfigurator(); |
|
87 |
|
|
88 |
if (treeNodes.size() == 1 ){ |
|
89 |
ITaxonTreeNode treeNode = treeNodes.iterator().next(); |
|
90 |
ITaxonTreeNode taxonNode = treeNode; |
|
91 |
taxonNode = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(taxonNode.getUuid()); |
|
92 |
if (taxonNode == null){ |
|
93 |
MessagingUtils.informationDialog("Node already deleted", "The taxon node was already deleted. Please reopen the taxon navigator to refresh the view."); |
|
94 |
return Status.CANCEL_STATUS; |
|
95 |
|
|
96 |
} |
|
97 |
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator(); |
|
98 |
if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){ |
|
99 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){ |
|
100 |
return Status.CANCEL_STATUS; |
|
101 |
} |
|
102 |
} else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){ |
|
103 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){ |
|
104 |
return Status.CANCEL_STATUS; |
|
105 |
} |
|
106 |
} else { |
|
107 |
|
|
108 |
if (taxonNode.hasChildNodes()){ |
|
109 |
DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog( |
|
110 |
config, |
|
111 |
HandlerUtil.getActiveShell(event), |
|
112 |
"Confirm Deletion", |
|
113 |
null, |
|
114 |
"Do you really want to delete the selected node? It has childnodes, they will be deleted, too.", |
|
115 |
MessageDialog.WARNING, new String[] { "Delete all children", |
|
116 |
"Move children to parent node", "Skip" }, 0); |
|
117 |
int result = dialog.open(); |
|
118 |
|
|
119 |
if (result == 0){ |
|
120 |
//delete all children |
|
121 |
configNodes.setChildHandling(ChildHandling.DELETE); |
|
122 |
config.setTaxonNodeConfig(configNodes); |
|
123 |
} else if (result == 1){ |
|
124 |
//move children |
|
125 |
configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT); |
|
126 |
config.setTaxonNodeConfig(configNodes); |
|
127 |
} else if (result == 2){ |
|
128 |
return Status.CANCEL_STATUS; |
|
129 |
} |
|
130 |
} else{ |
|
131 |
if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){ |
|
132 |
return Status.CANCEL_STATUS; |
|
133 |
} |
|
134 |
config.setTaxonNodeConfig(configNodes); |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
return Status.OK_STATUS; |
|
139 |
} |
|
140 |
|
|
141 |
/* (non-Javadoc) |
|
142 |
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent) |
|
143 |
*/ |
|
144 |
@Override |
|
145 |
public AbstractOperation prepareOperation(ExecutionEvent event) { |
|
146 |
return new RemotingDeleteTaxonNodeOperation(event.getTrigger(), |
|
147 |
false, |
|
148 |
treeNodes, |
|
149 |
config); |
|
150 |
} |
|
151 |
|
|
152 |
/* (non-Javadoc) |
|
153 |
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete() |
|
154 |
*/ |
|
155 |
@Override |
|
156 |
public void onComplete() { |
|
157 |
// TODO Auto-generated method stub |
|
158 |
|
|
159 |
} |
|
160 |
|
|
161 |
} |
Also available in: Unified diff
fix #5289