1
|
/**
|
2
|
* Copyright (C) 2015 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.taxeditor.view.sessions;
|
10
|
|
11
|
import java.util.Collections;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.eclipse.jface.viewers.ILabelProvider;
|
15
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
16
|
import org.eclipse.jface.viewers.StyledCellLabelProvider;
|
17
|
import org.eclipse.jface.viewers.StyledString;
|
18
|
import org.eclipse.jface.viewers.TreeViewer;
|
19
|
import org.eclipse.jface.viewers.Viewer;
|
20
|
import org.eclipse.jface.viewers.ViewerCell;
|
21
|
import org.eclipse.swt.SWT;
|
22
|
import org.eclipse.swt.custom.SashForm;
|
23
|
import org.eclipse.swt.events.SelectionAdapter;
|
24
|
import org.eclipse.swt.events.SelectionEvent;
|
25
|
import org.eclipse.swt.graphics.Image;
|
26
|
import org.eclipse.swt.layout.GridData;
|
27
|
import org.eclipse.swt.layout.GridLayout;
|
28
|
import org.eclipse.swt.widgets.Button;
|
29
|
import org.eclipse.swt.widgets.Composite;
|
30
|
import org.eclipse.swt.widgets.Dialog;
|
31
|
import org.eclipse.swt.widgets.Display;
|
32
|
import org.eclipse.swt.widgets.Label;
|
33
|
import org.eclipse.swt.widgets.Shell;
|
34
|
import org.eclipse.swt.widgets.Text;
|
35
|
import org.eclipse.ui.dialogs.FilteredTree;
|
36
|
import org.eclipse.ui.dialogs.PatternFilter;
|
37
|
import org.eclipse.wb.swt.SWTResourceManager;
|
38
|
|
39
|
import eu.etaxonomy.cdm.cache.CdmModelFieldPropertyFromClass;
|
40
|
import eu.etaxonomy.cdm.cache.CdmRemoteCacheManager;
|
41
|
import eu.etaxonomy.cdm.cache.EntityCacherDebugResult;
|
42
|
import eu.etaxonomy.cdm.cache.EntityCacherDebugResult.CdmEntityInfo;
|
43
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
44
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
45
|
import net.sf.ehcache.Cache;
|
46
|
import net.sf.ehcache.Element;
|
47
|
|
48
|
/**
|
49
|
* @author cmathew
|
50
|
* @date 17 Feb 2015
|
51
|
*/
|
52
|
public class InspectSessionsDialog extends Dialog {
|
53
|
|
54
|
protected Object result;
|
55
|
protected Shell shlInspectSessions;
|
56
|
private Text txtDebugInfo;
|
57
|
private Label lblDebugInformation;
|
58
|
|
59
|
private final Cache cdmlibModelCache;
|
60
|
|
61
|
private final ICdmEntitySession activeSession;
|
62
|
|
63
|
private TreeViewer treeViewer;
|
64
|
private Button btnClose;
|
65
|
private EntityCacherDebugResult entityCacherDebugResult;
|
66
|
private SashForm sashForm;
|
67
|
private Composite compositeDebug;
|
68
|
|
69
|
/**
|
70
|
* Create the dialog.
|
71
|
* @param parent
|
72
|
* @param style
|
73
|
*/
|
74
|
public InspectSessionsDialog(Shell parent, int style) {
|
75
|
super(parent, style);
|
76
|
setText("Inspect Active Session");
|
77
|
cdmlibModelCache = CdmRemoteCacheManager.INSTANCE().getCdmModelGetMethodsCache();
|
78
|
activeSession = CdmStore.getCurrentSessionManager().getActiveSession();
|
79
|
if (activeSession != null){
|
80
|
//TODO
|
81
|
entityCacherDebugResult = activeSession.debug(false);
|
82
|
}
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Open the dialog.
|
87
|
*/
|
88
|
public Object open() {
|
89
|
|
90
|
createContents();
|
91
|
setDebugInfoText();
|
92
|
treeViewer.setContentProvider(new SessionsTreeContentProvider());
|
93
|
treeViewer.setLabelProvider(new SessionsTreeLabelProvider());
|
94
|
|
95
|
treeViewer.setInput(getRootElements());
|
96
|
shlInspectSessions.open();
|
97
|
shlInspectSessions.layout();
|
98
|
Display display = getParent().getDisplay();
|
99
|
while (!shlInspectSessions.isDisposed()) {
|
100
|
if (!display.readAndDispatch()) {
|
101
|
display.sleep();
|
102
|
}
|
103
|
}
|
104
|
return result;
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* Create contents of the dialog.
|
109
|
*/
|
110
|
private void createContents() {
|
111
|
shlInspectSessions = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
|
112
|
shlInspectSessions.setSize(641, 631);
|
113
|
shlInspectSessions.setText("Inspect Sessions");
|
114
|
shlInspectSessions.setLayout(new GridLayout(1, false));
|
115
|
|
116
|
sashForm = new SashForm(shlInspectSessions, SWT.VERTICAL);
|
117
|
sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
118
|
|
119
|
PatternFilter filter = new PatternFilter();
|
120
|
FilteredTree tree = new FilteredTree(sashForm, SWT.MULTI | SWT.H_SCROLL | SWT.BORDER
|
121
|
| SWT.V_SCROLL, filter, true);
|
122
|
treeViewer = tree.getViewer();
|
123
|
//treeViewer = new TreeViewer(sashForm, SWT.BORDER);
|
124
|
//Tree tree = treeViewer.getTree();
|
125
|
|
126
|
compositeDebug = new Composite(sashForm, SWT.NONE);
|
127
|
compositeDebug.setLayout(new GridLayout(1, false));
|
128
|
|
129
|
lblDebugInformation = new Label(compositeDebug, SWT.NONE);
|
130
|
lblDebugInformation.setAlignment(SWT.CENTER);
|
131
|
lblDebugInformation.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
|
132
|
lblDebugInformation.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
|
133
|
lblDebugInformation.setText("Debug Information");
|
134
|
|
135
|
txtDebugInfo = new Text(compositeDebug, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
|
136
|
txtDebugInfo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
137
|
sashForm.setWeights(new int[] {338, 184});
|
138
|
|
139
|
btnClose = new Button(shlInspectSessions, SWT.NONE);
|
140
|
btnClose.addSelectionListener(new SelectionAdapter() {
|
141
|
@Override
|
142
|
public void widgetSelected(SelectionEvent e) {
|
143
|
shlInspectSessions.dispose();
|
144
|
}
|
145
|
});
|
146
|
GridData gd_btnClose = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
147
|
gd_btnClose.widthHint = 70;
|
148
|
btnClose.setLayoutData(gd_btnClose);
|
149
|
btnClose.setText("Close");
|
150
|
}
|
151
|
|
152
|
private void setDebugInfoText() {
|
153
|
txtDebugInfo.setText(entityCacherDebugResult == null? "No session" : entityCacherDebugResult.toString());
|
154
|
}
|
155
|
private CdmEntityInfo[] getRootElements() {
|
156
|
|
157
|
List<CdmEntityInfo> rootElements = entityCacherDebugResult == null? null : entityCacherDebugResult.getRootElements();
|
158
|
return rootElements == null ? new CdmEntityInfo[0]: rootElements.toArray(new CdmEntityInfo[rootElements.size()]);
|
159
|
}
|
160
|
|
161
|
class SessionsTreeContentProvider implements ITreeContentProvider {
|
162
|
|
163
|
@Override
|
164
|
public void dispose() {
|
165
|
|
166
|
}
|
167
|
|
168
|
@Override
|
169
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
170
|
|
171
|
@Override
|
172
|
public Object[] getElements(Object inputElement) {
|
173
|
return (CdmEntityInfo[])inputElement;
|
174
|
}
|
175
|
|
176
|
@Override
|
177
|
public Object[] getChildren(Object parentElement) {
|
178
|
List<CdmEntityInfo> children = ((CdmEntityInfo)parentElement).getChildren();
|
179
|
Collections.sort(children, (c1, c2)->{
|
180
|
String str1 = (c1 == null) ? "": c1.getLabel();
|
181
|
String str2 = (c2 == null) ? "": c2.getLabel();
|
182
|
return str1.compareTo(str2);
|
183
|
});
|
184
|
return children.toArray();
|
185
|
}
|
186
|
|
187
|
@Override
|
188
|
public Object getParent(Object element) {
|
189
|
CdmEntityInfo cei = (CdmEntityInfo)element;
|
190
|
return cei.getParent();
|
191
|
}
|
192
|
|
193
|
@Override
|
194
|
public boolean hasChildren(Object element) {
|
195
|
List<CdmEntityInfo> children = ((CdmEntityInfo)element).getChildren();
|
196
|
if(children != null && !children.isEmpty()) {
|
197
|
return true;
|
198
|
} else {
|
199
|
return false;
|
200
|
}
|
201
|
}
|
202
|
|
203
|
public CdmModelFieldPropertyFromClass getFromCdmlibModelCache(String className) {
|
204
|
Element e = cdmlibModelCache.get(className);
|
205
|
if (e == null) {
|
206
|
return null;
|
207
|
} else {
|
208
|
return (CdmModelFieldPropertyFromClass) e.getObjectValue();
|
209
|
}
|
210
|
}
|
211
|
}
|
212
|
|
213
|
class SessionsTreeLabelProvider extends StyledCellLabelProvider implements ILabelProvider {
|
214
|
|
215
|
@Override
|
216
|
public void update(ViewerCell cell) {
|
217
|
CdmEntityInfo cei = (CdmEntityInfo)cell.getElement();
|
218
|
StyledString text = new StyledString();
|
219
|
if(cei != null) {
|
220
|
text.append(cei.getLabel());
|
221
|
}
|
222
|
cell.setText(text.toString());
|
223
|
cell.setStyleRanges(text.getStyleRanges());
|
224
|
super.update(cell);
|
225
|
}
|
226
|
|
227
|
@Override
|
228
|
public Image getImage(Object element) {
|
229
|
return null;
|
230
|
}
|
231
|
|
232
|
@Override
|
233
|
public String getText(Object element) {
|
234
|
CdmEntityInfo cei = (CdmEntityInfo)element;
|
235
|
return cei.getLabel();
|
236
|
}
|
237
|
}
|
238
|
}
|