Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jorphan.gui » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *   http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    *
   17    */
   18   
   19   package org.apache.jorphan.gui;
   20   
   21   import java.util.ArrayList;
   22   import java.util.Arrays;
   23   import java.util.List;
   24   
   25   import javax.swing.event.TableModelListener;
   26   import javax.swing.event.EventListenerList;
   27   import javax.swing.table.DefaultTableModel;
   28   import javax.swing.tree.TreeNode;
   29   
   30   import org.apache.jorphan.reflect.Functor;
   31   
   32   public abstract class AbstractTreeTableModel extends DefaultTableModel implements TreeTableModel {
   33   
   34       protected TreeNode rootNode = null;
   35       protected EventListenerList listener = new EventListenerList();
   36   
   37       protected transient ArrayList objects = new ArrayList();
   38   
   39       protected transient List headers = new ArrayList();
   40   
   41       protected transient ArrayList classes = new ArrayList();
   42   
   43       protected transient ArrayList readFunctors = new ArrayList();
   44   
   45       protected transient ArrayList writeFunctors = new ArrayList();
   46   
   47       public AbstractTreeTableModel(TreeNode root) {
   48           this.rootNode = root;
   49       }
   50   
   51       public AbstractTreeTableModel(TreeNode root, boolean editable) {
   52           this.rootNode = root;
   53       }
   54   
   55       public AbstractTreeTableModel(String[] headers,
   56               Functor[] readFunctors,
   57               Functor[] writeFunctors,
   58               Class[] editorClasses) {
   59           this.headers.addAll(Arrays.asList(headers));
   60           this.classes.addAll(Arrays.asList(editorClasses));
   61           this.readFunctors = new ArrayList(Arrays.asList(readFunctors));
   62           this.writeFunctors = new ArrayList(Arrays.asList(writeFunctors));
   63       }
   64   
   65       /**
   66        * The root node for the TreeTable
   67        * @return the root node
   68        */
   69       public Object getRootNode() {
   70           return this.rootNode;
   71       }
   72   
   73       /* (non-Javadoc)
   74        * @see org.apache.jorphan.gui.TreeTableModel#getValueAt(java.lang.Object, int)
   75        */
   76       public Object getValueAt(Object node, int col) {
   77           return null;
   78       }
   79   
   80       /* (non-Javadoc)
   81        * @see org.apache.jorphan.gui.TreeTableModel#isCellEditable(java.lang.Object, int)
   82        */
   83       public boolean isCellEditable(Object node, int col) {
   84           return false;
   85       }
   86   
   87       /* (non-Javadoc)
   88        * @see org.apache.jorphan.gui.TreeTableModel#setValueAt(java.lang.Object, java.lang.Object, int)
   89        */
   90       public void setValueAt(Object val, Object node, int column) {
   91       }
   92   
   93       /**
   94        * The implementation is exactly the same as ObjectTableModel.getColumnCount.
   95        */
   96       public int getColumnCount() {
   97           return headers.size();
   98       }
   99   
  100       /**
  101        * The implementation is exactly the same as ObjectTableModel.getRowCount.
  102        */
  103       public int getRowCount() {
  104           if (objects == null) {
  105               return 0;
  106           }
  107           return objects.size();
  108       }
  109   
  110       /**
  111        * By default the abstract class returns true. It is up to subclasses
  112        * to override the implementation.
  113        */
  114       public boolean isCellEditable(int rowIndex, int columnIndex) {
  115           return true;
  116       }
  117   
  118       public Class getColumnClass(int arg0) {
  119           return (Class) classes.get(arg0);
  120       }
  121   
  122       /**
  123        * Subclasses need to implement the logic for the method and
  124        * return the value at the specific cell.
  125        */
  126       public Object getValueAt(int rowIndex, int columnIndex) {
  127           return null;
  128       }
  129   
  130       /**
  131        *
  132        */
  133       public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  134   
  135       }
  136   
  137       /**
  138        *
  139        */
  140       public String getColumnName(int columnIndex) {
  141           return (String) headers.get(columnIndex);
  142       }
  143   
  144       public int getChildCount(Object parent) {
  145           return 0;
  146       }
  147   
  148       public Object getChild(Object parent, int index) {
  149           return null;
  150       }
  151   
  152       /**
  153        * the implementation checks if the Object is a treenode. If it is,
  154        * it returns isLeaf(), otherwise it returns false.
  155        * @param node
  156        * @return whether object is a leaf node or not
  157        */
  158       public boolean isLeaf(Object node) {
  159           if (node instanceof TreeNode) {
  160               return ((TreeNode)node).isLeaf();
  161           } else {
  162               return false;
  163           }
  164       }
  165   
  166       /**
  167        *
  168        */
  169       public void addTableModelListener(TableModelListener l) {
  170           this.listener.add(TableModelListener.class,l);
  171       }
  172   
  173       /**
  174        *
  175        */
  176       public void removeTableModelListener(TableModelListener l) {
  177           this.listener.remove(TableModelListener.class,l);
  178       }
  179   
  180       public void nodeStructureChanged(TreeNode node) {
  181   
  182       }
  183   
  184       public void fireTreeNodesChanged(TreeNode source,
  185               Object[] path,
  186               int[] indexes,
  187               Object[] children) {
  188   
  189       }
  190   
  191       public void clearData() {
  192           int size = getRowCount();
  193           objects.clear();
  194           super.fireTableRowsDeleted(0, size);
  195       }
  196   }

Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jorphan.gui » [javadoc | source]