(no commit message)
authorKatja Luther <k.luther@bgbm.org>
Mon, 8 Dec 2014 09:09:22 +0000 (09:09 +0000)
committerKatja Luther <k.luther@bgbm.org>
Mon, 8 Dec 2014 09:09:22 +0000 (09:09 +0000)
.gitattributes
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java [new file with mode: 0644]

index a4527e0a6e67032cfac29f197d3946f130dca1f2..dce01148023157ef303519812866e96f0c47c37f 100644 (file)
@@ -472,6 +472,7 @@ eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/o
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteSynonymOperation.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonBaseOperation.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonOperation.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/RemoveHomotypicalGroupBasionymOperation.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistContentProvider.java -text
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java
new file mode 100644 (file)
index 0000000..2f0d090
--- /dev/null
@@ -0,0 +1,113 @@
+package eu.etaxonomy.taxeditor.editor.name.operation;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+\r
+import eu.etaxonomy.cdm.api.service.ITaxonService;\r
+import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;\r
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
+import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.taxon.Synonym;\r
+import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;\r
+import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
+import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;\r
+import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;\r
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;\r
+import eu.etaxonomy.taxeditor.store.CdmStore;\r
+\r
+public class MoveSynonymToAnotherAcceptedTaxonOperation extends\r
+               AbstractPostTaxonOperation {\r
+\r
+       /**\r
+        * The synonym to be moved.\r
+        */\r
+       private final Synonym synonym;\r
+\r
+       private final Taxon oldTaxon;\r
+       \r
+       \r
+       /**\r
+        * <p>Constructor for MoveSynonymToAnotherAcceptedTaxon.</p>\r
+        *\r
+        * @param label a {@link java.lang.String} object.\r
+        * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.\r
+        * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.\r
+        * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.\r
+        \r
+        * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.\r
+        */\r
+       public MoveSynonymToAnotherAcceptedTaxonOperation(String label, IUndoContext undoContext,\r
+                       UUID oldTaxonUUID, UUID synonymUUID, Taxon taxon, IPostOperationEnabled postOperationEnabled) {\r
+               \r
+               super(label, undoContext, taxon, postOperationEnabled);\r
+               List<String> propertyPaths =  new ArrayList<String>();\r
+               propertyPaths.add("synonymRelations");\r
+               this.element = (Taxon) CdmStore.getService(ITaxonService.class).load(taxon.getUuid(),propertyPaths);\r
+               this.oldTaxon = (Taxon) CdmStore.getService(ITaxonService.class).load(oldTaxonUUID);\r
+               this.synonym = (Synonym) CdmStore.getService(ITaxonService.class).load(synonymUUID);\r
+               if(synonym == null){\r
+                       throw new IllegalArgumentException(\r
+                                       "A null synonym was provided.");\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+\r
+       // Get synonym name\r
+               TaxonNameBase<?, ?> synonymName = synonym.getName();\r
+               monitor.worked(20);\r
+\r
+               \r
+\r
+               // Switch groups\r
+               \r
+               monitor.worked(40);\r
+               SynonymRelationship synRel = synonym.getSynonymRelations().iterator().next();\r
+               \r
+               \r
+               \r
+               ((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();\r
+               \r
+               \r
+               \r
+               try {\r
+                       synRel = CdmStore.getService(ITaxonService.class).moveSynonymToAnotherTaxon(synRel, this.element, true, synRel.getType(), null, null, true);\r
+               } catch (HomotypicalGroupChangeException e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
+               ((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();\r
+               \r
+               \r
+\r
+               // Redraw editor if it exists\r
+               return postExecute(synRel.getSynonym());\r
+       }\r
+\r
+       @Override\r
+       public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+}\r