Package ucar.ui.prefs

Class BeanTable<T>

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible

    public class BeanTable<T>
    extends JPanel
    A JTable that uses JavaBeans to store the data.

    The columns of the JTable are the Properties of the Javabean, found through introspection.

    The properties may be editable if they have type primitive or String. and you list the editable properties in a static method editableProperties() in the bean, eg :

     static public String editableProperties() {
       return "ID serverName active writeDirectory";
     }
     
    or as an instance method with a no parameter constructor
     MyClass() {}
     
     public String editableProperties() {
       return "ID serverName active writeDirectory";
     }
     

    You may hide properties by listing them in a static method hiddenProperties() in the bean, eg :

     static public String hiddenProperties() {
       return "hideThisProperty DDDirectory";
     }
     
    * or as an instance method with a no parameter constructor
     MyClass() {}
     
     public String hiddenProperties() {
       return "ID serverName active writeDirectory";
     }
     

    The data can be made persistent through a PreferencesExt store. The width and order of the columns is persistent. The javabean class may add or delete properties, and the stored data will be reasonably intact.

    See Also:
    Serialized Form
    • Field Detail

      • beanClass

        protected Class<T> beanClass
      • innerbean

        protected T innerbean
      • jtable

        protected JTable jtable
      • debug

        protected boolean debug
      • debugStore

        protected boolean debugStore
      • debugBean

        protected boolean debugBean
      • debugSelected

        protected boolean debugSelected
    • Constructor Detail

      • BeanTable

        public BeanTable​(Class<T> bc,
                         PreferencesExt pstore,
                         boolean canAddDelete,
                         String header,
                         String tooltip,
                         T bean)
        Constructor.
        Parameters:
        bc - JavaBean class
        pstore - store data in this PreferencesExt store.
        canAddDelete - allow changes to the jtable - adds a New and Delete button to bottom panel
        header - optional header label
        tooltip - optional tooltip label
        bean - needed for inner classes to call reflected methods on
    • Method Detail

      • setHeader

        public void setHeader​(String header)
      • setProperty

        public void setProperty​(String propertyName,
                                String displayName,
                                String toolTipText)
      • setPropertyEditable

        public void setPropertyEditable​(String propertyName,
                                        boolean isHidden)
      • setPropertyHidden

        public void setPropertyHidden​(String propertyName,
                                      boolean isHidden)
      • addListSelectionListener

        public void addListSelectionListener​(ListSelectionListener l)
        Add listener: ListSelectionEvent sent when a new row is selected
      • removeListSelectionListener

        public void removeListSelectionListener​(ListSelectionListener l)
        Remove listener
      • getSelectedBean

        @Nullable
        public T getSelectedBean()
        Get the currently selected bean, or null if none selected.
        Returns:
        the currently selected bean, or null if none selected
      • getSelectedBeans

        public List<T> getSelectedBeans()
        Get the currently selected beans. Use this for multiple selection
        Returns:
        ArrayList of currently selected beans (wont be null).
        See Also:
        setSelectionMode(int)
      • getSelectedCells

        public ArrayList<Object> getSelectedCells()
        Get the currently selected cells. Use this for multiple row selection, when columnSelection is on
        Returns:
        ArrayList of currently selected cells (wont be null).
      • clearSelectedCells

        public void clearSelectedCells()
        Set the currently selected cells (0, false or null). Use this for multiple row selection, when columnSelection is on
      • addBean

        public void addBean​(T bean)
      • addBeans

        public void addBeans​(List<T> newBeans)
      • setBeans

        public void setBeans​(List<T> beans)
      • clearBeans

        public void clearBeans()
      • getBeans

        public List<T> getBeans()
      • getJTable

        public JTable getJTable()
      • setFontSize

        public void setFontSize​(int size)
      • setSelectionMode

        public void setSelectionMode​(int mode)
        Set the selection mode on the JTable
        Parameters:
        mode - : JTable.setSelectionMode
        See Also:
        JTable.setSelectionMode(int)
      • setSelectedBean

        public void setSelectedBean​(T bean)
        Set which row is selected.
        Parameters:
        bean - select this one; must be in the list.
      • clearSelection

        public void clearSelection()
      • setSelectedBeans

        public void setSelectedBeans​(List<T> want)
        Set which rows are selected. must also call setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        Parameters:
        want - select these
      • refresh

        public void refresh()
      • setColumnSelectionAllowed

        public void setColumnSelectionAllowed​(boolean b)
        Set the ColumnSelection is allowed (default false)
        Parameters:
        b - allowed or not
      • saveState

        public void saveState​(boolean saveData)
        Save state to the PreferencesExt.
      • fireBeanDataChanged

        public void fireBeanDataChanged​(T bean)
        Notifies the TableModel that the data in the specified bean has changed. The TableModel will then fire an event of its own, which its listeners will hear (usually a JTable).
        Parameters:
        bean - a bean that has changed.
      • restoreState

        protected void restoreState()
        Restore state from PreferencesExt