1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.view.sessions;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
import net.sf.ehcache.Cache;
|
15
|
import net.sf.ehcache.Element;
|
16
|
|
17
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
18
|
import org.eclipse.jface.viewers.StyledCellLabelProvider;
|
19
|
import org.eclipse.jface.viewers.StyledString;
|
20
|
import org.eclipse.jface.viewers.TreeViewer;
|
21
|
import org.eclipse.jface.viewers.Viewer;
|
22
|
import org.eclipse.jface.viewers.ViewerCell;
|
23
|
import org.eclipse.swt.SWT;
|
24
|
import org.eclipse.swt.layout.GridData;
|
25
|
import org.eclipse.swt.layout.GridLayout;
|
26
|
import org.eclipse.swt.widgets.Dialog;
|
27
|
import org.eclipse.swt.widgets.Display;
|
28
|
import org.eclipse.swt.widgets.Label;
|
29
|
import org.eclipse.swt.widgets.Shell;
|
30
|
import org.eclipse.swt.widgets.Text;
|
31
|
import org.eclipse.swt.widgets.Tree;
|
32
|
import org.eclipse.wb.swt.SWTResourceManager;
|
33
|
|
34
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmModelFieldPropertyFromClass;
|
35
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
|
36
|
import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
|
37
|
import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult.CdmEntityInfo;
|
38
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
39
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
40
|
|
41
|
/**
|
42
|
* @author cmathew
|
43
|
* @date 17 Feb 2015
|
44
|
*
|
45
|
*/
|
46
|
public class InspectSessionsDialog extends Dialog {
|
47
|
|
48
|
protected Object result;
|
49
|
protected Shell shlInspectSessions;
|
50
|
private Text text;
|
51
|
private Label lblDebugInformation;
|
52
|
|
53
|
private final Cache cdmlibModelCache;
|
54
|
|
55
|
private final ICdmEntitySession activeSession;
|
56
|
|
57
|
private TreeViewer treeViewer;
|
58
|
/**
|
59
|
* Create the dialog.
|
60
|
* @param parent
|
61
|
* @param style
|
62
|
*/
|
63
|
public InspectSessionsDialog(Shell parent, int style) {
|
64
|
super(parent, style);
|
65
|
setText("SWT Dialog");
|
66
|
cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
|
67
|
activeSession = CdmStore.getCurrentSessionManager().getActiveSession();
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Open the dialog.
|
72
|
* @return the result
|
73
|
*/
|
74
|
public Object open() {
|
75
|
createContents();
|
76
|
treeViewer.setContentProvider(new SessionsTreeContentProvider());
|
77
|
treeViewer.setLabelProvider(new SessionsTreeLabelProvider());
|
78
|
treeViewer.setInput(getRootElements());
|
79
|
shlInspectSessions.open();
|
80
|
shlInspectSessions.layout();
|
81
|
Display display = getParent().getDisplay();
|
82
|
while (!shlInspectSessions.isDisposed()) {
|
83
|
if (!display.readAndDispatch()) {
|
84
|
display.sleep();
|
85
|
}
|
86
|
}
|
87
|
return result;
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Create contents of the dialog.
|
92
|
*/
|
93
|
private void createContents() {
|
94
|
shlInspectSessions = new Shell(getParent(), getStyle());
|
95
|
shlInspectSessions.setSize(641, 529);
|
96
|
shlInspectSessions.setText("Inspect Sessions");
|
97
|
shlInspectSessions.setLayout(new GridLayout(1, false));
|
98
|
|
99
|
TreeViewer treeViewer = new TreeViewer(shlInspectSessions, SWT.BORDER);
|
100
|
Tree tree = treeViewer.getTree();
|
101
|
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
102
|
|
103
|
lblDebugInformation = new Label(shlInspectSessions, SWT.NONE);
|
104
|
lblDebugInformation.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
|
105
|
lblDebugInformation.setText("Debug Information :");
|
106
|
|
107
|
text = new Text(shlInspectSessions, SWT.BORDER);
|
108
|
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
109
|
|
110
|
}
|
111
|
|
112
|
private CdmEntityInfo[] getRootElements() {
|
113
|
EntityCacherDebugResult ecdr = activeSession.debug();
|
114
|
return (CdmEntityInfo[]) ecdr.getRootElements().toArray();
|
115
|
}
|
116
|
|
117
|
class SessionsTreeContentProvider implements ITreeContentProvider {
|
118
|
|
119
|
|
120
|
|
121
|
/* (non-Javadoc)
|
122
|
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
123
|
*/
|
124
|
@Override
|
125
|
public void dispose() {
|
126
|
|
127
|
}
|
128
|
|
129
|
/* (non-Javadoc)
|
130
|
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
131
|
*/
|
132
|
@Override
|
133
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
134
|
|
135
|
|
136
|
}
|
137
|
|
138
|
/* (non-Javadoc)
|
139
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
|
140
|
*/
|
141
|
@Override
|
142
|
public Object[] getElements(Object inputElement) {
|
143
|
return (CdmEntityInfo[])inputElement;
|
144
|
}
|
145
|
|
146
|
/* (non-Javadoc)
|
147
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
148
|
*/
|
149
|
@Override
|
150
|
public Object[] getChildren(Object parentElement) {
|
151
|
List<CdmEntityInfo> children = ((CdmEntityInfo)parentElement).getChildren();
|
152
|
return children.toArray();
|
153
|
}
|
154
|
|
155
|
/* (non-Javadoc)
|
156
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
157
|
*/
|
158
|
@Override
|
159
|
public Object getParent(Object element) {
|
160
|
CdmEntityInfo cei = (CdmEntityInfo)element;
|
161
|
return cei.getParent();
|
162
|
}
|
163
|
|
164
|
/* (non-Javadoc)
|
165
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
166
|
*/
|
167
|
@Override
|
168
|
public boolean hasChildren(Object element) {
|
169
|
List<CdmEntityInfo> children = ((CdmEntityInfo)element).getChildren();
|
170
|
if(children != null && !children.isEmpty()) {
|
171
|
return true;
|
172
|
} else {
|
173
|
return false;
|
174
|
}
|
175
|
}
|
176
|
|
177
|
public CdmModelFieldPropertyFromClass getFromCdmlibModelCache(String className) {
|
178
|
Element e = cdmlibModelCache.get(className);
|
179
|
if (e == null) {
|
180
|
return null;
|
181
|
} else {
|
182
|
return (CdmModelFieldPropertyFromClass) e.getObjectValue();
|
183
|
}
|
184
|
}
|
185
|
|
186
|
}
|
187
|
|
188
|
class SessionsTreeLabelProvider extends StyledCellLabelProvider {
|
189
|
|
190
|
@Override
|
191
|
public void update(ViewerCell cell) {
|
192
|
CdmEntityInfo cei = (CdmEntityInfo)cell.getElement();
|
193
|
StyledString text = new StyledString();
|
194
|
if(cei != null) {
|
195
|
text.append(cei.getLabel());
|
196
|
}
|
197
|
cell.setText(text.toString());
|
198
|
cell.setStyleRanges(text.getStyleRanges());
|
199
|
super.update(cell);
|
200
|
}
|
201
|
}
|
202
|
}
|
203
|
|
204
|
|