From 5dd980ce8a01e667089fbde565909b9f523625b4 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Mon, 22 Jun 2009 16:25:57 +0000 Subject: [PATCH] fixes 777 --- .gitattributes | 11 +- .../ApplicationWorkbenchWindowAdvisor.java | 18 +++ .../taxeditor/editor/EditorUtil.java | 12 +- .../taxeditor/editor/GroupedComposite.java | 7 +- .../editor/MultiPageTaxonEditor.java | 30 +++-- .../taxeditor/editor/TaxonEditorInput.java | 112 +++++++++++------- .../editor/TaxonEditorInputFactory.java | 2 +- .../taxeditor/editor/ViewerConfiguration.java | 15 +++ .../editor/images/ImageComposite.java | 8 ++ .../images/TaxonHasNoImagesComposite.java | 8 ++ .../taxeditor/editor/name/NameComposite.java | 9 ++ taxeditor-navigation/plugin.xml | 38 ++++-- .../taxeditor/navigation/NavigationUtil.java | 78 +++++++++--- .../handler/CreateChildTaxonHandler.java | 6 +- ...ndler.java => DeleteTaxonNodeHandler.java} | 16 +-- .../navigation/handler/EditTaxonHandler.java | 10 +- .../navigation/handler/MoveTaxonHandler.java | 35 ++++-- .../handler/QuickCreateChildTaxonHandler.java | 18 ++- .../navigation/navigator/NavigatorRoot.java | 13 +- .../NavigatorSynonymContentProvider.java | 7 +- .../NavigatorTaxonContentProvider.java | 13 +- .../NavigatorTaxonLabelProvider.java | 12 +- ...NavigatorTaxonomicTreeContentProvider.java | 75 ++++++++++++ .../NavigatorTaxonomicTreeLabelProvider.java | 69 +++++++++++ .../navigator/OpenTaxonActionProvider.java | 6 +- .../navigator/TaxonDropAdapterAssistant.java | 65 +++++----- .../navigation/navigator/TaxonLinkHelper.java | 13 +- .../navigation/navigator/TaxonNavigator.java | 39 ++++-- .../TaxonNavigatorDataChangeBehavior.java | 6 +- .../navigation/search/SearchResultView.java | 12 +- .../taxonomictree/TaxonomicTreeView.java | 49 ++++---- .../taxeditor/dialogs/LoginDialog.java | 109 +++++++++++++++++ .../taxeditor/model/AbstractUtility.java | 6 +- .../{TaxonUtil.java => TaxonNodeUtil.java} | 92 ++++++-------- .../operations/AbstractPostOperation.java | 18 +++ ...hangeConceptRelationshipTypeOperation.java | 4 +- .../ChangeConceptToSynonymOperation.java | 4 +- .../operations/CreateChildTaxonOperation.java | 16 +-- .../DeleteConceptRelationOperation.java | 4 +- ...ion.java => DeleteTaxonNodeOperation.java} | 35 +++--- .../operations/MoveTaxonOperation.java | 24 ++-- ...java => DeleteTaxonNodeOperationTest.java} | 17 +-- .../operations/MoveTaxonOperationTest.java | 21 +++- 43 files changed, 806 insertions(+), 356 deletions(-) rename taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/{DeleteTaxonHandler.java => DeleteTaxonNodeHandler.java} (70%) create mode 100644 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeContentProvider.java create mode 100644 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeLabelProvider.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/LoginDialog.java rename taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/{TaxonUtil.java => TaxonNodeUtil.java} (59%) rename taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/{DeleteTaxonOperation.java => DeleteTaxonNodeOperation.java} (69%) rename taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/{DeleteTaxonOperationTest.java => DeleteTaxonNodeOperationTest.java} (74%) diff --git a/.gitattributes b/.gitattributes index 00e944603..fb6707b44 100644 --- a/.gitattributes +++ b/.gitattributes @@ -832,7 +832,7 @@ taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationU taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/RecentNamesContributionItem.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/WorkbenchUndoContextAdapterFactory.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/CreateChildTaxonHandler.java -text -taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonHandler.java -text +taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/QuickCreateChildTaxonHandler.java -text @@ -844,6 +844,8 @@ taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/N taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorSynonymLabelProvider.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonContentProvider.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonLabelProvider.java -text +taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeContentProvider.java -text +taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeLabelProvider.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/OpenTaxonActionProvider.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonDropAdapterAssistant.java -text taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonLinkHelper.java -text @@ -962,6 +964,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSo taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredCdmResourceSelectionDialog.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredNameSelectionDialog.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/FilteredReferenceSelectionDialog.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/LoginDialog.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/SelectionDialogDetailsLabelProvider.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/SelectionDialogSelectionLabelProvider.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/UriDialog.java -text @@ -987,8 +990,8 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/NameUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ReferenceUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/Resources.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/SynonymUtil.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonNodeUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonTransfer.java -text -taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TimeUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/AbstractPersistentPostOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/AbstractPostOperation.java -text @@ -1011,7 +1014,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteDescriptio taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteImageOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteMisapplicationOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteSynonymOperation.java -text -taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonNodeOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/IPostOperationEnabled.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/RemoveHomotypicalGroupBasionymOperation.java -text @@ -1054,7 +1057,7 @@ taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteConc taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteDescriptionElementOperationTest.java -text taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteMisapplicationOperationTest.java -text taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteSynonymOperationTest.java -text -taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonOperationTest.java -text +taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonNodeOperationTest.java -text taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/MoveTaxonOperationTest.java -text taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/SwapSynonymAndAcceptedOperationTest.java -text taxeditor-store/src/test/resources/dbscripts/001_cdm.ddl -text diff --git a/taxeditor-application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java b/taxeditor-application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java index 06f6f9eb5..e82076f02 100644 --- a/taxeditor-application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java +++ b/taxeditor-application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java @@ -3,13 +3,16 @@ package eu.etaxonomy.taxeditor; import org.apache.log4j.Logger; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.window.Window; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; +import eu.etaxonomy.taxeditor.dialogs.LoginDialog; import eu.etaxonomy.taxeditor.preference.InitNomenclaturalCodePrefDialog; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; @@ -32,9 +35,16 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { configurer.setShowStatusLine(true); configurer.setShowPerspectiveBar(true); configurer.setTitle("EDIT Taxonomic Editor"); + } public void postWindowOpen() { + + // authentication; activate when needed +// if(authenticate() != Window.OK){ +// PlatformUI.getWorkbench().close(); +// } + checkNomenclaturalCode(); } @@ -59,5 +69,13 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { code + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu."); } } + + private int authenticate(){ + Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getShell(); + + LoginDialog loginDialog = new LoginDialog(shell); + return loginDialog.open(); + } } \ No newline at end of file diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java index 81f18acc2..ee9063d1d 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java @@ -84,17 +84,17 @@ public class EditorUtil extends AbstractUtility{ * Taxon Editors may be opened by supplying a taxon uuid only. * Session gets initialised here and is passed to the editor * - * @param uuid + * @param taxonNodeUuid * @return * @throws PartInitException */ - public static IEditorPart open(UUID uuid) throws PartInitException { - IEditorInput input = TaxonEditorInput.NewInstance(uuid); + public static IEditorPart open(UUID taxonNodeUuid) throws PartInitException { + IEditorInput input = TaxonEditorInput.NewInstance(taxonNodeUuid); return open(input, MultiPageTaxonEditor.ID); } /** - * An unitialized taxon is one that hasn't been saved yet. As such, it should appear in neither + * An uninitialized taxon is one that hasn't been saved yet. As such, it should appear in neither * the list of recent names nor in the taxonomic tree when opened. * * @param parentTaxon The UUID of the parental taxon or null if this is @@ -102,8 +102,8 @@ public class EditorUtil extends AbstractUtility{ * @return The EditorPart. * @throws PartInitException */ - public static IEditorPart openEmpty(UUID parentTaxonUuid) throws PartInitException{ - TaxonEditorInput input = TaxonEditorInput.NewEmptyInstance(parentTaxonUuid); + public static IEditorPart openEmpty(UUID parentTaxonNodeUuid) throws PartInitException{ + TaxonEditorInput input = TaxonEditorInput.NewEmptyInstance(parentTaxonNodeUuid); return open(input, MultiPageTaxonEditor.ID); } diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/GroupedComposite.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/GroupedComposite.java index 341c17cde..93a185042 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/GroupedComposite.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/GroupedComposite.java @@ -485,13 +485,12 @@ abstract public class GroupedComposite extends Composite implements IHasProperty } /** - * Supposed to be overridden in implementing classes + * Implement in derived classes * * @param text */ - protected void parse(String text) { - logger.warn("No parse method defined for this composite."); - } + protected abstract void parse(String text); + /** * If the user hitting carriage return should cause something to happen - diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java index 93575de9c..d521cb585 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java @@ -50,14 +50,15 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart implements IConver private static final Logger logger = Logger.getLogger(MultiPageTaxonEditor.class); public static final String ID = "eu.etaxonomy.taxeditor.editor.multipagetaxonview"; - - private Taxon taxon; + private boolean dirty; private ConversationHolder conversation; private IDataChangeBehavior dataChangeBehavior; private IUndoContext undoContext; + private TaxonEditorInput input; + public MultiPageTaxonEditor() { super(); @@ -75,7 +76,7 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart implements IConver @Override protected void createPages() { - TaxonEditorInput input = (TaxonEditorInput) getEditorInput(); + input = (TaxonEditorInput) getEditorInput(); conversation = input.getConversationHolder(); conversation.registerForDataStoreChanges(this); @@ -149,21 +150,24 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart implements IConver @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { - if (!(input instanceof IEditorInput)) + if (!(input instanceof TaxonEditorInput)) throw new PartInitException( - "Invalid Input: Must be IEditorInput"); + "Invalid Input: Must be TaxonEditorInput"); + // FIXME looks like we do it differently now // Get taxon from editor input - if (input.getAdapter(Taxon.class) != null) { - taxon = (Taxon) input.getAdapter(Taxon.class); - } else { - taxon = null; - } +// if (input.getAdapter(Taxon.class) != null) { +// taxon = (Taxon) input.getAdapter(Taxon.class); +// } else { +// taxon = null; +// } + + this.input = (TaxonEditorInput) input; try { // Listen for name changes, // change tab for this taxon editor accordingly - taxon.addPropertyChangeListener("name", + getTaxon().addPropertyChangeListener("name", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { setPartName(); @@ -189,7 +193,7 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart implements IConver protected void setPartName() { String partName = null; - TaxonNameBase name = taxon.getName(); + TaxonNameBase name = getTaxon().getName(); if (name != null) { partName = name.getTitleCache(); @@ -211,7 +215,7 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart implements IConver } public Taxon getTaxon(){ - return this.taxon; + return input.getTaxon(); } /* diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java index ecc5c2958..ff9bb4e41 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java @@ -9,7 +9,6 @@ package eu.etaxonomy.taxeditor.editor; -import java.util.Set; import java.util.UUID; import org.apache.log4j.Logger; @@ -22,9 +21,8 @@ import org.eclipse.ui.IPersistableElement; import eu.etaxonomy.cdm.api.conversation.ConversationHolder; import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.cdm.model.taxon.TaxonBase; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -38,11 +36,12 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe private static final Logger logger = Logger .getLogger(TaxonEditorInput.class); - private Taxon taxon; private ConversationHolder conversation; + + private TaxonNode taxonNode; - private TaxonEditorInput(Taxon taxon, ConversationHolder conversation){ - this.taxon = taxon; + private TaxonEditorInput(TaxonNode taxonNode, ConversationHolder conversation){ + this.taxonNode = taxonNode; this.conversation = conversation; } @@ -55,65 +54,74 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe public static TaxonEditorInput NewInstance(UUID uuid){ ConversationHolder conversation = CdmStore.NewTransactionalConversation(); - TaxonBase taxonBase = CdmStore.getTaxonService().getTaxonByUuid(uuid); + TaxonNode taxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(uuid); - if(taxonBase == null){ + if(taxonNode == null){ MessageDialog.openWarning(EditorUtil.getShell(), "Not yet implemented", "Selected element is not if type TaxonBase."); return null; } Taxon taxon; - if (taxonBase instanceof Synonym) { - // TODO: in case of pro parte synonym or any other where we might have multiple - // accepted taxa we have to provide a mechanism that can deal with that - // TODO set focus to the synonym - Set acceptedTaxa = ((Synonym) taxonBase).getAcceptedTaxa(); - if(acceptedTaxa.size() != 1){ - String message; - if(acceptedTaxa.size() == 0){ - message = "There is no accepted taxon for the chosen synonym. "; - }else{ - message = "Multiple taxa found for the chosen synonym."; - } - MessageDialog.openWarning(EditorUtil.getShell(), "Not yet implemented", message); - return null; - }else{ - taxon = acceptedTaxa.toArray(new Taxon[0])[0]; - } - } else { - taxon = (Taxon) taxonBase; - } - + // FIXME had to disable synonym handling for now while implementing taxonNode +// if (taxonBase instanceof Synonym) { +// // TODO: in case of pro parte synonym or any other where we might have multiple +// // accepted taxa we have to provide a mechanism that can deal with that +// // TODO set focus to the synonym +// Set acceptedTaxa = ((Synonym) taxonBase).getAcceptedTaxa(); +// if(acceptedTaxa.size() != 1){ +// String message; +// if(acceptedTaxa.size() == 0){ +// message = "There is no accepted taxon for the chosen synonym. "; +// }else{ +// message = "Multiple taxa found for the chosen synonym."; +// } +// MessageDialog.openWarning(EditorUtil.getShell(), "Not yet implemented", message); +// return null; +// }else{ +// taxon = acceptedTaxa.toArray(new Taxon[0])[0]; +// } +// } else { +// taxon = (Taxon) taxonBase; +// } + + logger.trace(TaxonEditorInput.class.getSimpleName() + " created"); - return new TaxonEditorInput(taxon, conversation); + return new TaxonEditorInput(taxonNode, conversation); } - public static TaxonEditorInput NewEmptyInstance(UUID parentTaxonUuid){ + public static TaxonEditorInput NewEmptyInstance(UUID parentTaxonNodeUuid){ ConversationHolder conversation = CdmStore.NewTransactionalConversation(); TaxonNameBase name = PreferencesUtil.getInstanceOfPreferredNameClass(); Taxon newTaxon = null; - if(parentTaxonUuid == null){ - newTaxon = Taxon.NewInstance(name, CdmStore.getDefault().getDefaultSec()); - }else{ - Taxon parentTaxon = (Taxon) CdmStore.getTaxonService().getTaxonByUuid(parentTaxonUuid); - newTaxon = Taxon.NewInstance(name, parentTaxon.getSec()); - parentTaxon.addTaxonomicChild(newTaxon, null, null); - } + TaxonNode newTaxonNode = null; + + // FIXME adding of root taxon nodes disabled for now. Still have to find a way to + // which taxonomic tree the node shoul dbe added +// if(parentTaxonNodeUuid == null){ +// newTaxon = Taxon.NewInstance(name, CdmStore.getDefault().getDefaultSec()); +// newTaxonNode = new TaxonNode(); +// }else{ + TaxonNode parentTaxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(parentTaxonNodeUuid); + + newTaxon = Taxon.NewInstance(name, parentTaxonNode.getTaxon().getSec()); + + newTaxonNode = parentTaxonNode.addChild(newTaxon, parentTaxonNode.getReferenceForParentChildRelation(), parentTaxonNode.getMicroReferenceForParentChildRelation()); +// } // add the new taxon to the editors persistence context - CdmStore.getTaxonService().save(newTaxon); + CdmStore.getTaxonService().saveTaxonNode(newTaxonNode); - return new TaxonEditorInput(newTaxon, conversation); + return new TaxonEditorInput(newTaxonNode, conversation); } /* (non-Javadoc) * @see org.eclipse.ui.IEditorInput#exists() */ public boolean exists() { - return taxon != null; + return taxonNode != null; } /* (non-Javadoc) @@ -127,7 +135,7 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe * @see org.eclipse.ui.IEditorInput#getName() */ public String getName() { - TaxonNameBase name = taxon.getName(); + TaxonNameBase name = getTaxon().getName(); if (name == null || name.getTitleCache() == null) { return "New taxon"; } else { @@ -155,7 +163,11 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe public Object getAdapter(Class adapter) { if (adapter == Taxon.class) { - return taxon; + return taxonNode.getTaxon(); + } + + if (adapter == TaxonNode.class) { + return taxonNode; } return null; @@ -169,13 +181,23 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe */ public boolean equals(Object obj) { if (obj.getClass().equals(TaxonEditorInput.class) - && taxon.equals(((TaxonEditorInput) obj).taxon)) + && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())) return true; return false; } + /** + * @return the taxon + */ public Taxon getTaxon(){ - return taxon; + return taxonNode.getTaxon(); + } + + /** + * @return the taxonNode + */ + public TaxonNode getTaxonNode() { + return taxonNode; } /* diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInputFactory.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInputFactory.java index 48e92ffa1..68977b967 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInputFactory.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInputFactory.java @@ -17,7 +17,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.ui.IElementFactory; import org.eclipse.ui.IMemento; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.store.StoreUtil; diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/ViewerConfiguration.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/ViewerConfiguration.java index b513ef847..41badf1f1 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/ViewerConfiguration.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/ViewerConfiguration.java @@ -28,4 +28,19 @@ public class ViewerConfiguration extends SourceViewerConfiguration { public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { return annotationHover; } + +// /* (non-Javadoc) +// * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer) +// */ +// @Override +// public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { +// ContentAssistant contentAssistant = new ContentAssistant(); +// IContentAssistProcessor assistProcessor = new NameCompletionProcessor(); +// contentAssistant.setContentAssistProcessor(assistProcessor, NAME); +// contentAssistant.setContentAssistProcessor(assistProcessor, IDocument.DEFAULT_CONTENT_TYPE); +// contentAssistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); +// return contentAssistant; +// } + + } diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/ImageComposite.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/ImageComposite.java index bff2834fd..9aa1926f7 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/ImageComposite.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/ImageComposite.java @@ -162,4 +162,12 @@ public class ImageComposite extends GroupedComposite { image.dispose(); } } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#parse(java.lang.String) + */ + @Override + protected void parse(String text) { + throw new IllegalStateException("Parser should not be called on this object"); + } } diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/TaxonHasNoImagesComposite.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/TaxonHasNoImagesComposite.java index 58450c799..b0c09a09d 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/TaxonHasNoImagesComposite.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/images/TaxonHasNoImagesComposite.java @@ -109,4 +109,12 @@ public class TaxonHasNoImagesComposite extends GroupedComposite { public IPropertySource getPropertySource() { return null; } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#parse(java.lang.String) + */ + @Override + protected void parse(String text) { + throw new IllegalStateException("Parser should not be called on this object"); + } } diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java index 40ef693d7..3fa24f7d7 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java @@ -285,4 +285,13 @@ public abstract class NameComposite extends GroupedComposite{ // calculateErrors(); // activateParser(); } + + public boolean isDirty(){ + + TaxonNameBase name = getName(); + + + + return false; + } } \ No newline at end of file diff --git a/taxeditor-navigation/plugin.xml b/taxeditor-navigation/plugin.xml index bbb711c6c..b5c47ed07 100644 --- a/taxeditor-navigation/plugin.xml +++ b/taxeditor-navigation/plugin.xml @@ -157,7 +157,7 @@ name="Create Child Taxon"> @@ -279,26 +279,42 @@ + + + + + + + + + + + name="Taxon Node"> - + + value="eu.etaxonomy.cdm.model.taxon.TaxonNode"> + value="eu.etaxonomy.cdm.model.taxon.TaxonNode"> + value="eu.etaxonomy.cdm.model.taxon.TaxonNode"> @@ -346,13 +362,11 @@ + + - - - - @@ -375,7 +389,7 @@ class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonLinkHelper" id="eu.etaxonomy.taxeditor.navigation.taxonlinkhelper"> - + diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java index 9d02173cb..c7910c93c 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java @@ -9,6 +9,8 @@ package eu.etaxonomy.taxeditor.navigation; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import org.apache.log4j.Logger; @@ -33,8 +35,9 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; import org.eclipse.ui.navigator.CommonViewer; -import eu.etaxonomy.cdm.model.common.IdentifiableEntity; +import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.EditorUtil; import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; @@ -61,7 +64,7 @@ public class NavigationUtil extends AbstractUtility{ * * @param uuid */ - public static void openEditor(IdentifiableEntity selection) { + public static void openEditor(TaxonNode selection) { try { UUID entityUuid = selection.getUuid(); EditorUtil.open(entityUuid); @@ -79,11 +82,11 @@ public class NavigationUtil extends AbstractUtility{ getActiveWorkbenchWindow(); } - public static void openEmpty(Taxon parentTaxon) { + public static void openEmpty(TaxonNode parentTaxonNode) { try { - UUID parentTaxonUuid = parentTaxon == null ? null : parentTaxon.getUuid(); + UUID parentTaxonNodeUuid = parentTaxonNode == null ? null : parentTaxonNode.getUuid(); - EditorUtil.openEmpty(parentTaxonUuid); + EditorUtil.openEmpty(parentTaxonNodeUuid); } catch (PartInitException e) { logger.error("Error opening the editor", e); } @@ -130,16 +133,16 @@ public class NavigationUtil extends AbstractUtility{ * @param event * @return */ - public static Taxon getCurrentSelection(ExecutionEvent event){ + public static TaxonNode getCurrentSelection(ExecutionEvent event){ ISelection menuSelection = HandlerUtil.getActiveMenuSelection(event); // The selection should always be a tree selection since we are in the // taxonomic tree view. Just in case this will be used in another spot. if(menuSelection instanceof TreeSelection){ - Taxon taxon = (Taxon) ((TreeSelection) menuSelection).getFirstElement(); - logger.debug("Selected taxon: " + taxon); - return taxon; + TaxonNode taxonNode = (TaxonNode) ((TreeSelection) menuSelection).getFirstElement(); + logger.debug("Selected taxon: " + taxonNode); + return taxonNode; } return null; } @@ -157,13 +160,19 @@ public class NavigationUtil extends AbstractUtility{ return defaultUndoContext; } - public static boolean isDirty(Taxon taxon){ + /** + * Whether a taxonNode has unsaved changes. + * + * @param taxonNode + * @return + */ + public static boolean isDirty(TaxonNode taxonNode){ for (IEditorReference reference : getActivePage().getEditorReferences()) { TaxonEditorInput editorInput; try { editorInput = (TaxonEditorInput) reference.getEditorInput(); - if(editorInput.getTaxon().equals(taxon) && reference.isDirty()){ + if(editorInput.getTaxonNode().equals(taxonNode) && reference.isDirty()){ return true; } } catch (PartInitException e) { @@ -174,8 +183,9 @@ public class NavigationUtil extends AbstractUtility{ } /** - * @param parentElement - * @param childTaxon + * + * @param element + * @param parentElement */ public static void selectInNavigator(Object element, Object parentElement) { TaxonNavigator navigator = (TaxonNavigator) TaxeditorEditorPlugin.getDefault().getWorkbench(). @@ -186,8 +196,48 @@ public class NavigationUtil extends AbstractUtility{ if (parentElement != null) { viewer.setExpandedState(parentElement, true); } - viewer.setSelection(new StructuredSelection((Taxon) element)); + viewer.setSelection(new StructuredSelection((TaxonNode) element)); + } + } + } + + /** + * @param selection + */ + public static void openSearch(Object selection) { + if(selection instanceof Taxon){ + Taxon taxon = (Taxon) selection; + + handleOpeningOfMultipleTaxonNodes(taxon.getTaxonNodes()); + + }else if(selection instanceof Synonym){ + Synonym synonym = (Synonym) selection; + + Set taxonNodes = new HashSet(); + for (Taxon taxon : synonym.getAcceptedTaxa()){ + taxonNodes.addAll(taxon.getTaxonNodes()); } + handleOpeningOfMultipleTaxonNodes(taxonNodes); + + }else{ + warningDialog("You chose to open a name that has no connection to a taxa. The Editor does not support editing of such a content type at the moment."); + logger.warn("Could not open editor for selection. Selection was of type: " + selection.getClass().getSimpleName()); + } + + } + + /** + * @param taxonNodes + */ + private static void handleOpeningOfMultipleTaxonNodes( + Set taxonNodes) { + + if(taxonNodes.size() == 1){ + openEditor(taxonNodes.iterator().next()); + }else{ + // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open. + warningDialog("The accepted taxon is either in multiple taxonmoic views or the synonym has" + + " more than one accepted taxon. This case is not handled yet by the software."); } } } \ No newline at end of file diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/CreateChildTaxonHandler.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/CreateChildTaxonHandler.java index f3ca8a71f..0e2abacce 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/CreateChildTaxonHandler.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/CreateChildTaxonHandler.java @@ -14,7 +14,7 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.IHandler; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; /** @@ -29,10 +29,10 @@ public class CreateChildTaxonHandler extends AbstractHandler implements * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { - Taxon parentTaxon = NavigationUtil.getCurrentSelection(event); + TaxonNode parentTaxonNode = NavigationUtil.getCurrentSelection(event); // Open editor for new taxon - NavigationUtil.openEmpty(parentTaxon); + NavigationUtil.openEmpty(parentTaxonNode); return null; } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonHandler.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java similarity index 70% rename from taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonHandler.java rename to taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java index 87dd6744a..7b1c29407 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonHandler.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java @@ -18,27 +18,27 @@ import org.eclipse.core.commands.IHandler; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.operations.IUndoableOperation; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; -import eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation; +import eu.etaxonomy.taxeditor.operations.DeleteTaxonNodeOperation; /** * @author n.hoffmann * @created 06.04.2009 * @version 1.0 */ -public class DeleteTaxonHandler extends AbstractHandler implements IHandler{ +public class DeleteTaxonNodeHandler extends AbstractHandler implements IHandler{ private static final Logger logger = Logger - .getLogger(DeleteTaxonHandler.class); + .getLogger(DeleteTaxonNodeHandler.class); public Object execute(ExecutionEvent event) throws ExecutionException { - - Taxon taxon = NavigationUtil.getCurrentSelection(event); + // FIXME make operation handle taxon node? + TaxonNode taxonNode = NavigationUtil.getCurrentSelection(event); IUndoableOperation operation; try { - operation = new DeleteTaxonOperation(event.getCommand().getName(), - NavigationUtil.getUndoContext(), taxon); + operation = new DeleteTaxonNodeOperation(event.getCommand().getName(), + NavigationUtil.getUndoContext(), taxonNode); NavigationUtil.executeOperation(operation); } catch (NotDefinedException e) { logger.warn("Command name not set"); diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java index 8ee1c6f56..f5b3742e4 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java @@ -16,7 +16,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.handlers.HandlerUtil; -import eu.etaxonomy.cdm.model.common.IdentifiableEntity; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; /** @@ -33,9 +33,13 @@ public class EditTaxonHandler extends AbstractHandler { ISelection selection = HandlerUtil.getActiveMenuSelection(event); - IdentifiableEntity entity = (IdentifiableEntity) ((StructuredSelection) selection).getFirstElement(); + Object selectedObject = ((StructuredSelection) selection).getFirstElement(); - NavigationUtil.openEditor(entity); + if(selectedObject instanceof TaxonNode){ + NavigationUtil.openEditor((TaxonNode) selectedObject); + }else{ + throw new IllegalArgumentException("selectedObject is not of type TaxonNode"); + } return null; } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java index a4d26df9a..e435d1b2f 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java @@ -18,9 +18,11 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Shell; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.name.TaxonSearchDialog; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; +import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; /** @@ -28,40 +30,49 @@ import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; * @created 01.04.2009 * @version 1.0 */ -public class MoveTaxonHandler extends AbstractHandler { +public class MoveTaxonHandler extends AbstractHandler implements IPostOperationEnabled { private static final Logger logger = Logger .getLogger(MoveTaxonHandler.class); + private TaxonNode parentTaxonNode; /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { Shell shell = NavigationUtil.getShell(); - Taxon taxon = (Taxon) NavigationUtil.getCurrentSelection(event); - + TaxonNode taxonNode = NavigationUtil.getCurrentSelection(event); + Dialog dialog = new TaxonSearchDialog(shell); Object value = ((TaxonSearchDialog) dialog).open(); - logger.warn("child " +taxon.toString()); - logger.warn("parent " + ((Taxon) value).toString()); + logger.warn("child " +taxonNode.getTaxon().toString()); + logger.warn("parent " + ((TaxonNode) value).getTaxon().toString()); - if (value instanceof Taxon) { - Taxon parentTaxon = (Taxon) value; + if (value instanceof TaxonNode) { + parentTaxonNode = (TaxonNode) value; - if(NavigationUtil.isDirty(parentTaxon)){ + if(NavigationUtil.isDirty(parentTaxonNode)){ MessageDialog.openWarning(shell, "Unsaved Parent Taxon", "There are unsaved " + - "changes in the parent taxon. Pleas save first."); + "changes in the parent taxon. Please save first."); return null; } IUndoableOperation operation = new MoveTaxonOperation ("Move taxon to new parent", NavigationUtil.getUndoContext(), - taxon, parentTaxon); //$NON-NLS-1$ + taxonNode, parentTaxonNode, this); //$NON-NLS-1$ NavigationUtil.executeOperation(operation); } else { - logger.warn("TaxonSearchDialog did not return a Taxon object."); + logger.warn("TaxonSearchDialog did not return a TaxonNode object."); } return null; } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) + */ + public boolean postOperation(CdmBase objectAffectedByOperation) { + NavigationUtil.selectInNavigator(objectAffectedByOperation, parentTaxonNode); + return true; + } } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/QuickCreateChildTaxonHandler.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/QuickCreateChildTaxonHandler.java index cc91dcccd..c5f570b25 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/QuickCreateChildTaxonHandler.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/QuickCreateChildTaxonHandler.java @@ -25,6 +25,7 @@ import org.eclipse.ui.handlers.HandlerUtil; import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.EditorUtil; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; import eu.etaxonomy.taxeditor.operations.CreateChildTaxonOperation; @@ -41,7 +42,8 @@ public class QuickCreateChildTaxonHandler extends AbstractHandler implements IHandler, IPostOperationEnabled { private static final Logger logger = Logger .getLogger(QuickCreateChildTaxonHandler.class); - private Taxon parentTaxon; + + private TaxonNode parentTaxonNode; /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) @@ -49,9 +51,9 @@ public class QuickCreateChildTaxonHandler extends AbstractHandler implements public Object execute(ExecutionEvent event) throws ExecutionException { Shell shell = HandlerUtil.getActiveShell(event); - parentTaxon = NavigationUtil.getCurrentSelection(event); + parentTaxonNode = NavigationUtil.getCurrentSelection(event); - if(NavigationUtil.isDirty(parentTaxon)){ + if(NavigationUtil.isDirty(parentTaxonNode)){ MessageDialog.openWarning(shell, "Unsaved Parent Taxon", "There are unsaved " + "changes in the parent taxon. Pleas save first."); return null; @@ -68,20 +70,16 @@ public class QuickCreateChildTaxonHandler extends AbstractHandler implements CreateChildTaxonOperation operation; try { operation = new CreateChildTaxonOperation(event.getCommand().getName(), - NavigationUtil.getUndoContext(), parentTaxon, name, this); + NavigationUtil.getUndoContext(), parentTaxonNode, name, this); IStatus status = EditorUtil.executeOperation(operation); if(status.getCode() == TaxeditorStorePlugin.ERROR_SAVING_ZERO_NAME){ MessageDialog.openWarning(shell, "No Name Specified", "An attempt was made to save a taxon with" + " an empty name. Operation was cancelled"); - } - - - + } } catch (NotDefinedException e) { logger.warn("Command name not set"); } - logger.info("Taxon created"); } @@ -90,7 +88,7 @@ public class QuickCreateChildTaxonHandler extends AbstractHandler implements } public boolean postOperation(CdmBase objectAffectedByOperation) { - NavigationUtil.selectInNavigator(objectAffectedByOperation, parentTaxon); + NavigationUtil.selectInNavigator(objectAffectedByOperation, parentTaxonNode); return true; } } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorRoot.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorRoot.java index a553d922f..df1463f03 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorRoot.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorRoot.java @@ -19,7 +19,7 @@ import org.eclipse.ui.IElementFactory; import org.eclipse.ui.IMemento; import org.eclipse.ui.IPersistableElement; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; import eu.etaxonomy.taxeditor.store.CdmStore; /** @@ -28,18 +28,18 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @version 1.0 */ public class NavigatorRoot extends PlatformObject implements IAdaptable, IPersistableElement, IElementFactory { -// implements IAdaptable, IPersistableElement, IElementFactory { + private static final Logger logger = Logger.getLogger(NavigatorRoot.class); - public List getParentBeans() { - return CdmStore.getDefault().getRootTaxa(); + public List getParentBeans() { + List trees = CdmStore.getDefault().getTaxonomicTrees(); + return trees; } /* (non-Javadoc) * @see org.eclipse.ui.IPersistableElement#getFactoryId() */ public String getFactoryId() { - // TODO Auto-generated method stub return null; } @@ -47,15 +47,12 @@ public class NavigatorRoot extends PlatformObject implements IAdaptable, IPersis * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento) */ public void saveState(IMemento memento) { - // TODO Auto-generated method stub - } /* (non-Javadoc) * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento) */ public IAdaptable createElement(IMemento memento) { - // TODO Auto-generated method stub return null; } } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorSynonymContentProvider.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorSynonymContentProvider.java index c8f0842de..21770a3ff 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorSynonymContentProvider.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorSynonymContentProvider.java @@ -20,6 +20,7 @@ import org.eclipse.jface.viewers.Viewer; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonBase; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList; /** @@ -37,10 +38,12 @@ public class NavigatorSynonymContentProvider implements ITreeContentProvider { Object[] children = null; if (parentElement instanceof Synonym) { children = NO_CHILDREN; - } else if (parentElement instanceof Taxon) { + } else if (parentElement instanceof TaxonNode) { List list = new ArrayList(); - for (TaxonBase taxonBase : new IterableSynonymyList((Taxon) parentElement)) { + Taxon taxon = ((TaxonNode) parentElement).getTaxon(); + + for (TaxonBase taxonBase : new IterableSynonymyList(taxon)) { if (taxonBase instanceof Synonym) { list.add(taxonBase); } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonContentProvider.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonContentProvider.java index 846d62820..14d318dca 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonContentProvider.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonContentProvider.java @@ -14,7 +14,7 @@ import org.apache.log4j.Logger; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; /** * @author p.ciardelli @@ -27,18 +27,17 @@ public class NavigatorTaxonContentProvider implements ITreeContentProvider { public Object[] getChildren(Object parentElement) { - if (parentElement instanceof NavigatorRoot) { - return ((NavigatorRoot) parentElement).getParentBeans().toArray(); - } - - if (parentElement instanceof Taxon) { - return ((Taxon) parentElement).getTaxonomicChildren().toArray(); + if (parentElement instanceof TaxonNode) { + return ((TaxonNode) parentElement).getChildNodes().toArray(); } return new Object[0]; } public Object getParent(Object element) { +// if(element instanceof TaxonNode){ +// return ((TaxonNode) element).getParent(); +// } return null; } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonLabelProvider.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonLabelProvider.java index 7722fd420..0b5a61a19 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonLabelProvider.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonLabelProvider.java @@ -19,6 +19,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.ui.navigator.IDescriptionProvider; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; /** * @author p.ciardelli @@ -35,10 +36,9 @@ public class NavigatorTaxonLabelProvider extends ColumnLabelProvider } public String getText(Object element) { - if (element instanceof Taxon && - ((Taxon) element).getName() != null) { - - return ((Taxon) element).getName().getTitleCache(); + if (element instanceof TaxonNode){ + Taxon taxon = ((TaxonNode) element).getTaxon(); + return taxon.getName() != null ? taxon.getName().getTitleCache() : new String(); } return new String(); } @@ -47,8 +47,8 @@ public class NavigatorTaxonLabelProvider extends ColumnLabelProvider * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object) */ public String getDescription(Object anElement) { - if (anElement instanceof Taxon) { - Taxon data = (Taxon) anElement; + if (anElement instanceof TaxonNode) { + Taxon data = ((TaxonNode) anElement).getTaxon(); return "Taxon: " + data.getTitleCache(); //$NON-NLS-1$ } return null; diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeContentProvider.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeContentProvider.java new file mode 100644 index 000000000..093c296e9 --- /dev/null +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeContentProvider.java @@ -0,0 +1,75 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.navigation.navigator; + +import org.apache.log4j.Logger; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; + +/** + * @author n.hoffmann + * @created 17.06.2009 + * @version 1.0 + */ +public class NavigatorTaxonomicTreeContentProvider implements ITreeContentProvider { + private static final Logger logger = Logger + .getLogger(NavigatorTaxonomicTreeContentProvider.class); + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof NavigatorRoot) { + return ((NavigatorRoot) parentElement).getParentBeans().toArray(); + } + + if(parentElement instanceof TaxonomicTree) { + return ((TaxonomicTree) parentElement).getRootNodes().toArray(); + } + + return new Object[0]; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object element) { + return this.getChildren(element).length > 0; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + return this.getChildren(inputElement); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } +} diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeLabelProvider.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeLabelProvider.java new file mode 100644 index 000000000..c42d6dbcc --- /dev/null +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/NavigatorTaxonomicTreeLabelProvider.java @@ -0,0 +1,69 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.navigation.navigator; + +import org.apache.log4j.Logger; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.navigator.IDescriptionProvider; + +import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; + +/** + * @author n.hoffmann + * @created 17.06.2009 + * @version 1.0 + */ +public class NavigatorTaxonomicTreeLabelProvider extends ColumnLabelProvider +implements ILabelProvider, IDescriptionProvider, IStyledLabelProvider { + private static final Logger logger = Logger + .getLogger(NavigatorTaxonomicTreeLabelProvider.class); + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object) + */ + @Override + public Image getImage(Object element) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object) + */ + @Override + public String getText(Object element) { + if(element instanceof TaxonomicTree){ + String text = ((TaxonomicTree) element).getName().getText(); + return text != null ? text : "Unnamed Taxonomic Tree"; + } + return new String(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object) + */ + public String getDescription(Object anElement) { + if (anElement instanceof TaxonomicTree) { + return "Taxonomic Tree: " + ((TaxonomicTree) anElement).getTitleCache(); //$NON-NLS-1$ + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) + */ + public StyledString getStyledText(Object element) { + return new StyledString(getText(element)); + } +} diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/OpenTaxonActionProvider.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/OpenTaxonActionProvider.java index 55bdb7d43..f6540caf2 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/OpenTaxonActionProvider.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/OpenTaxonActionProvider.java @@ -20,7 +20,7 @@ import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionConstants; import org.eclipse.ui.navigator.ICommonActionExtensionSite; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; /** @@ -72,8 +72,8 @@ public class OpenTaxonActionProvider extends CommonActionProvider { if (selection instanceof TreeSelection) { Object[] selections = ((TreeSelection) selection).toArray(); for (Object element : ((TreeSelection) selection).toArray()) { - if (element instanceof Taxon) { - NavigationUtil.openEditor((Taxon) element); + if (element instanceof TaxonNode) { + NavigationUtil.openEditor((TaxonNode) element); } } } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonDropAdapterAssistant.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonDropAdapterAssistant.java index 78e66b535..59a34fbc3 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonDropAdapterAssistant.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonDropAdapterAssistant.java @@ -24,10 +24,11 @@ import org.eclipse.swt.dnd.TransferData; import org.eclipse.ui.navigator.CommonDropAdapter; import org.eclipse.ui.navigator.CommonDropAdapterAssistant; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.model.NameUtil; -import eu.etaxonomy.taxeditor.model.TaxonUtil; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; +import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; /** @@ -35,11 +36,13 @@ import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; * @created 03.06.2009 * @version 1.0 */ -public class TaxonDropAdapterAssistant extends CommonDropAdapterAssistant { +public class TaxonDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled{ private static final Logger logger = Logger .getLogger(TaxonDropAdapterAssistant.class); public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ + + private TaxonNode newParentTaxonNode; /* (non-Javadoc) * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) @@ -51,26 +54,16 @@ public class TaxonDropAdapterAssistant extends CommonDropAdapterAssistant { ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); if (selection instanceof TreeSelection) { Object element = ((TreeSelection) selection).getFirstElement(); - if (element instanceof Taxon) { - Taxon childTaxon = (Taxon) element; - if (target instanceof Taxon) { - Taxon parentTaxon = (Taxon) target; + if (element instanceof TaxonNode) { + TaxonNode childTaxonNode = (TaxonNode) element; + if (target instanceof TaxonNode) { + TaxonNode parentTaxonNode = (TaxonNode) target; - return moveTaxon(childTaxon, parentTaxon); + return moveTaxon(childTaxonNode, parentTaxonNode); } } } - -// IContainer target = getActualTarget((IResource) dropAdapter -// .getCurrentTarget()); -// IContainer target = -// if (target != null && target.isAccessible()) { -// try { -// target.refreshLocal(IResource.DEPTH_ONE, null); -// } catch (CoreException e) { -// } -// } - + return Status.CANCEL_STATUS; } @@ -80,7 +73,7 @@ public class TaxonDropAdapterAssistant extends CommonDropAdapterAssistant { @Override public IStatus validateDrop(Object target, int operation, TransferData transferType) { - if (target instanceof Taxon) { + if (target instanceof TaxonNode) { return Status.OK_STATUS; } return Status.CANCEL_STATUS; @@ -88,30 +81,32 @@ public class TaxonDropAdapterAssistant extends CommonDropAdapterAssistant { /** - * @param childTaxon + * @param childTaxonNode * @param parentTaxon * @return */ - private IStatus moveTaxon(Taxon childTaxon, Taxon newParentTaxon) { + private IStatus moveTaxon(TaxonNode childTaxonNode, TaxonNode newParentTaxonNode) { + + this.newParentTaxonNode = newParentTaxonNode; // Make sure parentTaxon is not a child - if (TaxonUtil.isTaxonChildOfTaxon(newParentTaxon, childTaxon)) { + if (childTaxonNode.getParent().equals(newParentTaxonNode)){ MessageDialog.openError(NavigationUtil.getShell(), "Can't move taxon.", - "'" + NameUtil.getDisplayName(childTaxon) + "' sits above " + - "'" + NameUtil.getDisplayName(newParentTaxon) + "' " + + "'" + NameUtil.getDisplayName(childTaxonNode.getTaxon()) + "' sits above " + + "'" + NameUtil.getDisplayName(newParentTaxonNode.getTaxon()) + "' " + "in the taxonomic hierarchy."); return Status.CANCEL_STATUS; } // Make sure taxon is not being dropped onto itself - if (childTaxon.equals(newParentTaxon)) { + if (childTaxonNode.equals(newParentTaxonNode)) { return Status.CANCEL_STATUS; } // Make sure parent taxon does not have unsaved changes - if (NavigationUtil.isDirty(newParentTaxon)){ + if (NavigationUtil.isDirty(newParentTaxonNode)){ MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + "changes in the parent taxon. Pleas save first."); return Status.CANCEL_STATUS; @@ -122,14 +117,24 @@ public class TaxonDropAdapterAssistant extends CommonDropAdapterAssistant { logger.error("Workspace undo context is null. DND operation cancelled"); return Status.CANCEL_STATUS; } + IUndoableOperation operation = new MoveTaxonOperation - ("Move Taxon", workspaceUndoContext, childTaxon, newParentTaxon); + ("Move Taxon", workspaceUndoContext, childTaxonNode, newParentTaxonNode, this); NavigationUtil.executeOperation(operation); - logger.info("Moved taxon " + childTaxon + " to new parent " + newParentTaxon); - NavigationUtil.selectInNavigator(childTaxon, newParentTaxon); + logger.info("Moved taxon " + childTaxonNode + " to new parent " + newParentTaxonNode); + + NavigationUtil.selectInNavigator(childTaxonNode, newParentTaxonNode); return Status.OK_STATUS; } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) + */ + public boolean postOperation(CdmBase objectAffectedByOperation) { + NavigationUtil.selectInNavigator(objectAffectedByOperation, newParentTaxonNode); + return true; + } } diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonLinkHelper.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonLinkHelper.java index 5d6b42b15..5513f6ac0 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonLinkHelper.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonLinkHelper.java @@ -19,6 +19,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.navigator.ILinkHelper; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; /** @@ -43,9 +44,9 @@ public class TaxonLinkHelper implements ILinkHelper { if (selection == null || selection.isEmpty()) { return; } - if (selection.getFirstElement() instanceof Taxon) { - Taxon taxon = (Taxon) selection.getFirstElement(); - TaxonEditorInput taxonEditorInput = TaxonEditorInput.NewInstance(taxon.getUuid()); + if (selection.getFirstElement() instanceof TaxonNode) { + TaxonNode taxonNode = (TaxonNode) selection.getFirstElement(); + TaxonEditorInput taxonEditorInput = TaxonEditorInput.NewInstance(taxonNode.getUuid()); IEditorPart editor = null; if ((editor = page.findEditor(taxonEditorInput)) != null) { page.bringToTop(editor); @@ -58,9 +59,9 @@ public class TaxonLinkHelper implements ILinkHelper { */ public IStructuredSelection findSelection(IEditorInput editorInput) { if (editorInput instanceof TaxonEditorInput) { - Taxon taxon = ((TaxonEditorInput) editorInput).getTaxon(); - if (taxon != null) { - return new StructuredSelection(taxon); + TaxonNode taxonNode = ((TaxonEditorInput) editorInput).getTaxonNode(); + if (taxonNode != null) { + return new StructuredSelection(taxonNode); } } return StructuredSelection.EMPTY; diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java index e04500b5c..9aa4e6fe8 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java @@ -19,7 +19,6 @@ import java.util.UUID; import org.apache.log4j.Logger; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IMemento; import org.eclipse.ui.IViewSite; @@ -28,7 +27,9 @@ import org.eclipse.ui.navigator.CommonNavigator; import eu.etaxonomy.cdm.api.conversation.ConversationHolder; import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; -import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; import eu.etaxonomy.taxeditor.model.DataChangeBridge; import eu.etaxonomy.taxeditor.model.IDataChangeBehavior; @@ -98,8 +99,7 @@ public class TaxonNavigator extends CommonNavigator implements IConversationEnab } } if (treePaths.size() > 0) { - TreePath[] treePathsArray = (TreePath[]) treePaths.toArray(new TreePath[treePaths.size()]); - this.getCommonViewer().setExpandedTreePaths(treePathsArray); + this.getCommonViewer().setExpandedTreePaths(treePaths.toArray(new TreePath[0])); } } @@ -108,13 +108,16 @@ public class TaxonNavigator extends CommonNavigator implements IConversationEnab * @return */ private TreePath createTreePathFromString(String string) { - List pathList = new ArrayList(); + List pathList = new ArrayList(); + + if(string.length() == 0) return null; + for (String uuid : string.split(" ")) { - Taxon taxon = (Taxon) CdmStore.getTaxonService().getTaxonByUuid(UUID.fromString(uuid)); - if (taxon == null) { + TaxonNode taxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(UUID.fromString(uuid)); + if (taxonNode == null) { return null; } - pathList.add(taxon); + pathList.add(taxonNode); } return new TreePath(pathList.toArray()); } @@ -133,8 +136,12 @@ public class TaxonNavigator extends CommonNavigator implements IConversationEnab String path = ""; for (int i = 0; i < pathLength; i++) { Object segment = treePath.getSegment(i); - if (segment instanceof Taxon) { - path += ((Taxon) segment).getUuid().toString() + " "; + // FIXME I don't see the meaning of filtering out objects here. + // Each time a new content type is added to the navigator we have to add it here as + // well. What is the worst that could happen when a "Non-taxon tree path segment" is encountered + // or when exactly could this happen? Anomalies should also be handled in the restore code. (n.hoffmann) + if ((segment instanceof TaxonomicTree) || (segment instanceof TaxonNode)) { + path += ((CdmBase) segment).getUuid().toString() + " "; } else { logger.warn("Non-taxon tree path segment " + segment); } @@ -149,7 +156,6 @@ public class TaxonNavigator extends CommonNavigator implements IConversationEnab */ public void createPartControl(Composite aParent) { super.createPartControl(aParent); - ViewerComparator comparator = getCommonViewer().getComparator(); restoreState(memento); } @@ -168,6 +174,7 @@ public class TaxonNavigator extends CommonNavigator implements IConversationEnab if(dataChangeBehavior == null){ dataChangeBehavior = new TaxonNavigatorDataChangeBehavior(this); } + DataChangeBridge.handleDataChange(changeEvents, dataChangeBehavior); } @@ -177,4 +184,14 @@ public class TaxonNavigator extends CommonNavigator implements IConversationEnab } return super.getFrameToolTipText(element); } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#dispose() + */ + @Override + public void dispose() { + conversation.unregisterForDataStoreChanges(this); + + super.dispose(); + } } \ No newline at end of file diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDataChangeBehavior.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDataChangeBehavior.java index 5a0fa027e..9a7510a04 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDataChangeBehavior.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDataChangeBehavior.java @@ -10,6 +10,7 @@ package eu.etaxonomy.taxeditor.navigation.navigator; import org.apache.log4j.Logger; +import org.eclipse.ui.navigator.CommonViewer; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType; @@ -55,10 +56,11 @@ public class TaxonNavigatorDataChangeBehavior extends AbstractDataChangeBehaviou */ public void reactOnDataChange(CdmDataChangeMap events) { - if(isRelevant(events)){ - source.getCommonViewer().refresh(); + CommonViewer viewer = source.getCommonViewer(); + + viewer.refresh(); logger.info("DataStore update caused a refresh of the taxonomic tree"); diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java index 0217ab6b8..ecf653ade 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java @@ -29,6 +29,7 @@ import org.eclipse.ui.part.ViewPart; import eu.etaxonomy.cdm.api.conversation.ConversationHolder; import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; import eu.etaxonomy.cdm.model.common.IdentifiableEntity; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; import eu.etaxonomy.taxeditor.navigation.NavigationUtil; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -65,14 +66,9 @@ public class SearchResultView extends ViewPart implements IConversationEnabled{ resultViewer.setLabelProvider(new SearchResultLabelProvider()); resultViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { - try { - IdentifiableEntity selection = (IdentifiableEntity) ((StructuredSelection) event.getSelection()).getFirstElement(); - NavigationUtil.openEditor(selection); - }catch (IllegalArgumentException e){ - // pass - }catch (Exception e) { - logger.warn("Could not open editor from search result.", e); - } + Object selection = ((StructuredSelection) event.getSelection()).getFirstElement(); + + NavigationUtil.openSearch(selection); } }); diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/taxonomictree/TaxonomicTreeView.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/taxonomictree/TaxonomicTreeView.java index c14ee24f9..7a0878058 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/taxonomictree/TaxonomicTreeView.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/taxonomictree/TaxonomicTreeView.java @@ -12,10 +12,8 @@ package eu.etaxonomy.taxeditor.navigation.taxonomictree; import java.util.List; import org.apache.log4j.Logger; -import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; @@ -47,12 +45,8 @@ import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; import eu.etaxonomy.taxeditor.model.DataChangeBridge; import eu.etaxonomy.taxeditor.model.IDataChangeBehavior; -import eu.etaxonomy.taxeditor.model.NameUtil; import eu.etaxonomy.taxeditor.model.TaxonTransfer; -import eu.etaxonomy.taxeditor.model.TaxonUtil; -import eu.etaxonomy.taxeditor.navigation.NavigationUtil; import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; -import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; import eu.etaxonomy.taxeditor.store.CdmStore; /** @@ -63,7 +57,8 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @version 1.0 * @author n.hoffmann */ -@Deprecated public class TaxonomicTreeView extends ViewPart implements IConversationEnabled, IPostOperationEnabled { +@Deprecated +public class TaxonomicTreeView extends ViewPart implements IConversationEnabled, IPostOperationEnabled { private static final Logger logger = Logger.getLogger(TaxonomicTreeView.class); public static final String ID = "eu.etaxonomy.taxeditor.navigation.taxonomictree.treeView"; //$NON-NLS-1$ @@ -155,7 +150,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore; if (element instanceof Taxon) { // FIXME call EditTaxonHandler logger.info("Doubleclick on taxon element. Should open editor now"); - NavigationUtil.openEditor((Taxon) element); +// NavigationUtil.openEditor((Taxon) element); } } } @@ -208,15 +203,15 @@ import eu.etaxonomy.taxeditor.store.CdmStore; newParentTaxon = (Taxon) event.item.getData(); // Make sure parentTaxon is not a child - if (TaxonUtil.isTaxonChildOfTaxon(newParentTaxon, taxon)) { - - MessageDialog.openError(NavigationUtil.getShell(), "Can't move taxon.", - "'" + NameUtil.getDisplayName(taxon) + "' sits above " + - "'" + NameUtil.getDisplayName(newParentTaxon) + "' " + - "in the taxonomic hierarchy."); - - return; - } +// if (TaxonNodeUtil.isTaxonChildOfTaxon(newParentTaxon, taxon)) { +// +// MessageDialog.openError(NavigationUtil.getShell(), "Can't move taxon.", +// "'" + NameUtil.getDisplayName(taxon) + "' sits above " + +// "'" + NameUtil.getDisplayName(newParentTaxon) + "' " + +// "in the taxonomic hierarchy."); +// +// return; +// } // Make sure taxon is not being dropped onto itself if (taxon.equals(newParentTaxon)) { @@ -224,18 +219,18 @@ import eu.etaxonomy.taxeditor.store.CdmStore; } // Make sure parent taxon does not have unsaved changes - if (NavigationUtil.isDirty(newParentTaxon)){ - MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + - "changes in the parent taxon. Pleas save first."); - return; - } +// if (NavigationUtil.isDirty(newParentTaxon)){ +// MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + +// "changes in the parent taxon. Pleas save first."); +// return; +// } } - - IUndoableOperation operation = new MoveTaxonOperation - ("Move Taxon", NavigationUtil.getUndoContext(), taxon, newParentTaxon); - - NavigationUtil.executeOperation(operation); +// +// IUndoableOperation operation = new MoveTaxonOperation +// ("Move Taxon", NavigationUtil.getUndoContext(), taxon, newParentTaxon); +// +// NavigationUtil.executeOperation(operation); } }); } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/LoginDialog.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/LoginDialog.java new file mode 100644 index 000000000..90a632b58 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/LoginDialog.java @@ -0,0 +1,109 @@ +// $Id$ +/** + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * http://www.e-taxonomy.eu + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * See LICENSE.TXT at the top of this package for the full license terms. + */ + +package eu.etaxonomy.taxeditor.dialogs; + +import org.apache.log4j.Logger; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.springframework.security.BadCredentialsException; +import org.springframework.security.providers.UsernamePasswordAuthenticationToken; + +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + * @author n.hoffmann + * @created 16.06.2009 + * @version 1.0 + */ +public class LoginDialog extends Dialog { + + + private static final Logger logger = Logger.getLogger(LoginDialog.class); + + private static Text passwordText; + private static Text usernameText; + + /** + * @param parentShell + */ + public LoginDialog(Shell parentShell) { + super(parentShell); + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + //add controls to composite as necessary + + + // Label for the heading + final CLabel titleLabel = new CLabel(composite, SWT.NONE); + titleLabel.setText("User Login"); + + // Label for the username + final CLabel userNameLabel = new CLabel(composite, SWT.NONE); + userNameLabel.setText("Username"); + + // Textfield for the username + usernameText = new Text(composite, SWT.BORDER); + usernameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // Label for the password + final CLabel passwordLabel = new CLabel(composite, SWT.NONE); + passwordLabel.setText("Password"); + + // Textfield for the password + passwordText = new Text(composite, SWT.BORDER); + passwordText.setEchoChar('*'); + passwordText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + + return composite; + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + @Override + protected void okPressed() { + + String username = usernameText.getText().trim(); + String password = passwordText.getText().trim(); + + // password is stored as salted md5 hash + String passwordHash = password; + + UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, passwordHash); + + try{ + CdmStore.getAuthenticationManager().authenticate(token); + }catch(BadCredentialsException e){ + logger.error("Bad credentials"); + }catch(IllegalArgumentException e){ + logger.error("Null argument for either user or password"); + } + + super.okPressed(); + } + + +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java index 467cc4e06..cfd94de7d 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java @@ -76,8 +76,12 @@ public abstract class AbstractUtility { * This method is for developer convenience. */ public static void notImplementedMessage(){ + warningDialog("Not yet implemented"); + } + + public static void warningDialog(String warning){ MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.OK); - messageBox.setText("Not yet implemented"); + messageBox.setText(warning); messageBox.open(); } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonUtil.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonNodeUtil.java similarity index 59% rename from taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonUtil.java rename to taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonNodeUtil.java index 2046f30ae..37bc50143 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonUtil.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonNodeUtil.java @@ -17,8 +17,10 @@ import org.apache.log4j.Logger; import eu.etaxonomy.cdm.api.conversation.ConversationHolder; import eu.etaxonomy.cdm.model.name.TaxonNameBase; +import eu.etaxonomy.cdm.model.reference.ReferenceBase; +import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.cdm.model.taxon.TaxonBase; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -27,30 +29,29 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @created 25.03.2009 * @version 1.0 */ -public class TaxonUtil { +public class TaxonNodeUtil { private static final Logger logger = Logger - .getLogger(TaxonUtil.class); - + .getLogger(TaxonNodeUtil.class); /** - * TODO error handling. throw exceptions if something goes wrong * - * @param taxonUuid + * @param taxonNodeUuid * @return */ - public static boolean deleteTaxonBaseIsolated(UUID taxonUuid){ + public static boolean deleteTaxonNodeIsolated(UUID taxonNodeUuid){ // get a new conversation ConversationHolder conversation = CdmStore.NewTransactionalConversation(); - // find the taxonBase - TaxonBase taxonBase = CdmStore.getTaxonService().findByUuid(taxonUuid); - // delete the taxonBase - CdmStore.getTaxonService().delete(taxonBase); + + TaxonNode taxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid); + + boolean result = taxonNode.remove(); + // commit the conversation and throw it away conversation.commit(true); - return true; + return result; } - public static Taxon addChildTaxonBaseIsolated(UUID taxonUuid, TaxonNameBase newTaxonName){ + public static TaxonNode addChildTaxonBaseIsolated(UUID taxonNodeUuid, TaxonNameBase newTaxonName){ // disallow saving of zero length names if(newTaxonName.getFullTitleCache().length() == 0){ return null; @@ -59,32 +60,41 @@ public class TaxonUtil { // get a new conversation ConversationHolder conversation = CdmStore.NewTransactionalConversation(); // find the taxonBase - Taxon parentTaxon = (Taxon) CdmStore.getTaxonService().findByUuid(taxonUuid); + TaxonNode parentTaxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid); // logic to add new taxon name - Taxon childTaxon = Taxon.NewInstance(newTaxonName, parentTaxon.getSec()); - parentTaxon.addTaxonomicChild(childTaxon, null, null); + Taxon childTaxon = Taxon.NewInstance(newTaxonName, parentTaxonNode.getTaxon().getSec()); + TaxonNode childTaxonNode = parentTaxonNode.addChild(childTaxon); //not needed here: CdmStore.getTaxonService().save(parentTaxon); // commit the conversation and throw it away conversation.commit(true); - return childTaxon; + return childTaxonNode; } - public static boolean moveTaxonBaseIsolated(UUID taxonUuid, UUID newParentTaxonUuid){ + /** + * + * @param taxonNodeUuid + * @param newParentTaxonNodeUuid + * @return + */ + public static TaxonNode moveTaxonBaseIsolated(UUID taxonNodeUuid, UUID newParentTaxonNodeUuid){ // get a new conversation ConversationHolder conversation = CdmStore.NewTransactionalConversation(); - // find the taxonBases - Taxon taxon = (Taxon) CdmStore.getTaxonService().findByUuid(taxonUuid); - Taxon newParentTaxon = (Taxon) CdmStore.getTaxonService().findByUuid(newParentTaxonUuid); - - Taxon oldParent = taxon.getTaxonomicParent(); - if (oldParent != null) { - oldParent.removeTaxonomicChild(taxon); - } + // find the taxon node + TaxonNode taxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid); + // store all relevant information of taxon node and delete the taxon node. + Taxon taxon = taxonNode.getTaxon(); + ReferenceBase parentChildReference = taxonNode.getReferenceForParentChildRelation(); + String parentChildMicroReference = taxonNode.getMicroReferenceForParentChildRelation(); + Synonym synonymUsed = taxonNode.getSynonymToBeUsed(); + + taxonNode.remove(); - newParentTaxon.addTaxonomicChild(taxon, null, null); + TaxonNode newParentTaxonNode = CdmStore.getTaxonService().getTaxonNodeByUuid(newParentTaxonNodeUuid); + TaxonNode newChild = newParentTaxonNode.addChild(taxon, parentChildReference, parentChildMicroReference, synonymUsed); + // commit the conversation conversation.commit(true); - return true; + return newChild; } /** @@ -118,30 +128,4 @@ public class TaxonUtil { return relations.toArray(new TaxonRelationship[0])[0]; } - - /** - * Returns true if child belongs to the children, grandchildren, - * etc. of parent. - * - * @param child - * @param parent - * @return - */ - public static boolean isTaxonChildOfTaxon(Taxon child, Taxon parent) { - - // Traverse all checkTaxon's children - for (Taxon childTaxon : parent.getTaxonomicChildren()) { - - if (childTaxon.equals(child)) { - return true; - } else { - - // Compare taxon with childTaxon's children - if (isTaxonChildOfTaxon(child, childTaxon)) { - return true; - } - } - } - return false; - } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/AbstractPostOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/AbstractPostOperation.java index 9ee7ead76..54d8685b9 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/AbstractPostOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/AbstractPostOperation.java @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Status; import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; /** * @author p.ciardelli @@ -39,6 +40,11 @@ public abstract class AbstractPostOperation extends AbstractOperation { */ protected Taxon taxon; + /** + * A reference to the taxons TaxonNode + */ + protected TaxonNode taxonNode; + /** * * @param label @@ -66,6 +72,18 @@ public abstract class AbstractPostOperation extends AbstractOperation { this.postOperationEnabled = postOperationEnabled; } + /** + * + * @param label + * @param undoContext + * @param taxonNode + * @param postOperationEnabled + */ + public AbstractPostOperation(String label, IUndoContext undoContext, TaxonNode taxonNode, IPostOperationEnabled postOperationEnabled){ + this(label, undoContext, taxonNode.getTaxon(), postOperationEnabled); + this.taxonNode = taxonNode; + } + /** * This method will try to call the post operation on a possibly registered * IPostOperationEnabled implementor. Objects that were affected by the operation diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptRelationshipTypeOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptRelationshipTypeOperation.java index 2538d9283..d48cc38ae 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptRelationshipTypeOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptRelationshipTypeOperation.java @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.IStatus; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; /** * @author n.hoffmann @@ -45,7 +45,7 @@ public class ChangeConceptRelationshipTypeOperation extends AbstractPostOperatio super(label, undoContext, taxon, postOperationEnabled); this.relatedTaxon = relatedTaxon; - this.taxonRelationship = TaxonUtil.getRelationshipBetweenTwoTaxa(relatedTaxon, taxon); + this.taxonRelationship = TaxonNodeUtil.getRelationshipBetweenTwoTaxa(relatedTaxon, taxon); this.oldRelationshipType = taxonRelationship.getType(); this.newRelationshipType = type; } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptToSynonymOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptToSynonymOperation.java index 607a95323..48f9c795e 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptToSynonymOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/ChangeConceptToSynonymOperation.java @@ -22,7 +22,7 @@ import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; /** * @author p.ciardelli @@ -45,7 +45,7 @@ public class ChangeConceptToSynonymOperation extends IPostOperationEnabled editor) { super(label, undoContext, taxon, editor); - this.taxonRelationship = TaxonUtil.getRelationshipBetweenTwoTaxa(concept, taxon); + this.taxonRelationship = TaxonNodeUtil.getRelationshipBetweenTwoTaxa(concept, taxon); this.oldRelationshipType = taxonRelationship.getType(); this.concept = concept; diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateChildTaxonOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateChildTaxonOperation.java index 21b99e8c6..78aee4422 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateChildTaxonOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateChildTaxonOperation.java @@ -19,8 +19,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; /** @@ -34,7 +34,7 @@ public class CreateChildTaxonOperation extends AbstractPostOperation { private TaxonNameBase newTaxonName; - private Taxon childTaxon; + private TaxonNode childTaxonNode; /** @@ -45,8 +45,8 @@ public class CreateChildTaxonOperation extends AbstractPostOperation { * @param conversationEnabled */ public CreateChildTaxonOperation(String label, IUndoContext undoContext, - Taxon taxon, TaxonNameBase name, IPostOperationEnabled postOperationEnabled) { - super(label, undoContext, taxon, postOperationEnabled); + TaxonNode taxonNode, TaxonNameBase name, IPostOperationEnabled postOperationEnabled) { + super(label, undoContext, taxonNode, postOperationEnabled); this.newTaxonName = name; } @@ -59,10 +59,10 @@ public class CreateChildTaxonOperation extends AbstractPostOperation { public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - childTaxon = TaxonUtil.addChildTaxonBaseIsolated(taxon.getUuid(), newTaxonName); + childTaxonNode = TaxonNodeUtil.addChildTaxonBaseIsolated(taxonNode.getUuid(), newTaxonName); - if(childTaxon != null){ - return postExecute(childTaxon); + if(childTaxonNode != null){ + return postExecute(childTaxonNode); }else{ return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, TaxeditorStorePlugin.ERROR_SAVING_ZERO_NAME, "Attempt to save taxon with zero length name", null); } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteConceptRelationOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteConceptRelationOperation.java index 39aba56e4..304ab1d74 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteConceptRelationOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteConceptRelationOperation.java @@ -19,7 +19,7 @@ import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; /** * Deletes a relation between two taxa. @@ -47,7 +47,7 @@ public class DeleteConceptRelationOperation extends AbstractPostOperation { this.relatedTaxon = relatedTaxon; - relationship = TaxonUtil.getRelationshipBetweenTwoTaxa(relatedTaxon, taxon); + relationship = TaxonNodeUtil.getRelationshipBetweenTwoTaxa(relatedTaxon, taxon); relationshipType = relationship.getType(); diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonNodeOperation.java similarity index 69% rename from taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java rename to taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonNodeOperation.java index 5c7e89ee5..2ab5632d5 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonNodeOperation.java @@ -19,37 +19,32 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Shell; -import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; /** - * Delete a taxon from the model. + * Delete a taxon node from its TaxonomicTree and thus from the current taxonomic view. * - * TODO: Currently all data in session data repository has to be saved before deleting - * a taxon and the whole logic is happening here. This way we would have to implement - * the same logic in another place if we want to delete outside of an operation context - * (NOT undoable). Therefore it is desirable to have the logic implemented in another - * place and merely call a method here. * * @author n.hoffmann * @created 16.01.2009 * @version 1.0 */ -public class DeleteTaxonOperation extends AbstractPostOperation { +public class DeleteTaxonNodeOperation extends AbstractPostOperation { @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(DeleteTaxonOperation.class); + private static Logger logger = Logger.getLogger(DeleteTaxonNodeOperation.class); /** * The taxonomical parent of the taxon to be deleted. */ - private Taxon parentTaxon; + private TaxonNode parentTaxonNode; - public DeleteTaxonOperation(String text, IUndoContext undoContext, - Taxon taxon) { - super(text, undoContext, taxon, null); + public DeleteTaxonNodeOperation(String text, IUndoContext undoContext, + TaxonNode taxonNode) { + super(text, undoContext, taxonNode, null); - parentTaxon = taxon.getTaxonomicParent(); + parentTaxonNode = taxonNode.getParent(); } /* (non-Javadoc) @@ -66,15 +61,15 @@ public class DeleteTaxonOperation extends AbstractPostOperation { } // Prompt user for confirmation - if(! MessageDialog.openConfirm((Shell) info.getAdapter(Shell.class), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName + "'?")){ + if(! MessageDialog.openConfirm((Shell) info.getAdapter(Shell.class), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName + "' from this taxonomic view?")){ monitor.done(); return Status.CANCEL_STATUS; } - // If the taxon has children, cancel operation + // If the taxon node has child nodes, cancel operation // TODO add option to continue, and delete children - if (taxon.hasTaxonomicChildren()) { + if (taxonNode.getChildNodes().size() > 0) { MessageDialog.openInformation((Shell) info.getAdapter(Shell.class), "Cannot delete taxon", "'" + taxonName + "' has taxonomic children. " + "These must be manually deleted before their parent."); @@ -83,7 +78,7 @@ public class DeleteTaxonOperation extends AbstractPostOperation { } // delete the taxon in an isolated conversation - TaxonUtil.deleteTaxonBaseIsolated(taxon.getUuid()); + TaxonNodeUtil.deleteTaxonNodeIsolated(taxonNode.getUuid()); return postExecute(null); @@ -105,7 +100,7 @@ public class DeleteTaxonOperation extends AbstractPostOperation { public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { // FIXME we have to add old citation - parentTaxon.addTaxonomicChild(taxon, null, null); + parentTaxonNode.addChild(taxon); // FIXME readding has to take place in an isolated conversation as well // so that all the mediation magic does the rest for us return postExecute(null); diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java index 46079d15a..6674fb0fa 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java @@ -17,8 +17,8 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.model.TaxonUtil; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.model.TaxonNodeUtil; /** * Change the taxonomic parent of a given taxon. @@ -34,20 +34,20 @@ public class MoveTaxonOperation extends AbstractPostOperation { /** * A reference to the new taxonomical parent. */ - private Taxon newParentTaxon; + private TaxonNode newParentTaxonNode; /** * A reference to the former taxonomical parent */ - private Taxon oldParentTaxon; + private TaxonNode oldParentTaxonNode; public MoveTaxonOperation(String label, IUndoContext undoContext, - Taxon taxon, Taxon newParentTaxon) { - super(label, undoContext, taxon); + TaxonNode taxonNode, TaxonNode newParentTaxonNode, IPostOperationEnabled postOperationEnabled) { + super(label, undoContext, taxonNode, null); - this.newParentTaxon = newParentTaxon; + this.newParentTaxonNode = newParentTaxonNode; - // Save old parent taxon for undo - this.oldParentTaxon = taxon.getTaxonomicParent(); + // Save old parent TaxonNode for undo + this.oldParentTaxonNode = taxonNode.getParent(); } /* (non-Javadoc) @@ -57,9 +57,9 @@ public class MoveTaxonOperation extends AbstractPostOperation { public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - TaxonUtil.moveTaxonBaseIsolated(taxon.getUuid(), newParentTaxon.getUuid()); + TaxonNode newTaxonNode = TaxonNodeUtil.moveTaxonBaseIsolated(taxonNode.getUuid(), newParentTaxonNode.getUuid()); - return Status.OK_STATUS; + return postExecute(newTaxonNode); } /* (non-Javadoc) @@ -78,7 +78,7 @@ public class MoveTaxonOperation extends AbstractPostOperation { public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - TaxonUtil.moveTaxonBaseIsolated(taxon.getUuid(), oldParentTaxon.getUuid()); + TaxonNodeUtil.moveTaxonBaseIsolated(taxonNode.getUuid(), oldParentTaxonNode.getUuid()); return Status.OK_STATUS; } diff --git a/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonOperationTest.java b/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonNodeOperationTest.java similarity index 74% rename from taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonOperationTest.java rename to taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonNodeOperationTest.java index f49d4312d..19007f517 100644 --- a/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonOperationTest.java +++ b/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/DeleteTaxonNodeOperationTest.java @@ -17,19 +17,22 @@ import org.junit.BeforeClass; import org.junit.Test; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.operations.DeleteTaxonNodeOperation; /** * @author n.hoffmann * @created 08.04.2009 * @version 1.0 */ -public class DeleteTaxonOperationTest extends AbstractTaxeditorOperationTest{ +public class DeleteTaxonNodeOperationTest extends AbstractTaxeditorOperationTest{ private static final Logger logger = Logger - .getLogger(DeleteTaxonOperationTest.class); + .getLogger(DeleteTaxonNodeOperationTest.class); private static Taxon child; + private static TaxonNode taxonNode; + /** * @throws java.lang.Exception */ @@ -42,11 +45,11 @@ public class DeleteTaxonOperationTest extends AbstractTaxeditorOperationTest{ taxon.addTaxonomicChild(child, null, null); - operation = new DeleteTaxonOperation("Delete Taxon", undoContext, taxon); + operation = new DeleteTaxonNodeOperation("Delete Taxon", undoContext, taxonNode); } /** - * Test method for {@link eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. + * Test method for {@link eu.etaxonomy.taxeditor.operations.DeleteTaxonNodeOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. * @throws ExecutionException */ @Test @@ -59,7 +62,7 @@ public class DeleteTaxonOperationTest extends AbstractTaxeditorOperationTest{ } /** - * Test method for {@link eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. + * Test method for {@link eu.etaxonomy.taxeditor.operations.DeleteTaxonNodeOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. * @throws ExecutionException */ @Test @@ -72,7 +75,7 @@ public class DeleteTaxonOperationTest extends AbstractTaxeditorOperationTest{ } /** - * Test method for {@link eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. + * Test method for {@link eu.etaxonomy.taxeditor.operations.DeleteTaxonNodeOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}. * @throws ExecutionException */ @Test diff --git a/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/MoveTaxonOperationTest.java b/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/MoveTaxonOperationTest.java index 2f262e40b..d717a3e36 100644 --- a/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/MoveTaxonOperationTest.java +++ b/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/operations/MoveTaxonOperationTest.java @@ -16,6 +16,8 @@ import org.junit.BeforeClass; import org.junit.Test; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; /** @@ -27,19 +29,32 @@ public class MoveTaxonOperationTest extends AbstractTaxeditorOperationTest { private static Taxon oldParentTaxon; private static Taxon newParentTaxon; + private static TaxonomicTree tree; + private static TaxonNode oldParentTaxonNode; + private static TaxonNode newParentTaxonNode; + private static TaxonNode taxonNode; /** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { + + taxon = Taxon.NewInstance(null, null); + + + oldParentTaxon = Taxon.NewInstance(null, null); newParentTaxon = Taxon.NewInstance(null, null); -// oldParentTaxon.addTaxonomicChild(taxon, null, null); - taxon.setTaxonomicParent(oldParentTaxon, null, null); - operation = new MoveTaxonOperation("Move Taxon To Different Parent", undoContext, taxon, newParentTaxon); + tree = TaxonomicTree.NewInstance(null); + oldParentTaxonNode = tree.addRoot(oldParentTaxon, null); + newParentTaxonNode = tree.addRoot(newParentTaxon, null); + + taxonNode = oldParentTaxonNode.addChild(taxon); + + operation = new MoveTaxonOperation("Move Taxon To Different Parent", undoContext, taxonNode, newParentTaxonNode, postOperation); } /** -- 2.34.1