]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogContentProvider.java
5e28228a11cf330d649597952d0634ea462e022f
1 package org
.argeo
.security
.ui
.views
;
3 import java
.text
.DateFormat
;
4 import java
.text
.SimpleDateFormat
;
8 import org
.argeo
.ArgeoLogListener
;
9 import org
.eclipse
.jface
.viewers
.ILazyContentProvider
;
10 import org
.eclipse
.jface
.viewers
.TableViewer
;
11 import org
.eclipse
.jface
.viewers
.Viewer
;
13 /** A content provider maintaing an array of lines */
14 class LogContentProvider
implements ILazyContentProvider
, ArgeoLogListener
{
15 private DateFormat dateFormat
= new SimpleDateFormat("HH:mm:ss");
17 private final TableViewer viewer
;
18 private List
<String
> lines
;
20 public LogContentProvider(TableViewer viewer
) {
24 public synchronized void dispose() {
28 @SuppressWarnings("unchecked")
29 public synchronized void inputChanged(Viewer viewer
, Object oldInput
,
31 lines
= (List
<String
>) newInput
;
34 this.viewer
.setItemCount(lines
.size());
37 public void updateElement(int index
) {
38 viewer
.replace(lines
.get(index
), index
);
41 public synchronized void appendLog(String username
, Long timestamp
,
42 String level
, String category
, String thread
, Object msg
,
48 String message
= msg
.toString();
49 StringBuffer buf
= new StringBuffer("");
50 buf
.append(dateFormat
.format(new Date(timestamp
))).append(" ");
51 buf
.append(level
).append(" ");
53 String lastLine
= null;
54 for (String line
: message
.split("\n")) {
56 lastLine
= buf
+ line
;
63 if (exception
!= null) {
64 for (String ste
: exception
) {
69 final Object lastElement
= lastLine
;
70 viewer
.getTable().getDisplay().asyncExec(new Runnable() {
72 viewer
.setItemCount(lines
.size());
73 if (lastElement
!= null)
74 viewer
.reveal(lastElement
);
78 // private class LogLine {
79 // private String message;