Project

General

Profile

« Previous | Next » 

Revision ed60b90e

Added by Patrick Plitzner over 4 years ago

ref #6554 Evaluate expansion state at widget creation time

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/StoreUtil.java
22 22
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23 23
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
24 24
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
25
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
25 26

  
26 27
/**
27 28
 * <p>StoreUtil class.</p>
......
133 134
	    return title.replace("&", "&&");
134 135
	}
135 136

  
137
    public static String getPrefKey(Class<? extends AbstractFormSection> sectionClass, Object entity) {
138
        return sectionClass.getCanonicalName()+";"+entity.getClass().getCanonicalName();
139
    }
140

  
136 141
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractFormSection.java
26 26
import org.eclipse.swt.widgets.Display;
27 27
import org.eclipse.swt.widgets.TypedListener;
28 28
import org.eclipse.swt.widgets.Widget;
29
import org.eclipse.ui.forms.events.ExpansionEvent;
30
import org.eclipse.ui.forms.events.IExpansionListener;
31 29
import org.eclipse.ui.forms.widgets.Section;
32 30
import org.eclipse.ui.forms.widgets.TableWrapLayout;
33 31
import org.eclipse.ui.forms.widgets.ToggleHyperlink;
......
37 35
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
38 36
import eu.etaxonomy.taxeditor.model.AbstractUtility;
39 37
import eu.etaxonomy.taxeditor.model.MessagingUtils;
40
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
41 38

  
42 39
/**
43 40
 * <p>
......
167 164
	 */
168 165
	public void setEntity(ENTITY entity) {
169 166
		this.entity = entity;
170
		addExpandListener();
171 167
	}
172 168

  
173 169
	/**
......
590 586

  
591 587
	}
592 588

  
593
    public class ExpandListener implements IExpansionListener{
594
		@Override
595
		public void expansionStateChanging(ExpansionEvent e) {
596
		}
597
		@Override
598
		public void expansionStateChanged(ExpansionEvent e) {
599
			PreferencesUtil.getPreferenceStore().setValue(getPrefKey(), e.getState());
600
		}
601
    }
602

  
603
    /**
604
     * Adds a custom implementation of IExpansionListener to this section
605
     * which stores the expansion state in the preferences
606
     */
607
	protected void addExpandListener() {
608
		PreferencesUtil.getPreferenceStore().setDefault(getPrefKey(), isExpanded());
609
		setExpanded(PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey()));
610
		addExpansionListener(new ExpandListener());
611
	}
612

  
613
	private String getPrefKey() {
614
		return this.getClass().getCanonicalName()+";"+entity.getClass().getCanonicalName();
615
	}
616

  
617

  
618 589
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/CdmSectionPart.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.view.detail;
11 11

  
12
import java.awt.Event;
13 12
import java.util.EventObject;
14 13

  
15 14
import org.eclipse.jface.util.IPropertyChangeListener;
......
27 26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28 27
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
29 28
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
29
import eu.etaxonomy.taxeditor.store.StoreUtil;
30 30
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
31 31
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
32 32
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
33 33
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
34 34
import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
35 35
import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
36
import eu.etaxonomy.taxeditor.ui.section.name.NameDetailSection;
37 36
import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection;
38 37
import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
39 38
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
......
42 41
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeoScopeDetailSection;
43 42
import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
44 43
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
45
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection;
46
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailElement;
47 44
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailSection;
48
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailSection;
49 45

  
50 46
/**
51 47
 * <p>
......
151 147
			return true;
152 148
		}
153 149

  
154
		
150

  
155 151
		formSection.setEntity((T) input);
156 152

  
157 153
		return true;
......
194 190
		}
195 191
	}
196 192

  
193
	@Override
194
	protected void expansionStateChanged(boolean expanded) {
195
	    super.expansionStateChanged(expanded);
196
	    PreferencesUtil.getPreferenceStore().setValue(StoreUtil.getPrefKey(formSection.getClass(), formSection.getEntity()), expanded);
197
	}
198

  
197 199
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmDataViewerE4.java
22 22
import org.eclipse.swt.widgets.Display;
23 23
import org.eclipse.ui.forms.IFormPart;
24 24
import org.eclipse.ui.forms.ManagedForm;
25
import org.eclipse.ui.forms.widgets.ExpandableComposite;
25 26
import org.eclipse.ui.forms.widgets.ScrolledForm;
26 27

  
27 28
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
30 31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
31 32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
32 33
import eu.etaxonomy.taxeditor.remoting.CdmEagerLoadingException;
34
import eu.etaxonomy.taxeditor.store.StoreUtil;
33 35
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
34 36
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
35 37
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
......
169 171
		body.layout();
170 172
	}
171 173

  
174
    protected int getSectionStyle(Class<? extends AbstractFormSection> clazz){
175
        int style = ExpandableComposite.TWISTIE;
176
        if(PreferencesUtil.getPreferenceStore().getBoolean(StoreUtil.getPrefKey(clazz, getInput()))){
177
            style |= ExpandableComposite.EXPANDED;
178
        }
179
        return style;
180
    }
181

  
172 182
	protected abstract void showParts();
173 183

  
174 184
	public void destroySections() {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsViewerE4.java
618 618
    }
619 619

  
620 620
    private void createDerivedUnitBaseElementSection(RootElement parent) {
621
        DerivedUnitGeneralDetailSection derivedUnitGeneralDetailSection = formFactory.createDerivedUnitGeneralDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
621
        DerivedUnitGeneralDetailSection derivedUnitGeneralDetailSection = formFactory.createDerivedUnitGeneralDetailSection(getConversationHolder(), parent, this, getSectionStyle(DerivedUnitGeneralDetailSection.class));
622 622
        //TODO for DerivateEditor do not use facade anymore to avoid this special case handling #4539
623 623
        if(!(AbstractUtility.getActivePart() instanceof IDerivedUnitFacadePart)){
624 624
            derivedUnitGeneralDetailSection.setShowOnlyDerivedUnitData(true);
......
627 627

  
628 628
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
629 629

  
630
        DerivedUnitBaseDetailSection derivedUnitBaseDetailSection = formFactory.createDerivedUnitBaseDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
630
        DerivedUnitBaseDetailSection derivedUnitBaseDetailSection = formFactory.createDerivedUnitBaseDetailSection(getConversationHolder(), parent, this, getSectionStyle(DerivedUnitBaseDetailSection.class));
631 631
        addPart(derivedUnitBaseDetailSection);
632 632

  
633 633
        //for editors working with facades
634 634
        if(AbstractUtility.getActivePart() instanceof IDerivedUnitFacadePart){
635 635
            formFactory.createHorizontalSeparator(parent, SWT.BORDER);
636
            GatheringEventDetailSection gatheringEventDetailSection = formFactory.createGatheringEventDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
636
            GatheringEventDetailSection gatheringEventDetailSection = formFactory.createGatheringEventDetailSection(getConversationHolder(), parent, this, getSectionStyle(GatheringEventDetailSection.class));
637 637
            addPart(gatheringEventDetailSection);
638 638

  
639 639
            formFactory.createHorizontalSeparator(parent, SWT.BORDER);
640
            FieldUnitDetailSection fieldUnitDetailSection = formFactory.createFieldUnitDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
640
            FieldUnitDetailSection fieldUnitDetailSection = formFactory.createFieldUnitDetailSection(getConversationHolder(), parent, this, getSectionStyle(FieldUnitDetailSection.class));
641 641
            addPart(fieldUnitDetailSection);
642 642
        }
643 643
        else{
644 644

  
645 645
            if(PreferencesUtil.isShowTaxonAssociations()){
646 646
                formFactory.createHorizontalSeparator(parent, SWT.BORDER);
647
                TaxonAssociationDetailSection taxonAssociationDetailSection = formFactory.createTaxonAssociationDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
647
                TaxonAssociationDetailSection taxonAssociationDetailSection = formFactory.createTaxonAssociationDetailSection(getConversationHolder(), parent, this, getSectionStyle(TaxonAssociationDetailSection.class));
648 648
                addPart(taxonAssociationDetailSection);
649 649
            }
650 650
            formFactory.createHorizontalSeparator(parent, SWT.BORDER);
651
            DerivedUnitFacadeIdentifierSection identifierDetailSection = formFactory.createDerivedUnitFacadeIdentifierSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
651
            DerivedUnitFacadeIdentifierSection identifierDetailSection = formFactory.createDerivedUnitFacadeIdentifierSection(getConversationHolder(), parent, getSectionStyle(DerivedUnitFacadeIdentifierSection.class));
652 652
            addPart(identifierDetailSection);
653 653
        }
654 654
        if(!PreferencesUtil.isDeterminationOnlyForFieldUnits()){
655 655
            formFactory.createHorizontalSeparator(parent, SWT.BORDER);
656
            DeterminationDetailSection determinationDetailSection = formFactory.createDeterminationDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
656
            DeterminationDetailSection determinationDetailSection = formFactory.createDeterminationDetailSection(getConversationHolder(), parent, this, getSectionStyle(DeterminationDetailSection.class));
657 657
            addPart(determinationDetailSection);
658 658
        }
659 659

  
660 660
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
661
        DerivedUnitTypeDesignationSection derivedUnitTypeDesignationSection = formFactory.createDerivedUnitTypeDesignationSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
661
        DerivedUnitTypeDesignationSection derivedUnitTypeDesignationSection = formFactory.createDerivedUnitTypeDesignationSection(getConversationHolder(), parent, this, getSectionStyle(DerivedUnitTypeDesignationSection.class));
662 662
        addPart(derivedUnitTypeDesignationSection);
663 663

  
664 664
    }
665 665

  
666 666
    private void createFieldUnitSection(RootElement parent) {
667
        FieldUnitGeneralDetailSection fielUnitGeneralDetailSection = formFactory.createFieldUnitGeneralDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
667
        FieldUnitGeneralDetailSection fielUnitGeneralDetailSection = formFactory.createFieldUnitGeneralDetailSection(getConversationHolder(), parent, this, getSectionStyle(FieldUnitGeneralDetailSection.class));
668 668

  
669 669
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
670 670

  
671
        GatheringEventDetailSection gatheringEventDetailSection = formFactory.createGatheringEventDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
671
        GatheringEventDetailSection gatheringEventDetailSection = formFactory.createGatheringEventDetailSection(getConversationHolder(), parent, this, getSectionStyle(GatheringEventDetailSection.class));
672 672

  
673 673
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
674 674

  
675
        FieldUnitDetailSection fieldUnitDetailSection = formFactory.createFieldUnitDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
675
        FieldUnitDetailSection fieldUnitDetailSection = formFactory.createFieldUnitDetailSection(getConversationHolder(), parent, this, getSectionStyle(FieldUnitDetailSection.class));
676 676

  
677 677
        addPart(fielUnitGeneralDetailSection);
678 678
        addPart(gatheringEventDetailSection);
......
680 680

  
681 681
        if(PreferencesUtil.isDeterminationOnlyForFieldUnits()){
682 682
            formFactory.createHorizontalSeparator(parent, SWT.BORDER);
683
            DeterminationDetailSection determinationDetailSection = formFactory.createDeterminationDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
683
            DeterminationDetailSection determinationDetailSection = formFactory.createDeterminationDetailSection(getConversationHolder(), parent, this, getSectionStyle(DeterminationDetailSection.class));
684 684
            addPart(determinationDetailSection);
685 685
        }
686 686
    }

Also available in: Unified diff