eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java -text
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java -text
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java -text
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeHomotypicGroupOperation.java -text
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeMisappliedNameToSynonymOperation.java -text
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeSynonymToMisappliedNameOperation.java -text
import eu.etaxonomy.cdm.model.description.Feature;\r
import eu.etaxonomy.cdm.model.name.NameRelationshipType;\r
import eu.etaxonomy.cdm.model.name.Rank;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction;\r
+import eu.etaxonomy.taxeditor.datasource.CdmTransactionController;\r
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;\r
+import eu.etaxonomy.taxeditor.editor.name.CdmParserController;\r
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;\r
import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
import eu.etaxonomy.taxeditor.model.NameEditorInput;\r
+import eu.etaxonomy.taxeditor.navigation.RecentNamesView;\r
import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView;\r
import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer;\r
import eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry;\r
// ps.addPropertyListener(l)\r
}\r
\r
+ public static void saveAll(){\r
+ setIsSaving(true);\r
+ \r
+ // Get all open windows\r
+ for (IEditorPart taxonEditor : getOpenTaxonEditors()) {\r
+\r
+ // Save the dirty ones\r
+ if (taxonEditor.isDirty()) {\r
+ \r
+ \r
+ IEditorInput input = taxonEditor.getEditorInput();\r
+ if (input.getAdapter(Taxon.class) != null) {\r
+ Taxon taxon = (Taxon) input.getAdapter(Taxon.class);\r
+ CdmSessionDataRepository.getDefault().saveTaxon(taxon);\r
+ if (taxonEditor instanceof MultiPageTaxonEditor) {\r
+ ((MultiPageTaxonEditor) taxonEditor).setDirtyExtern(false);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ // Commit the transaction \r
+ CdmTransactionController.commitTransaction();\r
+ \r
+ // Force library objects to be associated with new transaction\r
+ CdmSessionDataRepository.getDefault().clearNonTaxonData();\r
+ \r
+ // Start a new transaction\r
+ CdmTransactionController.startTransaction();\r
+ \r
+ // Put all open taxa in the new transaction\r
+ CdmTransactionController.addSessionTaxaToTransaction();\r
+ \r
+ setIsSaving(false);\r
+ // TODO: delete undoHistory\r
+ }\r
+ \r
+ //public void deleteTaxon()\r
+ \r
/**\r
* @param input\r
* @return\r
return getActivePage().openEditor(input, editorId);\r
}\r
\r
+ /**\r
+ * Open an emtpy taxon editor\r
+ * \r
+ * @return\r
+ * @throws PartInitException\r
+ */\r
+ public static IEditorPart openTaxonEditor() \r
+ throws PartInitException{\r
+ return openTaxonEditor(null);\r
+ }\r
+ \r
+ /** \r
+ * Open a taxon editor for the given taxon\r
+ * \r
+ * @param taxon\r
+ * @return\r
+ * @throws PartInitException\r
+ */\r
public static IEditorPart openTaxonEditor(Taxon taxon)\r
throws PartInitException{\r
+ if(taxon == null){\r
+ TaxonNameBase name = CdmParserController.parseFullReference("", null, null);\r
+ name.setFullTitleCache("", false);\r
+ name.setTitleCache("", false);\r
+ taxon = Taxon.NewInstance(name, \r
+ CdmSessionDataRepository.getDefault().getDefaultSec());\r
+ }else{\r
+ // If this taxon is not visible in the tree, open node\r
+ TaxonomicTreeViewer treeViewer = getTreeViewer(); \r
+ if (treeViewer != null) {\r
+ treeViewer.revealTaxon(taxon);\r
+ }\r
+ \r
+ // Add to recent names list\r
+ RecentNamesView.addRecentName(taxon);\r
+ }\r
+ \r
IEditorInput input = new NameEditorInput(taxon);\r
return openEditor(input, MultiPageTaxonEditor.ID);\r
}\r
}\r
\r
public static IUndoContext getWorkbenchUndoContext() {\r
- return getOperationSupport().getUndoContext();\r
+ // TODO make this more specific than GLOBAL_UNDO_CONTEXT\r
+// return getOperationSupport().getUndoContext();\r
+ return IOperationHistory.GLOBAL_UNDO_CONTEXT;\r
}\r
\r
public static void doEditorSave(Taxon taxon, boolean confirm) {\r
* @version 1.0\r
*/\r
import org.apache.log4j.Logger;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.IOperationHistory;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.commands.operations.IUndoableOperation;\r
import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.ui.PartInitException;\r
\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
import eu.etaxonomy.taxeditor.UiUtil;\r
-import eu.etaxonomy.taxeditor.actions.SaveAllAction;\r
-import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
-import eu.etaxonomy.taxeditor.model.CdmUtil;\r
+import eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation;\r
\r
/**\r
* Delete this taxon from the CDM\r
private ImageDescriptor image = TaxEditorPlugin.getDefault()\r
.getImageDescriptor(ITaxEditorConstants.ACTIVE_DELETE_ICON);\r
\r
+ private IOperationHistory operationHistory;\r
+ private IUndoContext undoContext;\r
+ \r
Taxon taxon;\r
\r
public DeleteTaxonAction() {\r
super(text);\r
setImageDescriptor(image);\r
+ \r
+ operationHistory = UiUtil.getOperationHistory();\r
+ undoContext = UiUtil.getWorkbenchUndoContext();\r
}\r
\r
public DeleteTaxonAction(Taxon taxon) {\r
}\r
\r
public void run() {\r
- \r
- // Get taxon name for progress monitor\r
- String taxonName = CdmUtil.getDisplayName(taxon);\r
- \r
- // Get and start progress monitor\r
+ IUndoableOperation operation = new DeleteTaxonOperation\r
+ (this.getText(), undoContext, taxon);\r
+\r
IProgressMonitor monitor = UiUtil.getStatusLineProgressMonitor();\r
- monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10);\r
\r
- // Call save all action\r
- new SaveAllAction().run(null);\r
- monitor.worked(2);\r
- \r
- // If the taxon has children, cancel operation\r
- // TODO add option to continue, and delete children\r
- if (taxon.hasTaxonomicChildren()) {\r
- MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", \r
- "'" + CdmUtil.getDisplayName(taxon) + "' has taxonomic children. " +\r
- "These must be manually deleted before their parent.");\r
- monitor.done();\r
- return;\r
- }\r
- monitor.worked(1);\r
- \r
- // Close taxon's editor, if any is active\r
try {\r
- UiUtil.closeEditor(taxon, true);\r
- } catch (PartInitException e) {\r
- e.printStackTrace();\r
- }\r
- monitor.worked(1);\r
-\r
- // Delete taxon from CDM layer\r
- CdmSessionDataRepository.getDefault().deleteTaxon(taxon);\r
- monitor.worked(4);\r
- \r
- // Call save all action\r
- new SaveAllAction().run(null);\r
- monitor.worked(2);\r
- \r
- // Close the progress monitor\r
- monitor.done();\r
+ IStatus status = operationHistory.execute(operation, monitor, null);\r
+ } catch (ExecutionException e) {\r
+ logger.error("Error deleting taxon", e);\r
+ } \r
\r
- // Announce taxon was deleted on status line\r
- UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'.");\r
+ // Handle this in an operation so we are able to undo it\r
\r
-// Status status = new Status(IStatus.INFO, TaxEditorPlugin.PLUGIN_ID, \r
-// "Deleted.", null);\r
-// StatusManager.getManager().handle(status, StatusManager.SHOW);\r
+// \r
+// // Get taxon name for progress monitor\r
+// String taxonName = CdmUtil.getDisplayName(taxon);\r
+// \r
+// // Get and start progress monitor\r
+// IProgressMonitor monitor = UiUtil.getStatusLineProgressMonitor();\r
+// monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10);\r
+// \r
+// // Call save all action\r
+// new SaveAllAction().run(null);\r
+// monitor.worked(2);\r
+// \r
+// // If the taxon has children, cancel operation\r
+// // TODO add option to continue, and delete children\r
+// if (taxon.hasTaxonomicChildren()) {\r
+// MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", \r
+// "'" + CdmUtil.getDisplayName(taxon) + "' has taxonomic children. " +\r
+// "These must be manually deleted before their parent.");\r
+// monitor.done();\r
+// return;\r
+// }\r
+// monitor.worked(1);\r
+// \r
+// \r
+// // Close taxon's editor, if any is active\r
+// try {\r
+// UiUtil.closeEditor(taxon, true);\r
+// } catch (PartInitException e) {\r
+// e.printStackTrace();\r
+// }\r
+// monitor.worked(1);\r
+//\r
+// // Delete taxon from CDM layer\r
+// CdmSessionDataRepository.getDefault().deleteTaxon(taxon);\r
+// monitor.worked(4);\r
+// \r
+// \r
+// \r
+// // Call save all action\r
+// new SaveAllAction().run(null);\r
+// monitor.worked(2);\r
+// \r
+// // Close the progress monitor\r
+// monitor.done();\r
+// \r
+// // Announce taxon was deleted on status line\r
+// UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'.");\r
+// \r
+//// Status status = new Status(IStatus.INFO, TaxEditorPlugin.PLUGIN_ID, \r
+//// "Deleted.", null);\r
+//// StatusManager.getManager().handle(status, StatusManager.SHOW);\r
}\r
}
\ No newline at end of file
import org.apache.log4j.Logger;\r
import org.eclipse.jface.action.Action;\r
import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.ui.PartInitException;\r
\r
import eu.etaxonomy.cdm.model.name.BotanicalName;\r
import eu.etaxonomy.cdm.model.name.NonViralName;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
+import eu.etaxonomy.taxeditor.UiUtil;\r
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
\r
/**\r
\r
parentTaxon.addTaxonomicChild(taxon, null, null);\r
\r
- new OpenTaxonEditorAction(taxon).run();\r
+ // Open editor for new taxon\r
+ try {\r
+ UiUtil.openTaxonEditor(taxon);\r
+ } catch (PartInitException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ //new OpenTaxonEditorAction(taxon).run();\r
}\r
}
\ No newline at end of file
public OpenTaxonEditorAction() {\r
super(newTaxonText);\r
setImageDescriptor(image);\r
-// setActionDefinitionId(ID);\r
setId(ID);\r
}\r
\r
@Override\r
public void run() {\r
\r
- // Initialize taxon\r
- if (taxon == null) {\r
- \r
- // Passing the parser an empty string will return a new\r
- // new name object with the name class specified in the\r
- // preference store, i.e. BotanicalName\r
- TaxonNameBase name = CdmParserController.parseFullReference("", null, null);\r
- name.setFullTitleCache("", false);\r
- name.setTitleCache("", false);\r
- this.taxon = Taxon.NewInstance(name, \r
- CdmSessionDataRepository.getDefault().getDefaultSec());\r
- \r
- // Note: don't add taxon to repository - it's not yet valid\r
-\r
- } else {\r
- \r
- // If this taxon is not visible in the tree, open node\r
- TaxonomicTreeViewer treeViewer = UiUtil.getTreeViewer(); \r
- if (treeViewer != null) {\r
- treeViewer.revealTaxon(taxon);\r
- }\r
- \r
- // Add to recent names list\r
- RecentNamesView.addRecentName(taxon);\r
- }\r
- \r
try {\r
UiUtil.openTaxonEditor(taxon);\r
} catch (PartInitException e) {\r
--- /dev/null
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.taxeditor.operations;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.AbstractOperation;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.ui.PartInitException;\r
+\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.UiUtil;\r
+import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
+\r
+/**\r
+ * @author n.hoffmann\r
+ * @created 16.01.2009\r
+ * @version 1.0\r
+ */\r
+public class DeleteTaxonOperation extends AbstractEditorOperation {\r
+ private static Logger logger = Logger.getLogger(DeleteTaxonOperation.class);\r
+\r
+ private Taxon parentTaxon;\r
+ public DeleteTaxonOperation(String text, IUndoContext undoContext,\r
+ Taxon taxon) {\r
+ super(text, undoContext, taxon);\r
+\r
+ parentTaxon = taxon.getTaxonomicParent();\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+ */\r
+ @Override\r
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
+ throws ExecutionException {\r
+\r
+ // TODO move this logic to another place\r
+ \r
+ // Get taxon name\r
+ String taxonName = taxon.getName().getTitleCache();\r
+ \r
+ // Prompt user for confirmation\r
+ if(! MessageDialog.openConfirm(UiUtil.getShell(), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName + "'?")){\r
+ monitor.done();\r
+ return Status.CANCEL_STATUS;\r
+ }\r
+ \r
+ // Get and start progress monitor\r
+ monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10);\r
+ \r
+ // Call save all\r
+ UiUtil.saveAll();\r
+ monitor.worked(2);\r
+ \r
+ // If the taxon has children, cancel operation\r
+ // TODO add option to continue, and delete children\r
+ if (taxon.hasTaxonomicChildren()) {\r
+ MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", \r
+ "'" + taxonName + "' has taxonomic children. " +\r
+ "These must be manually deleted before their parent.");\r
+ monitor.done();\r
+ return Status.CANCEL_STATUS;\r
+ }\r
+ monitor.worked(1);\r
+ \r
+ \r
+ // Close taxon's editor, if any is active\r
+ try {\r
+ UiUtil.closeEditor(taxon, true);\r
+ } catch (PartInitException e) {\r
+ e.printStackTrace();\r
+ }\r
+ monitor.worked(1);\r
+\r
+ // Delete taxon from CDM layer\r
+ CdmSessionDataRepository.getDefault().removeTaxon(taxon);\r
+ monitor.worked(4);\r
+ \r
+ // Call save all\r
+ UiUtil.saveAll();\r
+ monitor.worked(2);\r
+ \r
+ // Close the progress monitor\r
+ monitor.done();\r
+ \r
+ // Announce taxon was deleted on status line\r
+ UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'.");\r
+ \r
+ return Status.OK_STATUS;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+ */\r
+ @Override\r
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
+ throws ExecutionException {\r
+ return execute(monitor, info);\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+ */\r
+ @Override\r
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
+ throws ExecutionException {\r
+ // FIXME we have to add old citation\r
+ parentTaxon.addTaxonomicChild(taxon, null, null);\r
+ CdmSessionDataRepository.getDefault().addTaxon(taxon);\r
+ return Status.OK_STATUS;\r
+ }\r
+}\r
--- /dev/null
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.taxeditor.operations;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
+\r
+/**\r
+ * @author n.hoffmann\r
+ * @created 16.01.2009\r
+ * @version 1.0\r
+ */\r
+public class MoveTaxonOperation extends AbstractEditorOperation {\r
+ \r
+\r
+ private static Logger logger = Logger.getLogger(MoveTaxonOperation.class);\r
+ private Taxon newParentTaxon;\r
+ private Taxon oldParentTaxon;\r
+\r
+ public MoveTaxonOperation(String label, IUndoContext undoContext,\r
+ Taxon taxon, Taxon newParentTaxon) {\r
+ super(label, undoContext, taxon);\r
+\r
+ this.newParentTaxon = newParentTaxon;\r
+ \r
+ // Save old parent taxon for undo\r
+ this.oldParentTaxon = taxon.getTaxonomicParent();\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+ */\r
+ @Override\r
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
+ throws ExecutionException {\r
+ CdmSessionDataRepository.getDefault().setTaxonomicParent(taxon, newParentTaxon);\r
+ CdmSessionDataRepository.getDefault().saveTaxon(taxon);\r
+ \r
+ return Status.OK_STATUS;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+ */\r
+ @Override\r
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
+ throws ExecutionException {\r
+ return execute(monitor, info);\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+ */\r
+ @Override\r
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
+ throws ExecutionException {\r
+ CdmSessionDataRepository.getDefault().setTaxonomicParent(taxon, oldParentTaxon);\r
+ CdmSessionDataRepository.getDefault().saveTaxon(taxon);\r
+ \r
+ return Status.OK_STATUS;\r
+ }\r
+}\r