001package ca.bc.webarts.widgets.treetable;
002
003import java.util.List;
004import java.util.Vector;
005
006import javax.swing.tree.DefaultMutableTreeNode;
007
008import org.jdesktop.swingx.treetable.TreeTableModel;
009
010public class SampleSortableTreeTabelModelImpl extends AbstractSortableTreeTableModel
011{
012
013  String[] columnNames =  { "Column1", "Column2", "Column3" };
014
015  Class[] columnClasses = {
016                           org.jdesktop.swingx.treetable.TreeTableModel.class,
017                           String.class ,
018                           String.class
019                          };
020
021  RootNode root_ = null;
022  static SampleSortableTreeTabelModelImpl instance = new SampleSortableTreeTabelModelImpl();
023
024  private static void  s(String s) { System.out.println("start: "+s);}
025  private static void e(String s) { System.out.println("end: "+s);}
026
027  private SampleSortableTreeTabelModelImpl()
028  {
029          System.out.println("Instatiation: "+"SampleSortableTreeTabelModelImpl()");
030
031  }
032
033
034        public void sortOrderChanged(SortEvent e)
035        {
036          s(this.getClass().getEnclosingMethod().getName());
037
038                int column = e.getColumn();
039                boolean ascending = e.isAscending();
040                List children = root_.getChildren();
041
042        }
043
044
045        public Class getColumnClass(int column)
046        {
047          //s(this.getClass().getEnclosingMethod().getName());
048          s("getColumnClass");
049                return columnClasses[column];
050        }
051
052        public static SampleSortableTreeTabelModelImpl getInstance()
053        {
054          //s(SampleSortableTreeTabelModelImpl.getClass().getEnclosingMethod().getName());
055          if (instance == null) instance = new SampleSortableTreeTabelModelImpl();
056
057                return instance;
058        }
059
060
061        public int getColumnCount()
062        {
063         // s(this.getClass().getEnclosingMethod().getName());
064         s("getColumnCount");
065                return columnNames.length;
066        }
067
068
069        public String getColumnName(int column)
070        {
071         // s(this.getClass().getEnclosingMethod().getName());
072         s("getColumnName");
073
074                return columnNames[column];
075        }
076
077
078        public Object getValueAt( Object node, int column )
079        {
080          //s(this.getClass().getEnclosingMethod().getName());
081          s("getValueAt");
082          String retVal = "A"+column;
083
084          return retVal;
085        }
086
087
088  public Object getRoot()
089  {
090          s("getRoot()");
091          return root_;
092  }
093
094  public int getHierarchicalColumn()
095  {
096          s(this.getClass().getEnclosingMethod().getName());
097    return 0;
098        }
099
100
101        public static class RootNode extends DefaultMutableTreeNode {
102
103                public final String rootName;
104
105  private static void  s(String s) { System.out.println("start: "+s);}
106  private static void e(String s) { System.out.println("end: "+s);}
107
108  public Vector getChildren()
109    {
110      s(this.getClass().getEnclosingMethod().getName());
111      return children;
112    }
113
114                public RootNode(String name)
115                {
116      s(this.getClass().getEnclosingMethod().getName());
117                        this.rootName = name;
118
119                        refresh();
120                }
121
122                public void refresh()
123                {
124      s(this.getClass().getEnclosingMethod().getName());
125
126                }
127
128                public String toString()
129                {
130      s(this.getClass().getEnclosingMethod().getName());
131                        return rootName;
132                }
133
134                public boolean getAllowsChildren() {
135      s(this.getClass().getEnclosingMethod().getName());
136                        return true;
137                }
138
139                public boolean isLeaf() {
140      s(this.getClass().getEnclosingMethod().getName());
141                        return false;
142                }
143        } // class RootNode
144
145}
146
147