#5277 Correct session intialisation and default feature tree caching
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 1 Dec 2015 15:01:06 +0000 (16:01 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 1 Dec 2015 15:03:07 +0000 (16:03 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptiveContentProvider.java
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermEditor.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/input/AbstractDefinedTermEditorInput.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/input/TermEditorInput.java

index 33626cb..b0aeb0f 100644 (file)
@@ -20,6 +20,7 @@ import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.cdm.model.description.IDescribable;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
+import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
@@ -38,7 +39,7 @@ public class DescriptiveContentProvider implements ITreeContentProvider {
        protected static final Object[] NO_CHILDREN = new Object[0];
        protected Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache;
        private boolean showOnlyIndividualAssociations;
-       private static FeatureTree defaultFeatureTree = null;
+
 
        public DescriptiveContentProvider(Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache) {
            this(featureNodeContainerCache, false);
@@ -146,9 +147,6 @@ public class DescriptiveContentProvider implements ITreeContentProvider {
         */
        private FeatureTree getFeatureTree(DescriptionBase description){
 
-           if(defaultFeatureTree == null) {
-               defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
-           }
            FeatureTree featureTree;
                // TODO change this to the feature tree associated with this taxon description
                if (description.hasStructuredData()){
@@ -159,7 +157,7 @@ public class DescriptiveContentProvider implements ITreeContentProvider {
 
                // create a transient tree with all features if none was selected
                if(featureTree == null){
-                       featureTree = defaultFeatureTree;
+                       featureTree = TermEditorInput.getDefaultFeatureTree();
                }
 
                return featureTree;
index 4629862..2b42986 100644 (file)
@@ -12,6 +12,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.dnd.transfer,
  eu.etaxonomy.taxeditor.editor,
  eu.etaxonomy.taxeditor.editor.definedterm,
+ eu.etaxonomy.taxeditor.editor.definedterm.input,
  eu.etaxonomy.taxeditor.featuretree,
  eu.etaxonomy.taxeditor.handler,
  eu.etaxonomy.taxeditor.io,
index 3c16224..11bea5c 100644 (file)
@@ -9,11 +9,6 @@
  */\r
 package eu.etaxonomy.taxeditor.editor.definedterm;\r
 \r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
 import org.eclipse.core.runtime.IProgressMonitor;\r
 import org.eclipse.jface.action.GroupMarker;\r
 import org.eclipse.jface.action.MenuManager;\r
@@ -40,17 +35,12 @@ import org.eclipse.ui.part.EditorPart;
 \r
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;\r
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;\r
-import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
 import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
 import eu.etaxonomy.cdm.model.common.OrderedTermBase;\r
-import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;\r
 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;\r
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;\r
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;\r
-import eu.etaxonomy.taxeditor.session.ICdmEntitySession;\r
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;\r
 import eu.etaxonomy.taxeditor.store.CdmStore;\r
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;\r
 \r
@@ -59,7 +49,7 @@ import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
  * @date 3 Jan 2012\r
  *\r
  */\r
-public class DefinedTermEditor extends EditorPart implements IConversationEnabled, ISelectionListener, IDirtyMarkable, IPostOperationEnabled, ICdmEntitySessionEnabled {\r
+public class DefinedTermEditor extends EditorPart implements IConversationEnabled, ISelectionListener, IDirtyMarkable, IPostOperationEnabled {\r
 \r
        public static final String ID = "eu.etaxonomy.taxeditor.editor.definedTerm";\r
 \r
@@ -70,8 +60,6 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
        private ISelectionService selectionService;\r
        private boolean dirty;\r
 \r
-       private final ICdmEntitySession cdmEntitySession;\r
-\r
 \r
        private final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;\r
        /**\r
@@ -80,7 +68,6 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
        public DefinedTermEditor() {\r
                super();\r
                conversation = CdmStore.createConversation();\r
-               cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);\r
        }\r
 \r
        @Override\r
@@ -161,9 +148,7 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
        @Override\r
        public void doSave(IProgressMonitor monitor) {\r
                getConversationHolder().commit();\r
-               if(CdmStore.getCurrentSessionManager().isRemoting()) {\r
-                   CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()), true);\r
-               }\r
+               getDefinedTermEditorInput().merge();\r
                setDirty(false);\r
                getDefinedTermEditorInput().initialiseVocabularies();\r
                viewer.refresh();\r
@@ -194,7 +179,7 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
        public void setFocus() {\r
            viewer.getControl().setFocus();\r
                getConversationHolder().bind();\r
-               cdmEntitySession.bind();\r
+               getDefinedTermEditorInput().bind();\r
        }\r
 \r
        @Override\r
@@ -275,34 +260,7 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
 \r
        @Override\r
        public void dispose() {\r
-           cdmEntitySession.dispose();\r
+           getDefinedTermEditorInput().dispose();\r
            super.dispose();\r
        }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()\r
-     */\r
-    @Override\r
-    public ICdmEntitySession getCdmEntitySession() {\r
-        return cdmEntitySession;\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()\r
-     */\r
-    @Override\r
-    public Set<TermVocabulary<DefinedTermBase>> getRootEntities() {\r
-        return getDefinedTermEditorInput().getVocabularies();\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()\r
-     */\r
-    @Override\r
-    public Map<Object, List<String>> getPropertyPathsMap() {\r
-        // TODO Auto-generated method stub\r
-        return null;\r
-    }\r
-\r
-\r
 }
\ No newline at end of file
index c18d397..0a41321 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$\r
 /**\r
  * Copyright (C) 2009 EDIT\r
- * European Distributed Institute of Taxonomy \r
+ * European Distributed Institute of Taxonomy\r
  * http://www.e-taxonomy.eu\r
- * \r
+ *\r
  * The contents of this file are subject to the Mozilla Public License Version 1.1\r
  * See LICENSE.TXT at the top of this package for the full license terms.\r
  */\r
@@ -16,19 +16,20 @@ import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;\r
 \r
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
+import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;\r
 \r
 /**\r
  * @author l.morris\r
  * @date 3 Jan 2012\r
  *\r
  */\r
-public abstract class AbstractDefinedTermEditorInput<T extends DefinedTermBase> implements IEditorInput {\r
+public abstract class AbstractDefinedTermEditorInput<T extends DefinedTermBase> extends CdmEntitySessionInput implements IEditorInput {\r
 \r
        /**\r
-        * \r
+        *\r
         */\r
        public AbstractDefinedTermEditorInput() {\r
-               super();\r
+               super(true);\r
        }\r
 \r
        @Override\r
@@ -59,7 +60,7 @@ public abstract class AbstractDefinedTermEditorInput<T extends DefinedTermBase>
        /**\r
         * @return\r
         */\r
-       public abstract List<String> getTermClasses();          \r
+       public abstract List<String> getTermClasses();\r
+\r
 \r
-       \r
 }
\ No newline at end of file
index aef64fe..518382f 100644 (file)
@@ -1,14 +1,15 @@
 // $Id$
 /**
 * Copyright (C) 2009 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.
 */
 package eu.etaxonomy.taxeditor.editor.definedterm.input;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
@@ -19,7 +20,10 @@ import eu.etaxonomy.cdm.model.common.DefinedTerm;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.TermStore;
 
 
 
@@ -32,10 +36,15 @@ public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm>
 
        private TermType termType;
        private Set<TermVocabulary<DefinedTermBase>> vocabularies;
+
+       // FIXME: the default feature should be move to CdmApplicationState
+       //        where it is a singleton instance variable
+       private static FeatureTree defaultFeatureTree = null;
+
        private List<String> termClasses = Arrays.asList(new String[]{
                        DefinedTerm.class.getName()
        });
-       
+
        public TermEditorInput(TermType termType) {
                this.termType = termType;
                vocabularies = new HashSet<TermVocabulary<DefinedTermBase>>();
@@ -56,21 +65,52 @@ public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm>
        public List<String> getTermClasses() {
                return termClasses;
        }
-       
+
        public TermType getTermType() {
                return termType;
        }
-       
+
        public void initialiseVocabularies() {
                if(vocabularies != null) {
                        vocabularies.clear();
-               } 
+               }
                List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(termType);
-               vocabularies.addAll(vocs);                      
+               vocabularies.addAll(vocs);
        }
-       
+
        public Set<TermVocabulary<DefinedTermBase>> getVocabularies() {
                return vocabularies;
        }
 
+       public void updateDefaultFeatureTree() {
+           for(TermVocabulary vocab : getVocabularies()) {
+               if(vocab != null && TermType.Feature.equals(vocab.getTermType())) {
+                   defaultFeatureTree = null;
+               }
+           }
+       }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Set<TermVocabulary<DefinedTermBase>>  getRootEntities() {
+        return getVocabularies();
+    }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void merge() {
+        if(CdmStore.getCurrentSessionManager().isRemoting()) {
+            CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()), true);
+            updateDefaultFeatureTree();
+        }
+    }
+
+    public static FeatureTree getDefaultFeatureTree() {
+        if(defaultFeatureTree == null) {
+            defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
+        }
+        return defaultFeatureTree;
+    }
 }
\ No newline at end of file