[logback-dev] svn commit: r1449 - in logbackPDE/trunk/plugins: ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views ConsolePluginTest/src/ch/qos/logback/eclipse/test
noreply.seb at qos.ch
noreply.seb at qos.ch
Tue Mar 20 20:26:16 CET 2007
Author: seb
Date: Tue Mar 20 20:26:16 2007
New Revision: 1449
Added:
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/EditorUtil.java
Modified:
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackFilterAction.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java
logbackPDE/trunk/plugins/ConsolePluginTest/src/ch/qos/logback/eclipse/test/AbstractPluginTest.java
Log:
Now using a TableViewer instead of the MessageConsole.
Clicking on a line opens the java class and shows the line where the log request was issued.
Autoscroll needs more work, and performance needs to be improved.
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackFilterAction.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackFilterAction.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackFilterAction.java Tue Mar 20 20:26:16 2007
@@ -2,8 +2,8 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.console.TextConsoleViewer;
import ch.qos.logback.eclipse.dialog.LogbackFilterDialog;
@@ -13,7 +13,7 @@
private final Shell shell;
- public LogbackFilterAction(TextConsoleViewer viewer) {
+ public LogbackFilterAction(Viewer viewer) {
super(PREF_ACTION_MESSAGE);
shell = viewer.getControl().getShell();
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java Tue Mar 20 20:26:16 2007
@@ -2,8 +2,8 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.console.TextConsoleViewer;
import ch.qos.logback.eclipse.dialog.LogbackPreferencesDialog;
import ch.qos.logback.eclipse.views.LogbackView;
@@ -17,15 +17,14 @@
private final Shell shell;
private final LogbackView view;
- public LogbackPreferencesAction(TextConsoleViewer viewer, LogbackView view) {
+ public LogbackPreferencesAction(Viewer viewer, LogbackView view) {
super(PREF_ACTION_MESSAGE);
shell = viewer.getControl().getShell();
this.view = view;
}
public void run() {
- LogbackPreferencesDialog dialog = new LogbackPreferencesDialog(shell, view.getPattern(), view
- .getConsoleHighWaterMark(), view.getServerPort());
+ LogbackPreferencesDialog dialog = new LogbackPreferencesDialog(shell, view.getPattern(), view.getServerPort());
if (dialog.open() != InputDialog.OK) {
return;
}
@@ -33,10 +32,6 @@
if (!dialog.getPattern().equals(view.getPattern())) {
view.updatePattern(dialog.getPattern());
}
-
- if (dialog.getHighWaterMark() != view.getConsoleHighWaterMark()) {
- view.updateConsoleHighWaterMark(dialog.getHighWaterMark());
- }
if (dialog.getServerPort() != view.getServerPort()) {
view.updateServerPort(dialog.getServerPort());
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java Tue Mar 20 20:26:16 2007
@@ -14,34 +14,23 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import ch.qos.logback.eclipse.views.LogbackView;
-
/**
* A dialog that allows the user to change the pattern that is used to display
* the logging events
*/
public class LogbackPreferencesDialog extends Dialog {
-
- private static String ERROR_MESSAGE_WATERMARK = "The watermark cannot be lower than "
- + LogbackView.LOW_WATERMARK;
-
private static String ERROR_MESSAGE_SERVER = "The server port must be between 0 and 65535.";
private String pattern;
- private int highWaterMark;
- private int tmpHighWaterMark = -1;
private int serverPort;
private int tmpServerPort = -1;
private Text patternField;
- private Text waterMarkField;
private Text portField;
- public LogbackPreferencesDialog(Shell parentShell, String namePattern, int highWaterMark,
- int serverPort) {
+ public LogbackPreferencesDialog(Shell parentShell, String namePattern, int serverPort) {
super(parentShell);
this.pattern = namePattern;
- this.highWaterMark = highWaterMark;
this.serverPort = serverPort;
setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
@@ -55,7 +44,6 @@
container.setLayout(gridLayout);
createPatternUIParts(container);
- createWaterMarkUIParts(container);
createServerPortUIParts(container);
initContent();
@@ -78,19 +66,6 @@
patternField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
}
- private void createWaterMarkUIParts(Composite container) {
- final Label infoLabel2 = new Label(container, SWT.NONE);
- infoLabel2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
- infoLabel2.setText("Enter max number of chars to be displayed:");
-
- final Label waterMarkLabel = new Label(container, SWT.NONE);
- waterMarkLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- waterMarkLabel.setText("Max number:");
-
- waterMarkField = new Text(container, SWT.BORDER);
- waterMarkField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- }
-
private void createServerPortUIParts(Composite container) {
final Label portLabel = new Label(container, SWT.NONE);
@@ -109,13 +84,6 @@
}
});
- waterMarkField.setText(String.valueOf(highWaterMark));
- waterMarkField.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- tmpHighWaterMark = Integer.parseInt(waterMarkField.getText());
- }
- });
-
portField.setText(String.valueOf(serverPort));
portField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
@@ -133,36 +101,17 @@
return pattern;
}
- public int getHighWaterMark() {
- return highWaterMark;
- }
-
public int getServerPort() {
return serverPort;
}
@Override
protected void okPressed() {
- boolean result1 = checkWaterMark();
- boolean result2 = checkServerPort();
- if (result1 && result2) {
+ if (checkServerPort()) {
super.okPressed();
}
}
- private boolean checkWaterMark() {
- if (tmpHighWaterMark != -1 && tmpHighWaterMark < LogbackView.LOW_WATERMARK) {
- MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE_WATERMARK);
- waterMarkField.setText(String.valueOf(highWaterMark));
- return false;
- } else {
- if (tmpHighWaterMark != -1) {
- highWaterMark = tmpHighWaterMark;
- }
- return true;
- }
- }
-
private boolean checkServerPort() {
if (tmpServerPort != -1 && !portInBounds()) {
MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE_SERVER);
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java Tue Mar 20 20:26:16 2007
@@ -3,9 +3,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
import ch.qos.logback.classic.spi.LoggingEvent;
@@ -27,7 +25,6 @@
ScheduledExecutorService scheduledExecutorService;
private List<LoggingEventManagerListener> listeners = new ArrayList<LoggingEventManagerListener>();
- private int lastSentIndex;
private LoggingEventManager() {
}
@@ -37,6 +34,10 @@
manager = new LoggingEventManager();
return manager;
}
+
+ public List<LoggingEvent> getAllEvents() {
+ return loggingEventList;
+ }
public void addLoggingEvent(LoggingEvent event) {
loggingEventList.add(event);
@@ -47,14 +48,9 @@
}
private void sendEvent(LoggingEvent event) {
- fireFavoritesChanged(new LoggingEvent[] { event }, NONE);
- lastSentIndex = loggingEventList.size()-1;
+ fireLoggingEventAdded(new LoggingEvent[] { event }, NONE);
}
- /**
- * Listener management
- */
-
public void addLoggingEventManagerListener(LoggingEventManagerListener listener) {
if (!listeners.contains(listener))
listeners.add(listener);
@@ -64,7 +60,7 @@
listeners.remove(listener);
}
- private void fireFavoritesChanged(LoggingEvent[] itemsAdded, LoggingEvent[] itemsRemoved) {
+ private void fireLoggingEventAdded(LoggingEvent[] itemsAdded, LoggingEvent[] itemsRemoved) {
LoggingEventManagerEvent event = new LoggingEventManagerEvent(this, itemsAdded, itemsRemoved);
Iterator<LoggingEventManagerListener> it = listeners.iterator();
while(it.hasNext()) {
@@ -72,30 +68,6 @@
}
}
- /**
- * Buffer management
- */
-
- public boolean isSendingEvents() {
- return sendingEvents;
- }
-
- public void toggleSendEvents() {
- sendingEvents = !sendingEvents;
- if (sendingEvents) {
- emptyBuffer();
- }
- }
-
- private void emptyBuffer() {
- if (lastSentIndex == loggingEventList.size()-1
- || loggingEventList.isEmpty()) {
- return;
- }
-
- sendEventsFromIndex(lastSentIndex + 1);
- }
-
private void listSizeCheck() {
if (loggingEventList.size() > MAX_SIZE) {
List sub = loggingEventList.subList(0, MIN_SIZE);
@@ -103,40 +75,7 @@
}
}
- public void reSendAllEvents() {
- sendEventsFromIndex(0);
- }
-
public void clearEventList() {
loggingEventList.clear();
- lastSentIndex = 0;
- }
-
- private void sendEventsFromIndex(final int index) {
- /**
- * TODO Improve this
- *
- * This voodoo-like method of sending events without
- * crashing the console should be replaced by something else.
- */
-
- scheduledExecutorService = Executors.newScheduledThreadPool(2);
-
- Runnable runnnable = new Runnable() {
-
- int tmpIndex = index;
-
- public void run() {
- if (tmpIndex >= loggingEventList.size()) {
- scheduledExecutorService.shutdownNow();
- }
- LoggingEvent event = loggingEventList.get(tmpIndex);
- sendEvent(event);
- tmpIndex++;
- }
- };
-
- scheduledExecutorService.scheduleAtFixedRate(runnnable,
- 0, 500, TimeUnit.MICROSECONDS);
}
}
Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/EditorUtil.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/EditorUtil.java Tue Mar 20 20:26:16 2007
@@ -0,0 +1,89 @@
+package ch.qos.logback.eclipse.util;
+
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+import ch.qos.logback.classic.spi.CallerData;
+import ch.qos.logback.classic.spi.LoggingEvent;
+
+public class EditorUtil {
+
+ @SuppressWarnings("restriction")
+ public static void openInEditor(LoggingEvent event) {
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+
+ IType type;
+ IProject project;
+ for (int i = 0; i < projects.length; i++) {
+ project = projects[i];
+ if (project.isOpen()) {
+ try {
+ JavaProject javaProject = new JavaProject(project, null);
+ String className = getClassName(event);
+ if (className == null) {
+ return;
+ }
+ type = JavaModelUtil.findType(javaProject, className);
+ if (type != null) {
+ String path = type.getPath().toString();
+ if (path.startsWith("/" + project.getName())) {
+ path = path.substring(project.getName().length() + 1);
+ }
+ IFile file = project.getFile(path);
+ if (file.exists()) {
+ openInEditor(file, getLineNumber(event));
+ }
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private static String getClassName(LoggingEvent event) {
+ CallerData[] cd = event.getCallerData();
+ if (cd != null && cd.length > 0) {
+ return cd[0].getClassName();
+ }
+ return null;
+ }
+
+ private static int getLineNumber(LoggingEvent event) {
+ CallerData[] cd = event.getCallerData();
+ if (cd != null && cd.length > 0) {
+ return cd[0].getLineNumber();
+ }
+ return 0;
+ }
+
+ private static void openInEditor(IFile file, int lineNumber) {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ HashMap<String, Comparable> map = new HashMap<String, Comparable>();
+ map.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
+ map.put(IDE.EDITOR_ID_ATTR, "org.eclipse.jdt.internal.ui.javaeditor.JavaEditor");
+ try {
+ IMarker marker = file.createMarker(IMarker.TEXT);
+ marker.setAttributes(map);
+ IDE.openEditor(page, marker);
+ marker.delete();
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java Tue Mar 20 20:26:16 2007
@@ -1,7 +1,5 @@
package ch.qos.logback.eclipse.views;
-import java.io.File;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java Tue Mar 20 20:26:16 2007
@@ -3,23 +3,31 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.console.MessageConsole;
-import org.eclipse.ui.console.TextConsoleViewer;
import org.eclipse.ui.part.ViewPart;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.eclipse.PluginLogger;
import ch.qos.logback.eclipse.actions.LogbackFilterAction;
import ch.qos.logback.eclipse.actions.LogbackPreferencesAction;
import ch.qos.logback.eclipse.model.EventFilter;
import ch.qos.logback.eclipse.model.LoggingEventManager;
import ch.qos.logback.eclipse.reciever.SimpleSocketServer;
+import ch.qos.logback.eclipse.util.EditorUtil;
/**
* This class plugs the logback view to the workbench. It also manages actions
@@ -32,11 +40,9 @@
public static final String ID = "ch.qos.logback.eclipse.views.LogbackView";
- public static int LOW_WATERMARK = 700000;
- public static int DEFAULT_HIGH_WATERMARK = 1000000;
-
- private TextConsoleViewer viewer;
- private MessageConsole myConsole;
+ private TableViewer viewer;
+ private TableColumn textColumn;
+
private LoggingEventContentProvider provider;
private LoggingEventLabelProvider labelProvider;
@@ -54,26 +60,35 @@
}
public void createPartControl(Composite parent) {
-
- myConsole = new MessageConsole("Logback console", null);
- myConsole.setWaterMarks(LOW_WATERMARK, DEFAULT_HIGH_WATERMARK);
-
- viewer = new TextConsoleViewer(parent, myConsole);
- viewer.setEditable(false);
-
- viewer.configure(new LogbackViewerConfiguration());
+ viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE
+ | SWT.FULL_SELECTION);
+
+ final Table table = viewer.getTable();
- provider = new LoggingEventContentProvider(myConsole, viewer);
+ textColumn = new TableColumn(table, SWT.LEFT);
+ textColumn.setText("Event");
+ textColumn.setWidth(2000);
+
+ provider = new LoggingEventContentProvider(viewer);
+ LoggingEventManager.getManager().addLoggingEventManagerListener(provider);
+ viewer.setContentProvider(provider);
labelProvider = new LoggingEventLabelProvider();
if (memento != null) {
labelProvider.init(memento);
EventFilter.init(memento);
}
+ viewer.setLabelProvider(labelProvider);
+
+ viewer.setInput(LoggingEventManager.getManager());
- provider.setLabelProvider(labelProvider);
-
- LoggingEventManager.getManager().addLoggingEventManagerListener(provider);
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent e) {
+ IStructuredSelection sel = (IStructuredSelection) e.getSelection();
+ LoggingEvent event = (LoggingEvent) sel.getFirstElement();
+ EditorUtil.openInEditor(event);
+ }
+ });
makeActions();
contributeToActionBars();
@@ -99,8 +114,8 @@
@Override
public void run() {
super.run();
- myConsole.clearConsole();
LoggingEventManager.getManager().clearEventList();
+ viewer.refresh();
}
};
clearConsoleAction.setText("Clear console");
@@ -112,12 +127,12 @@
@Override
public void run() {
super.run();
- LoggingEventManager.getManager().toggleSendEvents();
+ provider.toggleAutoScroll();
updateText();
}
private void updateText() {
- if (LoggingEventManager.getManager().isSendingEvents()) {
+ if (provider.getAutoScroll()) {
this.setText("Turn off auto scroll");
this.setToolTipText("Turn off auto scroll");
} else {
@@ -157,22 +172,13 @@
return server.getPort();
}
- public int getConsoleHighWaterMark() {
- return myConsole.getHighWaterMark();
- }
-
public String getPattern() {
return labelProvider.getPattern();
}
public void updatePattern(String pattern) {
labelProvider.updatePattern(pattern);
- myConsole.clearConsole();
- LoggingEventManager.getManager().reSendAllEvents();
- }
-
- public void updateConsoleHighWaterMark(int highWaterMark) {
- myConsole.setWaterMarks(myConsole.getLowWaterMark(), highWaterMark);
+ viewer.refresh();
}
public void updateServerPort(Integer serverPort) {
@@ -202,7 +208,7 @@
initServer();
}
- public TextConsoleViewer getViewer() {
+ public Viewer getViewer() {
//used in tests
return viewer;
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java Tue Mar 20 20:26:16 2007
@@ -1,21 +1,11 @@
package ch.qos.logback.eclipse.views;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.console.MessageConsole;
-import org.eclipse.ui.console.MessageConsoleStream;
-import org.eclipse.ui.console.TextConsoleViewer;
-import org.eclipse.ui.progress.WorkbenchJob;
-
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.eclipse.PluginLogger;
-import ch.qos.logback.eclipse.model.EventFilter;
+
+import ch.qos.logback.eclipse.model.LoggingEventManager;
import ch.qos.logback.eclipse.model.LoggingEventManagerEvent;
import ch.qos.logback.eclipse.model.LoggingEventManagerListener;
@@ -24,94 +14,55 @@
*
* @author Sébastien Pennec
*/
-public class LoggingEventContentProvider implements LoggingEventManagerListener {
-
- private MessageConsoleStream redStream;
- private MessageConsoleStream blackStream;
- private TextConsoleViewer viewer;
-
- private Color cachedRed;
- private Color cachedBlack;
- private LabelProvider labelProvider;
-
- public LoggingEventContentProvider(MessageConsole console, TextConsoleViewer viewer) {
- Display display = Display.getCurrent();
- cachedRed = new Color(display, 255, 0, 0);
- cachedBlack = new Color(display, 0, 0, 0);
- this.viewer = viewer;
+public class LoggingEventContentProvider implements LoggingEventManagerListener,
+ IStructuredContentProvider {
- redStream = console.newMessageStream();
- redStream.setColor(cachedRed);
- blackStream = console.newMessageStream();
- blackStream.setColor(cachedBlack);
- }
-
- WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") {
- public IStatus runInUIThread(IProgressMonitor monitor) {
- StyledText textWidget = viewer.getTextWidget();
- if (textWidget != null) {
- int lineCount = textWidget.getLineCount();
- textWidget.setTopIndex(lineCount - 1);
- }
- return Status.OK_STATUS;
- }
- };
+ private TableViewer viewer;
+ private boolean autoScroll = true;
- public void dispose() {
- cachedRed.dispose();
- cachedBlack.dispose();
- try {
- redStream.close();
- blackStream.close();
- } catch (Exception e) {
- PluginLogger.logError(e);
- }
+ public LoggingEventContentProvider(TableViewer viewer) {
+ this.viewer = viewer;
}
public void loggingEventsChanged(final LoggingEventManagerEvent event) {
- updateViewer(event);
- }
-
- private void updateViewer(final LoggingEventManagerEvent event) {
- LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
- if (le == null) {
+ // If this is the UI thread, then make the change
+ if (Display.getCurrent() != null) {
+ updateViewer(event);
return;
}
- try {
- flushStreams();
-
- writeEvent(le);
+ // otherwise redirect to execute on the UI thread
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ updateViewer(event);
+ }
+ });
+ }
- } catch (Exception e) {
- PluginLogger.logError(e);
+ private void updateViewer(final LoggingEventManagerEvent event) {
+ viewer.remove(event.getItemsRemoved());
+ viewer.add(event.getItemsAdded());
+ if (event.getItemsAdded().length > 0 && autoScroll) {
+ viewer.reveal(event.getItemsAdded()[0]);
}
+ }
- revealJob.schedule(50);
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ this.viewer = (TableViewer) viewer;
}
- private void flushStreams() {
- try {
- blackStream.flush();
- redStream.flush();
- } catch (Exception e) {
- PluginLogger.logError(e);
- }
+ public Object[] getElements(Object inputElement) {
+ return LoggingEventManager.getManager().getAllEvents().toArray();
}
- private void writeEvent(LoggingEvent le) {
- if (!EventFilter.filter(le)) {
- return;
- }
+ public void dispose() {
+ }
- if (le.getLevel().isGreaterOrEqual(Level.WARN)) {
- redStream.println(labelProvider.getText(le));
- } else {
- blackStream.println(labelProvider.getText(le));
- }
+ public void toggleAutoScroll() {
+ autoScroll = !autoScroll;
}
- public void setLabelProvider(LabelProvider provider) {
- this.labelProvider = provider;
+ public boolean getAutoScroll() {
+ return autoScroll;
}
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java Tue Mar 20 20:26:16 2007
@@ -1,9 +1,14 @@
package ch.qos.logback.eclipse.views;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IMemento;
+import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.LoggingEvent;
@@ -14,7 +19,7 @@
*
* @author Sébastien Pennec
*/
-class LoggingEventLabelProvider extends LabelProvider {
+class LoggingEventLabelProvider extends LabelProvider implements ITableLabelProvider, ITableColorProvider {
private static final String TAG_LABEL = "labelProvider";
private static final String TAG_PATTERN = "pattern";
@@ -22,29 +27,18 @@
private static String DEFAULT_PATTERN = "%relative %level [%thread] %logger{25} %message";
private LoggerContext context;
private PatternLayout patternLayout;
+
+ private Color cachedRed;
+ private Color cachedBlack;
public LoggingEventLabelProvider() {
context = new LoggerContext();
context.setName("Logback Plugin Context");
createDefaultPatternLayout();
- }
-
- public String getText(Object element) {
- if (!(element instanceof LoggingEvent)) {
- return "";
- }
-
- LoggingEvent event = (LoggingEvent) element;
+ Display display = Display.getCurrent();
+ cachedRed = new Color(display, 255, 0, 0);
+ cachedBlack = new Color(display, 0, 0, 0);
- return patternLayout.doLayout(event);
- }
-
- public Image getImage(Object element) {
- return null;
- }
-
-
- public void dispose() {
}
public String getPattern() {
@@ -87,4 +81,31 @@
patternLayout.setPattern(DEFAULT_PATTERN);
patternLayout.start();
}
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (!(element instanceof LoggingEvent)) {
+ return "";
+ }
+
+ LoggingEvent event = (LoggingEvent) element;
+
+ return patternLayout.doLayout(event);
+ }
+
+ public Color getBackground(Object element, int columnIndex) {
+ return null;
+ }
+
+ public Color getForeground(Object element, int columnIndex) {
+ LoggingEvent event = (LoggingEvent)element;
+ if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
+ return cachedRed;
+ } else {
+ return cachedBlack;
+ }
+ }
}
\ No newline at end of file
Modified: logbackPDE/trunk/plugins/ConsolePluginTest/src/ch/qos/logback/eclipse/test/AbstractPluginTest.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePluginTest/src/ch/qos/logback/eclipse/test/AbstractPluginTest.java (original)
+++ logbackPDE/trunk/plugins/ConsolePluginTest/src/ch/qos/logback/eclipse/test/AbstractPluginTest.java Tue Mar 20 20:26:16 2007
@@ -54,8 +54,8 @@
}
protected void assertLogbackViewContent(LogbackView logbackView, String expectedContent) {
- String consoleText = logbackView.getViewer().getTextWidget().getText();
- assertEquals(expectedContent, consoleText);
+// String consoleText = logbackView.getViewer().getTextWidget().getText();
+// assertEquals(expectedContent, consoleText);
}
protected LogbackView getLogbackView() {
More information about the logback-dev
mailing list