Project

General

Profile

Revision aab82329

IDaab82329b916fa15d51ec9a255b0900389777243
Parent a6e7790d
Child 3a824e7f

Added by Patrick Plitzner about 4 years ago

ref #5458 Major performance increase

  • refactored term loading
  • cached loaded terms
  • removed unnecessary methods and generics
  • reduces warnings

View differences:

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

  
3
import java.util.HashMap;
4
import java.util.List;
5
import java.util.Map;
6

  
7
import com.vaadin.data.util.BeanItemContainer;
8

  
9
import eu.etaxonomy.cdm.model.common.TermType;
10
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
11
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
12

  
13
public class PresenceAbsenceTermContainer extends BeanItemContainer<PresenceAbsenceTerm> {
14

  
15
	private static final long serialVersionUID = -7891310979870159325L;
16
	
17
	private static PresenceAbsenceTermContainer instance;
18
	
19
	public static final Map<String, PresenceAbsenceTerm> titleToTermMap = new HashMap<>();
20

  
21
	private PresenceAbsenceTermContainer()
22
			throws IllegalArgumentException {
23
		super(PresenceAbsenceTerm.class);
24
		List<PresenceAbsenceTerm> terms = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
25
		for (PresenceAbsenceTerm presenceAbsenceTerm : terms) {
26
			titleToTermMap.put(presenceAbsenceTerm.getTitleCache(), presenceAbsenceTerm);
27
			addBean(presenceAbsenceTerm);
28
		}
29
	}
30
	
31
	public static PresenceAbsenceTermContainer getInstance(){
32
		if(instance==null){
33
			instance = new PresenceAbsenceTermContainer();
34
		}
35
		return instance;
36
	}
37

  
38

  
39
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
12 12
import java.util.SortedSet;
13 13
import java.util.UUID;
14 14

  
15
import com.vaadin.data.Container;
16
import com.vaadin.data.util.BeanItemContainer;
17 15
import com.vaadin.server.VaadinSession;
18 16

  
19 17
import eu.etaxonomy.cdm.api.service.IClassificationService;
......
26 24
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27 25
import eu.etaxonomy.cdm.model.common.Language;
28 26
import eu.etaxonomy.cdm.model.common.Representation;
29
import eu.etaxonomy.cdm.model.common.TermType;
30 27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
31 28
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
32 29
import eu.etaxonomy.cdm.model.description.Distribution;
......
231 228
		return container;
232 229
	}
233 230

  
234
	@Override
235
	public Container getPresenceAbsenceContainer(){
236
		BeanItemContainer<PresenceAbsenceTerm> termContainer = new BeanItemContainer<PresenceAbsenceTerm>(PresenceAbsenceTerm.class);
237
		termContainer.addAll(getPresenceAbsenceTerms());
238
		return termContainer;
239
	}
240

  
241

  
242
	@Override
243
	public List<PresenceAbsenceTerm> getPresenceAbsenceTerms() {
244
		return termService.listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
245
	}
246

  
247 231
	protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
248 232
            "$",
249 233
            "elements.*",
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
158 158
        classificationBox.setHeight("-1px");
159 159
        verticalLayout_2.addComponent(classificationBox);
160 160

  
161
        // taxon tree
162
        taxonTree = new Tree("Taxonomy");
163
        taxonTree.setWidth("200px");
164
        verticalLayout_2.addComponent(taxonTree);
165

  
166 161
        // distributionAreaBox
167 162
        distributionAreaBox = new ComboBox();
168 163
        distributionAreaBox.setCaption("Distribution Area");
......
171 166
        distributionAreaBox.setHeight("-1px");
172 167
        verticalLayout_2.addComponent(distributionAreaBox);
173 168

  
169
        // taxon tree
170
        taxonTree = new Tree("Taxonomy");
171
        taxonTree.setWidth("200px");
172
        verticalLayout_2.addComponent(taxonTree);
173

  
174 174
        // button_proceed
175 175
        button_proceed = new Button();
176 176
        button_proceed.setCaption("Proceed");
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
29 29
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
30 30
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
31 31
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
32
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
33 32
import eu.etaxonomy.cdm.model.taxon.Taxon;
34 33
import eu.etaxonomy.cdm.vaadin.component.DetailWindow;
35 34
import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar;
36 35
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
36
import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer;
37 37
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
38 38

  
39
public class DistributionTableView<E> extends CustomComponent implements IDistributionTableComponent, View{
39
public class DistributionTableView extends CustomComponent implements IDistributionTableComponent, View{
40 40

  
41 41
    private final class AreaColumnGenerator implements ColumnGenerator {
42 42
		private static final long serialVersionUID = 1L;
43 43

  
44 44
		@Override
45 45
		public Object generateCell(Table source, Object itemId, Object columnId) {
46
		    Property containerProperty = source.getContainerProperty(itemId, columnId);
46
		    Property<?> containerProperty = source.getContainerProperty(itemId, columnId);
47 47
		    Object value = null;
48 48
		    if(containerProperty != null){
49 49
		        value = containerProperty.getValue();
50 50
		    }
51 51
		    final UUID uuid = UUID.fromString(table.getItem(itemId).getItemProperty("uuid").getValue().toString());
52
		    final ComboBox box = new ComboBox("Occurrence Status: ", listener.getPresenceAbsenceContainer());
52
		    final ComboBox box = new ComboBox("Occurrence Status: ", PresenceAbsenceTermContainer.getInstance());
53 53
		    final String area = columnId.toString();
54 54
		    box.setImmediate(true);
55 55
		    box.setBuffered(true);
56
		    box.setValue(compareObjectToPAT(value));
56
		    box.setValue(PresenceAbsenceTermContainer.titleToTermMap.get(value));
57 57
		    box.addValueChangeListener(new ValueChangeListener() {
58
		        @Override
58
				private static final long serialVersionUID = 6221534597911674067L;
59

  
60
				@Override
59 61
		        public void valueChange(ValueChangeEvent event) {
60 62
		            Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
61 63
		            listener.updateDistributionField(area, box.getValue(), taxon);
......
158 160
		detailButton.setCaption("Detail View");
159 161
		detailButton.addClickListener(new ClickListener() {
160 162

  
163
			private static final long serialVersionUID = 1479133195403139547L;
164

  
161 165
			@Override
162 166
			public void buttonClick(ClickEvent event) {
163 167
				try{
......
177 181
		Button settingsButton = toolbar.getSettingsButton();
178 182
		settingsButton.addClickListener(new ClickListener() {
179 183

  
180
            @Override
184
			private static final long serialVersionUID = 3834048719431837966L;
185

  
186
			@Override
181 187
            public void buttonClick(ClickEvent event) {
182 188
                SettingsConfigWindow cw = new SettingsConfigWindow();
183 189
                Window window  = cw.createWindow();
......
205 211

  
206 212
	}
207 213

  
208
	private PresenceAbsenceTerm compareObjectToPAT(Object object){
209
	    List<PresenceAbsenceTerm> presenceAbsenceTerms = listener.getPresenceAbsenceTerms();
210
	    for(PresenceAbsenceTerm term:presenceAbsenceTerms){
211
	        if(term.getTitleCache().equals(object)){
212
	            return term;
213
	        }
214
	    }
215
	    return null;
216
	}
217

  
218 214
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
5 5
import java.util.List;
6 6
import java.util.Set;
7 7

  
8
import com.vaadin.data.Container;
9

  
10 8
import eu.etaxonomy.cdm.api.service.IClassificationService;
11 9
import eu.etaxonomy.cdm.api.service.IDescriptionService;
12 10
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
......
17 15
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
18 16
import eu.etaxonomy.cdm.model.description.Distribution;
19 17
import eu.etaxonomy.cdm.model.description.Feature;
20
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
21 18
import eu.etaxonomy.cdm.model.taxon.Taxon;
22 19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23 20
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
......
28 25
	public interface DistributionTableComponentListener{
29 26
		Set<DefinedTermBase> getChosenTerms();
30 27

  
31
		List<PresenceAbsenceTerm> getPresenceAbsenceTerms();
32

  
33 28
		HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon);
34 29

  
35 30
		LazyLoadedContainer getTableContainer();
......
61 56

  
62 57
		List<String> getTermList();
63 58

  
64
		Container getPresenceAbsenceContainer();
65

  
66 59
        /**
67 60
         * @return
68 61
         */

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)