Revision 0c6a1a43
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/MoveSynonymToAnotherAcceptedTaxonHandler.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.name.handler; |
|
2 |
|
|
3 |
import java.util.UUID; |
|
4 |
|
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.eclipse.core.commands.AbstractHandler; |
|
7 |
import org.eclipse.core.commands.ExecutionEvent; |
|
8 |
import org.eclipse.core.commands.ExecutionException; |
|
9 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
10 |
import org.eclipse.core.commands.operations.IUndoContext; |
|
11 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
12 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
13 |
import org.eclipse.swt.widgets.Shell; |
|
14 |
import org.eclipse.ui.IEditorInput; |
|
15 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
18 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
19 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
20 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
22 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
23 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
|
24 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
25 |
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation; |
|
26 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
27 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
|
28 |
|
|
29 |
public class MoveSynonymToAnotherAcceptedTaxonHandler extends AbstractHandler implements IPostOperationEnabled { |
|
30 |
private static final Logger logger = Logger |
|
31 |
.getLogger(MoveSynonymToAnotherAcceptedTaxonHandler.class); |
|
32 |
private MultiPageTaxonEditor editor; |
|
33 |
|
|
34 |
@Override |
|
35 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
36 |
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event); |
|
37 |
Shell shell = HandlerUtil.getActiveShell(event); |
|
38 |
IEditorInput input = editor.getEditorInput(); |
|
39 |
if (!EditorUtil.forceUserSave(editor, shell)) { |
|
40 |
return null; |
|
41 |
} |
|
42 |
|
|
43 |
if (!(input instanceof TaxonEditorInput)) { |
|
44 |
logger.error("Editor input is not TaxonEditorInput"); |
|
45 |
return null; |
|
46 |
} |
|
47 |
|
|
48 |
// Get synonym from selection |
|
49 |
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
50 |
if (!(selection.getFirstElement() instanceof Synonym)) { |
|
51 |
logger.error("Selection does not contain a Synonym"); |
|
52 |
return null; |
|
53 |
} |
|
54 |
|
|
55 |
Synonym synonym = (Synonym) selection.getFirstElement(); |
|
56 |
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", null, null, null); |
|
57 |
Taxon oldParent = ((TaxonEditorInput)input).getTaxon(); |
|
58 |
|
|
59 |
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(), |
|
60 |
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor); |
|
61 |
|
|
62 |
EditorUtil.executeOperation(operation); |
|
63 |
|
|
64 |
|
|
65 |
return null; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
70 |
// TODO Auto-generated method stub |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public boolean onComplete() { |
|
76 |
// TODO Auto-generated method stub |
|
77 |
return false; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
} |
|
1 |
package eu.etaxonomy.taxeditor.editor.name.handler; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
import org.eclipse.core.commands.AbstractHandler; |
|
5 |
import org.eclipse.core.commands.ExecutionEvent; |
|
6 |
import org.eclipse.core.commands.ExecutionException; |
|
7 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
8 |
import org.eclipse.swt.widgets.Shell; |
|
9 |
import org.eclipse.ui.IEditorInput; |
|
10 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
11 |
|
|
12 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
13 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
14 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
15 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
16 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
17 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
|
18 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
19 |
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation; |
|
20 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
21 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
22 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
|
23 |
|
|
24 |
public class MoveSynonymToAnotherAcceptedTaxonHandler extends AbstractHandler implements IPostOperationEnabled { |
|
25 |
private static final Logger logger = Logger |
|
26 |
.getLogger(MoveSynonymToAnotherAcceptedTaxonHandler.class); |
|
27 |
private MultiPageTaxonEditor editor; |
|
28 |
|
|
29 |
@Override |
|
30 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
31 |
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event); |
|
32 |
Shell shell = HandlerUtil.getActiveShell(event); |
|
33 |
IEditorInput input = editor.getEditorInput(); |
|
34 |
if (!EditorUtil.forceUserSave(editor, shell)) { |
|
35 |
return null; |
|
36 |
} |
|
37 |
|
|
38 |
if (!(input instanceof TaxonEditorInput)) { |
|
39 |
logger.error("Editor input is not TaxonEditorInput"); |
|
40 |
return null; |
|
41 |
} |
|
42 |
|
|
43 |
// Get synonym from selection |
|
44 |
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
45 |
if (!(selection.getFirstElement() instanceof Synonym)) { |
|
46 |
logger.error("Selection does not contain a Synonym"); |
|
47 |
return null; |
|
48 |
} |
|
49 |
|
|
50 |
Synonym synonym = (Synonym) selection.getFirstElement(); |
|
51 |
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", null, null, ((TaxonEditorInput)input).getTaxonNode().getClassification()); |
|
52 |
if(newParentNode!=null){ |
|
53 |
Taxon oldParent = ((TaxonEditorInput)input).getTaxon(); |
|
54 |
|
|
55 |
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(), |
|
56 |
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor); |
|
57 |
|
|
58 |
AbstractUtility.executeOperation(operation); |
|
59 |
|
|
60 |
} |
|
61 |
return null; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
66 |
// TODO Auto-generated method stub |
|
67 |
return false; |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public boolean onComplete() { |
|
72 |
// TODO Auto-generated method stub |
|
73 |
return false; |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
} |
Also available in: Unified diff
Pre-select current classification for taxon node selection dialog
(#3462)