* Bug 11852 fixed: now filebrowser updates (again)
[scilab.git] / scilab / modules / ui_data / src / java / org / scilab / modules / ui_data / filebrowser / ScilabTreeTableModelAdapter.java
index 1a46133..a1b1081 100644 (file)
 
 package org.scilab.modules.ui_data.filebrowser;
 
-import javax.swing.table.AbstractTableModel;
 import javax.swing.JTree;
-import javax.swing.tree.TreePath;
 import javax.swing.event.TreeExpansionEvent;
 import javax.swing.event.TreeExpansionListener;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.tree.TreePath;
 
 /**
  * The tree table model abstract implementation
+ *
  * @author Calixte DENIZET
  */
-@SuppressWarnings(value = { "serial" })
+@SuppressWarnings(value = {"serial"})
 public class ScilabTreeTableModelAdapter extends AbstractTableModel {
 
     private JTree tree;
@@ -33,75 +36,86 @@ public class ScilabTreeTableModelAdapter extends AbstractTableModel {
 
     /**
      * Default constructor
+     *
      * @param treeTableModel the table model
      * @param tree the tree
      */
     public ScilabTreeTableModelAdapter(ScilabTreeTableModel treeTableModel, JTree tree) {
         this.tree = tree;
         this.treeTableModel = treeTableModel;
-        tree.addTreeExpansionListener(new TreeExpansionListener() {
+        tree.addTreeExpansionListener(
+        new TreeExpansionListener() {
             public void treeExpanded(TreeExpansionEvent event) {
                 fireTableDataChanged();
             }
+
             public void treeCollapsed(TreeExpansionEvent event) {
                 fireTableDataChanged();
             }
         });
+        tree.getModel()
+        .addTreeModelListener(
+        new TreeModelListener() {
+
+            @Override
+            public void treeStructureChanged(TreeModelEvent e) {
+                fireTableDataChanged();
+            }
+
+            @Override
+            public void treeNodesRemoved(TreeModelEvent e) {
+                fireTableDataChanged();
+            }
+
+            @Override
+            public void treeNodesInserted(TreeModelEvent e) {
+                fireTableDataChanged();
+            }
+
+            @Override
+            public void treeNodesChanged(TreeModelEvent e) {
+                fireTableDataChanged();
+            }
+        });
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public int getColumnCount() {
         return treeTableModel.getColumnCount();
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public String getColumnName(int column) {
         return treeTableModel.getColumnName(column);
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public Class getColumnClass(int column) {
         return treeTableModel.getColumnClass(column);
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public int getRowCount() {
         return tree.getRowCount();
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     protected Object nodeForRow(int row) {
         TreePath treePath = tree.getPathForRow(row);
         return treePath.getLastPathComponent();
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public Object getValueAt(int row, int column) {
         return treeTableModel.getValueAt(nodeForRow(row), column);
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public boolean isCellEditable(int row, int column) {
         return treeTableModel.isCellEditable(nodeForRow(row), column);
     }
 
-    /**
-     * {@inheritdoc}
-     */
+    /** {@inheritdoc} */
     public void setValueAt(Object value, int row, int column) {
         treeTableModel.setValueAt(value, nodeForRow(row), column);
     }