]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui/src/org/argeo/security/ui/views/AdminLogView.java
Remove old dirty system.out.println() call
[lgpl/argeo-commons.git] / org.argeo.security.ui / src / org / argeo / security / ui / views / AdminLogView.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.ui.views;
17
18 import java.util.ArrayList;
19
20 import org.argeo.ArgeoLogger;
21 import org.argeo.security.ui.SecurityUiPlugin;
22 import org.eclipse.jface.resource.JFaceResources;
23 import org.eclipse.jface.viewers.LabelProvider;
24 import org.eclipse.jface.viewers.TableViewer;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.graphics.Font;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Table;
29 import org.eclipse.ui.part.ViewPart;
30
31 /**
32 * Display log lines for all users with a virtual table.
33 */
34 public class AdminLogView extends ViewPart {
35 public static String ID = SecurityUiPlugin.PLUGIN_ID + ".adminLogView";
36
37 private TableViewer viewer;
38
39 private LogContentProvider logContentProvider;
40 private ArgeoLogger argeoLogger;
41
42 @Override
43 public void createPartControl(Composite parent) {
44 // FIXME doesn't return a monospace font in RAP
45 Font font = JFaceResources.getTextFont();
46 Table table = new Table(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL
47 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
48 table.setFont(font);
49
50 viewer = new TableViewer(table);
51 viewer.setLabelProvider(new LabelProvider());
52 logContentProvider = new LogContentProvider(viewer) {
53 private static final long serialVersionUID = -3401776448301180724L;
54
55 @Override
56 protected StringBuffer prefix(String username, Long timestamp,
57 String level, String category, String thread) {
58 return super
59 .prefix(username, timestamp, level, category, thread)
60 .append(norm(level, 5))
61 .append(' ')
62 .append(norm(username != null ? username
63 : "<anonymous>", 16)).append(' ');
64 }
65 };
66 viewer.setContentProvider(logContentProvider);
67 // viewer.setUseHashlookup(true);
68 viewer.setInput(new ArrayList<String>());
69
70 if (argeoLogger != null)
71 argeoLogger.registerForAll(logContentProvider, 1000, true);
72 }
73
74 @Override
75 public void setFocus() {
76 viewer.getTable().setFocus();
77 }
78
79 @Override
80 public void dispose() {
81 if (argeoLogger != null)
82 argeoLogger.unregisterForAll(logContentProvider);
83 }
84
85 public void setArgeoLogger(ArgeoLogger argeoLogger) {
86 this.argeoLogger = argeoLogger;
87 }
88
89 }