logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r774243 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: LogPanel.java LoggerNameTreePanel.java
Date Wed, 13 May 2009 07:15:54 GMT
Author: sdeboy
Date: Wed May 13 07:15:53 2009
New Revision: 774243

URL: http://svn.apache.org/viewvc?rev=774243&view=rev
Log:
Added 'find next' and 'clear find next' menu items to logger tree and logPanel popup menus

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java?rev=774243&r1=774242&r2=774243&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java Wed May 13
07:15:53 2009
@@ -114,6 +114,9 @@
 import javax.swing.table.TableColumnModel;
 import javax.swing.text.Document;
 
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
@@ -138,9 +141,6 @@
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.log4j.spi.LoggingEventFieldResolver;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
 
 /**
  * A LogPanel provides a view to a collection of LoggingEvents.<br>
@@ -621,6 +621,15 @@
      */
     LogPanelLoggerTreeModel logTreeModel = new LogPanelLoggerTreeModel();
     logTreePanel = new LoggerNameTreePanel(logTreeModel, preferenceModel);
+    logTreePanel.addPropertyChangeListener("searchExpression", new PropertyChangeListener()
+    {
+        public void propertyChange(PropertyChangeEvent evt)
+        {
+            findField.setText(evt.getNewValue().toString());
+            findNext();
+        }
+    });
+      
     tableModel.addLoggerNameListener(logTreeModel);
 
     /**
@@ -1320,24 +1329,80 @@
     /*
      * Popup definition
      */
-    p.add(clearFocusAction);
     p.add(menuItemFocusOn);
     p.add(menuDefineAddCustomFilter);
+    p.add(clearFocusAction);
+
+    p.add(new JSeparator());
+
+        final JMenuItem menuItemSearch =
+      new JMenuItem("Find next");
+    menuItemSearch.addActionListener(
+      new ActionListener() {
+        public void actionPerformed(ActionEvent evt) {
+          if (currentPoint != null) {
+            String operator = "~=";
+            int column = table.columnAtPoint(currentPoint);
+            int row = table.rowAtPoint(currentPoint);
+            String colName = table.getColumnName(column);
+            String value = "";
+
+            if (colName.equalsIgnoreCase(ChainsawConstants.TIMESTAMP_COL_NAME)) {
+            	value = timestampExpressionFormat.format(new Date(table.getValueAt(row, column).toString()));
+            } else {
+              Object o = table.getValueAt(row, column);
+
+              if (o != null) {
+                if (o instanceof String[]) {
+                  value = ((String[]) o)[0];
+                  operator = "~=";
+                } else {
+                  value = o.toString();
+                }
+              }
+            }
+
+            if (columnNameKeywordMap.containsKey(colName)) {
+              findField.setText(
+                columnNameKeywordMap.get(colName).toString() + " " + operator
+                + " '" + value + "'");
+              findNext();
+            }
+          }
+        }
+      });
+
+      final Action clearSearchAction =
+        new AbstractAction("Clear find next") {
+          public void actionPerformed(ActionEvent e) {
+            findField.setText(null);
+            updateRule(null);
+          }
+        };
+
+    p.add(menuItemSearch);
+    p.add(clearSearchAction);
+      
     p.add(new JSeparator());
 
     p.add(menuItemBestFit);
+
     p.add(new JSeparator());
 
     p.add(menuItemToggleDetails);
     p.add(menuItemLoggerTree);
     p.add(menuItemToggleToolTips);
+
     p.add(new JSeparator());
+
     p.add(menuItemScrollBottom);
 
     p.add(new JSeparator());
+
     p.add(menuItemToggleDock);
 
     p.add(new JSeparator());
+
     p.add(menuItemColorPanel);
     p.add(menuItemLogPanelPreferences);
 

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java?rev=774243&r1=774242&r2=774243&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
Wed May 13 07:15:53 2009
@@ -109,7 +109,11 @@
   private final Action editLoggerAction;
   private final JButton editLoggerButton = new SmallButton();
   private final Action expandAction;
+  private final Action findNextAction;
+  private final Action clearFindNextAction;
   private final JButton expandButton = new SmallButton();
+  private final JButton findNextButton = new SmallButton();
+  private final JButton clearFindNextButton = new SmallButton();
   private final Action focusOnAction;
   private final SmallToggleButton focusOnLoggerButton =
     new SmallToggleButton();
@@ -136,7 +140,7 @@
   private final JScrollPane scrollTree;
   private final JToolBar toolbar = new JToolBar();
 
-  //~ Constructors ============================================================
+    //~ Constructors ============================================================
 
   /**
    * Creates a new LoggerNameTreePanel object.
@@ -252,6 +256,8 @@
     toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
 
     expandAction = createExpandAction();
+    findNextAction = createFindNextAction();
+    clearFindNextAction = createClearFindNextAction();
     editLoggerAction = createEditLoggerAction();
     closeAction = createCloseAction();
     collapseAction = createCollapseAction();
@@ -590,6 +596,12 @@
     ignoreLoggerButton.setAction(hideAction);
     ignoreLoggerButton.setText(null);
 
+    findNextButton.setAction(findNextAction);
+    findNextButton.setText(null);
+
+    clearFindNextButton.setAction(clearFindNextAction);
+    clearFindNextButton.setText(null);
+
     expandButton.setFont(expandButton.getFont().deriveFont(Font.BOLD));
     collapseButton.setFont(collapseButton.getFont().deriveFont(Font.BOLD));
 
@@ -732,6 +744,55 @@
     return action;
   }
 
+    /**
+     * Creates an action that is used to find the next match of the selected node (similar
to default selection behavior
+     * except the search field is populated and the next match is selected.
+     * @return an Action
+     */
+    private Action createFindNextAction()
+    {
+      Action action = new AbstractAction()
+        {
+          public void actionPerformed(ActionEvent e)
+          {
+            findNextUsingCurrentlySelectedNode();
+          }
+        };
+
+      action.putValue(Action.NAME, "Find next");
+      action.putValue(
+        Action.SHORT_DESCRIPTION,
+        "Search using the selected node");
+      action.setEnabled(false);
+
+      return action;
+    }
+
+    /**
+     * Creates an action that is used to find the next match of the selected node (similar
to default selection behavior
+     * except the search field is populated and the next match is selected.
+     * @return an Action
+     */
+    private Action createClearFindNextAction()
+    {
+      Action action = new AbstractAction()
+        {
+          public void actionPerformed(ActionEvent e)
+          {
+            clearFindNext();
+          }
+        };
+
+      action.putValue(Action.NAME, "Clear find next");
+      action.putValue(
+        Action.SHORT_DESCRIPTION,
+        "Search using the selected node");
+      action.setEnabled(false);
+
+      return action;
+    }
+
+
   /**
    * DOCUMENT ME!
    *
@@ -810,6 +871,23 @@
       });
   }
 
+  private void findNextUsingCurrentlySelectedNode()
+  {
+      String selectedLogger = getCurrentlySelectedLoggerName();
+      TreePath[] paths = logTree.getSelectionPaths();
+
+      if (paths == null)
+      {
+        return;
+      }
+      firePropertyChange("searchExpression", null, "logger ~= " + selectedLogger);
+  }
+
+  private void clearFindNext()
+  {
+      firePropertyChange("searchExpression", null, "");
+  }
+
   /**
    * Expands the currently selected node (if any)
    * including all the children.
@@ -918,17 +996,20 @@
     if ((logger == null) || (logger.length() == 0))
     {
       focusOnAction.putValue(Action.NAME, "Focus On...");
-      hideAction.putValue(Action.NAME, "Ignore ...");
+      hideAction.putValue(Action.NAME, "Ignore...");
+      findNextAction.putValue(Action.NAME, "Find next...");
     }
     else
     {
       focusOnAction.putValue(Action.NAME, "Focus On '" + logger + "'");
       hideAction.putValue(Action.NAME, "Ignore '" + logger + "'");
+      findNextAction.putValue(Action.NAME, "Find next '" + logger + "'");
     }
 
     // need to ensure the button doens't update itself with the text, looks stupid otherwise
     focusOnLoggerButton.setText(null);
     ignoreLoggerButton.setText(null);
+    findNextButton.setText(null);
   }
 
   /**
@@ -972,6 +1053,8 @@
           }
 
           expandAction.setEnabled(path != null);
+          findNextAction.setEnabled(path != null);
+          clearFindNextAction.setEnabled(true);
 
           if (logger != null)
           {
@@ -1098,7 +1181,7 @@
     hideAction.setEnabled(!isFocusOnSelected());
   }
 
-  //~ Inner Classes ===========================================================
+    //~ Inner Classes ===========================================================
 
   /**
    * DOCUMENT ME!
@@ -1235,11 +1318,14 @@
     */
     private void initMenu()
     {
+      focusOnCheck.setAction(focusOnAction);
+      hideCheck.setAction(hideAction);
       add(expandAction);
       add(collapseAction);
       addSeparator();
-      focusOnCheck.setAction(focusOnAction);
-      hideCheck.setAction(hideAction);
+      add(findNextAction);
+      add(clearFindNextAction);
+      addSeparator();
       add(focusOnCheck);
       add(hideCheck);
 



Mime
View raw message