[logback-dev] svn commit: r1351 - in logbackPDE/trunk/plugins/ConsolePlugin: . src/main/java/ch/qos/logback/eclipse/actions src/main/java/ch/qos/logback/eclipse/dialog src/main/java/ch/qos/logback/eclipse/reciever src/main/java/ch/qos/logback/eclipse/views

noreply.seb at qos.ch noreply.seb at qos.ch
Mon Feb 26 12:54:28 CET 2007


Author: seb
Date: Mon Feb 26 12:54:28 2007
New Revision: 1351

Modified:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.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/LoggingEventLabelProvider.java
   logbackPDE/trunk/plugins/ConsolePlugin/todo.txt

Log:
Updated todo.txt
The user can now enter a port to listen to

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java	Mon Feb 26 12:54:28 2007
@@ -3,35 +3,43 @@
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.console.MessageConsole;
 import org.eclipse.ui.console.TextConsoleViewer;
 
-import ch.qos.logback.classic.PatternLayout;
 import ch.qos.logback.eclipse.dialog.LogbackPreferencesDialog;
+import ch.qos.logback.eclipse.views.LogbackView;
 
 /**
  * This action prompts the user for a string to setup the PatternLayout
  */
 public class LogbackPreferencesAction extends Action {
+  private static String PREF_ACTION_MESSAGE = "Preferences...";
+
   private final Shell shell;
-  private PatternLayout patternLayout;
-  private MessageConsole console;
+  private final LogbackView view;
 
-  public LogbackPreferencesAction(TextConsoleViewer viewer, PatternLayout layout, String text, MessageConsole console) {
-    super(text);
+  public LogbackPreferencesAction(TextConsoleViewer viewer, LogbackView view) {
+    super(PREF_ACTION_MESSAGE);
     shell = viewer.getControl().getShell();
-    this.patternLayout = layout;
-    this.console = console;
+    this.view = view;
   }
 
   public void run() {
-    LogbackPreferencesDialog dialog = new LogbackPreferencesDialog(shell, patternLayout.getPattern(), console.getHighWaterMark());
-    if (dialog.open() != InputDialog.OK)
+    LogbackPreferencesDialog dialog = new LogbackPreferencesDialog(shell, view.getPattern(), view
+        .getConsoleHighWaterMark(), view.getServerPort());
+    if (dialog.open() != InputDialog.OK) {
       return;
-    patternLayout.stop();
-    patternLayout.setPattern(dialog.getPattern());
-    patternLayout.start();
+    }
+
+    if (!dialog.getPattern().equals(view.getPattern())) {
+      view.updatePattern(dialog.getPattern());
+    }
+
+    if (dialog.getHighWaterMark() != view.getConsoleHighWaterMark()) {
+      view.updateConsoleHighWaterMark(dialog.getHighWaterMark());
+    }
     
-    console.setWaterMarks(console.getLowWaterMark(), dialog.getHighWaterMark());
+    if (dialog.getServerPort() != view.getServerPort()) {
+      view.updateServerPort(dialog.getServerPort());
+    }
   }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java	Mon Feb 26 12:54:28 2007
@@ -1,7 +1,5 @@
 package ch.qos.logback.eclipse.dialog;
 
-
-
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.SWT;
@@ -19,27 +17,34 @@
 import ch.qos.logback.eclipse.views.LogbackView;
 
 /**
- * A dialog that allows the user to change the pattern that is used to
- * display the logging events
+ * A dialog that allows the user to change the pattern that is used to display
+ * the logging events
  */
 public class LogbackPreferencesDialog extends Dialog {
-  
-  private static String ERROR_MESSAGE = "The watermark cannot be lower than " + LogbackView.LOW_WATERMARK;
-  
+
+  private static String ERROR_MESSAGE_WATERMARK = "The watermark cannot be lower than "
+      + LogbackView.LOW_WATERMARK;
+
+  private static String ERROR_MESSAGE_SERVER = "The server port must be between 0 and 65535.";
+
   private String pattern;
   private int highWaterMark;
-  private int tmpHighWaterMark;
-  
+  private int tmpHighWaterMark = -1;
+  private int serverPort;
+  private int tmpServerPort = -1;
+
   private Text patternField;
   private Text waterMarkField;
+  private Text portField;
 
-  public LogbackPreferencesDialog(Shell parentShell, String namePattern, int highWaterMark) {
+  public LogbackPreferencesDialog(Shell parentShell, String namePattern, int highWaterMark,
+      int serverPort) {
     super(parentShell);
     this.pattern = namePattern;
     this.highWaterMark = highWaterMark;
+    this.serverPort = serverPort;
 
-    setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE
-        | SWT.APPLICATION_MODAL);
+    setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
   }
 
   protected Control createDialogArea(Composite parent) {
@@ -49,9 +54,18 @@
     gridLayout.numColumns = 2;
     container.setLayout(gridLayout);
 
+    createPatternUIParts(container);
+    createWaterMarkUIParts(container);
+    createServerPortUIParts(container);
+
+    initContent();
+
+    return container;
+  }
+
+  private void createPatternUIParts(Composite container) {
     final Label infoLabel = new Label(container, SWT.NONE);
-    infoLabel
-        .setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
+    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);
@@ -62,10 +76,11 @@
     Rectangle bounds = patternField.getBounds();
     bounds.width = 150;
     patternField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
-    
+  }
+
+  private void createWaterMarkUIParts(Composite container) {
     final Label infoLabel2 = new Label(container, SWT.NONE);
-    infoLabel2
-        .setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
+    infoLabel2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
     infoLabel2.setText("Enter max number of chars to be displayed:");
 
     final Label waterMarkLabel = new Label(container, SWT.NONE);
@@ -74,9 +89,16 @@
 
     waterMarkField = new Text(container, SWT.BORDER);
     waterMarkField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
-    
-    initContent();
-    return container;
+  }
+
+  private void createServerPortUIParts(Composite container) {
+
+    final Label portLabel = new Label(container, SWT.NONE);
+    portLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+    portLabel.setText("Listening on port number");
+
+    portField = new Text(container, SWT.BORDER);
+    portField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
   }
 
   private void initContent() {
@@ -86,14 +108,22 @@
         pattern = patternField.getText();
       }
     });
-    
+
     waterMarkField.setText(String.valueOf(highWaterMark));
     waterMarkField.addModifyListener(new ModifyListener() {
       public void modifyText(ModifyEvent e) {
         tmpHighWaterMark = Integer.parseInt(waterMarkField.getText());
       }
     });
+
+    portField.setText(String.valueOf(serverPort));
+    portField.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        tmpServerPort = Integer.parseInt(portField.getText());
+      }
+    });
   }
+
   protected void configureShell(Shell newShell) {
     super.configureShell(newShell);
     newShell.setText("Logback View options");
@@ -102,19 +132,54 @@
   public String getPattern() {
     return pattern;
   }
-  
+
   public int getHighWaterMark() {
     return highWaterMark;
   }
 
+  public int getServerPort() {
+    return serverPort;
+  }
+
   @Override
   protected void okPressed() {
-    if (tmpHighWaterMark > LogbackView.LOW_WATERMARK) {
-      highWaterMark = tmpHighWaterMark;
+    boolean result1 = checkWaterMark();
+    boolean result2 = checkServerPort();
+    if (result1 && result2) {
       super.okPressed();
-    } else {
-      MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE);
+    }
+  }
+
+  private boolean checkWaterMark() {
+    if (tmpHighWaterMark != -1 && tmpHighWaterMark < LogbackView.LOW_WATERMARK) {
+      MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE_WATERMARK);
       waterMarkField.setText(String.valueOf(highWaterMark));
+      return false;
+    } else {
+      if (tmpHighWaterMark != -1) {
+        highWaterMark = tmpHighWaterMark;
+      }
+      return true;
+    }
+  }
+
+  private boolean checkServerPort() {
+    if (tmpServerPort != -1 && !portInBounds()) {
+      MessageDialog.openInformation(getShell(), "Logback View", ERROR_MESSAGE_SERVER);
+      portField.setText(String.valueOf(serverPort));
+      return false;
+    } else {
+      if (tmpServerPort != -1) {
+        serverPort = tmpServerPort;
+      }
+      return true;
+    }
+  }
+  
+  private boolean portInBounds() {
+    if (tmpServerPort > 0 && tmpServerPort <= 65535) {
+      return true;
     }
+    return false;
   }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	Mon Feb 26 12:54:28 2007
@@ -1,5 +1,6 @@
 package ch.qos.logback.eclipse.reciever;
 
+import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
 
@@ -14,11 +15,33 @@
  */
 public class SimpleSocketServer implements Runnable {
 
-  static int port = 4321;
-
+  private int port = 4321;
+  private ServerSocket serverSocket;
+  
   public void run() {
+    startAndLoop();
+  }
+  
+  public void setPort(int port) {
+    this.port = port;
+  }
+  
+  public int getPort() {
+    return port;
+  }
+  
+  public void restart() {
     try {
-      ServerSocket serverSocket = new ServerSocket(port);
+      serverSocket.close();
+      startAndLoop();
+    } catch (IOException e) {
+      PluginLogger.logError(e);
+    }
+  }
+  
+  private void startAndLoop() {
+    try {
+      serverSocket = new ServerSocket(port);
       while (true) {
         Socket socket = serverSocket.accept();
         new Thread(new SocketNode(socket)).start();
@@ -27,6 +50,4 @@
       PluginLogger.logError(e);
     }
   }
-  
-  
 }

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	Mon Feb 26 12:54:28 2007
@@ -11,6 +11,7 @@
 import org.eclipse.ui.console.TextConsoleViewer;
 import org.eclipse.ui.part.ViewPart;
 
+import ch.qos.logback.eclipse.PluginLogger;
 import ch.qos.logback.eclipse.actions.LogbackPreferencesAction;
 import ch.qos.logback.eclipse.model.LoggingEventManager;
 import ch.qos.logback.eclipse.reciever.SimpleSocketServer;
@@ -26,18 +27,19 @@
 
   public static int LOW_WATERMARK = 400000;
   public static int DEFAULT_HIGH_WATERMARK = 1000000;
-  
+
   private TextConsoleViewer viewer;
   private MessageConsole myConsole;
   private LoggingEventContentProvider provider;
   private LoggingEventLabelProvider labelProvider;
   private Action clearConsoleAction;
 
-  private static String PREF_ACTION_MESSAGE = "Preferences...";
+  private SimpleSocketServer server;
+  private Thread serverThread;
   private LogbackPreferencesAction preferencesAction;
 
   public LogbackView() {
-    launchSocketServer();
+    launchSocketServer(null);
   }
 
   public void createPartControl(Composite parent) {
@@ -65,8 +67,7 @@
   }
 
   private void makeActions() {
-    preferencesAction = new LogbackPreferencesAction(viewer, labelProvider.getPatternLayout(),
-        PREF_ACTION_MESSAGE, myConsole);
+    preferencesAction = new LogbackPreferencesAction(viewer, this);
 
     IMenuManager menu = getViewSite().getActionBars().getMenuManager();
     menu.add(preferencesAction);
@@ -86,8 +87,13 @@
 
   }
 
-  private void launchSocketServer() {
-    new Thread(new SimpleSocketServer()).start();
+  private void launchSocketServer(Integer port) {
+    server = new SimpleSocketServer();
+    if (port !=  null) {
+      server.setPort(port.intValue());
+    }
+    serverThread = new Thread(server);
+    serverThread.start();
   }
 
   @Override
@@ -101,4 +107,29 @@
     provider.dispose();
   }
 
+  public int getServerPort() {
+    return server.getPort();
+  }
+
+  public int getConsoleHighWaterMark() {
+    return myConsole.getHighWaterMark();
+  }
+
+  public String getPattern() {
+    return labelProvider.getPattern();
+  }
+
+  public void updatePattern(String pattern) {
+    labelProvider.updatePattern(pattern);
+  }
+
+  public void updateConsoleHighWaterMark(int highWaterMark) {
+    myConsole.setWaterMarks(myConsole.getLowWaterMark(), highWaterMark);
+  }
+
+  public void updateServerPort(Integer serverPort) {
+    launchSocketServer(serverPort);
+    PluginLogger.logInfo("Now listening on port: " + serverPort);
+  }
+
 }
\ No newline at end of file

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	Mon Feb 26 12:54:28 2007
@@ -46,7 +46,13 @@
   public void dispose() {
   }
 
-  public PatternLayout getPatternLayout() {
-    return patternLayout;
+  public String getPattern() {
+    return patternLayout.getPattern();
+  }
+  
+  public void updatePattern(String pattern) {
+    patternLayout.stop();
+    patternLayout.setPattern(pattern);
+    patternLayout.start();
   }
 }
\ No newline at end of file

Modified: logbackPDE/trunk/plugins/ConsolePlugin/todo.txt
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/todo.txt	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/todo.txt	Mon Feb 26 12:54:28 2007
@@ -4,8 +4,16 @@
 Color one line each two lines with a gray background.
 ->LineStyleListener might do the trick (StyledText component).
 
-OK -> Make the viewer always display the latest lines added
-
 Is it possible to use the logger without bringing the ErrorLog view up?
 
-Allow the user to change the socket's port
\ No newline at end of file
+Stack traces with links
+
+Filter logs: threshold
+
+Color certains lines. Based on keywords and colors.
+
+Save Preferences between sessions
+
+DONE:
+Allow the user to change the socket's port
+Make the viewer always display the latest lines added
\ No newline at end of file



More information about the logback-dev mailing list