[hg] main-silver: #223228: Assure that the columns are in a prop...

  • From:
  • To: , ,
  • Subject: [hg] main-silver: #223228: Assure that the columns are in a prop...
  • Date: Sun, 16 Dec 2012 16:35:29 -0800

changeset 700653bd5786 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/700653bd5786
description:
        #223228: Assure that the columns are in a proper state after whole 
table is refreshed.

diffstat:

 o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java        |   6 +-
 spi.viewmodel/src/org/netbeans/modules/viewmodel/OutlineTable.java |  45 
+++++++++-
 2 files changed, 46 insertions(+), 5 deletions(-)

diffs (159 lines):

diff --git a/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java 
b/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java
--- a/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java
+++ b/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java
@@ -594,6 +594,7 @@
     public void createDefaultColumnsFromModel() {
         TableModel model = getModel();
         if (model != null) {
+            firePropertyChange("createdDefaultColumnsFromModel", null, null);
             TableColumnModel colModel = getColumnModel();
             int modelColumnCount = model.getColumnCount();
             List<TableColumn> oldHiddenColumns = null;
@@ -670,8 +671,8 @@
                     }
                 }
             }
-            while (colModel.getColumnCount() > 0) {
-                colModel.removeColumn(colModel.getColumn(0));
+            for (int cc = colModel.getColumnCount(); cc > 0; ) {
+                colModel.removeColumn(colModel.getColumn(--cc));
             }
             if (colModel instanceof ETableColumnModel) {
                 ETableColumnModel etcm = (ETableColumnModel)colModel;
@@ -706,6 +707,7 @@
                     }
                 }
             }
+            firePropertyChange("createdDefaultColumnsFromModel", null, 
newColumns);
         }
     }
 
diff --git 
a/spi.viewmodel/src/org/netbeans/modules/viewmodel/OutlineTable.java 
b/spi.viewmodel/src/org/netbeans/modules/viewmodel/OutlineTable.java
--- a/spi.viewmodel/src/org/netbeans/modules/viewmodel/OutlineTable.java
+++ b/spi.viewmodel/src/org/netbeans/modules/viewmodel/OutlineTable.java
@@ -117,6 +117,7 @@
     Node.Property[]             columns; // Accessed from tests
     private TableColumn[]       tableColumns;
     private int[]               columnVisibleMap; // Column index -> visible 
index
+    private boolean             ignoreCreateDefaultColumnsFromModel;
     //private IndexedColumn[]     icolumns;
     private boolean             isDefaultColumnAdded;
     private int                 defaultColumnIndex; // The index of the tree 
column
@@ -141,6 +142,7 @@
 //        add(ttv, "East");
 //        tv = new BeanTreeView(); // To test only
 //        add(tv, "West");
+        
treeTable.getTable().addPropertyChangeListener("createdDefaultColumnsFromModel",
 new CreatedDefaultColumnsFromModel());
         treeTable.getTable().getColumnModel().addColumnModelListener(new 
TableColumnModelListener() {
 
             // Track column visibility changes.
@@ -365,6 +367,7 @@
             }
         }
         Node.Property[] columnsToSet = createColumns (cs, nodesColumnName);
+        ignoreCreateDefaultColumnsFromModel = true;
         treeTable.setNodesColumnName(nodesColumnName[0], nodesColumnName[1]);
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("setModel(): 
setNodesColumnName("+Arrays.toString(nodesColumnName)+") done");
@@ -379,10 +382,11 @@
         }
         if (treeNodeDisplayFormat == null) {
             treeTable.setProperties (columnsToSet);
-            updateTableColumns(columnsToSet);
+            updateTableColumns(columnsToSet, null);
         } else {
             treeTable.setProperties (new Property[]{});
         }
+        ignoreCreateDefaultColumnsFromModel = false;
         treeTable.setAllowedDragActions(model.getAllowedDragActions());
         treeTable.setAllowedDropActions(model.getAllowedDropActions(null));
         treeTable.setDynamicDropActions(model);
@@ -461,6 +465,7 @@
         String[] nodesColumnName = new String[] { null, null };
         ColumnModel[] cs = model.getColumns ();
         Node.Property[] columnsToSet = createColumns (cs, nodesColumnName);
+        ignoreCreateDefaultColumnsFromModel = true;
         treeTable.setNodesColumnName(nodesColumnName[0], nodesColumnName[1]);
         currentTreeModelRoot = new TreeModelRoot (model, treeTable);
         currentTreeModelRoot.setTreeNodeDisplayFormat(treeNodeDisplayFormat);
@@ -469,10 +474,11 @@
         // The root node must be ready when setting the columns
         if (treeNodeDisplayFormat == null) {
             treeTable.setProperties (columnsToSet);
-            updateTableColumns(columnsToSet);
+            updateTableColumns(columnsToSet, null);
         } else {
             treeTable.setProperties (new Property[]{});
         }
+        ignoreCreateDefaultColumnsFromModel = false;
         treeTable.setAllowedDragActions(model.getAllowedDragActions());
         treeTable.setAllowedDropActions(model.getAllowedDropActions(null));
 
@@ -719,7 +725,7 @@
         }
     }
 
-    private void updateTableColumns(Property[] columnsToSet) {
+    private void updateTableColumns(Property[] columnsToSet, TableColumn[] 
newTColumns) {
         TableColumnModel tcm = treeTable.getTable().getColumnModel();
         int tableModelColumnCount = tcm.getColumnCount();
         int modelColumnCount = 
treeTable.getTable().getModel().getColumnCount();
@@ -778,8 +784,12 @@
             }
         }
         setColumnsOrder();
+        if (newTColumns != null) {
+            this.tableColumns = newTColumns;
+        } else {
         this.tableColumns = tableColumns;
     }
+    }
 
     // Re-order the UI columns according to the defined order
     private void setColumnsOrder() {
@@ -995,9 +1005,28 @@
         }
     }
     
+    private class CreatedDefaultColumnsFromModel implements 
PropertyChangeListener {
+
+        @Override
+        public void propertyChange(PropertyChangeEvent evt) {
+            TableColumn[] columns = (TableColumn[]) evt.getNewValue();
+            if (columns == null) {
+                tableColumns = null;
+            } else if (!ignoreCreateDefaultColumnsFromModel) {
+                // Update the columns after they are reset:
+                Property[] properties = treeTable.getProperties();
+                if (properties != null) {
+                    updateTableColumns(properties, columns);
+                }
+            }
+        }
+        
+    }
+    
     static class MyTreeTable extends OutlineView {  // Accessed from tests
 
         private Reference dndModelRef = new WeakReference(null);
+        private Property[] properties;
 
         MyTreeTable () {
             super ();
@@ -1024,6 +1053,16 @@
             return getOutline();
         }
 
+        @Override
+        public void setProperties(Property[] newProperties) {
+            this.properties = newProperties;
+            super.setProperties(newProperties);
+        }
+        
+        Property[] getProperties() {
+            return properties;
+        }
+        
         void setNodesColumnName(String name, String description) {
             OutlineModel m = getOutline().getOutlineModel();
             if (m instanceof DefaultOutlineModel) {

[hg] main-silver: #223228: Assure that the columns are in a prop...

mentlicher 12/17/2012

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close