Project

General

Profile

Revision 3b0bc0db

ID3b0bc0dbe8c5269a2458d532e52ba320de7d2dfc
Parent e11ccba6
Child a8118bab

Added by Patrick Plitzner about 4 years ago

ref #5458 performance tweak for distribution status selection

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
1 1
package eu.etaxonomy.cdm.vaadin.container;
2 2

  
3 3
import java.util.Collection;
4
import java.util.HashSet;
4 5
import java.util.Set;
5 6

  
6 7
import com.vaadin.data.util.BeanItemContainer;
......
16 17

  
17 18
	private static final long serialVersionUID = -7891310979870159325L;
18 19

  
19
	public PresenceAbsenceTermContainer()
20
	private static PresenceAbsenceTermContainer instance;
21
	private static Collection<PresenceAbsenceTerm> defaultDistributionStatus;
22

  
23
	private PresenceAbsenceTermContainer()
20 24
			throws IllegalArgumentException {
21 25
		super(PresenceAbsenceTerm.class);
22
		Collection<PresenceAbsenceTerm> distributionStatus = (Set<PresenceAbsenceTerm>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
23
        if(distributionStatus==null || distributionStatus.isEmpty()){
24
            distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
25
        }
26
		initDataModel();
27
	}
28

  
29
    private void initDataModel() {
30
        Collection<PresenceAbsenceTerm> distributionStatus = new HashSet<>();
31
        distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
32
        defaultDistributionStatus = distributionStatus;
26 33
		TermCacher termCacher = TermCacher.getInstance();
34
		addAll(distributionStatus);
27 35
		for (PresenceAbsenceTerm presenceAbsenceTerm : distributionStatus) {
28 36
			termCacher.addPresenceAbsenceTerm(presenceAbsenceTerm);
29
			addBean(presenceAbsenceTerm);
30 37
		}
38
    }
39

  
40
	public static PresenceAbsenceTermContainer getInstance(){
41
	    if(instance==null){
42
	        instance = new PresenceAbsenceTermContainer();
43
	    }
44
        Collection<PresenceAbsenceTerm> distributionStatus = new HashSet<>();
45
        Object attribute = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
46
        if(attribute!=null){
47
            distributionStatus = (Set<PresenceAbsenceTerm>) attribute;
48
        }
49
        if(!distributionStatus.isEmpty() && !distributionStatus.equals(defaultDistributionStatus)){
50
            instance.removeAllItems();
51
            instance.addAll(distributionStatus);
52
            defaultDistributionStatus = distributionStatus;
53
        }
54
	    return instance;
31 55
	}
32 56

  
33 57
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
110 110
                    final Window popup = new Window("Choose distribution status");
111 111
                    final ListSelect termSelect = new ListSelect();
112 112
                    termSelect.setSizeFull();
113
                    termSelect.setContainerDataSource(new PresenceAbsenceTermContainer());
113
                    termSelect.setContainerDataSource(PresenceAbsenceTermContainer.getInstance());
114 114
                    Button btnOk = new Button("OK", new ClickListener() {
115 115
                        private static final long serialVersionUID = -3732219609337335697L;
116 116
                        @Override

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)