### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.views.log Index: src/org/eclipse/ui/internal/views/log/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/messages.properties,v retrieving revision 1.7 diff -u -r1.7 messages.properties --- src/org/eclipse/ui/internal/views/log/messages.properties 4 Dec 2007 13:51:47 -0000 1.7 +++ src/org/eclipse/ui/internal/views/log/messages.properties 7 Jan 2008 16:09:03 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007 IBM Corporation and others. +# Copyright (c) 2007, 2008 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -61,6 +61,7 @@ LogViewLabelProvider_truncatedMessage=... (Open log entry details for full message) LogViewLabelProvider_Session=Session +EventDetailsDialog_ConfigureFiltersLink=Configure filters... EventDetailsDialog_title= Event Details EventDetailsDialog_date=Date: EventDetailsDialog_severity=Severity: @@ -71,6 +72,14 @@ EventDetailsDialog_previous=View Details Of Previous Event EventDetailsDialog_next=View Details Of Next Event EventDetailsDialog_copy=Copy Event Details To Clipboard +EventDetailsDialog_FilterDialog=Filters +EventDetailsStackFilterDialog_AddFilter=Add... +EventDetailsStackFilterDialog_AddFilterTitle=Add filter +EventDetailsStackFilterDialog_AddFilterLabel=Add filter: +EventDetailsStackFilterDialog_EnableFilters=Enable filters +EventDetailsStackFilterDialog_FilterShouldntContainSemicolon=Filter shouldn't contain semicolon +EventDetailsStackFilterDialog_FiltersLabel=Filters let you hide stack trace entries. +EventDetailsStackFilterDialog_Remove=Remove... OpenLogDialog_title=Error Log OpenLogDialog_message=Opening log... Index: src/org/eclipse/ui/internal/views/log/Messages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Messages.java,v retrieving revision 1.8 diff -u -r1.8 Messages.java --- src/org/eclipse/ui/internal/views/log/Messages.java 31 Dec 2007 00:37:51 -0000 1.8 +++ src/org/eclipse/ui/internal/views/log/Messages.java 7 Jan 2008 16:09:03 -0000 @@ -68,6 +68,7 @@ public static String LogViewLabelProvider_Session; public static String LogViewLabelProvider_truncatedMessage; + public static String EventDetailsDialog_ConfigureFiltersLink; public static String EventDetailsDialog_title; public static String EventDetailsDialog_date; public static String EventDetailsDialog_severity; @@ -78,7 +79,15 @@ public static String EventDetailsDialog_previous; public static String EventDetailsDialog_next; public static String EventDetailsDialog_copy; + public static String EventDetailsDialog_FilterDialog; + public static String EventDetailsStackFilterDialog_AddFilter; + public static String EventDetailsStackFilterDialog_AddFilterTitle; + public static String EventDetailsStackFilterDialog_AddFilterLabel; + public static String EventDetailsStackFilterDialog_EnableFilters; + public static String EventDetailsStackFilterDialog_FilterShouldntContainSemicolon; + public static String EventDetailsStackFilterDialog_FiltersLabel; + public static String EventDetailsStackFilterDialog_Remove; public static String OpenLogDialog_title; public static String OpenLogDialog_message; public static String OpenLogDialog_cannotDisplay; Index: src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java,v retrieving revision 1.8 diff -u -r1.8 EventDetailsDialog.java --- src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java 31 Dec 2007 00:37:51 -0000 1.8 +++ src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java 7 Jan 2008 16:09:03 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,12 +16,16 @@ import java.util.*; import java.util.List; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.dialogs.*; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.*; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.dnd.*; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -60,6 +64,9 @@ private Comparator comparator = null; Collator collator; + // patterns for filtering stack traces + private String[] stackFilterPatterns = getFilters(); + // location configuration private Point dialogLocation; private Point dialogSize; @@ -101,10 +108,6 @@ } private void resetChildIndex() { - if (!(entry instanceof AbstractEntry)) { - return; - } - if (entryChildren == null) return; @@ -318,7 +321,9 @@ 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); @@ -581,7 +586,7 @@ private void createStackSection(Composite parent) { Composite container = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); + GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 6; container.setLayout(layout); @@ -589,15 +594,28 @@ gd.heightHint = 100; container.setLayoutData(gd); - Label label = new Label(container, SWT.NULL); + Label label = new Label(container, SWT.NONE); label.setText(Messages.EventDetailsDialog_exception); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 3; - label.setLayoutData(gd); + + Link link = new Link(container, SWT.NONE); + link.setText(Messages.EventDetailsDialog_ConfigureFiltersLink); + link.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + EventDetailsStackFilterDialog dialog = new EventDetailsStackFilterDialog(getShell()); + dialog.create(); + dialog.getShell().setText(Messages.EventDetailsDialog_FilterDialog); + if (dialog.open() == Window.OK) + // update filters and currently displayed stack trace + stackFilterPatterns = getFilters(); + updateProperties(); + } + + }); 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); } @@ -628,6 +646,63 @@ sessionDataText.setEditable(false); } + /** + * Loads filters from preferences. + * @return filters from preferences or empty array + * + * @since 3.4 + */ + private String[] getFilters() { + Preferences prefs = Activator.getDefault().getPluginPreferences(); + + if (!prefs.getBoolean(EventDetailsStackFilterDialog.FILTER_ENABLED)) { + return new String[0]; + } + + String filtersString = prefs.getString(EventDetailsStackFilterDialog.FILTER_LIST); + StringTokenizer st = new StringTokenizer(filtersString, ";"); //$NON-NLS-1$ + List filters = new ArrayList(); + while (st.hasMoreElements()) { + String filter = st.nextToken(); + filters.add(filter); + } + + return (String[]) filters.toArray(new String[filters.size()]); + } + + /** + * Filters stack trace. + * Every stack trace line is compared against all patterns. + * If line contains any of pattern strings, it's excluded from output. + * + * @returns filtered stack trace + * @since 3.4 + */ + private String filterStack(String stack) { + if (stackFilterPatterns.length == 0) { + return stack; + } + + StringTokenizer st = new StringTokenizer(stack, "\n"); //$NON-NLS-1$ + StringBuffer result = new StringBuffer(); + while (st.hasMoreTokens()) { + String stackElement = st.nextToken(); + + boolean filtered = false; + int i = 0; + while ((!filtered) && (i < stackFilterPatterns.length)) { + filtered = stackElement.indexOf(stackFilterPatterns[i]) >= 0; + i++; + } + + if (!filtered) { + result.append(stackElement).append("\n"); //$NON-NLS-1$ + } + } + + return result.toString(); + } + //--------------- configuration handling -------------- /** Index: src/org/eclipse/ui/internal/views/log/EventDetailsStackFilterDialog.java =================================================================== RCS file: src/org/eclipse/ui/internal/views/log/EventDetailsStackFilterDialog.java diff -N src/org/eclipse/ui/internal/views/log/EventDetailsStackFilterDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/views/log/EventDetailsStackFilterDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jacek Pospychala - bug 110836 + *******************************************************************************/ +package org.eclipse.ui.internal.views.log; + +import java.util.StringTokenizer; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.dialogs.*; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; + +/** + * Event Details Stack Filter dialog. + * Allows user to define patterns for filtering stack trace elements in Event Details dialog. + * + * @since 3.4 + */ +public class EventDetailsStackFilterDialog extends TrayDialog { + + public static final String FILTER_ENABLED = "detailsStackFilterEnabled"; //$NON-NLS-1$ + public static final String FILTER_LIST = "detailsStackFilterList"; //$NON-NLS-1$ + + Button okButton; + private Button filterEnabled; + private Button addFilter; + private Button removeFilter; + private List filterList; + + public EventDetailsStackFilterDialog(Shell parentShell) { + super(parentShell); + } + + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + createFilterSection(container); + Dialog.applyDialogFont(container); + return container; + } + + private void createFilterSection(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + comp.setLayout(layout); + comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label label = new Label(comp, SWT.NONE); + label.setText(Messages.EventDetailsStackFilterDialog_FiltersLabel); + GridData gd = new GridData(); + gd.horizontalSpan = 2; + label.setLayoutData(gd); + + filterEnabled = new Button(comp, SWT.CHECK); + filterEnabled.setText(Messages.EventDetailsStackFilterDialog_EnableFilters); + gd = new GridData(); + gd.horizontalSpan = 2; + filterEnabled.setLayoutData(gd); + filterEnabled.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + setEnabled(filterEnabled.getSelection()); + } + + }); + + filterList = new List(comp, SWT.BORDER); + gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + gd.verticalSpan = 3; + gd.widthHint = 300; + filterList.setLayoutData(gd); + filterList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeFilter.setEnabled(true); + } + }); + + addFilter = new Button(comp, SWT.NONE); + gd = new GridData(GridData.FILL_HORIZONTAL); + addFilter.setLayoutData(gd); + addFilter.setText(Messages.EventDetailsStackFilterDialog_AddFilter); + addFilter.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + addFilter(); + } + }); + + removeFilter = new Button(comp, SWT.NONE); + gd = new GridData(GridData.FILL_HORIZONTAL); + removeFilter.setLayoutData(gd); + removeFilter.setText(Messages.EventDetailsStackFilterDialog_Remove); + removeFilter.setEnabled(false); + removeFilter.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeFilter(); + } + }); + + // load preferences + Preferences prefs = Activator.getDefault().getPluginPreferences(); + filterEnabled.setSelection(prefs.getBoolean(FILTER_ENABLED)); + setEnabled(prefs.getBoolean(FILTER_ENABLED)); + String filters = prefs.getString(FILTER_LIST); + StringTokenizer st = new StringTokenizer(filters, ";"); //$NON-NLS-1$ + while (st.hasMoreElements()) { + filterList.add(st.nextToken()); + } + } + + private void addFilter() { + IInputValidator validator = new IInputValidator() { + + public String isValid(String newText) { + return newText.indexOf(';') >= 0 ? Messages.EventDetailsStackFilterDialog_FilterShouldntContainSemicolon : null; + } + + }; + InputDialog dialog = new InputDialog(getShell(), Messages.EventDetailsStackFilterDialog_AddFilterTitle, Messages.EventDetailsStackFilterDialog_AddFilterLabel, null, validator); + if (dialog.open() == Window.OK) { + String value = dialog.getValue().trim(); + + if (value.length() > 0) { + filterList.add(value); + } + } + } + + private void removeFilter() { + int index = filterList.getSelectionIndex(); + if (index != -1) { + filterList.remove(index); + } + + removeFilter.setEnabled(false); + } + + private void setEnabled(boolean enabled) { + filterList.setEnabled(enabled); + addFilter.setEnabled(enabled); + removeFilter.setEnabled(enabled && filterList.getSelectionIndex() != -1); + } + + protected void createButtonsForButtonBar(Composite parent) { + okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + protected void okPressed() { + // store preferences + Preferences prefs = Activator.getDefault().getPluginPreferences(); + + prefs.setValue(FILTER_ENABLED, filterEnabled.getSelection()); + + StringBuffer sb = new StringBuffer(); + String[] items = filterList.getItems(); + for (int i = 0; i < items.length; i++) { + sb.append(items[i]); + if (i < items.length - 1) { + sb.append(";"); //$NON-NLS-1$ + } + } + prefs.setValue(FILTER_LIST, sb.toString()); + + super.okPressed(); + } + +}