quick.dbtable
Class Column

java.lang.Object
  extended byjavax.swing.table.TableColumn
      extended byquick.dbtable.Column
All Implemented Interfaces:
java.io.Serializable

public class Column
extends javax.swing.table.TableColumn
implements java.io.Serializable

This class defines the properties of a column in DBTable. See Column FAQ

Version:
1.0 05/05/99
Author:
Benjamin D. Franklin
See Also:
Serialized Form

Field Summary
static java.lang.String BOUND_SQL_PROPERTY
           
static int CHECKBOX_CELL
           
static java.lang.String COLUMN_NAME_PROPERTY
           
static int COMBOBOX_CELL
           
static java.lang.String DATA_MAP_PROPERTY
           
static int DATE_CELL
           
static java.lang.String DATE_FORMAT_PROPERTY
           
static int DEFAULT_CELL
           
static java.lang.String DOCUMENT_PROPERTY
           
static java.lang.String EDITOR_PROPERTY
           
static int IMAGE_CELL
           
static java.lang.String LENGTH_PROPERTY
           
static java.lang.String NULLABLE_PROPERTY
           
static java.lang.String PRECISION_PROPERTY
           
static int RADIOBUTTON_CELL
           
static java.lang.String READ_ONLY_PROPERTY
           
static java.lang.String RENDERER_PROPERTY
           
static java.lang.String SCALE_PROPERTY
           
static java.lang.String SIGNED_PROPERTY
           
static int TEXTAREA_CELL
           
static java.lang.String TYPE_PROPERTY
           
static int USER_CELL
           
static java.lang.String VISIBLE_PROPERTY
           
 
Fields inherited from class javax.swing.table.TableColumn
CELL_RENDERER_PROPERTY, COLUMN_WIDTH_PROPERTY, HEADER_RENDERER_PROPERTY, HEADER_VALUE_PROPERTY
 
Constructor Summary
Column()
          Deprecated. This constructor is deprecated because lot of users don't change the model index id to value other than 0 which creates problems later on. use Column(int columnIndex) instead.
Column(int columnIndex)
          This calls the TableColumn's constructor This creates a default width of 75, a null renderer and a null editor for this column columnIndex starts from 1 to number of columns (note column index doesn't start from 0) If columnIndex is not properly assigned, this will create problems later on.
Column(int columnIndex, int width)
          This calls the TableColumn's constructor This creates a column of the specified width , a null renderer and a null editor
Column(int columnIndex, int width, javax.swing.table.TableCellRenderer cellRenderer, javax.swing.table.TableCellEditor cellEditor)
          Deprecated. Quicktable uses CellComponent instead of TableCellRenderer & cellEditor, use setUserCellEditor/setUserCellRenderer methods instead.
Column(int columnIndex, java.lang.String columnHeaderName)
          This calls the TableColumn's constructor This creates a default width of 75, a null renderer and a null editor for this column and sets the column header Name to this name
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 java.lang.String getBoundSql()
          returns the bound sql of this column
 java.lang.String getColumnName()
          returns the actual database column name
 DataMap getDataMap()
          returns the dataMap property of the column.
 java.lang.String getDateFormat()
          returns the date format of this column
 javax.swing.text.Document getDocument()
          returns the date format of this column
 int getLength()
          returns the length of the column, for non numeric
 java.lang.String getMethodName()
          gets the method name which is used by this column.
 boolean getNullable()
          returns the nullable property of this column
 int getPrecision()
          returns the precision of the column , if this is of type numeric , float, or double
 boolean getReadOnly()
          returns whether the column is readonly
 ResultSetMap getResultSetMap()
          gets the ResultSetMap for this column.
 int getScale()
          returns the scale of the column , if this is of type numeric , float, or double
 boolean getSigned()
          returns the signed property of the column
 int getType()
          returns the type of the database column, refer to java.sql.Types for the available types
 CellComponent getUserCellEditor()
          Gets the user Cell Editor
 CellComponent getUserCellRenderer()
          gets the user Cell Renderer
 boolean isVisible()
          returns whether the column is currently visible or not
 void refreshBoundCombo()
          Refresh the bound combo in this column
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void setBoundSql(java.lang.String sql)
          sets the bound column sql
 void setColumnName(java.lang.String val)
          Sets the actual database column name
 void setDataMap(DataMap val)
          sets the dataMap property of the column.
 void setDateFormat(java.lang.String dateFormat)
          If this is a date type column and if you want to display the date in a specific format, you can use this method.
 void setDocument(javax.swing.text.Document document)
          This is used to set the document, if this column has a textfield cell editor Masking & input validation can be done using document
 void setLength(int val)
          Sets the length of the column ( for non numeric columns only).
 void setMethodName(java.lang.String methodName)
          sets the method name which is used by this column.
 void setNullable(boolean val)
          sets the nullable property of this column setting this false, will prevent the cell of this column being emptied out.
 void setPrecision(int val)
          Sets the precision of the column , if this is of type numeric , float, or double
 void setPreferredWidth(int width)
           
 void setReadOnly(boolean val)
          Sets the read only property of the column
 void setResultSetMap(ResultSetMap val)
          Sets the ResultSetMap for this column.
 void setScale(int val)
          Sets the scale of the column , if this is of type numeric , float, or double
 void setSigned(boolean val)
          Sets the signed property of the column
 void setType(int val)
          Sets the type of the database column, refer to java.sql.Types for the available types use setType(Types.LONGVARCHAR) = If you need Textarea editor ( multiple line editing) , instead of textfield editor (single line editing) , use LONGVARCHAR even if the database type is VARCHAR
 void setUserCellEditor(CellComponent cc)
          Sets the user Cell Editor
 void setUserCellRenderer(CellComponent cc)
          Sets the user Cell Renderer
 void setVisible(boolean val)
          To hide/show this column When the column is invisible, this invisible column's data is still accessible.
 void setWidth(int width)
           
 
Methods inherited from class javax.swing.table.TableColumn
disableResizedPosting, enableResizedPosting, getCellEditor, getCellRenderer, getHeaderRenderer, getHeaderValue, getIdentifier, getMaxWidth, getMinWidth, getModelIndex, getPreferredWidth, getPropertyChangeListeners, getResizable, getWidth, setCellEditor, setCellRenderer, setHeaderRenderer, setHeaderValue, setIdentifier, setMaxWidth, setMinWidth, setModelIndex, setResizable, sizeWidthToFit
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_ONLY_PROPERTY

public static final java.lang.String READ_ONLY_PROPERTY
See Also:
Constant Field Values

TYPE_PROPERTY

public static final java.lang.String TYPE_PROPERTY
See Also:
Constant Field Values

COLUMN_NAME_PROPERTY

public static final java.lang.String COLUMN_NAME_PROPERTY
See Also:
Constant Field Values

SCALE_PROPERTY

public static final java.lang.String SCALE_PROPERTY
See Also:
Constant Field Values

PRECISION_PROPERTY

public static final java.lang.String PRECISION_PROPERTY
See Also:
Constant Field Values

LENGTH_PROPERTY

public static final java.lang.String LENGTH_PROPERTY
See Also:
Constant Field Values

NULLABLE_PROPERTY

public static final java.lang.String NULLABLE_PROPERTY
See Also:
Constant Field Values

SIGNED_PROPERTY

public static final java.lang.String SIGNED_PROPERTY
See Also:
Constant Field Values

BOUND_SQL_PROPERTY

public static final java.lang.String BOUND_SQL_PROPERTY
See Also:
Constant Field Values

DATE_FORMAT_PROPERTY

public static final java.lang.String DATE_FORMAT_PROPERTY
See Also:
Constant Field Values

DOCUMENT_PROPERTY

public static final java.lang.String DOCUMENT_PROPERTY
See Also:
Constant Field Values

DATA_MAP_PROPERTY

public static final java.lang.String DATA_MAP_PROPERTY
See Also:
Constant Field Values

EDITOR_PROPERTY

public static final java.lang.String EDITOR_PROPERTY
See Also:
Constant Field Values

RENDERER_PROPERTY

public static final java.lang.String RENDERER_PROPERTY
See Also:
Constant Field Values

VISIBLE_PROPERTY

public static final java.lang.String VISIBLE_PROPERTY
See Also:
Constant Field Values

IMAGE_CELL

public static final int IMAGE_CELL
See Also:
Constant Field Values

CHECKBOX_CELL

public static final int CHECKBOX_CELL
See Also:
Constant Field Values

RADIOBUTTON_CELL

public static final int RADIOBUTTON_CELL
See Also:
Constant Field Values

DEFAULT_CELL

public static final int DEFAULT_CELL
See Also:
Constant Field Values

DATE_CELL

public static final int DATE_CELL
See Also:
Constant Field Values

COMBOBOX_CELL

public static final int COMBOBOX_CELL
See Also:
Constant Field Values

TEXTAREA_CELL

public static final int TEXTAREA_CELL
See Also:
Constant Field Values

USER_CELL

public static final int USER_CELL
See Also:
Constant Field Values
Constructor Detail

Column

public Column()
Deprecated. This constructor is deprecated because lot of users don't change the model index id to value other than 0 which creates problems later on. use Column(int columnIndex) instead.

This calls the TableColumn's default constructor This creates a default model index of 0, default width of 75, a null renderer and a null editor for this column


Column

public Column(int columnIndex)
This calls the TableColumn's constructor This creates a default width of 75, a null renderer and a null editor for this column columnIndex starts from 1 to number of columns (note column index doesn't start from 0) If columnIndex is not properly assigned, this will create problems later on.


Column

public Column(int columnIndex,
              int width)
This calls the TableColumn's constructor This creates a column of the specified width , a null renderer and a null editor


Column

public Column(int columnIndex,
              java.lang.String columnHeaderName)
This calls the TableColumn's constructor This creates a default width of 75, a null renderer and a null editor for this column and sets the column header Name to this name


Column

public Column(int columnIndex,
              int width,
              javax.swing.table.TableCellRenderer cellRenderer,
              javax.swing.table.TableCellEditor cellEditor)
Deprecated. Quicktable uses CellComponent instead of TableCellRenderer & cellEditor, use setUserCellEditor/setUserCellRenderer methods instead.

This calls the TableColumn's constructor This creates a column of the specified width , a specified renderer and specified cell editor

Method Detail

getReadOnly

public boolean getReadOnly()
returns whether the column is readonly


setReadOnly

public void setReadOnly(boolean val)
Sets the read only property of the column


getDataMap

public DataMap getDataMap()
returns the dataMap property of the column. DataMap property allows to specify, how the data should be converted from the database format to display format, vice versa e.g If the data in database is 1200 and you want to display that as $1,200 then you need to convert 1200 to $1,200.

Since:
2.0.2
See Also:
DataMap

setDataMap

public void setDataMap(DataMap val)
sets the dataMap property of the column. DataMap property allows to specify, how the data should be converted from the database format to display format, vice versa e.g If the data in database is 1200 and you want to display that as $1,200 then you need to convert 1200 to $1,200.

Since:
2.0.2
See Also:
DataMap

getType

public int getType()
returns the type of the database column, refer to java.sql.Types for the available types


setType

public void setType(int val)
Sets the type of the database column, refer to java.sql.Types for the available types use setType(Types.LONGVARCHAR) = If you need Textarea editor ( multiple line editing) , instead of textfield editor (single line editing) , use LONGVARCHAR even if the database type is VARCHAR


getColumnName

public java.lang.String getColumnName()
returns the actual database column name


setColumnName

public void setColumnName(java.lang.String val)
Sets the actual database column name
 This won't set the column name in the Jtable, to set the columnname in Jtable
 use the setHeaderValue method, for example    yourColumn.setHeaderValue("Emp\nId");
 Note: Multiline column headers are not supported in Mac OS. So in Mac OS, setHeaderValue()
 with a header with newline will show in one line.
 


getScale

public int getScale()
returns the scale of the column , if this is of type numeric , float, or double


setScale

public void setScale(int val)
Sets the scale of the column , if this is of type numeric , float, or double


getPrecision

public int getPrecision()
returns the precision of the column , if this is of type numeric , float, or double


setPrecision

public void setPrecision(int val)
Sets the precision of the column , if this is of type numeric , float, or double


getLength

public int getLength()
returns the length of the column, for non numeric


setLength

public void setLength(int val)
Sets the length of the column ( for non numeric columns only). Setting this will limit the number of characters entered into the cell of this column


getNullable

public boolean getNullable()
returns the nullable property of this column


setNullable

public void setNullable(boolean val)
sets the nullable property of this column setting this false, will prevent the cell of this column being emptied out.


getSigned

public boolean getSigned()
returns the signed property of the column


setSigned

public void setSigned(boolean val)
Sets the signed property of the column


getBoundSql

public java.lang.String getBoundSql()
returns the bound sql of this column


setBoundSql

public void setBoundSql(java.lang.String sql)
sets the bound column sql
 If this column is bound with a column in another table, then a combo box
 celleditor will be used for this column & this sql will be used to fill
 that combobox.

 Case 1: (Using value bound sql)
   Lets say the data which you are trying to display is
   employee
   ---------
     1, emp_nam1, dept1
     1, emp_nam2, dept2
     1, emp_nam3, dept1

  For the third column, you want the users to enter values dep1, dep2 only
  and you have a department table which has these allowed data
  departmnet
  ----------
  no, dept
  1, dept1
  2, dept2

  Then you can set the boundsql to "select dept from department"
  When the user tries to edit any cell in this column, it will show
  a combobox with values dept1,dept2, so the user can select only these values

 Case 2: (Using key/value bound sql)
  Following is a employee database table
   employee
   ---------
   emp_no, name, dept_no
     1, emp_nam1, 1
     1, emp_nam2, 2
     1, emp_nam3, 1

   when you display in quicktable you want to display dept name, instead of dept no
     1, emp_nam1, dept1
     1, emp_nam2, dept2
     1, emp_nam3, dept1

   and when user modified the dept, you actually want to update the dept_no, instead
   of dept name, then you can set the boundsql to
  "select dept_no, dept_name from department"

  When the user tries to edit any cell in this column, it will show
  a combobox with values dept1,dept2, so the user can select only these values. Once
  the user select a new departmnet, the actual dept_no will be updated in database


setDateFormat

public void setDateFormat(java.lang.String dateFormat)
If this is a date type column and if you want to display the date in a specific format, you can use this method. Refer to the API documentation of java.text.SimpleDateFormat to learn more about constructing the date format
 Examples Using the US Locale:

  Format Pattern                         Result
  --------------                         -------
  "yyyy.MM.dd G 'at' hh:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT
  "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96
  "h:mm a"                          ->>  12:08 PM
  "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time
  "K:mm a, z"                       ->>  0:00 PM, PST
  "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PM

 Example : myColumn.setDateFormat("EEE, MMM d, ''yy");
 


getDateFormat

public java.lang.String getDateFormat()
returns the date format of this column


setDocument

public void setDocument(javax.swing.text.Document document)
This is used to set the document, if this column has a textfield cell editor Masking & input validation can be done using document


getDocument

public javax.swing.text.Document getDocument()
returns the date format of this column


refreshBoundCombo

public void refreshBoundCombo()
Refresh the bound combo in this column


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

Parameters:
listener - The PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - The PropertyChangeListener to be removed

setVisible

public void setVisible(boolean val)
To hide/show this column When the column is invisible, this invisible column's data is still accessible. If you really want to remove this column & if you don't need this cokumn's data , use the removeColumn method in ColumnModel. If that is the case, it is better to remove this column from the query itself.

Since:
2.0.2

isVisible

public boolean isVisible()
returns whether the column is currently visible or not

Since:
2.0.5.12

setPreferredWidth

public void setPreferredWidth(int width)

setWidth

public void setWidth(int width)

setUserCellEditor

public void setUserCellEditor(CellComponent cc)
Sets the user Cell Editor

Since:
2.0.2

getUserCellEditor

public CellComponent getUserCellEditor()
Gets the user Cell Editor

Since:
2.0.2

setUserCellRenderer

public void setUserCellRenderer(CellComponent cc)
Sets the user Cell Renderer

Since:
2.0.2

getUserCellRenderer

public CellComponent getUserCellRenderer()
gets the user Cell Renderer

Since:
2.0.2

getMethodName

public java.lang.String getMethodName()
gets the method name which is used by this column. while using DataObjects, this method will help to get the method name which is used by this column

Since:
2.0.2

setMethodName

public void setMethodName(java.lang.String methodName)
sets the method name which is used by this column. while using DataObjects, this method will help to set the method name which is used by this column

Since:
2.0.2

setResultSetMap

public void setResultSetMap(ResultSetMap val)
Sets the ResultSetMap for this column.
  QuickTable uses getObject() , setObject method in resultset to read the data. But in some special cases
  you have to handle it differently. This class helps to do that.

  Example :
    If the data type in database is nvarchar, then you have to use getString() ( getObject() doesn't work)
    If data is stored as stream in database, instead of using getObject() , you have to use getBinaryStream()

 Sample implementation
public class StreamResultSetMap extends ResultSetMap
{

   public Object getObject(ResultSet rs, int column) throws SQLException
   {
      InputStream in = rs.getBinaryStream(column);
      String value = createStringFromStream(in);
      return value;
   }

   public void setObject(PreparedStatement pStmt, int column, Object value) throws SQLException
   {
      rs.setBinaryStream(column,getStreamFromString(value), getLengthOfStreamFromValue(value));
   }
}

 //for a new select sql for dbtable, setResultSetMap should be called after createColumnModelFromQuery() and
 //before calling refresh()
 dbtable.createColumnModelFromQuery();
 yourColumn.setResultSetMap( new StreamResultSetMap() );
 dbtable.refresh();

Since:
2.0.4
See Also:
ResultSetMap

getResultSetMap

public ResultSetMap getResultSetMap()
gets the ResultSetMap for this column.

Since:
2.0.4
See Also:
setResultSetMap(ResultSetMap), ResultSetMap