[logback-dev] svn commit: r1450 - in logbackPDE/trunk/plugins/ConsolePlugin: icons src/main/java/ch/qos/logback/eclipse/model src/main/java/ch/qos/logback/eclipse/util src/main/java/ch/qos/logback/eclipse/views
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Mar 22 10:28:23 CET 2007
Author: seb
Date: Thu Mar 22 10:28:23 2007
New Revision: 1450
Added:
logbackPDE/trunk/plugins/ConsolePlugin/icons/call_hierarchy.gif (contents, props changed)
logbackPDE/trunk/plugins/ConsolePlugin/icons/lock_co.gif (contents, props changed)
Modified:
logbackPDE/trunk/plugins/ConsolePlugin/icons/ (props changed)
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/util/EditorUtil.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
Log:
New version of the table using the SWT.VIRTUAL attribute. Good performance benefit.
Double clicking on a line opens a java editor at the line where the request was issued.
Nicer icon set
Added: logbackPDE/trunk/plugins/ConsolePlugin/icons/call_hierarchy.gif
==============================================================================
Binary file. No diff available.
Added: logbackPDE/trunk/plugins/ConsolePlugin/icons/lock_co.gif
==============================================================================
Binary file. No diff available.
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 Thu Mar 22 10:28:23 2007
@@ -78,4 +78,15 @@
public void clearEventList() {
loggingEventList.clear();
}
+
+ public LoggingEvent getEvent(int index) {
+ if (index > loggingEventList.size()-1) {
+ return null;
+ }
+ return loggingEventList.get(index);
+ }
+
+ public int getEventCount() {
+ return loggingEventList.size();
+ }
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/EditorUtil.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/EditorUtil.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/util/EditorUtil.java Thu Mar 22 10:28:23 2007
@@ -72,7 +72,7 @@
private static void openInEditor(IFile file, int lineNumber) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- HashMap<String, Comparable> map = new HashMap<String, Comparable>();
+ HashMap<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
map.put(IDE.EDITOR_ID_ATTR, "org.eclipse.jdt.internal.ui.javaeditor.JavaEditor");
try {
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 Thu Mar 22 10:28:23 2007
@@ -1,8 +1,11 @@
package ch.qos.logback.eclipse.views;
+import java.net.URL;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -21,6 +24,7 @@
import org.eclipse.ui.part.ViewPart;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.eclipse.LogbackPlugin;
import ch.qos.logback.eclipse.PluginLogger;
import ch.qos.logback.eclipse.actions.LogbackFilterAction;
import ch.qos.logback.eclipse.actions.LogbackPreferencesAction;
@@ -61,13 +65,15 @@
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE
- | SWT.FULL_SELECTION);
+ | SWT.FULL_SELECTION | SWT.VIRTUAL);
final Table table = viewer.getTable();
textColumn = new TableColumn(table, SWT.LEFT);
textColumn.setText("Event");
textColumn.setWidth(2000);
+
+ viewer.setItemCount(0);
provider = new LoggingEventContentProvider(viewer);
LoggingEventManager.getManager().addLoggingEventManagerListener(provider);
@@ -80,8 +86,6 @@
}
viewer.setLabelProvider(labelProvider);
- viewer.setInput(LoggingEventManager.getManager());
-
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent e) {
IStructuredSelection sel = (IStructuredSelection) e.getSelection();
@@ -115,6 +119,7 @@
public void run() {
super.run();
LoggingEventManager.getManager().clearEventList();
+ viewer.getTable().setItemCount(0);
viewer.refresh();
}
};
@@ -143,8 +148,9 @@
};
autoScrollAction.setText("Turn off auto scroll");
autoScrollAction.setToolTipText("Turn off auto scroll");
- autoScrollAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+ URL url = LogbackPlugin.getDefault().getBundle().getEntry("/icons/lock_co.gif");
+ ImageDescriptor imgDesc = ImageDescriptor.createFromURL(url);
+ autoScrollAction.setImageDescriptor(imgDesc);
}
@@ -166,6 +172,7 @@
public void dispose() {
super.dispose();
provider.dispose();
+ labelProvider.dispose();
}
public int getServerPort() {
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 Thu Mar 22 10:28:23 2007
@@ -1,6 +1,6 @@
package ch.qos.logback.eclipse.views;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ILazyContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
@@ -14,8 +14,7 @@
*
* @author Sébastien Pennec
*/
-public class LoggingEventContentProvider implements LoggingEventManagerListener,
- IStructuredContentProvider {
+public class LoggingEventContentProvider implements LoggingEventManagerListener, ILazyContentProvider {
private TableViewer viewer;
private boolean autoScroll = true;
@@ -40,29 +39,36 @@
}
private void updateViewer(final LoggingEventManagerEvent event) {
- viewer.remove(event.getItemsRemoved());
- viewer.add(event.getItemsAdded());
+ //we should *not* add an element to the viewer here!
+ int count = LoggingEventManager.getManager().getEventCount();
+ viewer.setItemCount(count);
if (event.getItemsAdded().length > 0 && autoScroll) {
- viewer.reveal(event.getItemsAdded()[0]);
+ viewer.getTable().showItem(viewer.getTable().getItem(count -1));
}
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
this.viewer = (TableViewer) viewer;
}
-
- public Object[] getElements(Object inputElement) {
- return LoggingEventManager.getManager().getAllEvents().toArray();
- }
-
- public void dispose() {
- }
-
+
public void toggleAutoScroll() {
autoScroll = !autoScroll;
+ int size = LoggingEventManager.getManager().getEventCount();
+ if (autoScroll && size > 0) {
+ viewer.getTable().showItem(viewer.getTable().getItem(size -1));
+ }
}
public boolean getAutoScroll() {
return autoScroll;
}
+
+ public void dispose() {
+ //do nothing
+ }
+
+ public void updateElement(int index) {
+ System.out.println("update element: " + index);
+ viewer.replace(LoggingEventManager.getManager().getEvent(index), index);
+ }
}
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 Thu Mar 22 10:28:23 2007
@@ -1,5 +1,8 @@
package ch.qos.logback.eclipse.views;
+import java.net.URL;
+
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -12,25 +15,30 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.eclipse.LogbackPlugin;
/**
- * This class creates the label that will appear in the logback
- * window to display the content of a LoggingEvent.
+ * This class creates the label that will appear in the logback window to
+ * display the content of a LoggingEvent.
*
* @author Sébastien Pennec
*/
-class LoggingEventLabelProvider extends LabelProvider implements ITableLabelProvider, ITableColorProvider {
+class LoggingEventLabelProvider extends LabelProvider implements ITableLabelProvider,
+ ITableColorProvider {
private static final String TAG_LABEL = "labelProvider";
private static final String TAG_PATTERN = "pattern";
-
- private static String DEFAULT_PATTERN = "%relative %level [%thread] %logger{25} %message";
+
+ private static String DEFAULT_PATTERN = "%relative %level [%thread] %logger{25} %message %nopex";
private LoggerContext context;
private PatternLayout patternLayout;
-
+
private Color cachedRed;
private Color cachedBlack;
+ private ImageDescriptor stackTrace;
+ private Image stackImage;
+
public LoggingEventLabelProvider() {
context = new LoggerContext();
context.setName("Logback Plugin Context");
@@ -38,43 +46,49 @@
Display display = Display.getCurrent();
cachedRed = new Color(display, 255, 0, 0);
cachedBlack = new Color(display, 0, 0, 0);
-
+ loadImage();
+ }
+
+ private void loadImage() {
+ URL url = LogbackPlugin.getDefault().getBundle().getEntry("/icons/call_hierarchy.gif");
+ stackTrace = ImageDescriptor.createFromURL(url);
+ stackImage = stackTrace.createImage();
}
public String getPattern() {
return patternLayout.getPattern();
}
-
+
public void updatePattern(String pattern) {
patternLayout.stop();
patternLayout.setPattern(pattern);
patternLayout.start();
}
-
+
public void saveState(IMemento memento) {
IMemento mem = memento.createChild(TAG_LABEL);
mem.putString(TAG_PATTERN, patternLayout.getPattern());
}
-
+
public void init(IMemento memento) {
IMemento mem = memento.getChild(TAG_LABEL);
if (mem == null) {
createDefaultPatternLayout();
return;
}
-
+
String pattern = mem.getString(TAG_PATTERN);
if (pattern == null || pattern.length() == 0) {
createDefaultPatternLayout();
return;
}
-
+
patternLayout = new PatternLayout();
patternLayout.setContext(context);
patternLayout.setPattern(pattern);
patternLayout.start();
}
-
+
private void createDefaultPatternLayout() {
patternLayout = new PatternLayout();
patternLayout.setContext(context);
@@ -83,6 +97,12 @@
}
public Image getColumnImage(Object element, int columnIndex) {
+ LoggingEvent event = (LoggingEvent)element;
+
+ if (event.getThrowableInformation() != null) {
+ return stackImage;
+ }
+
return null;
}
@@ -90,9 +110,9 @@
if (!(element instanceof LoggingEvent)) {
return "";
}
-
+
LoggingEvent event = (LoggingEvent) element;
-
+
return patternLayout.doLayout(event);
}
@@ -101,11 +121,17 @@
}
public Color getForeground(Object element, int columnIndex) {
- LoggingEvent event = (LoggingEvent)element;
+ LoggingEvent event = (LoggingEvent) element;
if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
return cachedRed;
} else {
return cachedBlack;
}
}
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ stackImage.dispose();
+ }
}
\ No newline at end of file
More information about the logback-dev
mailing list