Project

General

Profile

« Previous | Next » 

Revision f8b0de79

Added by Patrick Plitzner about 6 years ago

ref #5458 Fix item initialization problems

View differences:

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

  
3
import java.util.Arrays;
4 3
import java.util.HashSet;
5
import java.util.List;
6 4
import java.util.Set;
7 5

  
8 6
import com.vaadin.data.Item;
9 7
import com.vaadin.data.util.HierarchicalContainer;
10 8

  
11
import eu.etaxonomy.cdm.api.service.IClassificationService;
12
import eu.etaxonomy.cdm.model.taxon.Classification;
13 9
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
14 10
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
15
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
16 11

  
17 12
public class TaxonNodeContainer extends HierarchicalContainer {
18 13

  
......
20 15
	public static final String LABEL = "titleCache";
21 16
	private Set<Object> itemCache = new HashSet<Object>();
22 17

  
23

  
24
	private final List<String> nodeInitStrategy = Arrays.asList(new String[]{
25
	        "taxon.sec",
26
	        "taxon.name",
27
	        "classification"
28
	});
29

  
30 18
	/**
31 19
	 * Creates a new taxon node container
32 20
	 * @param parentNode the parent node which will <b>not</b> be included
......
34 22
	 */
35 23
	public TaxonNodeContainer(UuidAndTitleCache<TaxonNode> parentNode) {
36 24
		addContainerProperty(LABEL, String.class, "[no taxon]");
37
		if(parentNode==null){
38
            //just load classifications
39
            IClassificationService classificationService = CdmSpringContextHelper.getClassificationService();
40
            List<Classification> classificationList = classificationService.listClassifications(null, null, null, nodeInitStrategy);
41
            for (Classification classification : classificationList) {
42
                TaxonNode rootNode = classification.getRootNode();
43
                Item item = addItem(rootNode);
44
                if(rootNode.getClassification()!=null){
45
                    item.getItemProperty(LABEL).setValue(rootNode.getClassification().getName().getText());
46
                }
47
            }
48
        }
49
		else{
50
		    addItem(parentNode);
51
		}
52 25
	}
53 26

  
54 27
	/**
......
57 30
	@Override
58 31
	public Item addItem(Object itemId) {
59 32
	    if(itemId instanceof UuidAndTitleCache){
60
	        if(!itemCache.contains(((UuidAndTitleCache<TaxonNode>) itemId).getId())){
61
	            return super.addItem(itemId);
33
	        UuidAndTitleCache<TaxonNode> uuidAndTitleCache = (UuidAndTitleCache<TaxonNode>) itemId;
34
            if(!itemCache.contains(uuidAndTitleCache.getId())){
35
	            Item item = super.addItem(itemId);
36
	            item.getItemProperty(TaxonNodeContainer.LABEL).setValue(uuidAndTitleCache.getTitleCache());
37
                return item;
62 38
	        }
63
        } else {
64
            return super.addItem(itemId);
65 39
        }
66 40
	    return null;
67 41
	}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java
9 9
 */
10 10
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
11 11

  
12
import java.sql.SQLException;
12 13
import java.util.Collection;
13 14
import java.util.Set;
14 15
import java.util.UUID;
......
32 33
import com.vaadin.ui.TreeTable;
33 34
import com.vaadin.ui.VerticalLayout;
34 35

  
35
import eu.etaxonomy.cdm.model.common.CdmBase;
36 36
import eu.etaxonomy.cdm.model.common.TermVocabulary;
37 37
import eu.etaxonomy.cdm.model.location.NamedArea;
38 38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39 39
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
40
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
40 41
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
41 42
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
43
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
42 44
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
43 45
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
44 46

  
......
71 73
        //init classification and taxon selection
72 74
        TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
73 75

  
74
        classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
76
        try {
77
            classificationBox.setContainerDataSource(new CdmSQLContainer(CdmQueryFactory.generateTableQuery("Classification")));
78
        } catch (SQLException e) {
79
            DistributionEditorUtil.showSqlError(e);
80
        }
75 81
        Object classificationSelection = null;
76 82
        if(classificationBox.getItemIds().size()==1){
77 83
            //only one classification exists
......
85 91
            classificationBox.setValue(classificationSelection);
86 92
            taxonTree.addExpandListener(this);
87 93

  
88
            UUID uuid = ((CdmBase) classificationSelection).getUuid();
89
            int id = ((CdmBase) classificationSelection).getId();
90
            String titleCache = ((TaxonNode) classificationSelection).getClassification().getTitleCache();
94
            String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue();
95
            int id = (int) classificationBox.getContainerProperty(classificationSelection, "id").getValue();
96
            String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue();
97
            UUID uuid = UUID.fromString(uuidString);
91 98
            UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
92 99
            taxonTree.setContainerDataSource(new TaxonNodeContainer(parent));
100
            addChildItems(parent);
93 101
            if(chosenTaxonNode!=null){
94 102
                taxonTree.select(new RowId(chosenTaxonNode.getId()));
95 103
            }
......
205 213
                String titleCache = parentNode.getClassification().getTitleCache();
206 214
                UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
207 215
                taxonTree.setContainerDataSource(new TaxonNodeContainer(parent));
208
            }
209
            else{
210
                taxonTree.setContainerDataSource(null);
216
                addChildItems(parent);
211 217
            }
212 218
        }
213

  
214 219
        else if(property==distAreaBox){
215 220
            TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
216 221
            NamedAreaContainer container = new NamedAreaContainer(vocabulary);
......
232 237
            TermVocabulary<NamedArea> term = null;
233 238
            //TODO use field converter
234 239
            if(taxonTree.getValue()!=null){
235
                taxonNode = CdmSpringContextHelper.getTaxonNodeService().find((Integer)((RowId) taxonTree.getValue()).getId()[0]);
240
                taxonNode = CdmSpringContextHelper.getTaxonNodeService().load(((UuidAndTitleCache<TaxonNode>)taxonTree.getValue()).getUuid());
236 241
            }
237 242
            if(taxonNode==null){
238 243
                taxonNode = (TaxonNode) classificationBox.getValue();
......
250 255
    @Override
251 256
    public void nodeExpand(ExpandEvent event) {
252 257
        UuidAndTitleCache<TaxonNode> parent = (UuidAndTitleCache<TaxonNode>) event.getItemId();
258
        addChildItems(parent);
259
    }
260

  
261
    /**
262
     * @param parent
263
     */
264
    private void addChildItems(UuidAndTitleCache<TaxonNode> parent) {
253 265
        Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent);
254 266
        taxonTree.setChildrenAllowed(parent, !children.isEmpty());
255 267
        for (UuidAndTitleCache<TaxonNode> child : children) {
256 268
            Item childItem = taxonTree.addItem(child);
257 269
            if(childItem!=null){
258 270
                taxonTree.setParent(child, parent);
259
                childItem.getItemProperty(TaxonNodeContainer.LABEL).setValue(child.getTitleCache());
260 271
            }
261 272
            Collection<UuidAndTitleCache<TaxonNode>> grandChildren = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(child);
262 273
            taxonTree.setChildrenAllowed(child, !grandChildren.isEmpty());

Also available in: Unified diff