3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
.sessions
;
12 import java
.text
.DecimalFormat
;
13 import java
.util
.Collection
;
15 import net
.sf
.ehcache
.Cache
;
16 import net
.sf
.ehcache
.statistics
.LiveCacheStatistics
;
18 import org
.eclipse
.jface
.action
.IMenuManager
;
19 import org
.eclipse
.jface
.action
.IToolBarManager
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.events
.SelectionAdapter
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Label
;
28 import org
.eclipse
.swt
.widgets
.Table
;
29 import org
.eclipse
.swt
.widgets
.TableColumn
;
30 import org
.eclipse
.swt
.widgets
.TableItem
;
31 import org
.eclipse
.swt
.widgets
.Text
;
32 import org
.eclipse
.ui
.part
.ViewPart
;
33 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
35 import eu
.etaxonomy
.cdm
.api
.cache
.CdmCacher
;
36 import eu
.etaxonomy
.taxeditor
.remoting
.cache
.CdmRemoteCacheManager
;
37 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
38 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
39 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManagerObserver
;
40 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
47 public class SessionsViewPart
extends ViewPart
implements ICdmEntitySessionManagerObserver
{
49 public static final String ID
= "eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"; //$NON-NLS-1$
50 private Table tableSessions
;
52 private final String
[] titles
= { "Owner", "In Memory", "On Disk"};
54 private final ICdmEntitySessionManager cdmEntitySessionManager
;
55 private Text txtNoOfSessions
;
56 private Text txtNoOfCaches
;
57 private Text txtDefaultInMemory
;
58 private Text txtCdmModelInMemory
;
59 private Text txtCdmModelOnDisk
;
60 private Text txtDefaultOnDisk
;
61 public SessionsViewPart() {
62 this.cdmEntitySessionManager
= CdmStore
.getCurrentSessionManager();
63 if(cdmEntitySessionManager
!= null) {
64 cdmEntitySessionManager
.addSessionObserver(this);
69 * Create contents of the view part.
73 public void createPartControl(Composite parent
) {
74 Composite container
= new Composite(parent
, SWT
.NONE
);
75 container
.setLayout(new GridLayout(6, false));
77 Label lblNoOfSessions
= new Label(container
, SWT
.NONE
);
78 lblNoOfSessions
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
79 lblNoOfSessions
.setAlignment(SWT
.RIGHT
);
80 GridData gd_lblNoOfSessions
= new GridData(SWT
.RIGHT
, SWT
.FILL
, false, false, 1, 1);
81 gd_lblNoOfSessions
.widthHint
= 115;
82 gd_lblNoOfSessions
.minimumHeight
= 30;
83 lblNoOfSessions
.setLayoutData(gd_lblNoOfSessions
);
84 lblNoOfSessions
.setText("No. of Sessions : ");
87 txtNoOfSessions
= new Text(container
, SWT
.BORDER
);
88 txtNoOfSessions
.setEditable(false);
89 txtNoOfSessions
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT
));
90 GridData gd_txtNoOfSessions
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
91 gd_txtNoOfSessions
.widthHint
= 50;
92 txtNoOfSessions
.setLayoutData(gd_txtNoOfSessions
);
94 new Label(container
, SWT
.NONE
);
95 new Label(container
, SWT
.NONE
);
96 new Label(container
, SWT
.NONE
);
97 new Label(container
, SWT
.NONE
);
99 Label lblNoOfCaches
= new Label(container
, SWT
.CENTER
);
100 lblNoOfCaches
.setAlignment(SWT
.RIGHT
);
101 lblNoOfCaches
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
102 GridData gd_lblNoOfCaches
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
103 gd_lblNoOfCaches
.widthHint
= 150;
104 lblNoOfCaches
.setLayoutData(gd_lblNoOfCaches
);
105 lblNoOfCaches
.setText("No. of entity caches : ");
108 txtNoOfCaches
= new Text(container
, SWT
.BORDER
);
109 txtNoOfCaches
.setEditable(false);
110 GridData gd_txtNoOfCaches
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
111 gd_txtNoOfCaches
.widthHint
= 50;
112 txtNoOfCaches
.setLayoutData(gd_txtNoOfCaches
);
114 new Label(container
, SWT
.NONE
);
115 new Label(container
, SWT
.NONE
);
116 new Label(container
, SWT
.NONE
);
117 new Label(container
, SWT
.NONE
);
120 Label lblDefaultCache
= new Label(container
, SWT
.CENTER
);
121 lblDefaultCache
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
122 lblDefaultCache
.setText("Default Cache, ");
123 lblDefaultCache
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
124 lblDefaultCache
.setAlignment(SWT
.RIGHT
);
127 Label lblDefaultInMemory
= new Label(container
, SWT
.CENTER
);
128 lblDefaultInMemory
.setText("in Memory : ");
129 lblDefaultInMemory
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
130 lblDefaultInMemory
.setAlignment(SWT
.RIGHT
);
131 lblDefaultInMemory
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
134 txtDefaultInMemory
= new Text(container
, SWT
.BORDER
);
135 txtDefaultInMemory
.setEditable(false);
136 GridData gd_txtDefaultInMemory
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
137 gd_txtDefaultInMemory
.widthHint
= 130;
138 txtDefaultInMemory
.setLayoutData(gd_txtDefaultInMemory
);
141 Label lblDefaultOnDisk
= new Label(container
, SWT
.CENTER
);
142 lblDefaultOnDisk
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
143 lblDefaultOnDisk
.setText("on Disk : ");
144 lblDefaultOnDisk
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
145 lblDefaultOnDisk
.setAlignment(SWT
.RIGHT
);
148 txtDefaultOnDisk
= new Text(container
, SWT
.BORDER
);
149 txtDefaultOnDisk
.setEditable(false);
150 txtDefaultOnDisk
.setText("");
151 GridData gd_txtDefaultOnDisk
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
152 gd_txtDefaultOnDisk
.widthHint
= 130;
153 txtDefaultOnDisk
.setLayoutData(gd_txtDefaultOnDisk
);
155 new Label(container
, SWT
.NONE
);
157 Label lblCdmModelCache
= new Label(container
, SWT
.CENTER
);
158 lblCdmModelCache
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
159 lblCdmModelCache
.setText("CDM Model Cache, ");
160 lblCdmModelCache
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
161 lblCdmModelCache
.setAlignment(SWT
.RIGHT
);
164 Label lblCdmModelInMemory
= new Label(container
, SWT
.CENTER
);
165 lblCdmModelInMemory
.setText("in Memory : ");
166 lblCdmModelInMemory
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
167 lblCdmModelInMemory
.setAlignment(SWT
.RIGHT
);
168 GridData gd_lblCdmModelInMemory
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
169 gd_lblCdmModelInMemory
.widthHint
= 86;
170 lblCdmModelInMemory
.setLayoutData(gd_lblCdmModelInMemory
);
173 txtCdmModelInMemory
= new Text(container
, SWT
.BORDER
);
174 txtCdmModelInMemory
.setEditable(false);
175 GridData gd_txtCdmModelInMemory
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
176 gd_txtCdmModelInMemory
.widthHint
= 130;
177 txtCdmModelInMemory
.setLayoutData(gd_txtCdmModelInMemory
);
180 Label lblCdmModelOnDisk
= new Label(container
, SWT
.CENTER
);
181 lblCdmModelOnDisk
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
182 lblCdmModelOnDisk
.setText("on Disk : ");
183 lblCdmModelOnDisk
.setFont(SWTResourceManager
.getFont("Ubuntu", 10, SWT
.NORMAL
));
184 lblCdmModelOnDisk
.setAlignment(SWT
.RIGHT
);
187 txtCdmModelOnDisk
= new Text(container
, SWT
.BORDER
);
188 txtCdmModelOnDisk
.setEditable(false);
189 txtCdmModelOnDisk
.setText("");
190 GridData gd_txtCdmModelOnDisk
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
191 gd_txtCdmModelOnDisk
.widthHint
= 130;
192 txtCdmModelOnDisk
.setLayoutData(gd_txtCdmModelOnDisk
);
194 new Label(container
, SWT
.NONE
);
196 Button btnRefresh
= new Button(container
, SWT
.NONE
);
197 btnRefresh
.addSelectionListener(new SelectionAdapter() {
199 public void widgetSelected(SelectionEvent e
) {
203 GridData gd_btnRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
204 gd_btnRefresh
.widthHint
= 100;
205 btnRefresh
.setLayoutData(gd_btnRefresh
);
206 btnRefresh
.setText("Refresh");
208 new Label(container
, SWT
.NONE
);
209 new Label(container
, SWT
.NONE
);
210 new Label(container
, SWT
.NONE
);
211 new Label(container
, SWT
.NONE
);
212 new Label(container
, SWT
.NONE
);
215 tableSessions
= new Table(container
, SWT
.BORDER
| SWT
.FULL_SELECTION
);
216 tableSessions
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 5, 1));
217 tableSessions
.setHeaderVisible(true);
218 tableSessions
.setLinesVisible(true);
220 new Label(container
, SWT
.NONE
);
228 * Create the actions.
230 private void createActions() {
233 for (String title
: titles
) {
234 TableColumn column
= new TableColumn(tableSessions
, SWT
.NULL
);
235 column
.setWidth(200);
236 column
.setText(title
);
244 public void changed() {
245 tableSessions
.removeAll();
246 if(cdmEntitySessionManager
!= null) {
247 Collection
<ICdmEntitySession
> sessions
= cdmEntitySessionManager
.getSessions();
248 txtNoOfSessions
.setText(String
.valueOf(sessions
.size()));
249 for(ICdmEntitySession session
: sessions
) {
250 if(session
.getOwner() != null) {
251 TableItem item
= new TableItem(tableSessions
, SWT
.NULL
);
252 item
.setText(session
.getOwner().toString());
253 String activePrefix
= "";
254 if(session
.isActive()) {
257 item
.setText(0, activePrefix
+ session
.getOwner().toString());
258 LiveCacheStatistics cacheStatistics
= session
.getCacheStatistics();
259 item
.setText(1, getInMemoryStats(cacheStatistics
));
260 item
.setText(2, getOnDiskStats(cacheStatistics
));
263 for (int i
=0; i
<titles
.length
; i
++) {
264 tableSessions
.getColumn (i
).pack ();
268 CdmRemoteCacheManager instance
= CdmRemoteCacheManager
.getInstance();
269 int cdmEnityCacheSize
= instance
.getDefaultCacheManager().getCacheNames().length
;
270 txtNoOfCaches
.setText(String
.valueOf(cdmEnityCacheSize
));
272 Cache defaultCache
= instance
.getDefaultCacheManager().getCache(CdmCacher
.DEFAULT_CACHE_NAME
);
273 txtDefaultInMemory
.setText("");
274 txtDefaultOnDisk
.setText("");
275 if(defaultCache
!= null) {
276 LiveCacheStatistics liveCacheStatistics
= defaultCache
.getLiveCacheStatistics();
277 txtDefaultInMemory
.setText(getInMemoryStats(liveCacheStatistics
));
278 txtDefaultOnDisk
.setText(getOnDiskStats(liveCacheStatistics
));
281 Cache cdmModelGetMethodsCache
= instance
.getCdmModelGetMethodsCache();
282 txtCdmModelInMemory
.setText("");
283 txtCdmModelOnDisk
.setText("");
284 if(cdmModelGetMethodsCache
!= null) {
285 LiveCacheStatistics liveCacheStatistics
= cdmModelGetMethodsCache
.getLiveCacheStatistics();
286 txtCdmModelInMemory
.setText(getInMemoryStats(liveCacheStatistics
));
287 txtCdmModelOnDisk
.setText(getOnDiskStats(liveCacheStatistics
));
292 private String
getInMemoryStats(LiveCacheStatistics statistics
) {
293 long localHeapSize
= statistics
.getLocalHeapSize();
295 long localHeapSizeInBytes
= statistics
.getLocalHeapSizeInBytes();
296 String localHeapSizeInBytesStr
=
297 (new DecimalFormat("#.##")).format(localHeapSizeInBytes
/1048576.0);
298 return String
.valueOf(localHeapSize
) + " objects / " + localHeapSizeInBytesStr
+ " Mb";
301 private String
getOnDiskStats(LiveCacheStatistics statistics
) {
302 long localDiskSize
= statistics
.getLocalDiskSize();
304 long localDiskSizeInBytes
= statistics
.getLocalDiskSizeInBytes();
305 String localDiskSizeInBytesStr
=
306 (new DecimalFormat("#.##")).format(localDiskSizeInBytes
/1048576.0);
307 return String
.valueOf(localDiskSize
) + " objects / " + localDiskSizeInBytesStr
+ " Mb";
311 * Initialize the toolbar.
313 private void initializeToolBar() {
314 IToolBarManager toolbarManager
= getViewSite().getActionBars().getToolBarManager();
318 * Initialize the menu.
320 private void initializeMenu() {
321 IMenuManager menuManager
= getViewSite().getActionBars().getMenuManager();
325 public void setFocus() {