[logback-dev] svn commit: r1378 - in logbackPDE/trunk/plugins/ConsolePlugin: . META-INF lib src/main/java/ch/qos/logback/eclipse/actions src/main/java/ch/qos/logback/eclipse/dialog src/main/java/ch/qos/logback/eclipse/model src/main/java/ch/qos/logback/eclipse/views
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Mar 1 18:17:22 CET 2007
Author: seb
Date: Thu Mar 1 18:17:22 2007
New Revision: 1378
Added:
logbackPDE/trunk/plugins/ConsolePlugin/lib/janino-2.4.3.jar (contents, props changed)
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/dialog/LogbackFilterDialog.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java
Modified:
logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF
logbackPDE/trunk/plugins/ConsolePlugin/build.properties
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
Log:
First version of a EvaluatorFilter editor
Modified: logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF Thu Mar 1 18:17:22 2007
@@ -6,7 +6,8 @@
Bundle-ClassPath: logbackPlugin.jar,
lib/slf4j-api-1.2.jar,
lib/logback-classic-0.9.jar,
- lib/logback-core-0.9.1-SNAPSHOT.jar
+ lib/logback-core-0.9.1-SNAPSHOT.jar,
+ lib/janino-2.4.3.jar
Bundle-Activator: ch.qos.logback.eclipse.LogbackPlugin
Bundle-Vendor: QOS.ch
Bundle-Localization: plugin
Modified: logbackPDE/trunk/plugins/ConsolePlugin/build.properties
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/build.properties (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/build.properties Thu Mar 1 18:17:22 2007
@@ -6,6 +6,7 @@
lib/,\
lib/logback-classic-0.9.jar,\
lib/logback-core-0.9.1-SNAPSHOT.jar,\
- lib/logback-core-0.9.jar
+ lib/logback-core-0.9.jar,\
+ lib/janino-2.4.3.jar
source.logbackPlugin.jar = src/main/java/
source.lib/logback-core-0.9.jar = src/main/java/
Added: logbackPDE/trunk/plugins/ConsolePlugin/lib/janino-2.4.3.jar
==============================================================================
Binary file. No diff available.
Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackFilterAction.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackFilterAction.java Thu Mar 1 18:17:22 2007
@@ -0,0 +1,27 @@
+package ch.qos.logback.eclipse.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.console.TextConsoleViewer;
+
+import ch.qos.logback.eclipse.dialog.LogbackFilterDialog;
+
+
+public class LogbackFilterAction extends Action {
+ private static String PREF_ACTION_MESSAGE = "Filter...";
+
+ private final Shell shell;
+
+ public LogbackFilterAction(TextConsoleViewer viewer) {
+ super(PREF_ACTION_MESSAGE);
+ shell = viewer.getControl().getShell();
+ }
+
+ public void run() {
+ LogbackFilterDialog dialog = new LogbackFilterDialog(shell);
+ if (dialog.open() != InputDialog.OK) {
+ return;
+ }
+ }
+}
Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackFilterDialog.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackFilterDialog.java Thu Mar 1 18:17:22 2007
@@ -0,0 +1,234 @@
+package ch.qos.logback.eclipse.dialog;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+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.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+
+import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
+import ch.qos.logback.core.filter.EvaluatorFilter;
+import ch.qos.logback.eclipse.model.EventFilter;
+import ch.qos.logback.eclipse.model.FilterContentProvider;
+
+public class LogbackFilterDialog extends Dialog {
+
+ private static String ERROR_MESSAGE_EXPRESSION = "The new expression is not correct.";
+
+ private TableViewer viewer;
+ private TableColumn codeColumn;
+ private TableColumn onMatchColumn;
+ private TableColumn onMismatchColumn;
+
+ private Text expressionField;
+ private Text matchField;
+ private Text mismatchField;
+
+ private EvaluatorFilter current = null;
+
+ public LogbackFilterDialog(Shell parentShell) {
+ super(parentShell);
+
+ setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+ container.setSize(1000, 3000);
+
+ FillLayout layout = new FillLayout();
+ layout.type = SWT.VERTICAL;
+ container.setLayout(layout);
+
+ createTable(container);
+ Composite editComposite = new Composite(container, SWT.BORDER);
+ editComposite.setSize(1000, 1000);
+ createEditionUIPart(editComposite);
+
+ //initContent();
+
+ return container;
+ }
+
+ private void createEditionUIPart(Composite container) {
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ container.setLayout(gridLayout);
+
+ final Label infoLabel = new Label(container, SWT.NONE);
+ infoLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
+ infoLabel.setText("Enter java code in the expression field.");
+ final Label infoLabel2 = new Label(container, SWT.NONE);
+ infoLabel2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
+ infoLabel2.setText("Enter ACCEPT, DENY or NEUTRAL in the other two fields.");
+
+ expressionField = new Text(container, SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.heightHint = 75;
+ gridData.widthHint = 300;
+ gridData.horizontalSpan = 2;
+ gridData.verticalSpan = 2;
+ expressionField.setLayoutData(gridData);
+
+ final Label infoLabel3 = new Label(container, SWT.NONE);
+ infoLabel3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 1, 1));
+ infoLabel3.setText("Action on filter match");
+ matchField = new Text(container, SWT.BORDER);
+ Rectangle bounds2 = matchField.getBounds();
+ bounds2.width = 150;
+ matchField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+
+ final Label infoLabel4 = new Label(container, SWT.NONE);
+ infoLabel4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 1, 1));
+ infoLabel4.setText("Action on filter mismatch");
+ mismatchField = new Text(container, SWT.BORDER);
+ Rectangle bounds3 = mismatchField.getBounds();
+ bounds3.width = 150;
+ mismatchField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+
+ final Button saveButton = new Button(container, SWT.PUSH);
+ saveButton.setText("Save");
+ saveButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ saveCurrentFilter();
+ viewer.refresh();
+ }
+ });
+
+ final Button newButton = new Button(container, SWT.PUSH);
+ newButton.setText("New");
+ newButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ viewer.setSelection(StructuredSelection.EMPTY);
+ createNewFilter();
+ viewer.refresh();
+ }
+ });
+
+ final Button deleteButton = new Button(container, SWT.PUSH);
+ deleteButton.setText("Delete");
+ deleteButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ deleteCurrentFilter();
+ viewer.refresh();
+ }
+ });
+ }
+
+ private void createTable(Composite container) {
+ viewer = new TableViewer(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE
+ | SWT.FULL_SELECTION);
+
+ FilterContentProvider.getProvider().setViewer(viewer);
+
+ final Table table = viewer.getTable();
+
+ codeColumn = new TableColumn(table, SWT.LEFT);
+ codeColumn.setText("Expression");
+ codeColumn.setWidth(200);
+
+ onMatchColumn = new TableColumn(table, SWT.LEFT);
+ onMatchColumn.setText("On match");
+ onMatchColumn.setWidth(80);
+
+ onMismatchColumn = new TableColumn(table, SWT.LEFT);
+ onMismatchColumn.setText("On mismatch");
+ onMismatchColumn.setWidth(80);
+
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ viewer.setContentProvider(FilterContentProvider.getProvider());
+ viewer.setLabelProvider(FilterContentProvider.getProvider());
+ viewer.setInput(FilterContentProvider.getProvider());
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ StructuredSelection sel = (StructuredSelection)event.getSelection();
+ if (!sel.equals(StructuredSelection.EMPTY)) {
+ editFilter(sel.getFirstElement());
+ }
+ }
+ });
+ }
+
+ private void editFilter(Object element) {
+ current = (EvaluatorFilter)element;
+ JaninoEventEvaluator eval = (JaninoEventEvaluator)current.getEvaluator();
+ expressionField.setText(eval.getExpression());
+ }
+
+ private void saveCurrentFilter() {
+ current.stop();
+ JaninoEventEvaluator eval = (JaninoEventEvaluator)current.getEvaluator();
+ eval.stop();
+ String oldExp = eval.getExpression();
+ eval.setExpression(expressionField.getText());
+ eval.start();
+ if (!eval.isStarted()) {
+ eval.stop();
+ eval.setExpression(oldExp);
+ eval.start();
+ MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE_EXPRESSION);
+ }
+ EventFilter.add(current);
+ emptyEditionUI();
+ }
+
+ private void emptyEditionUI() {
+ current = null;
+ expressionField.setText("");
+ expressionField.redraw();
+ matchField.setText("");
+ matchField.redraw();
+ mismatchField.setText("");
+ mismatchField.redraw();
+ }
+
+ private void createNewFilter() {
+ current = FilterContentProvider.getProvider().createNewFilter();
+ expressionField.setText("Enter an expression");
+ matchField.setText("Enter an action");
+ mismatchField.setText("Enter an action");
+ }
+
+ private void deleteCurrentFilter() {
+ current.stop();
+ JaninoEventEvaluator eval = (JaninoEventEvaluator) current.getEvaluator();
+ eval.stop();
+ EventFilter.remove(current);
+ FilterContentProvider.getProvider().remove(current);
+ emptyEditionUI();
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Logback View Filtering");
+ }
+}
Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/EventFilter.java Thu Mar 1 18:17:22 2007
@@ -0,0 +1,75 @@
+package ch.qos.logback.eclipse.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.filter.EvaluatorFilter;
+
+public class EventFilter {
+
+ private static ContextBase context = new ContextBase();
+
+ private static List<EvaluatorFilter> filterList = new ArrayList<EvaluatorFilter>();
+
+ private static EvaluatorFilter first;
+
+ static {
+ {
+ EvaluatorFilter filter = new EvaluatorFilter();
+ filter.setContext(context);
+ JaninoEventEvaluator eval = new JaninoEventEvaluator();
+ eval.setExpression("level == DEBUG");
+ eval.setContext(context);
+ eval.setName("eval1");
+ filter.setEvaluator(eval);
+ filter.setName("filter1");
+ filter.setOnMatch("ACCEPT");
+ eval.start();
+ filter.start();
+ filterList.add(filter);
+ }
+ {
+ EvaluatorFilter filter = new EvaluatorFilter();
+ filter.setContext(context);
+ JaninoEventEvaluator eval = new JaninoEventEvaluator();
+ eval.setExpression("level == INFO");
+ eval.setContext(context);
+ eval.setName("eval1");
+ filter.setEvaluator(eval);
+ filter.setName("filter1");
+ filter.setOnMatch("ACCEPT");
+ eval.start();
+ filter.start();
+ filterList.add(filter);
+ }
+ }
+
+ public static boolean filter(LoggingEvent event) {
+ return true;
+ }
+
+ public static Context getContext() {
+ return context;
+ }
+
+ public static List<EvaluatorFilter> getAllFilters() {
+ return filterList;
+ }
+
+ public static void add(EvaluatorFilter filter) {
+ if (!filterList.contains(filter)) {
+ filterList.add(filter);
+ }
+ }
+
+ public static void remove(EvaluatorFilter filter) {
+ if (!filterList.contains(filter)) {
+ filterList.remove(filter);
+ }
+ }
+
+}
Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/FilterContentProvider.java Thu Mar 1 18:17:22 2007
@@ -0,0 +1,74 @@
+package ch.qos.logback.eclipse.model;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+
+import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
+import ch.qos.logback.core.filter.EvaluatorFilter;
+
+public class FilterContentProvider extends LabelProvider
+implements ITableLabelProvider, IStructuredContentProvider {
+
+ private static FilterContentProvider provider = new FilterContentProvider();
+
+ private TableViewer viewer;
+
+ public static FilterContentProvider getProvider() {
+ return provider;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return EventFilter.getAllFilters().toArray();
+ }
+
+ public void setViewer(TableViewer viewer) {
+ this.viewer = viewer;
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ EvaluatorFilter filter = (EvaluatorFilter)element;
+ JaninoEventEvaluator eval = (JaninoEventEvaluator)filter.getEvaluator();
+ switch (columnIndex) {
+ case 0:
+ return eval.getExpression();
+ case 1:
+ return "onMatch";
+ case 2:
+ return "onMismatch";
+ }
+
+ return null;
+ }
+
+ public void remove(EvaluatorFilter filter) {
+ EventFilter.remove(filter);
+ viewer.remove(filter);
+ viewer.refresh();
+ }
+
+ public EvaluatorFilter createNewFilter() {
+ EvaluatorFilter current = new EvaluatorFilter();
+ current.setContext(EventFilter.getContext());
+ current.setName("evaluator filter");
+ JaninoEventEvaluator eval = new JaninoEventEvaluator();
+ eval.setContext(EventFilter.getContext());
+ eval.setName("evaluator");
+ current.setEvaluator(eval);
+ return current;
+ }
+
+}
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 1 18:17:22 2007
@@ -19,6 +19,7 @@
import org.eclipse.ui.part.ViewPart;
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.LoggingEventManager;
import ch.qos.logback.eclipse.reciever.SimpleSocketServer;
@@ -46,6 +47,7 @@
private SimpleSocketServer server;
private Thread serverThread;
private LogbackPreferencesAction preferencesAction;
+ private LogbackFilterAction filterAction;
public LogbackView() {
launchSocketServer(null);
@@ -93,6 +95,9 @@
IMenuManager menu = getViewSite().getActionBars().getMenuManager();
menu.add(preferencesAction);
+ filterAction = new LogbackFilterAction(viewer);
+ menu.add(filterAction);
+
clearConsoleAction = new Action() {
@Override
public void run() {
More information about the logback-dev
mailing list