Fixes #2422
authorn.hoffmann <n.hoffmann@localhost>
Mon, 30 May 2011 14:21:55 +0000 (14:21 +0000)
committern.hoffmann <n.hoffmann@localhost>
Mon, 30 May 2011 14:21:55 +0000 (14:21 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/AuthorshipDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/HybridDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NonViralNameDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonBaseDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonBaseDetailSection.java

index 252402155bf2fd98a7a72e9f95b64daa3195e2f7..dac11ef17b9ada4aaa38089319a8f872c2ffcd62 100644 (file)
@@ -18,6 +18,8 @@ import org.eclipse.swt.widgets.Composite;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement;
@@ -169,6 +171,8 @@ public abstract class AbstractCdmDetailElement<T> extends
                        return;
                }
                
+               handleTitleCacheRelevantChange(event);
+               
                Object eventSource = event.getSource();
                
                if(eventSource instanceof ICdmFormElement){
@@ -183,12 +187,28 @@ public abstract class AbstractCdmDetailElement<T> extends
                                }
                                
                                handleEvent(eventSource);
-                               if(getParentElement() instanceof AbstractCdmDetailSection)
-                                       ((AbstractCdmDetailSection)getParentElement()).updateTitle();
+                               
+                               updateParentSection();
                        }
                }
        }
 
+       protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
+               boolean isRelevant = getEntity() instanceof TaxonNameBase || getEntity() instanceof TaxonBase;
+               isRelevant &= this instanceof AbstractIdentifiableEntityDetailElement; 
+               
+               if(isRelevant){
+                       ((AbstractIdentifiableEntityDetailElement) this).updateToggleableCacheField();
+                       updateParentSection();
+               }
+       }
+       
+       private void updateParentSection(){
+               if(getParentElement() instanceof AbstractCdmDetailSection){
+                       ((AbstractCdmDetailSection) getParentElement()).updateTitle();
+               }
+       }
+
        /**
         * <p>handleEvent</p>
         *
index 859c892c213fb27bc752a51cf7316da57e6882a5..5e6516ff6f384bdb7b990a816011ae142a8a8d4e 100644 (file)
@@ -138,7 +138,7 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSecti
                if(getEntity() != null && (getEntity() instanceof IdentifiableEntity)){
                         title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
                }
-               this.setText(getHeading() + title);
+               this.setText(String.format("%s%s", getHeading(), title));
                setTextClient(createToolbar());
        }
        
index 776d6835084c8c8ca1ce443940f8da3a72b968ec..4cd5efe012e137b8e70421cbe2d6fd45d70ededf 100644 (file)
@@ -23,7 +23,13 @@ public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentif
                        ICdmFormElement formElement) {
                super(formFactory, formElement);
        }
-
+       
+       public void updateToggleableCacheField(){
+               if(! getEntity().isProtectedTitleCache()){
+                       toggleable_cache.setText(getEntity().generateTitle());
+               }
+       }
+       
        protected void handleToggleableCacheField(){
                boolean pushedState = toggleable_cache.getState();
                
@@ -31,8 +37,6 @@ public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentif
                                pushedState);
                setIrrelevant(pushedState,
                                Arrays.asList(new Object[] { toggleable_cache }));
-               if(! pushedState){
-                       toggleable_cache.setText(getEntity().generateTitle());
-               }
+               updateToggleableCacheField();
        }       
 }
index b84715445ad9db4942445c11d7fbfff8cb5a2ba5..f210ebd88101f48375fafe766507a63f50f46456 100644 (file)
@@ -20,9 +20,8 @@ import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
 import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
-import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 import eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement;
 import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
 
@@ -36,11 +35,9 @@ import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionEleme
  * @version 1.0
  */
 public class AuthorshipDetailElement extends
-               AbstractCdmDetailElement<NonViralName> implements
+       AbstractIdentifiableEntityDetailElement<NonViralName> implements
                IEnableableFormElement {
 
-       private ToggleableTextElement toggleable_cache;
-
        private AbstractSelectionElement selection_exBasionymAuthorTeam;
        private AbstractSelectionElement selection_basionymAuthorTeam;
        private AbstractSelectionElement selection_exCombinationAuthorTeam;
@@ -145,15 +142,22 @@ public class AuthorshipDetailElement extends
                                                        .getSelection());
                }
 
-               if (eventSource != toggleable_cache) {
-                       toggleable_cache.setText(getEntity().getAuthorshipCache());
-               }
+//             if (eventSource != toggleable_cache) {
+//                     toggleable_cache.setText(getEntity().getAuthorshipCache());
+//             }
 
-               // we have to notify the parent if this is embedded in the nonviral name
-               // section
-               // maybe we can handle this a little bit more elegant
-               if (getParentElement() instanceof AbstractCdmDetailSection)
+//              we have to notify the parent if this is embedded in the nonviral name
+//              section
+//              maybe we can handle this a little bit more elegant
+//             if (getParentElement() instanceof AbstractCdmDetailSection)
                        firePropertyChangeEvent(new CdmPropertyChangeEvent(
                                        getParentElement(), null));
        }
+       
+       @Override
+       public void updateToggleableCacheField() {
+               if(! getEntity().isProtectedAuthorshipCache()){
+                       toggleable_cache.setText(getEntity().getAuthorshipCache());
+               }
+       }
 }
index b55c3f5a17f5e86416e4285d80d9761a82855758..2b8e6b33a78359f5c2bedf1b09456d1065d12b3d 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.ui.section.name;
 
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
@@ -55,12 +56,13 @@ public class HybridDetailElement extends AbstractCdmDetailElement<NonViralName>
                if(eventSource == checkbox_monomHybrid){
                        getEntity().setMonomHybrid(checkbox_monomHybrid.getSelection());
                }
-               else if(eventSource == checkbox_monomHybrid){
+               else if(eventSource == checkbox_binomHybrid){
                        getEntity().setBinomHybrid(checkbox_binomHybrid.getSelection());
                }
-               else if(eventSource == checkbox_monomHybrid){
+               else if(eventSource == checkbox_trinomHybrid){
                        getEntity().setTrinomHybrid(checkbox_trinomHybrid.getSelection());
                }
+               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 
 }
index 127445c697f468a5645d5a95ec908972a6544fee..6ae1fa914d639d3fa56a0bb909a2c0c3956e4594 100644 (file)
@@ -20,6 +20,7 @@ import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.ZoologicalName;
 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
 import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
@@ -28,10 +29,8 @@ import eu.etaxonomy.taxeditor.ui.forms.ISelectableElement;
 import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator;
 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 import eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement;
 
 /**
@@ -41,9 +40,8 @@ import eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement;
  * @created Feb 26, 2010
  * @version 1.0
  */
-public class NameDetailElement extends AbstractCdmDetailElement<NonViralName> implements ISelectableElement, IEnableableFormElement{
+public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<NonViralName> implements ISelectableElement, IEnableableFormElement{
 
-       private ToggleableTextElement toggleable_cache;
        private AbstractTermComboElement<Rank> combo_rank;
        private TextWithLabelElement text_appendedPhrase;
        private TextWithLabelElement text_uninomial;
@@ -184,9 +182,7 @@ public class NameDetailElement extends AbstractCdmDetailElement<NonViralName> im
                        getEntity().setAppendedPhrase(text_appendedPhrase.getText());
                }
                else if(eventSource == toggleable_cache){
-                       getEntity().setNameCache(toggleable_cache.getText(), toggleable_cache.getState());
-                       //setEnabled(! text_nameCache.getState(), Arrays.asList(new Object[]{text_nameCache, combo_nomenclaturalCode}));
-                       if(! isIrrelevant()) setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
+                       handleToggleableCacheField();
                }
                else if(eventSource == text_infragenericEpithet){
                        getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
@@ -209,10 +205,10 @@ public class NameDetailElement extends AbstractCdmDetailElement<NonViralName> im
                        toggleable_cache.setText(getEntity().getNameCache());
                }
                
-               // we have to notify the parent if this is embedded in the nonviral name section
-               // maybe we can handle this a little bit more elegant
-               if(getParentElement() instanceof AbstractCdmDetailSection)
-                       firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));
+//             // we have to notify the parent if this is embedded in the nonviral name section
+//             // maybe we can handle this a little bit more elegant
+//             if(getParentElement() instanceof AbstractCdmDetailSection)
+//                     firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));
        }
                
        /*
@@ -227,4 +223,11 @@ public class NameDetailElement extends AbstractCdmDetailElement<NonViralName> im
        public SelectionArbitrator getSelectionArbitrator() {
                return selectionArbitrator;
        }
+       
+       @Override
+       public void updateToggleableCacheField() {
+               if(! getEntity().isProtectedNameCache()){
+                       toggleable_cache.setText(getEntity().getNameCache());
+               }
+       }
 }
index 17b19a994e519479e858d79b8e9d201e5a892fec..e72ba626d2784de5f6377515303f8e279078e271 100644 (file)
@@ -21,9 +21,8 @@ import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EnumComboType;
 import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 import eu.etaxonomy.taxeditor.ui.term.NomenclaturalCodeComboElement;
 
 /**
@@ -36,11 +35,10 @@ import eu.etaxonomy.taxeditor.ui.term.NomenclaturalCodeComboElement;
  * @version 1.0
  */
 public class NonViralNameDetailElement extends
-               AbstractCdmDetailElement<NonViralName> {
+       AbstractIdentifiableEntityDetailElement<NonViralName> {
 
        private NameDetailSection section_name;
        private AuthorshipDetailSection section_author;
-       private ToggleableTextElement toggleable_cache;
        private NomenclaturalCodeComboElement combo_nomenclaturalCode;
 
        /**
index 392e6dc673a8dc6a58e9c849c066bcee88cd0686..b0d5b881d345cb6158897bed69fa56cb073dd67c 100644 (file)
@@ -23,10 +23,7 @@ import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 import eu.etaxonomy.taxeditor.ui.selection.ReferenceSelectionElement;
 
 /**
@@ -38,7 +35,7 @@ import eu.etaxonomy.taxeditor.ui.selection.ReferenceSelectionElement;
  * @created Feb 26, 2010
  * @version 1.0
  */
-public class TaxonBaseDetailElement extends AbstractCdmDetailElement<TaxonBase> {
+public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase> {
 
        private CheckboxElement checkbox_doubtful;
 
@@ -48,8 +45,6 @@ public class TaxonBaseDetailElement extends AbstractCdmDetailElement<TaxonBase>
 
        private TextWithLabelElement text_appendedPhrase;
 
-       private ToggleableTextElement toggleable_cache;
-
        private CheckboxElement checkbox_excluded;
 
        private CheckboxElement checkbox_unplaced;
@@ -110,37 +105,19 @@ public class TaxonBaseDetailElement extends AbstractCdmDetailElement<TaxonBase>
                setIrrelevant(toggleable_cache.getState(),
                                Arrays.asList(new Object[] { toggleable_cache }));
        }
-
-       /** {@inheritDoc} */
+       
        @Override
-       public void propertyChange(PropertyChangeEvent event) {
-               Object eventSource = event.getSource();
-               if (eventSource instanceof ICdmFormElement) {
-                       ICdmFormElement element = (ICdmFormElement) eventSource;
-                       ICdmFormElement parentElement = element.getParentElement();
-                       if (parentElement instanceof NonViralNameDetailElement) {
-                               String title = getEntity().generateTitle();
-                               getEntity().setTitleCache(title);
-                               toggleable_cache.setText(title);
-                               if (getParentElement() instanceof AbstractCdmDetailSection)
-                                       ((AbstractCdmDetailSection) getParentElement())
-                                                       .updateTitle();
-                       }
-               }
-
-               super.propertyChange(event);
+       protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
+               String title = getEntity().generateTitle();
+               getEntity().setTitleCache(title);
+               super.handleTitleCacheRelevantChange(event);
        }
 
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
                if (eventSource.equals(toggleable_cache)) {
-                       getEntity().setTitleCache(toggleable_cache.getText(),
-                                       toggleable_cache.getState());
-                       // setEnabled(! toggleable_titleCache.getState(), Arrays.asList(new
-                       // Object[]{toggleable_titleCache}));
-                       setIrrelevant(toggleable_cache.getState(),
-                                       Arrays.asList(new Object[] { toggleable_cache }));
+                       handleToggleableCacheField();
                } else if (eventSource.equals(checkbox_doubtful)) {
                        getEntity().setDoubtful(checkbox_doubtful.getSelection());
                } else if (eventSource.equals(checkbox_useNameCache)) {
@@ -155,9 +132,6 @@ public class TaxonBaseDetailElement extends AbstractCdmDetailElement<TaxonBase>
                        ((Taxon) getEntity()).setUnplaced(checkbox_unplaced.getSelection());
                }
 
-               if (eventSource != toggleable_cache) {
-                       toggleable_cache.setText(getEntity().getTitleCache());
-               }
                firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }
index 6329af4b4c1364a60f302ca94cbbdbc4caafc31b..124d4a157ce5429c797e5e1133f034bc89608b2b 100644 (file)
@@ -16,8 +16,8 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
+import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
 
@@ -68,6 +68,14 @@ public class TaxonBaseDetailSection extends AbstractCdmDetailSection<TaxonBase>
                return DetailType.TAXONBASE;
        }
 
+       @Override
+       protected void setSectionTitle() {
+               if(getEntity().generateTitle().equals(getEntity().getTitleCache())){
+                       System.out.println("test");
+               }
+               super.setSectionTitle();
+       }
+       
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#getTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
         */