fixes #2189
authorn.hoffmann <n.hoffmann@localhost>
Tue, 11 Jan 2011 10:57:57 +0000 (10:57 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 11 Jan 2011 10:57:57 +0000 (10:57 +0000)
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainerTree.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/FeatureMenuPreferences.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/VocabularyTermWizard.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/VocabularyTermWizardPage.java

index 108befda7a077f3bc579e02befe09fb8c600e883..900665e9e54e599c08c09e78cc862039c3863490 100644 (file)
 package eu.etaxonomy.taxeditor.model;
 
 import java.util.ArrayList;
 package eu.etaxonomy.taxeditor.model;
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 import java.util.List;
-import java.util.Set;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
@@ -85,11 +82,17 @@ public class FeatureNodeContainer{
         * @return
         */
        private void buildLeaf(FeatureNode featureNode){
         * @return
         */
        private void buildLeaf(FeatureNode featureNode){
+               if(featureNode.getFeature() == null){
+                       throw new IllegalArgumentException("The given feature node does not have a feature.");
+               }
+               
+               Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
+               
                // get feature node container for the given feature
                // get feature node container for the given feature
-               FeatureNodeContainer container = containerTree.getFeatureNodeContainerByFeature(featureNode.getFeature());
+               FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
                
                // get description elements for the given feature
                
                // get description elements for the given feature
-               List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(featureNode.getFeature());
+               List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(feature);
                // no description elements, so we should also remove the feature node container
                if(elements.isEmpty()){
                        if(container != null){
                // no description elements, so we should also remove the feature node container
                if(elements.isEmpty()){
                        if(container != null){
@@ -143,8 +146,11 @@ public class FeatureNodeContainer{
                        if(parentFeatureNode.isRoot()){
                                containerTree.getRoot().addChild(this);
                        }else{
                        if(parentFeatureNode.isRoot()){
                                containerTree.getRoot().addChild(this);
                        }else{
-                               FeatureNodeContainer parentContainer = new FeatureNodeContainer(containerTree);
-                               parentContainer.setFeatureNode(parentFeatureNode);
+                               FeatureNodeContainer parentContainer = containerTree.getFeatureNodeContainer(parentFeatureNode);
+                               if(parentContainer == null){
+                                       parentContainer = new FeatureNodeContainer(containerTree);
+                                       parentContainer.setFeatureNode(parentFeatureNode);
+                               }
                                
                                parentContainer.addChild(this);
                                
                                
                                parentContainer.addChild(this);
                                
index d7fb13fc4d9d400f109d7797c4c0abbad87c52f6..8af49fff076237e893fe768204d2ad949d7912d9 100644 (file)
@@ -121,7 +121,7 @@ public class FeatureNodeContainerTree {
        }
        
        
        }
        
        
-       public FeatureNodeContainer getFeatureNodeContainerByFeature(Feature feature) {         
+       public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {          
                List<FeatureNodeContainer> leafs = root.getLeafs();
                
                for(FeatureNodeContainer container : leafs){
                List<FeatureNodeContainer> leafs = root.getLeafs();
                
                for(FeatureNodeContainer container : leafs){
@@ -132,6 +132,17 @@ public class FeatureNodeContainerTree {
                return null;
        }
        
                return null;
        }
        
+       public FeatureNodeContainer getFeatureNodeContainer(FeatureNode featureNode){
+               List<FeatureNodeContainer> leafs = root.getLeafs();
+               
+               for(FeatureNodeContainer container : leafs){
+                       if(container.getFeatureNode().equals(featureNode)){
+                               return container;
+                       }
+               }
+               return null;
+       }
+       
        public void addContainer(FeatureNodeContainer container){
                featureNodeContainers.add(container);
        }
        public void addContainer(FeatureNodeContainer container){
                featureNodeContainers.add(container);
        }
index fd82c3c82690f071e255dbf86ad46ed662860191..e1391acc63d0542042d2ef270afe2135d057001f 100644 (file)
@@ -87,6 +87,7 @@ public class FeatureMenuPreferences extends AbstractMenuPreferences<Feature> {
                                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
                            dialog.open();
                            
                                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
                            dialog.open();
                            
+                           
                            tableViewer.setInput(TermStore.getFeatures());
                            tableViewer.reveal(selection);
                        }
                            tableViewer.setInput(TermStore.getFeatures());
                            tableViewer.reveal(selection);
                        }
index efed7f53f3edd8dd043c5eadb0fea498994321fc..e143939e09350fb3925fec5da1271f2c5e1019bd 100644 (file)
@@ -13,8 +13,11 @@ package eu.etaxonomy.taxeditor.preference.wizard;
 import org.eclipse.jface.wizard.Wizard;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import org.eclipse.jface.wizard.Wizard;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Representation;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Representation;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.store.TermStore;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.store.TermStore;
@@ -26,7 +29,7 @@ import eu.etaxonomy.taxeditor.store.TermStore;
  * @created 12.06.2009
  * @version 1.0
  */
  * @created 12.06.2009
  * @version 1.0
  */
-public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
+public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard implements IConversationEnabled {
        
        public T term = null;
        
        
        public T term = null;
        
@@ -34,13 +37,16 @@ public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
 
        private Class<T> termClass;
 
 
        private Class<T> termClass;
 
+       private ConversationHolder conversation;
+
        /**
         * <p>Constructor for VocabularyTermWizard.</p>
         *
         * @param vocabularyClass a {@link java.lang.Class} object.
         */
        /**
         * <p>Constructor for VocabularyTermWizard.</p>
         *
         * @param vocabularyClass a {@link java.lang.Class} object.
         */
-       public VocabularyTermWizard(Class<T> vocabularyClass){          
-               this.termClass = vocabularyClass;
+       public VocabularyTermWizard(Class<T> vocabularyClass){  
+               conversation = CdmStore.createConversation();
+               termClass = vocabularyClass;
        }
        
        /**
        }
        
        /**
@@ -51,7 +57,7 @@ public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
         */
        public VocabularyTermWizard(Class<T> vocabularyClass, T selectedTerm){
                this(vocabularyClass);          
         */
        public VocabularyTermWizard(Class<T> vocabularyClass, T selectedTerm){
                this(vocabularyClass);          
-               this.term = selectedTerm;
+               term = (T) CdmStore.getService(ITermService.class).load(selectedTerm.getUuid());
                editMode = true;
        }
        
                editMode = true;
        }
        
@@ -73,15 +79,14 @@ public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
        @Override
        public boolean performFinish() {
 
        @Override
        public boolean performFinish() {
 
-               ConversationHolder conversation = CdmStore.createConversation();
-               
                if(editMode){
                        TermStore.updateVocabulary(getTerm());
                }else{
                        TermStore.saveTerm(getTerm());
                }
                
                if(editMode){
                        TermStore.updateVocabulary(getTerm());
                }else{
                        TermStore.saveTerm(getTerm());
                }
                
-               conversation.commit(false);
+               getConversationHolder().commit(false);
+               getConversationHolder().close();
                
                return true;
        }
                
                return true;
        }
@@ -134,6 +139,10 @@ public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
        public T getTerm() {
                return term;
        }
        public T getTerm() {
                return term;
        }
+       
+       public Representation getRepresentation(){
+               return term != null ? term.getRepresentation(CdmStore.getDefaultLanguage()) : null;
+       }
 
        /**
         * <p>isEditMode</p>
 
        /**
         * <p>isEditMode</p>
@@ -153,4 +162,21 @@ public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard {
                return termClass;
        }
 
                return termClass;
        }
 
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       @Override
+       public void update(CdmDataChangeMap changeEvents) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+        */
+       @Override
+       public ConversationHolder getConversationHolder() {
+               return conversation;
+       }
+
 }
 }
index af1273f12bf65d1ebc9afa116ec72eeadfdce677..ffb37c01138bb23cfce61a2ecfe6f3835e90769d 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Representation;
 
 /**
  * <p>VocabularyTermWizardPage class.</p>
 
 /**
  * <p>VocabularyTermWizardPage class.</p>
@@ -35,8 +36,6 @@ public class VocabularyTermWizardPage<T extends DefinedTermBase> extends WizardP
        private Text text_label;
        private Text text_labelAbbreviation;
        private Text text_description;
        private Text text_label;
        private Text text_labelAbbreviation;
        private Text text_description;
-
-       private T term = null;
        
        /**
         * <p>Constructor for VocabularyTermWizardPage.</p>
        
        /**
         * <p>Constructor for VocabularyTermWizardPage.</p>
@@ -90,13 +89,11 @@ public class VocabularyTermWizardPage<T extends DefinedTermBase> extends WizardP
                
                setControl(composite);
                
                
                setControl(composite);
                
-               if(getWizard().getTerm() != null){
-                       DefinedTermBase<T> term = getWizard().getTerm();
-                       text_label.setText(term.getLabel());
-                       // why can't we access labelAbbreviation
-//                     text_labelAbbreviation.setText(feature.get)
-                       // why can't we access the term string?
-//                     text_description.setText(feature.getT)
+               if(getWizard().getRepresentation() != null){
+                       Representation representation = getWizard().getRepresentation();
+                       text_label.setText(representation.getLabel());
+                       text_labelAbbreviation.setText(representation.getAbbreviatedLabel());
+                       text_description.setText(representation.getDescription());
                }
                
                setPageComplete(false);
                }
                
                setPageComplete(false);
@@ -108,11 +105,22 @@ public class VocabularyTermWizardPage<T extends DefinedTermBase> extends WizardP
         */
        /** {@inheritDoc} */
        public void modifyText(ModifyEvent e) {
         */
        /** {@inheritDoc} */
        public void modifyText(ModifyEvent e) {
+               Object eventSource = e.getSource();
+               if(eventSource == text_label){
+                       getWizard().getRepresentation().setLabel(text_label.getText());
+               }
+               else if(eventSource == text_labelAbbreviation){
+                       getWizard().getRepresentation().setAbbreviatedLabel(text_labelAbbreviation.getText());
+               }
+               else if(eventSource == text_description){
+                       getWizard().getRepresentation().setText(text_description.getText());
+               }  
+               
+               
                if(text_label.getText().length() > 0){
                        setPageComplete(true);
                if(text_label.getText().length() > 0){
                        setPageComplete(true);
-                               
-                       getWizard().setTerm(text_description.getText(), text_label.getText(), text_labelAbbreviation.getText());
-               } else {
+               }
+               else {
                        setPageComplete(false);
                }
        }
                        setPageComplete(false);
                }
        }