]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/AdminLogView.java
Internationalization support
[lgpl/argeo-commons.git] / security / plugins / org.argeo.security.ui / src / main / java / org / argeo / security / ui / views / AdminLogView.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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
54 @Override
55 protected StringBuffer prefix(String username, Long timestamp,
56 String level, String category, String thread) {
57 return super
58 .prefix(username, timestamp, level, category, thread)
59 .append(norm(level, 5))
60 .append(' ')
61 .append(norm(username != null ? username
62 : "<anonymous>", 16)).append(' ');
63 }
64 };
65 viewer.setContentProvider(logContentProvider);
66 // viewer.setUseHashlookup(true);
67 viewer.setInput(new ArrayList<String>());
68
69 if (argeoLogger != null)
70 argeoLogger.registerForAll(logContentProvider, 1000, true);
71 }
72
73 @Override
74 public void setFocus() {
75 viewer.getTable().setFocus();
76 }
77
78 @Override
79 public void dispose() {
80 if (argeoLogger != null)
81 argeoLogger.unregisterForAll(logContentProvider);
82 }
83
84 public void setArgeoLogger(ArgeoLogger argeoLogger) {
85 this.argeoLogger = argeoLogger;
86 }
87
88 }