cleanup
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / PolytomousKeyEditorInput.java
index 7debadbe5f651385094cb514c28934cf3ef1bb08..e1b8578389013a5883ca5e35792b888957f178e1 100644 (file)
@@ -1,75 +1,86 @@
 /**
- * 
- */
+* 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.editor.key.polytomous;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.taxeditor.editor.key.AbstractIdentificationEditorInput;
-import eu.etaxonomy.taxeditor.session.ISessionEventListener;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author n.hoffmann
- *
  */
-public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<PolytomousKey> implements ISessionEventListener {
+public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<PolytomousKey> {
+
+    private PolytomousKey key;
+
+
+    protected PolytomousKeyEditorInput(ConversationHolder conversation,
+            UUID polytomousKeyUuid) {
+        super(conversation);
+        List<String> propertyPath = new ArrayList<>();
+        propertyPath.add("root");
+        propertyPath.add("root.*");
+        this.key = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, propertyPath);
+    }
+
+    public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid) throws Exception{
+        try{
+            ConversationHolder conversation = CdmStore.createConversation();
+            return new PolytomousKeyEditorInput(conversation, polytomousKeyUuid);
+        }catch(Exception e){
+            throw e;
+        }
+    }
+
+    @Override
+    public PolytomousKey getKey() {
+        return key;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        if (object instanceof PolytomousKeyEditorInput
+                && getKey() != null
+                && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
+                ){
+            return true;
+        }
+        return super.equals(object);
+    }
+
+    @Override
+    public  List<PolytomousKey> getRootEntities() {
+        return Arrays.asList(key);
+    }
 
-       private PolytomousKey key;
+    @Override
+    public void merge() {
+       key = CdmStore.getService(IPolytomousKeyService.class).merge(key,true).getMergedEntity();
+    }
 
-       protected PolytomousKeyEditorInput(ConversationHolder conversation,
-                       PolytomousKey key) {
-               super(conversation);
-               CdmStore.getCurrentSessionManager().bind(this);
-               CdmStore.getCurrentSessionManager().load(key);
-               this.key = key;
-       }
-       
-       
+    @Override
+    public Map<Object, List<String>> getPropertyPathsMap() {
+        Map<Object,List<String>> propertyPathsMap = new HashMap<>();
 
-       public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid) throws Exception{
-               try{
-                       ConversationHolder conversation = CdmStore.createConversation();
-                       
-                       return NewInstance(polytomousKeyUuid, conversation);
-               }catch(Exception e){
-                       throw e;
-               }
-       }
-       
-       public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid, ConversationHolder conversation) throws Exception{
-               PolytomousKey polytomousKey = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, null);
-                       
-               return new PolytomousKeyEditorInput(conversation, polytomousKey);
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getName()
-        */
-       @Override
-       public String getName() {
-               return key.getTitleCache();
-       }
-       
-       @Override
-       public PolytomousKey getKey() {
-               return key;
-       }
-       
-       /* (non-Javadoc)
-        * @see java.lang.Object#equals(java.lang.Object)
-        */
-       @Override
-       public boolean equals(Object object) {
-               if (object instanceof PolytomousKeyEditorInput
-                               && getKey() != null
-                               && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
-               ){
-                       return true;
-               }
-               return super.equals(object);
-       }
-}
+        List<String> polytomousKeyNodePropertyPaths = Arrays.asList(new String[] {
+                "statement" //$NON-NLS-1$
+        });
+         propertyPathsMap.put("children", polytomousKeyNodePropertyPaths); //$NON-NLS-1$
+         return propertyPathsMap;
+    }
+}
\ No newline at end of file