Author: rob.stryker(a)jboss.com
Date: 2008-12-02 17:29:47 -0500 (Tue, 02 Dec 2008)
New Revision: 12223
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/EventDetailsDialog.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/LogLabelProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/ServerLogView.java
Log:
JBIDE-3307 - added icons, double-click to explore
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/EventDetailsDialog.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/EventDetailsDialog.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/EventDetailsDialog.java 2008-12-02
22:29:47 UTC (rev 12223)
@@ -0,0 +1,255 @@
+package org.jboss.ide.eclipse.as.ui.views;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.StringTokenizer;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.views.log.Messages;
+
+/**
+ * Displays details about Log Entry.
+ * Event information is split in three sections: details, stack trace and session.
Details
+ * contain event date, message and severity. Stack trace is displayed if an exception is
bound
+ * to event. Stack trace entries can be filtered.
+ */
+public class EventDetailsDialog extends TrayDialog {
+
+ private AbstractEntry entry;
+ private LogLabelProvider labelProvider;
+ private TreeViewer provider;
+
+ private static int COPY_ID = 22;
+
+
+ private Label dateLabel;
+ private Label severityImageLabel;
+ private Label severityLabel;
+ private Text msgText;
+ private Text stackTraceText;
+ private Clipboard clipboard;
+ private Button copyButton;
+
+ // patterns for filtering stack traces
+ private String[] stackFilterPatterns = null;
+
+ /**
+ *
+ * @param parentShell shell in which dialog is displayed
+ * @param selection entry initially selected and to be displayed
+ * @param provider viewer
+ * @param comparator comparator used to order all entries
+ */
+ protected EventDetailsDialog(Shell parentShell, AbstractEntry selection, TreeViewer
provider) {
+ super(parentShell);
+ this.provider = provider;
+ labelProvider = (LogLabelProvider) this.provider.getLabelProvider();
+ this.entry = selection;
+ setShellStyle(SWT.MODELESS | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.CLOSE | SWT.BORDER |
SWT.TITLE);
+ clipboard = new Clipboard(parentShell.getDisplay());
+ }
+
+ private boolean isChild(AbstractEntry entry) {
+ return entry.getParent(entry) != null;
+ }
+
+ public void create() {
+ super.create();
+ getShell().setSize(500, 550);
+ applyDialogFont(buttonBar);
+ getButton(IDialogConstants.OK_ID).setFocus();
+ }
+
+ protected void buttonPressed(int buttonId) {
+ if (IDialogConstants.OK_ID == buttonId)
+ okPressed();
+ else if (IDialogConstants.CANCEL_ID == buttonId)
+ cancelPressed();
+ else if (COPY_ID == buttonId)
+ copyPressed();
+ }
+
+
+ protected void copyPressed() {
+ StringWriter writer = new StringWriter();
+ PrintWriter pwriter = new PrintWriter(writer);
+
+ entry.write(pwriter);
+ pwriter.flush();
+ String textVersion = writer.toString();
+ try {
+ pwriter.close();
+ writer.close();
+ } catch (IOException e) { // do nothing
+ }
+ // set the clipboard contents
+ clipboard.setContents(new Object[] {textVersion}, new Transfer[]
{TextTransfer.getInstance()});
+ }
+
+
+ public void updateProperties() {
+ if (entry instanceof LogEntry) {
+ LogEntry logEntry = (LogEntry) entry;
+
+ String strDate = logEntry.getFormattedDate();
+ dateLabel.setText(strDate);
+ severityImageLabel.setImage(labelProvider.getColumnImage(entry, 0));
+ severityLabel.setText(logEntry.getSeverityText());
+ msgText.setText(logEntry.getMessage() != null ? logEntry.getMessage() : "");
//$NON-NLS-1$
+ String stack = logEntry.getStack();
+
+ if (stack != null) {
+ stack = filterStack(stack);
+ stackTraceText.setText(stack);
+ } else {
+ stackTraceText.setText(Messages.EventDetailsDialog_noStack);
+ }
+ } else {
+ dateLabel.setText(""); //$NON-NLS-1$
+ severityImageLabel.setImage(null);
+ severityLabel.setText(""); //$NON-NLS-1$
+ msgText.setText(""); //$NON-NLS-1$
+ stackTraceText.setText(""); //$NON-NLS-1$
+ }
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ container.setLayout(layout);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ container.setLayoutData(gd);
+
+ createDetailsSection(container);
+ createStackSection(container);
+ updateProperties();
+ Dialog.applyDialogFont(container);
+ return container;
+ }
+
+ private void createToolbarButtonBar(Composite parent) {
+ Composite comp = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 0;
+ //layout.numColumns = 1;
+ comp.setLayout(layout);
+ comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ ((GridData) comp.getLayoutData()).verticalAlignment = SWT.BOTTOM;
+
+ Composite container = new Composite(comp, SWT.NONE);
+ layout = new GridLayout();
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ copyButton = createButton(container, COPY_ID, "", false); //$NON-NLS-1$
+ GridData gd = new GridData();
+ copyButton.setLayoutData(gd);
+ copyButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
+ copyButton.setToolTipText(Messages.EventDetailsDialog_copy);
+
+ // set numColumns at the end, after all createButton() calls, which change this value
+ layout.numColumns = 2;
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ // create OK button only by default
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+
+ private void createDetailsSection(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 0;
+ layout.numColumns = 2;
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ createTextSection(container);
+ createToolbarButtonBar(container);
+ }
+
+ private void createTextSection(Composite parent) {
+ Composite textContainer = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ layout.marginHeight = layout.marginWidth = 0;
+ textContainer.setLayout(layout);
+ textContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label label = new Label(textContainer, SWT.NONE);
+ label.setText(Messages.EventDetailsDialog_date);
+ dateLabel = new Label(textContainer, SWT.NULL);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ dateLabel.setLayoutData(gd);
+
+ label = new Label(textContainer, SWT.NONE);
+ label.setText(Messages.EventDetailsDialog_severity);
+ severityImageLabel = new Label(textContainer, SWT.NULL);
+ severityLabel = new Label(textContainer, SWT.NULL);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ severityLabel.setLayoutData(gd);
+
+ label = new Label(textContainer, SWT.NONE);
+ label.setText(Messages.EventDetailsDialog_message);
+ gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
+ label.setLayoutData(gd);
+ msgText = new Text(textContainer, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
+ msgText.setEditable(false);
+ gd = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING |
GridData.GRAB_VERTICAL);
+ gd.horizontalSpan = 2;
+ gd.heightHint = 44;
+ gd.grabExcessVerticalSpace = true;
+ msgText.setLayoutData(gd);
+ }
+
+ private void createStackSection(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginHeight = 0;
+ layout.marginWidth = 6;
+ container.setLayout(layout);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 100;
+ container.setLayoutData(gd);
+
+ Label label = new Label(container, SWT.NONE);
+ label.setText(Messages.EventDetailsDialog_exception);
+ gd = new GridData();
+ gd.verticalAlignment = SWT.BOTTOM;
+ label.setLayoutData(gd);
+
+ stackTraceText = new Text(container, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL |
SWT.BORDER);
+ gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalSpan = 2;
+ stackTraceText.setLayoutData(gd);
+ stackTraceText.setEditable(false);
+ }
+
+ private String filterStack(String stack) {
+ return stack;
+ }
+
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/LogLabelProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/LogLabelProvider.java 2008-12-02
18:59:43 UTC (rev 12222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/LogLabelProvider.java 2008-12-02
22:29:47 UTC (rev 12223)
@@ -4,6 +4,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
@@ -16,7 +17,7 @@
import org.jboss.ide.eclipse.as.ui.JBossServerUISharedImages;
import org.jboss.ide.eclipse.as.ui.views.ServerLogView.EventCategory;
-public class LogLabelProvider extends LabelProvider {
+public class LogLabelProvider extends LabelProvider implements ITableLabelProvider {
public Image getImage(Object element) {
if( element instanceof EventCategory ) {
int type = ((EventCategory)element).getType();
@@ -80,38 +81,54 @@
public String getText(Object element) {
if( element instanceof EventCategory ) {
int type = ((EventCategory)element).getType();
+ if( type == 0 )
+ return "Unknown Event Type";
if( type == IEventCodes.POLLING_CODE)
return "Server Startup / Shutdown";
if( type == IEventCodes.PUBLISHING_CODE)
return "Publishing";
}
-
if( element instanceof LogEntry ) {
- // queue for Decoration
- String message = ((LogEntry)element).getMessage();
- return message + addSuffix((LogEntry)element);
+ return ((LogEntry)element).getMessage();
}
return element == null ? "" : element.toString();//$NON-NLS-1$
}
- protected String addSuffix(LogEntry entry) {
- long diff = new Date().getTime() - entry.getDate().getTime();
- long sec = diff / 1000;
- long minutes = sec / 60;
- if( minutes > 0 )
- sec -= (minutes * 60);
- long hours = minutes / 60;
- if( hours > 0 ) {
- minutes -= (hours * 60);
- sec -= (hours * 60 * 60);
+ protected String getSuffix(Object entry2) {
+ if( entry2 instanceof LogEntry ) {
+ LogEntry entry = (LogEntry)entry2;
+ long diff = new Date().getTime() - entry.getDate().getTime();
+ long sec = diff / 1000;
+ long minutes = sec / 60;
+ if( minutes > 0 )
+ sec -= (minutes * 60);
+ long hours = minutes / 60;
+ if( hours > 0 ) {
+ minutes -= (hours * 60);
+ sec -= (hours * 60 * 60);
+ }
+ if( hours > 0 ) {
+ return hours + " hours, " + minutes + " minutes ago";
+ } else if( minutes > 0 ) {
+ return minutes + " minutes, " + sec + " seconds ago";
+ } else {
+ return sec + " seconds ago";
+ }
}
- if( hours > 0 ) {
- return " [" + hours + " hours, " + minutes + " minutes
ago]";
- } else if( minutes > 0 ) {
- return " [" + minutes + " minutes, " + sec + " seconds
ago]";
- } else {
- return " [" + sec + " seconds ago]";
- }
+ return "";
}
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if( columnIndex == 0 )
+ return getImage(element);
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if(columnIndex == 0)
+ return getText(element);
+ else
+ return getSuffix(element);
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/ServerLogView.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/ServerLogView.java 2008-12-02
18:59:43 UTC (rev 12222)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/ServerLogView.java 2008-12-02
22:29:47 UTC (rev 12223)
@@ -1,8 +1,18 @@
package org.jboss.ide.eclipse.as.ui.views;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import org.eclipse.core.filesystem.EFS;
@@ -15,20 +25,30 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.util.Policy;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IMemento;
@@ -38,6 +58,7 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.XMLMemento;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.internal.views.log.Messages;
import org.eclipse.ui.internal.views.log.SharedImages;
@@ -51,12 +72,28 @@
public class ServerLogView extends ViewPart implements IServerLogListener {
public static final String VIEW_ID =
"org.jboss.ide.eclipse.as.ui.view.serverLogView";
+ public final static byte MESSAGE = 0x0;
+ public final static byte DATE = 0x1;
+ public static int ASCENDING = 1;
+ public static int DESCENDING = -1;
+
+ private int MESSAGE_ORDER;
+ private int DATE_ORDER;
+ private static final String P_COLUMN_1 = "column1"; //$NON-NLS-1$
+ private static final String P_COLUMN_2 = "column2"; //$NON-NLS-1$
+ public static final String P_ORDER_TYPE = "orderType"; //$NON-NLS-1$
+ public static final String P_ORDER_VALUE = "orderValue"; //$NON-NLS-1$
private IServer server;
private TreeViewer viewer;
private File fInputFile;
+ private String fDirectory;
private IMemento fMemento;
- private Action fDeleteLogAction, fOpenLogAction;
+ private Action fDeleteLogAction, fOpenLogAction,
+ fReadLogAction, fExportLogAction;
+ private TreeColumn fColumn1;
+ private TreeColumn fColumn2;
+ private Comparator fComparator;
private List<AbstractEntry> elements;
public ServerLogView() {
super();
@@ -65,16 +102,49 @@
public void init(IViewSite site, IMemento memento) throws PartInitException {
super.init(site, memento);
- fMemento = memento;
+ if (memento == null)
+ this.fMemento = XMLMemento.createWriteRoot("SERVERLOGVIEW"); //$NON-NLS-1$
+ else
+ this.fMemento = memento;
+ fMemento.putInteger(P_COLUMN_1, fMemento.getInteger(P_COLUMN_1) != null &&
fMemento.getInteger(P_COLUMN_1) > 0 ? fMemento.getInteger(P_COLUMN_1) : 350);
+ fMemento.putInteger(P_COLUMN_2, fMemento.getInteger(P_COLUMN_2) != null &&
fMemento.getInteger(P_COLUMN_2) > 0 ? fMemento.getInteger(P_COLUMN_2) : 150);
+ fMemento.putInteger(P_ORDER_VALUE, fMemento.getInteger(P_ORDER_VALUE) != null
&& fMemento.getInteger(P_ORDER_VALUE) != 0 ? fMemento.getInteger(P_ORDER_VALUE) :
DESCENDING);
+ fMemento.putInteger(P_ORDER_TYPE, fMemento.getInteger(P_ORDER_TYPE) != null &&
fMemento.getInteger(P_ORDER_TYPE) != 0 ? fMemento.getInteger(P_ORDER_TYPE) : DATE);
+
+ // initialize column ordering
+ final byte type = this.fMemento.getInteger(P_ORDER_TYPE).byteValue();
+ switch (type) {
+ case DATE :
+ DATE_ORDER = this.fMemento.getInteger(P_ORDER_VALUE).intValue();
+ MESSAGE_ORDER = DESCENDING;
+ break;
+ case MESSAGE :
+ MESSAGE_ORDER = this.fMemento.getInteger(P_ORDER_VALUE).intValue();
+ DATE_ORDER = DESCENDING;
+ break;
+ default :
+ DATE_ORDER = DESCENDING;
+ MESSAGE_ORDER = DESCENDING;
+ }
+ setComparator(fMemento.getInteger(P_ORDER_TYPE).byteValue());
}
+ public void saveState(IMemento memento) {
+ if (this.fMemento == null || memento == null)
+ return;
+ this.fMemento.putInteger(P_COLUMN_1, fColumn1.getWidth());
+ this.fMemento.putInteger(P_COLUMN_2, fColumn2.getWidth());
+ memento.putMemento(this.fMemento);
+ }
+
public void createPartControl(Composite parent) {
Composite child = new Composite(parent, SWT.NONE);
child.setLayout(new FillLayout());
viewer = new TreeViewer(child);
+ createColumns(viewer);
viewer.setContentProvider(new LogContentProvider());
viewer.setLabelProvider(new LogLabelProvider());
viewer.setInput(this);
-
+ viewer.setAutoExpandLevel(2);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection)event.getSelection();
@@ -83,15 +153,71 @@
}
});
- IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ Object[] o = ((IStructuredSelection)viewer.getSelection()).toArray();
+ if( o != null && o.length > 0 && o[0] != null && o[0]
instanceof AbstractEntry)
+ new EventDetailsDialog(viewer.getTree().getShell(), (AbstractEntry)o[0],
viewer).open();
+ }
+ });
+
+ IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
+
+ fExportLogAction = createExportLogAction();
+ toolBarManager.add(fExportLogAction);
+ toolBarManager.add(new Separator());
+ final Action clearAction = createClearAction();
+ toolBarManager.add(clearAction);
fDeleteLogAction = createDeleteLogAction();
- toolbar.add(fDeleteLogAction);
+ toolBarManager.add(fDeleteLogAction);
fOpenLogAction = createOpenLogAction();
- toolbar.add(fOpenLogAction);
-
+ toolBarManager.add(fOpenLogAction);
+ fReadLogAction = createReadLogAction();
+ toolBarManager.add(fReadLogAction);
+
setLogFile(null);
}
+ protected void createColumns(final TreeViewer viewer) {
+ fColumn1 = new TreeColumn(viewer.getTree(), SWT.LEFT);
+ fColumn1.setText(Messages.LogView_column_message);
+ fColumn1.setWidth(fMemento.getInteger(P_COLUMN_1).intValue());
+ fColumn1.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ MESSAGE_ORDER *= -1;
+ ViewerComparator comparator = getViewerComparator(MESSAGE);
+ viewer.setComparator(comparator);
+ setComparator(MESSAGE);
+ fMemento.putInteger(P_ORDER_VALUE, MESSAGE_ORDER);
+ fMemento.putInteger(P_ORDER_TYPE, MESSAGE);
+ setColumnSorting(fColumn1, MESSAGE_ORDER);
+ }
+ });
+
+
+ fColumn2 = new TreeColumn(viewer.getTree(), SWT.LEFT);
+ fColumn2.setText(Messages.LogView_column_date);
+ fColumn2.setWidth(fMemento.getInteger(P_COLUMN_2).intValue());
+ fColumn2.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DATE_ORDER *= -1;
+ ViewerComparator comparator = getViewerComparator(DATE);
+ viewer.setComparator(comparator);
+ setComparator(DATE);
+ fMemento.putInteger(P_ORDER_VALUE, DATE_ORDER);
+ fMemento.putInteger(P_ORDER_TYPE, DATE);
+ setColumnSorting(fColumn2, DATE_ORDER);
+ }
+ });
+
+ viewer.getTree().setHeaderVisible(true);
+ }
+
+ private void setColumnSorting(TreeColumn column, int order) {
+ viewer.getTree().setSortColumn(column);
+ viewer.getTree().setSortDirection(order == ASCENDING ? SWT.UP : SWT.DOWN);
+ }
+
public void setServer(IServer server) {
if( this.server != null )
ServerLogger.getDefault().removeListener(this.server, this);
@@ -106,7 +232,12 @@
protected void setLogFile(File file) {
fInputFile = file;
+ fDirectory = fInputFile == null ? null : fInputFile.getParent();
elements.clear();
+ reloadLog();
+ }
+
+ protected void reloadLog() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.beginTask("Importing Server Log", IProgressMonitor.UNKNOWN);
@@ -122,14 +253,15 @@
} catch (InterruptedException e) { // do nothing
} finally {
asyncRefresh(false);
+ updateButtons();
}
- updateButtons();
}
private void updateButtons() {
- fDeleteLogAction.setEnabled(fInputFile != null && fInputFile.exists());
- fOpenLogAction.setEnabled(fInputFile != null && fInputFile.exists());
+ fDeleteLogAction.setEnabled(exists(fInputFile));
+ fOpenLogAction.setEnabled(exists(fInputFile));
+ fExportLogAction.setEnabled(exists(fInputFile));
}
private void asyncRefresh(final boolean activate) {
@@ -156,6 +288,10 @@
}
}
+ protected boolean exists(File f) {
+ return f != null && f.exists();
+ }
+
public void logging(IStatus status, IServer server) {
if( server != null && server.equals(this.server)) {
LogEntry entry = new LogEntry(status);
@@ -237,6 +373,9 @@
public boolean equals(Object other) {
return other instanceof EventCategory && ((EventCategory)other).getType() ==
val;
}
+ public int hashCode() {
+ return val;
+ }
}
public boolean shouldSort() {
@@ -250,6 +389,31 @@
/* Stolen from log view and can be changed but in a rush */
+ private Action createReadLogAction() {
+ Action action = new Action(Messages.LogView_readLog_restore) {
+ public void run() {
+ reloadLog();
+ }
+ };
+ action.setToolTipText(Messages.LogView_readLog_restore_tooltip);
+ action.setImageDescriptor(SharedImages.getImageDescriptor(SharedImages.DESC_READ_LOG));
+ action.setDisabledImageDescriptor(SharedImages.getImageDescriptor(SharedImages.DESC_READ_LOG_DISABLED));
+ return action;
+ }
+
+ private Action createClearAction() {
+ Action action = new Action(Messages.LogView_clear) {
+ public void run() {
+ handleClear();
+ }
+ };
+ action.setImageDescriptor(SharedImages.getImageDescriptor(SharedImages.DESC_CLEAR));
+ action.setDisabledImageDescriptor(SharedImages.getImageDescriptor(SharedImages.DESC_CLEAR_DISABLED));
+ action.setToolTipText(Messages.LogView_clear_tooltip);
+ action.setText(Messages.LogView_clear);
+ return action;
+ }
+
private Action createOpenLogAction() {
Action action = new Action() {
public void run() {
@@ -264,6 +428,18 @@
return action;
}
+ private Action createExportLogAction() {
+ Action action = new Action(Messages.LogView_export) {
+ public void run() {
+ handleExport();
+ }
+ };
+ action.setToolTipText(Messages.LogView_export_tooltip);
+ action.setImageDescriptor(SharedImages.getImageDescriptor(SharedImages.DESC_EXPORT));
+ action.setDisabledImageDescriptor(SharedImages.getImageDescriptor(SharedImages.DESC_EXPORT_DISABLED));
+ action.setEnabled(fInputFile != null && fInputFile.exists());
+ return action;
+ }
private void openLog() {
try {
IWorkbench wb = PlatformUI.getWorkbench();
@@ -328,5 +504,141 @@
}
});
}
+
+ private void handleExport() {
+ FileDialog dialog = new FileDialog(getViewSite().getShell(), SWT.SAVE);
+ dialog.setFilterExtensions(new String[] {"*.log"}); //$NON-NLS-1$
+ if (fDirectory != null)
+ dialog.setFilterPath(fDirectory);
+ String path = dialog.open();
+ if (path != null) {
+ if (path.indexOf('.') == -1 && !path.endsWith(".log"))
//$NON-NLS-1$
+ path += ".log"; //$NON-NLS-1$
+ File outputFile = new Path(path).toFile();
+ fDirectory = outputFile.getParent();
+ if (outputFile.exists()) {
+ String message = NLS.bind(Messages.LogView_confirmOverwrite_message,
outputFile.toString());
+ if (!MessageDialog.openQuestion(getViewSite().getShell(),Messages.LogView_exportLog,
message))
+ return;
+ }
+ Reader in = null;
+ Writer out = null;
+ try {
+ out = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8");
//$NON-NLS-1$
+ in = new InputStreamReader(new FileInputStream(fInputFile), "UTF-8");
//$NON-NLS-1$
+ copy(in, out);
+ } catch (IOException ex) {
+ try {
+ if (in != null)
+ in.close();
+ if (out != null)
+ out.close();
+ } catch (IOException e1) { // do nothing
+ }
+ }
+ }
+ }
+
+ private void copy(Reader input, Writer output) {
+ BufferedReader reader = null;
+ BufferedWriter writer = null;
+ try {
+ reader = new BufferedReader(input);
+ writer = new BufferedWriter(output);
+ String line;
+ while (reader.ready() && ((line = reader.readLine()) != null)) {
+ writer.write(line);
+ writer.newLine();
+ }
+ } catch (IOException e) { // do nothing
+ } finally {
+ try {
+ if (reader != null)
+ reader.close();
+ if (writer != null)
+ writer.close();
+ } catch (IOException e1) {
+ // do nothing
+ }
+ }
+ }
+
+ private void setComparator(byte sortType) {
+ if (sortType == DATE) {
+ fComparator = new Comparator() {
+ public int compare(Object e1, Object e2) {
+ long date1 = 0;
+ long date2 = 0;
+ if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) {
+ date1 = ((LogEntry) e1).getDate().getTime();
+ date2 = ((LogEntry) e2).getDate().getTime();
+ } else if ((e1 instanceof LogSession) && (e2 instanceof LogSession)) {
+ date1 = ((LogSession) e1).getDate() == null ? 0 : ((LogSession)
e1).getDate().getTime();
+ date2 = ((LogSession) e2).getDate() == null ? 0 : ((LogSession)
e2).getDate().getTime();
+ }
+ if (date1 == date2) {
+ int result = elements.indexOf(e2) - elements.indexOf(e1);
+ if (DATE_ORDER == DESCENDING)
+ result *= DESCENDING;
+ return result;
+ }
+ if (DATE_ORDER == DESCENDING)
+ return date1 > date2 ? DESCENDING : ASCENDING;
+ return date1 < date2 ? DESCENDING : ASCENDING;
+ }
+ };
+ } else {
+ fComparator = new Comparator() {
+ public int compare(Object e1, Object e2) {
+ if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) {
+ LogEntry entry1 = (LogEntry) e1;
+ LogEntry entry2 = (LogEntry) e2;
+ return Policy.getComparator().compare(entry1.getMessage(), entry2.getMessage()) *
MESSAGE_ORDER;
+ }
+ return 0;
+ }
+ };
+ }
+ }
+
+ private ViewerComparator getViewerComparator(byte sortType) {
+ if (sortType == MESSAGE) {
+ return new ViewerComparator() {
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) {
+ LogEntry entry1 = (LogEntry) e1;
+ LogEntry entry2 = (LogEntry) e2;
+ return getComparator().compare(entry1.getMessage(), entry2.getMessage()) *
MESSAGE_ORDER;
+ }
+ return 0;
+ }
+ };
+ } else {
+ return new ViewerComparator() {
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ long date1 = 0;
+ long date2 = 0;
+ if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) {
+ date1 = ((LogEntry) e1).getDate().getTime();
+ date2 = ((LogEntry) e2).getDate().getTime();
+ } else if ((e1 instanceof LogSession) && (e2 instanceof LogSession)) {
+ date1 = ((LogSession) e1).getDate() == null ? 0 : ((LogSession)
e1).getDate().getTime();
+ date2 = ((LogSession) e2).getDate() == null ? 0 : ((LogSession)
e2).getDate().getTime();
+ }
+
+ if (date1 == date2) {
+ int result = elements.indexOf(e2) - elements.indexOf(e1);
+ if (DATE_ORDER == DESCENDING)
+ result *= DESCENDING;
+ return result;
+ }
+ if (DATE_ORDER == DESCENDING)
+ return date1 > date2 ? DESCENDING : ASCENDING;
+ return date1 < date2 ? DESCENDING : ASCENDING;
+ }
+ };
+ }
+ }
+
}