Use UUIDs instead of CDM objects in AlignmentEditorInput
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 7 Jul 2015 12:11:27 +0000 (12:11 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 7 Jul 2015 12:11:27 +0000 (12:11 +0000)
This avoids session conflicts because the object will be loaded into the correct session when processing the editor input during initialization of the editor.

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/EditSequenceHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditorInput.java

index 961273cee7cfb60867264ac63868e7d1e6e9a10e..74926e0b6827b8906d2c17e5a7578ce049944580 100644 (file)
@@ -27,7 +27,7 @@ public class EditSequenceHandler extends AbstractHandler {
         ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
         TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);
         if(treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence){
-            AlignmentEditorInput input = new AlignmentEditorInput((Sequence)treeNodeOfSelection.getValue());  //TODO Should there always be a new instance created here? What if the specified CDM node is already opened in an AlignmentEditor? => Possible create Singleton that keeps instances by sequence objects in a map.
+            AlignmentEditorInput input = new AlignmentEditorInput(((Sequence)treeNodeOfSelection.getValue()).getUuid());  //TODO Should there always be a new instance created here? What if the specified CDM node is already opened in an AlignmentEditor? => Possible create Singleton that keeps instances by sequence objects in a map.
             try {
                 EditorUtil.open(input);
             }
index 905ad361bf56cd07684a5b7aa008acebb4e9f202..8bbc475dc6e0bbd54406cff575b0ab3edd093d0d 100644 (file)
@@ -317,8 +317,8 @@ public class AlignmentEditor extends EditorPart {
                updateStatusBar();
 
                if (getEditorInput() instanceof AlignmentEditorInput) {
-                       if (((AlignmentEditorInput)getEditorInput()).getSequenceNode() != null) {
-                           Sequence sequenceNode = ((AlignmentEditorInput)getEditorInput()).getSequenceNode();
+                       if (((AlignmentEditorInput)getEditorInput()).getSequenceNodeUuid() != null) {
+                           Sequence sequenceNode = CdmStore.getService(ISequenceService.class).load(((AlignmentEditorInput)getEditorInput()).getSequenceNodeUuid());
                        //re-load into the current session if it is already persisted in the DB
                        if(sequenceNode!=null && sequenceNode.getId()!=0){
                            sequenceNode = CdmStore.getService(ISequenceService.class).load(sequenceNode.getUuid());
@@ -367,7 +367,7 @@ public class AlignmentEditor extends EditorPart {
             monitor.beginTask(taskName, 3);
 
             //re-loading sequence to avoid session conflicts
-               Sequence sequenceNode = CdmStore.getService(ISequenceService.class).load(((AlignmentEditorInput)getEditorInput()).getSequenceNode().getUuid());
+               Sequence sequenceNode = CdmStore.getService(ISequenceService.class).load(((AlignmentEditorInput)getEditorInput()).getSequenceNodeUuid());
                StringAdapter stringProvider = new StringAdapter(getEditableConsensusArea().getAlignmentModel(), false);  // Throws an exception if a token has more than one character.
 
                // Write consensus sequence:
index 9d6201d20164b432dbedb322ccbe87a4e4bedb6f..eea3525e261e92769fcc5e33c8e7da1415742171 100644 (file)
 package eu.etaxonomy.taxeditor.editor.molecular;
 
 
+import java.util.UUID;
+
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;
 
-import eu.etaxonomy.cdm.model.molecular.Sequence;
-
 
 
 /**
@@ -25,14 +25,14 @@ import eu.etaxonomy.cdm.model.molecular.Sequence;
  */
 public class AlignmentEditorInput implements IEditorInput {
     private static final String name = "AlignmentEditor";
-    
-    
-    private final Sequence sequenceNode;
-    
 
-    public AlignmentEditorInput(Sequence sequenceNode) {
+
+    private final UUID sequenceNodeUuid;
+
+
+    public AlignmentEditorInput(UUID sequenceNodeUuid) {
                super();
-               this.sequenceNode = sequenceNode;
+               this.sequenceNodeUuid = sequenceNodeUuid;
        }
 
 
@@ -45,7 +45,7 @@ public class AlignmentEditorInput implements IEditorInput {
         return null;
     }
 
-    
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.IEditorInput#exists()
      */
@@ -55,7 +55,7 @@ public class AlignmentEditorInput implements IEditorInput {
         return false;
     }
 
-    
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
      */
@@ -64,7 +64,7 @@ public class AlignmentEditorInput implements IEditorInput {
         // TODO Auto-generated method stub
         return null;
     }
-    
+
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.IEditorInput#getName()
@@ -73,7 +73,7 @@ public class AlignmentEditorInput implements IEditorInput {
     public String getName() {
         return name;
     }
-    
+
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.IEditorInput#getPersistable()
@@ -82,7 +82,7 @@ public class AlignmentEditorInput implements IEditorInput {
     public IPersistableElement getPersistable() {
         return null;
     }
-    
+
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.IEditorInput#getToolTipText()
@@ -94,13 +94,13 @@ public class AlignmentEditorInput implements IEditorInput {
 
 
        /**
-        * Returns the sequence CDM node that should be edited by the {@link AlignmentEditor} this object
+        * Returns the {@link UUID} of the sequence CDM node that should be edited by the {@link AlignmentEditor} this object
         * is used with.
-        * 
-        * @return the CDM node to work on
+        *
+        * @return the uuid of the CDM node to work on
         */
-       public Sequence getSequenceNode() {
-               return sequenceNode;
+       public UUID getSequenceNodeUuid() {
+               return sequenceNodeUuid;
        }
 
 
@@ -109,25 +109,30 @@ public class AlignmentEditorInput implements IEditorInput {
                final int prime = 31;
                int result = 1;
                result = prime * result
-                               + ((sequenceNode == null) ? 0 : sequenceNode.hashCode());
+                               + ((sequenceNodeUuid == null) ? 0 : sequenceNodeUuid.hashCode());
                return result;
        }
 
 
        @Override
        public boolean equals(Object obj) {
-               if (this == obj)
-                       return true;
-               if (obj == null)
-                       return false;
-               if (getClass() != obj.getClass())
-                       return false;
+               if (this == obj) {
+            return true;
+        }
+               if (obj == null) {
+            return false;
+        }
+               if (getClass() != obj.getClass()) {
+            return false;
+        }
                AlignmentEditorInput other = (AlignmentEditorInput) obj;
-               if (sequenceNode == null) {
-                       if (other.sequenceNode != null)
-                               return false;
-               } else if (!sequenceNode.equals(other.sequenceNode))
-                       return false;
+               if (sequenceNodeUuid == null) {
+                       if (other.sequenceNodeUuid != null) {
+                return false;
+            }
+               } else if (!sequenceNodeUuid.equals(other.sequenceNodeUuid)) {
+            return false;
+        }
                return true;
        }
 }