logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r356982 - in /logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw: LogPanel.java LogPanelPreferenceModel.java
Date Thu, 15 Dec 2005 06:18:00 GMT
Author: psmith
Date: Wed Dec 14 22:17:52 2005
New Revision: 356982

URL: http://svn.apache.org/viewcvs?rev=356982&view=rev
Log:
Fixed a rather annoying table bug whereby non-standard columns
kept getting added over an over and over again.

This approach means we need to treat the column List more like a Set
but guarantee the order of insertion is consistent.

When the ChainsawCyclicTableModel fires it's new KeyEvents we make sure
we're not doubling up there too.

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

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanel.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanel.java?rev=356982&r1=356981&r2=356982&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanel.java (original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanel.java Wed Dec 14 22:17:52
2005
@@ -837,8 +837,13 @@
     tableModel.addNewKeyListener(
       new NewKeyListener() {
         public void newKeyAdded(NewKeyEvent e) {
+           // don't add the column if we already know about it, this could be if we've seen
it before and saved the column preferences
+            if(table.getColumn(e.getKey())!=null){
+                return;
+            }
           TableColumn col = new TableColumn(e.getNewModelIndex());
           col.setHeaderValue(e.getKey());
+          
           table.addColumn(col);
         }
       });
@@ -1481,12 +1486,12 @@
   }
 
     private void updatePreferenceModelColumnDetails() {
-        preferenceModel.getColumns().clear();
+        preferenceModel.clearColumns();
         for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
     
             TableColumn c = table.getColumnModel().getColumn(i);
     
-            preferenceModel.getColumns().add(c);
+            preferenceModel.addColumn(c);
         }
     }
     

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java?rev=356982&r1=356981&r2=356982&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
(original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
Wed Dec 14 22:17:52 2005
@@ -35,6 +35,8 @@
 import java.util.Properties;
 import java.util.Set;
 
+import javax.swing.table.TableColumn;
+
 
 /**
  *  Used to encapsulate all the preferences for a given LogPanel
@@ -74,8 +76,44 @@
   private List columns = new ArrayList();
   private Collection hiddenLoggers = new HashSet();
   
+  /**
+   * Returns an <b>unmodifiable</b> list of the columns.
+   * 
+   * The reason it is unmodifiable is to enforce the requirement that
+   * the List is actually unique columns.  IT _could_ be a set,
+   * but we need to maintain the order of insertion.
+   * 
+   * @return
+   */
   public List getColumns() {
-      return columns;
+      return Collections.unmodifiableList(columns);
+  }
+  
+  public void clearColumns(){
+      columns.clear();
+  }
+  
+  public boolean addColumn(TableColumn column){
+      if(containsHeaderValue(column)){
+          return false;
+      }else{
+          return columns.add(column);
+      }
+  }
+  
+  /**
+   * Quite an inefficient search mechanism to make sure we don't allow duplicate Column headers
+   * @param column
+   * @return
+   */
+  private boolean containsHeaderValue(TableColumn column) {
+      for (Iterator iter = columns.iterator(); iter.hasNext();) {
+        TableColumn c = (TableColumn) iter.next();
+        if(c.getHeaderValue().equals(column.getHeaderValue())){
+            return true;
+        }
+      }
+      return false;
   }
 
   public void setColumns(List columns) {
@@ -151,7 +189,8 @@
     setDetailPaneVisible(model.isDetailPaneVisible());
     setLogTreePanelVisible(model.isLogTreePanelVisible());
 
-    setColumns(model.getColumns());
+    // we have to copy the list, because getColumns() is unmodifiable
+    setColumns(new ArrayList(model.getColumns()));
     setHiddenLoggers(model.getHiddenLoggers());
     
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message