From 83117514f529beb67d779214d56009afc300a598 Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Tue, 5 Nov 2013 08:54:48 +0000 Subject: [PATCH] smaller fixes --- ...ltiPageTaxonEditorDataChangeBehaviour.java | 2 +- .../name/handler/DeleteTaxonBaseHandler.java | 1 + .../navigator/handler/DeleteHandler.java | 69 ++++++++++++------- .../navigator/operation/CopyOperation.java | 4 +- .../navigator/operation/DeleteOperation.java | 58 +++++++++++----- .../AbstractPersistentPostOperation.java | 1 + .../operation/AbstractPostOperation.java | 3 +- 7 files changed, 93 insertions(+), 45 deletions(-) diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditorDataChangeBehaviour.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditorDataChangeBehaviour.java index 80812aef3..2ff0bd9bb 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditorDataChangeBehaviour.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditorDataChangeBehaviour.java @@ -83,7 +83,7 @@ public class MultiPageTaxonEditorDataChangeBehaviour extends AbstractDataChangeB // 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."); } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java index dab4585d4..ee188ef28 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java @@ -87,6 +87,7 @@ public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler, return ; } IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); + operation = new DeleteTaxonOperation(commandName, editor.getUndoContext(),(Taxon) selectedElement, null, activePage, this, editor); //editor.dispose(); diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java index 88a37c649..06daa8920 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java @@ -27,6 +27,8 @@ import org.eclipse.ui.IWorkbenchPage; 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; @@ -64,38 +66,51 @@ public class DeleteHandler extends AbstractHandler implements IHandler{ } Iterator selectionIterator = selection.iterator(); - Set treeNodes = new HashSet(); + Set treeNodes = new HashSet(); 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; } @@ -104,11 +119,17 @@ public class DeleteHandler extends AbstractHandler implements IHandler{ 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) { diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/CopyOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/CopyOperation.java index 25c8632a1..c6b3c56bc 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/CopyOperation.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/CopyOperation.java @@ -48,7 +48,7 @@ public class CopyOperation extends AbstractPostOperation { public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - String name = taxonNode.getTaxon().getName().getTitleCache(); + String name = ((TaxonNode)taxonNode).getTaxon().getName().getTitleCache(); final Clipboard cb = new Clipboard(null); TextTransfer textTransfer = TextTransfer.getInstance(); @@ -56,7 +56,7 @@ public class CopyOperation extends AbstractPostOperation { cb.setContents(new Object[]{name}, transfers); - return postExecute(taxonNode); + return postExecute(((TaxonNode)taxonNode)); //return null; } diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java index 48a89b97d..9968fa9cd 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java @@ -22,9 +22,11 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationController; 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; @@ -42,7 +44,8 @@ import eu.etaxonomy.taxeditor.store.StoreUtil; */ public class DeleteOperation extends AbstractPersistentPostOperation{ - private Set treeNodes; + private Set treeNodes; + private TaxonDeletionConfigurator config; /** @@ -55,13 +58,32 @@ public class DeleteOperation extends AbstractPersistentPostOperation{ * @param treeNodes a {@link java.util.Set} object. */ public DeleteOperation(String label, IUndoContext undoContext, - Set treeNodes, + ITreeNode taxonNode, TaxonDeletionConfigurator config, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) { super(label, undoContext, postOperationEnabled, conversationEnabled); - this.treeNodes = treeNodes; + this.taxonNode = taxonNode; + this.config = config; } + /** + *

Constructor for DeleteTreeNodeOperation.

+ * + * @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 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) @@ -73,34 +95,36 @@ public class DeleteOperation extends AbstractPersistentPostOperation{ 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); } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPersistentPostOperation.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPersistentPostOperation.java index ab05864c6..37ff63f70 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPersistentPostOperation.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPersistentPostOperation.java @@ -95,6 +95,7 @@ public abstract class AbstractPersistentPostOperation extends AbstractPostOperat if (!conversationEnabled.getConversationHolder().isClosed()){ + conversationEnabled.getConversationHolder().bind(); conversationEnabled.getConversationHolder().commit(true); } IStatus status = super.postExecute(objectAffectedByOperation); diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPostOperation.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPostOperation.java index 5f3ffed22..6d35611cf 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPostOperation.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPostOperation.java @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IStatus; 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; @@ -43,7 +44,7 @@ public abstract class AbstractPostOperation extends AbstractOperation { /** * A reference to the taxons TaxonNode */ - protected TaxonNode taxonNode; + protected ITreeNode taxonNode; protected UUID parentNodeUuid; -- 2.34.1