Refactoring of property change handling. Also fixes #2363
authorn.hoffmann <n.hoffmann@localhost>
Tue, 7 Jun 2011 13:10:55 +0000 (13:10 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 7 Jun 2011 13:10:55 +0000 (13:10 +0000)
17 files changed:
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialogs/filteredSelection/AbstractFilteredCdmResourceSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialogs/filteredSelection/ReferenceSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/AbstractCdmFormElement.java
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/classification/ClassificationDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/PolytomousKeyNodeDetailElement.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/occurrence/FieldObservationDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/GatheringEventDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/GeneralDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/ReferenceSelectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/CdmSectionPart.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java

index 0525acbbd6cdb37a84a69d0d2bd0f31dce3fe086..38cd1c5b7d076e10dc66d215463bea3def3bddd2 100644 (file)
@@ -199,9 +199,14 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmB
         * @return a {@link java.lang.String} object.
         */
        protected String getTitle(T cdmObject) {
+               if(cdmObject == null){
+                       return "";
+               }
+               
                if (cdmObject instanceof IIdentifiableEntity) {
                        return ((IIdentifiableEntity) cdmObject).getTitleCache();                       
                }
+               
                throw new IllegalArgumentException("Generic method only" +
                                " supports cdmObject of type IIdentifiableEntity." +
                                " Please implement specific method in subclass.");
index 175049c442719b5c9cb06abd5c1df1075c43269f..35a7f53da4fa396f17ece1f465e6ccd791d99b52 100644 (file)
@@ -82,7 +82,9 @@ public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelecti
        /** {@inheritDoc} */
        @Override
        protected String getTitle(Reference cdmObject) {
-               if(cdmObject.getAuthorTeam() == null){
+               if(cdmObject == null){
+                       return "";
+               }else if(cdmObject.getAuthorTeam() == null){
                        return super.getTitle(cdmObject);
                }else{
                        return ReferenceBaseDefaultCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorTeam().getTitleCache());
index 8a57b0aa28e17f61f9a926846aa7fee6e26ceef5..d372d15ff39fcb6e1d7be987ac64784d4a9a1cca 100644 (file)
@@ -13,6 +13,7 @@ import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
 import org.eclipse.ui.forms.widgets.Section;
 
 import eu.etaxonomy.taxeditor.store.StoreUtil;
@@ -233,11 +234,20 @@ public abstract class AbstractCdmFormElement implements IPropertyChangeEmitter,
        /** {@inheritDoc} */
        public void firePropertyChangeEvent(CdmPropertyChangeEvent event) {
                Assert.isNotNull(propertyChangeListeners, "Property change listeners are not present");
+               
                for(Object listener : propertyChangeListeners){
                        ((IPropertyChangeListener)listener).propertyChange(event);
                }
        }
        
+       public void firePropertyChangeEvent(Object object){
+               firePropertyChangeEvent(object, null);
+       }
+       
+       public void firePropertyChangeEvent(Object object, PropertyChangeEvent originatingEvent){
+               firePropertyChangeEvent(new CdmPropertyChangeEvent(object, originatingEvent));
+       }
+       
 
        /**
         * {@inheritDoc}
index dac11ef17b9ada4aaa38089319a8f872c2ffcd62..f20cd8780a9ed1cd16b200d0cb9f95331fcca692 100644 (file)
@@ -185,9 +185,11 @@ public abstract class AbstractCdmDetailElement<T> extends
                                                return;
                                        }
                                }
-                               
+                               // call specific handler implementation
                                handleEvent(eventSource);
-                               
+                               // refire the event
+                               firePropertyChangeEvent(this, event);
+                               // update possible parents
                                updateParentSection();
                        }
                }
@@ -210,7 +212,7 @@ public abstract class AbstractCdmDetailElement<T> extends
        }
 
        /**
-        * <p>handleEvent</p>
+        * Gets called when the source of the event is a child widget of this widget.
         *
         * @param eventSource a {@link java.lang.Object} object.
         */
index 05c499996243b093b06bb4c532e9302c7dea5a3a..25821d71a5b18f3ef8f566e9f076980bc19d76ec 100644 (file)
@@ -106,7 +106,5 @@ public class ClassificationDetailElement extends
                } else if (eventSource == text_microReference) {
                        getEntity().setMicroReference(text_microReference.getText());
                }
-
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }
index 0240d1caab934585ce2d84af9084b2ffece37547..f45d1264796317b156b4ef13be94a63e8606c8c4 100644 (file)
@@ -157,9 +157,6 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode>
                } else if (eventSource == checkbox_openInEditor) {
                        setOpenInEditor(checkbox_openInEditor.getSelection());
                }
-
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
-
        }
 
        /**
index 2b004eaa0d2dffb656d205c7806404ae5410715f..defd67798f5bcdf08149bf547662fc0d3e8d7cf6 100644 (file)
@@ -114,7 +114,5 @@ public class PolytomousKeyNodeDetailElement extends
                } else if (eventSource == selection_otherNode) {
                        getEntity().setOtherNode(selection_otherNode.getEntity());
                }
-
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }
index 2b8e6b33a78359f5c2bedf1b09456d1065d12b3d..6cb687c411a2783fd522a7a138aa37e66a8c502c 100644 (file)
@@ -62,7 +62,6 @@ public class HybridDetailElement extends AbstractCdmDetailElement<NonViralName>
                else if(eventSource == checkbox_trinomHybrid){
                        getEntity().setTrinomHybrid(checkbox_trinomHybrid.getSelection());
                }
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 
 }
index 6ae1fa914d639d3fa56a0bb909a2c0c3956e4594..0823179168a970ab6730312e3395cedf664c5f46 100644 (file)
@@ -21,7 +21,6 @@ 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;
 import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
@@ -29,7 +28,6 @@ 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.section.AbstractCdmDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 import eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement;
 
@@ -176,7 +174,8 @@ public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<N
        public void handleEvent(Object eventSource){
                if(eventSource == combo_rank){
                        getEntity().setRank(combo_rank.getSelection());
-                       clearCheckRankWarnings();       
+                       clearCheckRankWarnings();
+                       updateContent();
                }               
                else if(eventSource == text_appendedPhrase){
                        getEntity().setAppendedPhrase(text_appendedPhrase.getText());
@@ -199,16 +198,6 @@ public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<N
                else if(eventSource == checkbox_anamorphic){
                        ((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
                }
-               
-               
-               if(eventSource != toggleable_cache && !toggleable_cache.getLayoutComposite().isDisposed()){
-                       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));
        }
                
        /*
index e72ba626d2784de5f6377515303f8e279078e271..819e6f6e3d7313180d446bf29e547dde44865788 100644 (file)
@@ -145,16 +145,11 @@ public class NonViralNameDetailElement extends
        @Override
        public void handleEvent(Object eventSource) {
                if (eventSource == toggleable_cache) {
-                       getEntity().setTitleCache(toggleable_cache.getText(),
-                                       toggleable_cache.getState());
+                       handleToggleableCacheField();
                        // we never want the fullTitleCache to be protected since we only
                        // use it for
                        // initiating the free text name editor
                        getEntity().setProtectedFullTitleCache(false);
-                       boolean irrelevant = toggleable_cache.getState();
-                       List<Object> except = Arrays
-                                       .asList(new Object[] { toggleable_cache });
-                       setIrrelevant(irrelevant, except);
                } else if (eventSource == section_name || eventSource == section_author) {
                        if (getParentElement() instanceof AbstractCdmDetailSection)
                                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
@@ -166,7 +161,5 @@ public class NonViralNameDetailElement extends
                        section_name.setEntity(getEntity());
                        getLayoutComposite().layout();
                }
-
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }
index cbf150ff11fb645d87214617df0e6b73156d6664..735fac83d2bab8ec912bf502e754210f218cc5dc 100644 (file)
@@ -95,6 +95,5 @@ public class FieldObservationDetailElement extends AbstractCdmDetailElement<Deri
                else if(eventSource == combo_sex){
                        getEntity().setSex(combo_sex.getSelection());
                }
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }
index 73a01940ba71b3e9b0ffe6cc0f32593083a36e0a..f47e243da2ff0da7e5a6606f3c59eb0b193a0f4e 100644 (file)
@@ -154,6 +154,5 @@ public class GatheringEventDetailElement extends
                        getEntity().setGatheringEventDescription(
                                        text_gatheringEventDescription.getText());
                }
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }
index 91eb4e87a10ecdbfe7d894fb9dfd785e46654146..1f0e004105431ed067f626bbc7de77c600dbea8a 100644 (file)
@@ -133,7 +133,6 @@ public class GeneralDetailElement extends
                if (eventSource != toggleableText_titleCache) {
                        toggleableText_titleCache.setText(getEntity().getTitleCache());
                }
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 
 }
index 60dc85c60e7506e72b90f018177e9a9ee349e4a4..5489fc70158e6004975b8cc1e39ceb095dbf7df4 100644 (file)
@@ -110,7 +110,6 @@ public class UserDetailElement extends AbstractCdmDetailElement<User> {
                        getEntity().setCredentialsNonExpired(
                                        checkbox_credentialsNonExpired.getSelection());
                }
-               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 
 }
index d5bdc19487ac06c9e402a4f8205b3f74e20b1120..18629c9aec8f74f09dd89bb11995cd51a17ff025 100644 (file)
@@ -68,11 +68,13 @@ public class ReferenceSelectionElement extends
                Reference newSelection = ReferenceSelectionDialog.select(getShell(),
                                getConversationHolder(), entity);
 
-               Reference freshlyLoadedSelection = null;
-               if (newSelection != null)
-                       freshlyLoadedSelection = CdmStore.getService(
-                                       IReferenceService.class).load(newSelection.getUuid());
-
-               setSelectionInternal(freshlyLoadedSelection);
+               setSelectionInternal(newSelection);
+               
+//             Reference freshlyLoadedSelection = null;
+//             if (newSelection != null)
+//                     freshlyLoadedSelection = CdmStore.getService(
+//                                     IReferenceService.class).load(newSelection.getUuid());
+//
+//             setSelectionInternal(freshlyLoadedSelection);
        }
 }
index 2a8321d4287ae0a5f59d235cc70620327ef9ccc6..097d78afeb6c0f8c21542d06914b622da99c7861 100644 (file)
@@ -23,7 +23,7 @@ import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
-import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
 
@@ -103,8 +103,8 @@ public class CdmSectionPart<T> extends SectionPart implements
                        Object eventSource = event.getSource();
 
                        if (formSection.equals(eventSource)
-                                       || (eventSource instanceof ICdmFormElement && formSection
-                                                       .containsFormElement((ICdmFormElement) eventSource))) {
+                                       || (eventSource instanceof AbstractCdmDetailElement && formSection
+                                                       .containsFormElement((AbstractCdmDetailElement) eventSource))) {
                                markDirty();
                        }
                }
index 941e099f317aa236e5aa933549a8c74c80be93da..e9ed4f3d393429d18390ac80262673ebe7bef048 100644 (file)
@@ -115,10 +115,10 @@ public class DetailsViewer extends AbstractCdmDataViewer {
                super(parent, viewPart);
        }
 
-       // START HACK TO MAKE THE DERIVED UNIT FACADE WORKING
+       // START HACK TO MAKE THE DERIVED UNIT FACADE WORK
        // since we are getting implementations of DerivedUnitBase from the bulk
        // editor
-       // and not derived unit base objects,
+       // and not derived unit facade objects,
 
        /*
         * (non-Javadoc)
@@ -150,7 +150,7 @@ public class DetailsViewer extends AbstractCdmDataViewer {
                super.markViewPartDirty();
        }
 
-       // END HACK TO MAKE THE DERIVED UNIT FACADE WORKING
+       // END HACK TO MAKE THE DERIVED UNIT FACADE WORK
 
        /*
         * (non-Javadoc)