// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
private static final Logger logger = Logger
.getLogger(ChangeSynonymToAcceptedTaxonHandler.class);
private MultiPageTaxonEditor editor;
-
+
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
/** {@inheritDoc} */
- public Object execute(ExecutionEvent event) throws ExecutionException {
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);
Shell shell = HandlerUtil.getActiveShell(event);
IEditorInput input = editor.getEditorInput();
-
+
if (!(input instanceof TaxonEditorInput)) {
logger.error("Editor input is not TaxonEditorInput");
return null;
}
Synonym synonym = (Synonym) selection.getFirstElement();
-
+
// Force user to save taxon - not really necessary though, is it?
if (!EditorUtil.forceUserSave(editor, shell)) {
return null;
// Get taxon
Taxon taxon = ((TaxonEditorInput) input).getTaxon();
-
+
TaxonNode parentNode = (TaxonNode) HibernateProxyHelper.deproxy(((TaxonEditorInput) input).getTaxonNode().getParent());
-
+
List<UUID> excludeTaxa = null;
-
- TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select parent", excludeTaxa, null, null);
-
+
+ TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select parent", excludeTaxa, null, ((TaxonEditorInput) input).getTaxonNode().getClassification());
+
if(newParentNode != null){
-
+
// TODO get synonyms from homotypical group and add them as homotypic synonyms to new accepted taxon
// apply confirmation dialog
HomotypicalGroup group = synonym.getHomotypicGroup();
Set<TaxonNameBase> namesInGroup = group.getTypifiedNames();
// FIXME with this implementation we can not create a taxonNode that is a direct child of the classification node
- AbstractPostOperation operation = new ChangeSynonymToAcceptedTaxonOperation("Change synonym to accepted taxon", EditorUtil.getUndoContext(),
+ AbstractPostOperation operation = new ChangeSynonymToAcceptedTaxonOperation("Change synonym to accepted taxon", EditorUtil.getUndoContext(),
taxon, newParentNode, synonym, namesInGroup, this, editor); //$NON-NLS-1$
EditorUtil.executeOperation(operation);
}
-
+
return null;
}
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
*/
/** {@inheritDoc} */
- public boolean postOperation(CdmBase objectAffectedByOperation) {
-
+ @Override
+ public boolean postOperation(CdmBase objectAffectedByOperation) {
+
// Redraw existing editor
((IPostOperationEnabled) editor).postOperation(null);
-
+
editor.doSave(EditorUtil.getMonitor());
-
+
if (objectAffectedByOperation instanceof TaxonNode) {
-
+
// Open new unsaved editor with existing taxon's parent as temporary parent
TaxonNode newNode = (TaxonNode) objectAffectedByOperation;
// TaxonNode newNode = parentNode.addChild(newTaxon);
-
+
try {
// TODO
/*
* doesn't work yet.
*/
EditorUtil.openTaxonNode(newNode.getUuid());
-
+
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
*
* @return a boolean.
*/
- public boolean onComplete() {
+ @Override
+ public boolean onComplete() {
// TODO Auto-generated method stub
return false;
}
-package eu.etaxonomy.taxeditor.editor.name.handler;\r
-\r
-import java.util.UUID;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.commands.common.NotDefinedException;\r
-import org.eclipse.core.commands.operations.IUndoContext;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.taxon.Synonym;\r
-import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
-import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
-import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;\r
-import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;\r
-import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;\r
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;\r
-import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;\r
-\r
-public class MoveSynonymToAnotherAcceptedTaxonHandler extends AbstractHandler implements IPostOperationEnabled {\r
- private static final Logger logger = Logger\r
- .getLogger(MoveSynonymToAnotherAcceptedTaxonHandler.class);\r
- private MultiPageTaxonEditor editor;\r
- \r
- @Override\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);\r
- Shell shell = HandlerUtil.getActiveShell(event);\r
- IEditorInput input = editor.getEditorInput();\r
- if (!EditorUtil.forceUserSave(editor, shell)) {\r
- return null;\r
- }\r
- \r
- if (!(input instanceof TaxonEditorInput)) {\r
- logger.error("Editor input is not TaxonEditorInput");\r
- return null;\r
- }\r
-\r
- // Get synonym from selection\r
- StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);\r
- if (!(selection.getFirstElement() instanceof Synonym)) {\r
- logger.error("Selection does not contain a Synonym");\r
- return null;\r
- }\r
-\r
- Synonym synonym = (Synonym) selection.getFirstElement();\r
- TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", null, null, null);\r
- Taxon oldParent = ((TaxonEditorInput)input).getTaxon();\r
- \r
- MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(),\r
- oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);\r
- \r
- EditorUtil.executeOperation(operation);\r
- \r
-\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean postOperation(CdmBase objectAffectedByOperation) {\r
- // TODO Auto-generated method stub\r
- return false;\r
- }\r
-\r
- @Override\r
- public boolean onComplete() {\r
- // TODO Auto-generated method stub\r
- return false;\r
- }\r
- \r
- \r
-\r
-}\r
+package eu.etaxonomy.taxeditor.editor.name.handler;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+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.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
+
+public class MoveSynonymToAnotherAcceptedTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
+ private static final Logger logger = Logger
+ .getLogger(MoveSynonymToAnotherAcceptedTaxonHandler.class);
+ private MultiPageTaxonEditor editor;
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);
+ Shell shell = HandlerUtil.getActiveShell(event);
+ IEditorInput input = editor.getEditorInput();
+ if (!EditorUtil.forceUserSave(editor, shell)) {
+ return null;
+ }
+
+ if (!(input instanceof TaxonEditorInput)) {
+ logger.error("Editor input is not TaxonEditorInput");
+ return null;
+ }
+
+ // Get synonym from selection
+ StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
+ if (!(selection.getFirstElement() instanceof Synonym)) {
+ logger.error("Selection does not contain a Synonym");
+ return null;
+ }
+
+ Synonym synonym = (Synonym) selection.getFirstElement();
+ TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", null, null, ((TaxonEditorInput)input).getTaxonNode().getClassification());
+ if(newParentNode!=null){
+ Taxon oldParent = ((TaxonEditorInput)input).getTaxon();
+
+ MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(),
+ oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
+
+ AbstractUtility.executeOperation(operation);
+
+ }
+ return null;
+ }
+
+ @Override
+ public boolean postOperation(CdmBase objectAffectedByOperation) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean onComplete() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+
+}
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
import eu.etaxonomy.taxeditor.editor.Page;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionToOtherTaxonOperation;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
} else if (element instanceof DescriptionBase){
uuid = ((DescriptionBase)element).getUuid();
}
-
+
if (uuid != null){
descriptions.add((TaxonDescription) CdmStore.getService(IDescriptionService.class).load(uuid, null));
}
List<UUID> excludeTaxa = new ArrayList<UUID>();
editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
excludeTaxa.add(descriptions.get(0).getTaxon().getUuid());
+
+ //get current taxon node
+ TaxonNode node = null;
+ Classification classification = null;
+ MultiPageTaxonEditor taxonEditor = EditorUtil.getActiveMultiPageTaxonEditor();
+ if(taxonEditor!=null){
+ node = ((TaxonEditorInput) taxonEditor.getEditorInput()).getTaxonNode();
+ classification = node.getClassification();
+ }
TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
editor.getConversationHolder(),
"Choose the accepted taxon",
excludeTaxa,
- null,
- null);
+ node,
+ classification);
if (newAcceptedTaxonNode == null) {
return null;
navigator.getConversationHolder(),
"Choose the accepted taxon",
excludeTaxa,
- null,
- null);
+ sourceTaxonNode,
+ sourceTaxonNode.getClassification());
if (dialogTaxonNode == null) {
return null;
}
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
// TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
if (taxonNodes.size() >= 1){
+ Classification classification = taxonNodes.iterator().next().getClassification();
boolean moveToNewParent = true;
if (PreferencesUtil.getSortNodesNaturally()){
if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
moveToNewParent = false;
}
- parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa, null, null);
+ parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa, null, classification);
}else{
- parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, null);
+ parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, classification);
}
if(parentTaxonNode != null){
if(NavigationUtil.isDirty(parentTaxonNode)){
return (T) ClassificationSelectionDialog.select(shell, conversation, (Classification) currentSelection);
}
if(clazz.equals(TaxonNode.class)){
- return (T) TaxonNodeSelectionDialog.select(shell, conversation, null, null, (TaxonNode) currentSelection, null);
+ return (T) TaxonNodeSelectionDialog.select(shell, conversation, null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification());
}
if(clazz.equals(Reference.class)){
return (T) ReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection);