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