// close open editors
if((event.getEntity() instanceof TaxonNode)
&& input.getTaxonNode().equals(event.getEntity())){
- EditorUtil.close(source);
+ //EditorUtil.close(source);
logger.debug("Closing open editor for deleted taxon.");
}
}
return ;
}
IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+
operation = new DeleteTaxonOperation(commandName, editor.getUndoContext(),(Taxon) selectedElement, null, activePage, this, editor);
//editor.dispose();
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+import eu.etaxonomy.cdm.model.common.ITreeNode;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
}
Iterator selectionIterator = selection.iterator();
- Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
+ Set<ITreeNode> treeNodes = new HashSet<ITreeNode>();
while (selectionIterator.hasNext()){
Object object = selectionIterator.next();
- if(object instanceof ITaxonTreeNode) {
- treeNodes.add((ITaxonTreeNode) object);
+ if(object instanceof ITreeNode) {
+ treeNodes.add((ITreeNode) object);
}
}
-
+ boolean allEditorsClosed = true;
+ for (ITreeNode treeNode : treeNodes){
+ if(treeNode instanceof TaxonNode) {
+ allEditorsClosed &= closeObsoleteEditor((TaxonNode) treeNode);
+ }
+ }
AbstractPostOperation operation = null;
- try {
-
-
- boolean allEditorsClosed = true;
- for (ITaxonTreeNode treeNode : treeNodes){
- if(treeNode instanceof TaxonNode) {
- allEditorsClosed &= closeObsoleteEditor((TaxonNode) treeNode);
+ if (treeNodes.size() == 1 ){
+ try {
+
+
+ if (allEditorsClosed){
+ TaxonNode taxonNode = (TaxonNode)treeNodes.iterator().next();
+ operation = new DeleteOperation(
+ event.getCommand().getName(), NavigationUtil.getUndoContext(),
+ taxonNode, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
+
+ NavigationUtil.executeOperation(operation);
}
- }
-
- if (allEditorsClosed){
- operation = new DeleteOperation(
- event.getCommand().getName(), NavigationUtil.getUndoContext(),
- treeNodes, taxonNavigator, taxonNavigator);
- NavigationUtil.executeOperation(operation);
- }
-
+
-
- } catch (NotDefinedException e) {
- NavigationUtil.warn(getClass(), "Command name not set");
+ } catch (NotDefinedException e) {
+ NavigationUtil.warn(getClass(), "Command name not set");
+ }
+ } else{
+ try{
+ if (allEditorsClosed){
+ operation = new DeleteOperation(
+ event.getCommand().getName(), NavigationUtil.getUndoContext(),
+ treeNodes, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
+
+ NavigationUtil.executeOperation(operation);
+ }
+ }catch (NotDefinedException e) {
+ NavigationUtil.warn(getClass(), "Command name not set");
+ }
}
return null;
}
boolean result = true;
for (IEditorReference ref : activePage.getEditorReferences()) {
try {
+ String treeIndex = ((ITreeNode)taxonNode).treeIndex();
+
+
IEditorInput input = ref.getEditorInput();
if (input instanceof TaxonEditorInput) {
TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
- if (taxonNode.equals(node)) {
+ //if node is a child of taxonNode then close the editor
+ if( ((ITreeNode) node).treeIndex().startsWith(treeIndex)){
+ //if (taxonNode.equals(node)) {
result &= activePage.closeEditor(ref.getEditor(false), true);
+
}
}
} catch (PartInitException e) {
public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
throws ExecutionException {\r
\r
- String name = taxonNode.getTaxon().getName().getTitleCache();\r
+ String name = ((TaxonNode)taxonNode).getTaxon().getName().getTitleCache();\r
\r
final Clipboard cb = new Clipboard(null);\r
TextTransfer textTransfer = TextTransfer.getInstance();\r
\r
cb.setContents(new Object[]{name}, transfers);\r
\r
- return postExecute(taxonNode); \r
+ return postExecute(((TaxonNode)taxonNode)); \r
//return null;\r
}\r
\r
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
+import eu.etaxonomy.cdm.model.common.ITreeNode;
import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
*/
public class DeleteOperation extends AbstractPersistentPostOperation{
- private Set<ITaxonTreeNode> treeNodes;
+ private Set<ITreeNode> treeNodes;
+ private TaxonDeletionConfigurator config;
/**
* @param treeNodes a {@link java.util.Set} object.
*/
public DeleteOperation(String label, IUndoContext undoContext,
- Set<ITaxonTreeNode> treeNodes,
+ ITreeNode taxonNode, TaxonDeletionConfigurator config,
IPostOperationEnabled postOperationEnabled,
IConversationEnabled conversationEnabled) {
super(label, undoContext, postOperationEnabled, conversationEnabled);
- this.treeNodes = treeNodes;
+ this.taxonNode = taxonNode;
+ this.config = config;
}
+ /**
+ * <p>Constructor for DeleteTreeNodeOperation.</p>
+ *
+ * @param label a {@link java.lang.String} object.
+ * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
+ * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
+ * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
+ * @param treeNodes a {@link java.util.Set} object.
+ */
+ public DeleteOperation(String label, IUndoContext undoContext,
+ Set<ITreeNode> treeNodes, TaxonDeletionConfigurator config,
+ IPostOperationEnabled postOperationEnabled,
+ IConversationEnabled conversationEnabled) {
+ super(label, undoContext, postOperationEnabled, conversationEnabled);
+ this.treeNodes = treeNodes;
+ this.config = config;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
bind();
monitor.worked(20);
- for (ITaxonTreeNode treeNode : treeNodes){
- if(treeNode instanceof TaxonNode){
+ ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
+ ITaxonNodeService service = controller.getTaxonNodeService();
+ if(taxonNode != null && taxonNode instanceof TaxonNode){
//((TaxonNode) treeNode).delete();
- taxon = ((TaxonNode) treeNode).getTaxon();
- ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
-
- ITaxonService service = controller.getTaxonService();
+ taxon = ((TaxonNode)taxonNode).getTaxon();
try {
-
- service.deleteTaxon(taxon, new TaxonDeletionConfigurator(), ((TaxonNode) treeNode).getClassification());
-
+ service.deleteTaxonNode((TaxonNode)taxonNode, config);
} catch (DataChangeNoRollbackException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ throw new ExecutionException(e.getMessage());
}
- }else if(treeNode instanceof Classification){
- Classification taxonomicTree = (Classification) treeNode;
+ }else if(taxonNode != null && taxonNode instanceof Classification){
+ Classification taxonomicTree = (Classification) taxonNode;
if(taxonomicTree.hasChildNodes()){
StoreUtil.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
"is not empty. Please delete included taxa first");
}else{
CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
}
+ } else {
+ try {
+ service.deleteTaxonNodes(treeNodes, config);
+ } catch (DataChangeNoRollbackException e) {
+ throw new ExecutionException(e.getMessage());
+ }
}
- }
+
monitor.worked(40);
return postExecute(null);
}
if (!conversationEnabled.getConversationHolder().isClosed()){
+ conversationEnabled.getConversationHolder().bind();
conversationEnabled.getConversationHolder().commit(true);
}
IStatus status = super.postExecute(objectAffectedByOperation);
import org.eclipse.core.runtime.Status;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.ITreeNode;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
/**
* A reference to the taxons TaxonNode
*/
- protected TaxonNode taxonNode;
+ protected ITreeNode taxonNode;
protected UUID parentNodeUuid;