1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.debug;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import com.vaadin.data.util.HierarchicalContainer;
|
14
|
import com.vaadin.data.util.IndexedContainer;
|
15
|
import com.vaadin.data.util.filter.SimpleStringFilter;
|
16
|
import com.vaadin.shared.ui.label.ContentMode;
|
17
|
import com.vaadin.ui.CustomComponent;
|
18
|
import com.vaadin.ui.Label;
|
19
|
import com.vaadin.ui.TextField;
|
20
|
import com.vaadin.ui.Tree;
|
21
|
import com.vaadin.ui.VerticalLayout;
|
22
|
import com.vaadin.ui.VerticalSplitPanel;
|
23
|
|
24
|
import eu.etaxonomy.cdm.cache.CdmTransientEntityCacher;
|
25
|
import eu.etaxonomy.cdm.cache.EntityCacherDebugResult;
|
26
|
import eu.etaxonomy.cdm.cache.EntityCacherDebugResult.CdmEntityInfo;
|
27
|
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
|
28
|
import eu.etaxonomy.cdm.vaadin.view.name.CachingPresenter;
|
29
|
|
30
|
/**
|
31
|
* @author a.kohlbecker
|
32
|
* @since Jan 22, 2018
|
33
|
*
|
34
|
*/
|
35
|
public class EntityCacheDebuggerComponent extends CustomComponent {
|
36
|
|
37
|
private static final long serialVersionUID = 993360128659237814L;
|
38
|
|
39
|
CachingPresenter presenter;
|
40
|
CdmTransientEntityCacher cacher;
|
41
|
EntityCacherDebugResult debugResults;
|
42
|
|
43
|
VerticalLayout layout = new VerticalLayout();
|
44
|
VerticalSplitPanel splitPanel = new VerticalSplitPanel();
|
45
|
|
46
|
private Tree entityTree;
|
47
|
|
48
|
public EntityCacheDebuggerComponent(CachingPresenter presenter){
|
49
|
|
50
|
this.presenter = presenter;
|
51
|
this.cacher = (CdmTransientEntityCacher) presenter.getCache();
|
52
|
// TODO implement checkbox for includeIgnored
|
53
|
boolean includeIgnored = true;
|
54
|
debugResults = new EntityCacherDebugResult(cacher, presenter.getRootEntities(), includeIgnored);
|
55
|
initContent();
|
56
|
}
|
57
|
|
58
|
private void initContent() {
|
59
|
|
60
|
|
61
|
TextField filterField = new TextFieldNFix();
|
62
|
filterField.setInputPrompt("Enter filter text");
|
63
|
filterField.addTextChangeListener(e -> filterTree(e.getText()));
|
64
|
filterField.setWidth("100%");
|
65
|
|
66
|
entityTree = new Tree("Cache Content");
|
67
|
buildTree(entityTree, debugResults.getRootElements());
|
68
|
|
69
|
Label debugInformation = new Label(); // );
|
70
|
debugInformation.setCaption("Debug Information");
|
71
|
debugInformation.setValue(debugResults.toString());
|
72
|
debugInformation.setContentMode(ContentMode.PREFORMATTED);
|
73
|
|
74
|
setCompositionRoot(layout);
|
75
|
|
76
|
entityTree.setSizeUndefined();
|
77
|
debugInformation.setSizeUndefined();
|
78
|
debugInformation.setReadOnly(true);
|
79
|
splitPanel.setFirstComponent(entityTree);
|
80
|
splitPanel.setSecondComponent(debugInformation);
|
81
|
splitPanel.setSplitPosition(50, Unit.PERCENTAGE);
|
82
|
splitPanel.setSizeFull();
|
83
|
|
84
|
layout.addComponents(filterField, splitPanel);
|
85
|
layout.setSizeFull();
|
86
|
layout.setExpandRatio(splitPanel, 1.0f);
|
87
|
|
88
|
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* @param value
|
93
|
* @return
|
94
|
*/
|
95
|
private void filterTree(String text) {
|
96
|
IndexedContainer indexedContainer = (IndexedContainer)entityTree.getContainerDataSource();
|
97
|
indexedContainer.removeAllContainerFilters();
|
98
|
|
99
|
if(!text.isEmpty()){
|
100
|
SimpleStringFilter filter = new SimpleStringFilter("label", text, true, false);
|
101
|
indexedContainer.addContainerFilter(filter);
|
102
|
((HierarchicalContainer)entityTree.getContainerDataSource()).rootItemIds().forEach(rid -> entityTree.expandItemsRecursively(rid));
|
103
|
}
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @param entityTree
|
108
|
* @param rootElements
|
109
|
*/
|
110
|
private void buildTree(Tree tree, List<CdmEntityInfo> childElements) {
|
111
|
|
112
|
HierarchicalContainer container = new HierarchicalContainer();
|
113
|
|
114
|
container.addContainerProperty("label", String.class, "");
|
115
|
tree.setItemCaptionPropertyId("label");
|
116
|
buildTree(container, childElements, null);
|
117
|
|
118
|
tree.setContainerDataSource(container);
|
119
|
|
120
|
container.setItemSorter(new CdmEntityInfoSorter());
|
121
|
|
122
|
}
|
123
|
|
124
|
private void buildTree(HierarchicalContainer container, List<CdmEntityInfo> childElements, Object parentItemId) {
|
125
|
for(CdmEntityInfo cei : childElements){
|
126
|
String itemId = cei.getLabel();
|
127
|
container.addItem(itemId);
|
128
|
container.getItem(itemId).getItemProperty("label").setValue(itemId);
|
129
|
if(parentItemId != null){
|
130
|
container.setParent(itemId, parentItemId);
|
131
|
}
|
132
|
if(cei.getChildren().isEmpty()){
|
133
|
container.setChildrenAllowed(itemId, false);
|
134
|
} else {
|
135
|
buildTree(container, cei.getChildren(), itemId);
|
136
|
}
|
137
|
}
|
138
|
}
|
139
|
|
140
|
|
141
|
}
|