[logback-dev] svn commit: r1341 - in logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse: actions dialog reciever views

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Feb 22 15:14:56 CET 2007


Author: seb
Date: Thu Feb 22 15:14:56 2007
New Revision: 1341

Added:
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/actions/
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackViewPatternAction.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/dialog/
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPatternDialog.java
Modified:
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java

Log:
Added an action to modify the PatternLayout's pattern from the plugin

Added: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackViewPatternAction.java
==============================================================================
--- (empty file)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackViewPatternAction.java	Thu Feb 22 15:14:56 2007
@@ -0,0 +1,32 @@
+package ch.qos.logback.eclipse.actions;
+
+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 ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.eclipse.dialog.LogbackPatternDialog;
+
+/**
+ * This action prompts the user for a string to setup the PatternLayout
+ */
+public class LogbackViewPatternAction extends Action {
+  private final Shell shell;
+  private PatternLayout patternLayout;
+
+  public LogbackViewPatternAction(Viewer viewer, PatternLayout layout, String text) {
+    super(text);
+    shell = viewer.getControl().getShell();
+    this.patternLayout = layout;
+  }
+
+  public void run() {
+    LogbackPatternDialog dialog = new LogbackPatternDialog(shell, patternLayout.getPattern());
+    if (dialog.open() != InputDialog.OK)
+      return;
+    patternLayout.stop();
+    patternLayout.setPattern(dialog.getPattern());
+    patternLayout.start();
+  }
+}

Added: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPatternDialog.java
==============================================================================
--- (empty file)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPatternDialog.java	Thu Feb 22 15:14:56 2007
@@ -0,0 +1,77 @@
+package ch.qos.logback.eclipse.dialog;
+
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+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;
+
+/**
+ * A dialog that allows the user to change the pattern that is used to
+ * display the logging events
+ */
+public class LogbackPatternDialog extends Dialog {
+  private String pattern;
+
+  private Text patternField;
+
+  public LogbackPatternDialog(Shell parentShell, String namePattern) {
+    super(parentShell);
+    this.pattern = namePattern;
+
+    setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE
+        | SWT.APPLICATION_MODAL);
+  }
+
+  protected Control createDialogArea(Composite parent) {
+    Composite container = (Composite) super.createDialogArea(parent);
+    container.setSize(1000, 1000);
+    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 a pattern to setup the PatternLayout:");
+
+    final Label patternLabel = new Label(container, SWT.NONE);
+    patternLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+    patternLabel.setText("Pattern:");
+
+    patternField = new Text(container, SWT.BORDER);
+    Rectangle bounds = patternField.getBounds();
+    bounds.width = 150;
+    patternField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+    
+    initContent();
+    return container;
+  }
+
+  private void initContent() {
+    patternField.setText(pattern != null ? pattern : "");
+    patternField.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        pattern = patternField.getText();
+      }
+    });
+  }
+
+  protected void configureShell(Shell newShell) {
+    super.configureShell(newShell);
+    newShell.setText("Logback View PatternLayout options");
+  }
+
+  public String getPattern() {
+    return pattern;
+  }
+}

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	Thu Feb 22 15:14:56 2007
@@ -19,7 +19,6 @@
   public void run() {
     try {
       ServerSocket serverSocket = new ServerSocket(port);
-      //PluginLogger.logInfo("Listening on port: " + port);
       while (true) {
         Socket socket = serverSocket.accept();
         new Thread(new SocketNode(socket)).start();

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java	Thu Feb 22 15:14:56 2007
@@ -45,7 +45,6 @@
     } catch (java.io.EOFException e) {
       PluginLogger.logInfo("Caught java.io.EOFException closing connection.");
     } catch (java.net.SocketException e) {
-      PluginLogger.logInfo("Caught java.net.SocketException closing connection.");
     } catch (IOException e) {
       PluginLogger.logInfo("Caught java.io.IOException: " + e);
       PluginLogger.logInfo("Closing connection.");

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	Thu Feb 22 15:14:56 2007
@@ -1,16 +1,12 @@
 package ch.qos.logback.eclipse.views;
 
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.ISharedImages;
-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.eclipse.actions.LogbackViewPatternAction;
 import ch.qos.logback.eclipse.model.LoggingEventManager;
 import ch.qos.logback.eclipse.reciever.SimpleSocketServer;
 
@@ -25,8 +21,11 @@
 
   private TextConsoleViewer viewer;
   private MessageConsole myConsole;
-  private Action action1;
-  private Action action2;
+  private LoggingEventContentProvider provider;
+  private LoggingEventLabelProvider labelProvider;
+  
+  private static String PL_ACTION_MESSAGE = "PatternLayout...";
+  private LogbackViewPatternAction patternLayoutAction;
   
   public LogbackView() {
     launchSocketServer();
@@ -35,54 +34,45 @@
   public void createPartControl(Composite parent) {
     
     myConsole = new MessageConsole("My Console", null); 
-    myConsole.setWaterMarks(100000, 40000);
+    myConsole.setWaterMarks(40000, 100000);
+    
     viewer = new TextConsoleViewer(parent, myConsole);
     
-    LoggingEventContentProvider pro = new LoggingEventContentProvider();
-    pro.setLabelProvider(new LoggingEventLabelProvider());
-    pro.setConsole(myConsole);
+    provider = new LoggingEventContentProvider();
+    labelProvider = new LoggingEventLabelProvider();
+    provider.setLabelProvider(labelProvider);
+    provider.setConsole(myConsole);
     
-    LoggingEventManager.getManager().addLoggingEventManagerListener(pro);
+    LoggingEventManager.getManager().addLoggingEventManagerListener(provider);
     
     makeActions();
-    contributeToActionBars();
+    //contributeToActionBars();
   }
 
-  private void contributeToActionBars() {
-    IActionBars bars = getViewSite().getActionBars();
-    fillLocalToolBar(bars.getToolBarManager());
-  }
-
-  private void fillLocalToolBar(IToolBarManager manager) {
-    manager.add(action1);
-    manager.add(action2);
-  }
+//  private void contributeToActionBars() {
+//    IActionBars bars = getViewSite().getActionBars();
+//    fillLocalToolBar(bars.getToolBarManager());
+//  }
+//
+//  private void fillLocalToolBar(IToolBarManager manager) {
+////    manager.add(action1);
+////    manager.add(action2);
+//  }
 
   private void makeActions() {
-    action1 = new Action() {
-      public void run() {
-        showMessage("Action 1 executed");
-      }
-    };
-    action1.setText("Action 1");
-    action1.setToolTipText("Action 1 tooltip");
-    action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
-        ISharedImages.IMG_OBJS_INFO_TSK));
-
-    action2 = new Action() {
-      public void run() {
-        showMessage("Action 2 executed");
-      }
-    };
-    action2.setText("Action 2");
-    action2.setToolTipText("Action 2 tooltip");
-    action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
-        ISharedImages.IMG_OBJS_INFO_TSK));
+    patternLayoutAction = new LogbackViewPatternAction(viewer, labelProvider.getPatternLayout(), PL_ACTION_MESSAGE);
+//    action1.setText("Action 1");
+//    action1.setToolTipText("Action 1 tooltip");
+//    action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+//        ISharedImages.IMG_OBJS_INFO_TSK));
+    
+    IMenuManager menu = getViewSite().getActionBars().getMenuManager();
+    menu.add(patternLayoutAction);
   }
 
-  private void showMessage(String message) {
-    MessageDialog.openInformation(getSite().getShell(), "Logback View", message);
-  }
+//  private void showMessage(String message) {
+//    MessageDialog.openInformation(getSite().getShell(), "Logback View", message);
+//  }
 
   private void launchSocketServer() {
     new Thread(new SimpleSocketServer()).start();
@@ -93,4 +83,10 @@
     viewer.getControl().setFocus();
   }
 
+  @Override
+  public void dispose() {
+    super.dispose();
+    provider.dispose();
+  }
+
 }
\ No newline at end of file

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java	Thu Feb 22 15:14:56 2007
@@ -45,4 +45,8 @@
 
   public void dispose() {
   }
+
+  public PatternLayout getPatternLayout() {
+    return patternLayout;
+  }
 }
\ No newline at end of file



More information about the logback-dev mailing list