ref #8200 Replace description label with cache element in details view
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 28 Mar 2019 13:04:55 +0000 (14:04 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 28 Mar 2019 13:04:55 +0000 (14:04 +0100)
 - Fix potential cache update problems

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/FactualDataPartE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionDetailElement.java

index 3a74a725ae0017318ff993081f420d2a0c7a5c43..02c1dfe1a41645297f8800d8c2fa522af5f7b049 100644 (file)
@@ -13,7 +13,6 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -36,15 +35,12 @@ import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Tree;
 
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.IDescribable;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
@@ -209,18 +205,6 @@ public class FactualDataPartE4 extends AbstractCdmEditorPartE4
     @Optional
     private void updateView(@UIEventTopic(WorkbenchEventConstants.SAVE_TAXON)boolean refresh){
         if(refresh){
-            List<? extends CdmBase> rootEntities = getRootEntities();
-            for (CdmBase cdmBase : rootEntities) {
-                if (cdmBase != null){
-                    if(cdmBase.isInstanceOf(Taxon.class)){
-                        Taxon taxon = HibernateProxyHelper.deproxy(cdmBase, Taxon.class);
-                        Set<TaxonDescription> descriptions = taxon.getDescriptions();
-                        for (TaxonDescription taxonDescription : descriptions) {
-                            taxonDescription.setTitleCache(null, false);
-                        }
-                    }
-                }
-            }
             viewer.refresh();
         }
     }
index 7ff50ee6f84f5e87f433249bab1243f1a35b6f25..305e10396a76664619f0c46e7998c708385fbc7a 100644 (file)
@@ -1,23 +1,22 @@
 /**
 * Copyright (C) 2007 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.ui.section.description;
 
-import org.eclipse.swt.SWT;
+import java.util.Arrays;
+
+import org.eclipse.jface.util.PropertyChangeEvent;
 
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
-import eu.etaxonomy.cdm.model.term.FeatureTree;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
-import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 
 /**
  * <p>DescriptionDetailElement class.</p>
@@ -26,46 +25,47 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
  * @created Mar 5, 2010
  * @version 1.0
  */
-public class DescriptionDetailElement extends AbstractCdmDetailElement<DescriptionBase> {
+public class DescriptionDetailElement extends AbstractIdentifiableEntityDetailElement<DescriptionBase> {
 
-       private TextWithLabelElement detailDescription;
-       private EntitySelectionElement<FeatureTree> selection_featureTree;
+//     private EntitySelectionElement<FeatureTree> selection_featureTree;
 
-       /**
-        * <p>Constructor for DescriptionDetailElement.</p>
-        *
-        * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
-        * @param style a int.
-        */
        public DescriptionDetailElement(CdmFormFactory cdmFormFactory,
                        ICdmFormElement formElement, int style) {
                super(cdmFormFactory, formElement);
        }
-       
-       /** {@inheritDoc} */
+
        @Override
        protected void createControls(ICdmFormElement formElement, DescriptionBase entity, int style) {
-               detailDescription = formFactory.createMultiLineTextWithLabel(this, "Label", 50, SWT.WRAP);
-               detailDescription.setText(entity.getTitleCache());
-               
-               // TODO I initially thought that we can handle the entity's descriptive system with a feature tree 
-               // Since descriptiveSystem is a Set of Features that are present or allowed for the current description, 
+        toggleable_cache = formFactory.createToggleableTextField(this, "Label", entity.getTitleCache(), entity.isProtectedTitleCache(), style);
+               // TODO I initially thought that we can handle the entity's descriptive system with a feature tree
+               // Since descriptiveSystem is a Set of Features that are present or allowed for the current description,
                // it is similar to a FeatureTree (you can get this information from a feature tree) but not the same.
                // Please correct this once it is clear what descriptive system will be used for in CDM
 //             selection_featureTree = formFactory.createSelectionElement(FeatureTree.class, getConversationHolder(), formElement, "Feature Tree", null, EntitySelectionElement.ALL, style);
        }
-               
-       /** {@inheritDoc} */
+
+    @Override
+    protected void updateContent() {
+        super.updateContent();
+        toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
+        setIrrelevant(toggleable_cache.getState(),
+                Arrays.asList(new Object[] { toggleable_cache}));
+    }
+
+    @Override
+    protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
+        if(!getEntity().isProtectedTitleCache()){
+            String title = getEntity().generateTitle();
+            getEntity().setTitleCache(title, false);
+        }
+        super.updateToggleableCacheField();
+    }
+
        @Override
        public void handleEvent(Object eventSource) {
-               if(eventSource == detailDescription){
-                       getEntity().setTitleCache(detailDescription.getText(), true);
-               }
-               else if(eventSource == selection_featureTree){
-                       FeatureTree featureTree = selection_featureTree.getSelection();
-                       //descriptive system is not available anymore since v3.3 
-//                     getEntity().setDescriptiveSystem(featureTree.getDistinctFeatures());
-               }
+        if (eventSource == toggleable_cache) {
+            getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
+            setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[] { toggleable_cache }));
+        }
        }
 }