| java.lang.Object net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.CellComponentFactory
CellComponentFactory | public class CellComponentFactory (Code) | | author: gwg author: This class is used by other parts of SQuirreL to handle all author: DataType-specific behavior for the ContentsTab. author: This includes reading/updating the DB, formatting data for display, author: validating user input, converting user input into an internal object author: of the appropriate type, and saving the data to or reading from a file. author: The actual work is handled by separate DataType-specific classes, author: so this class is a facade that selects the class to use and calls author: the desired method on that class. All of the DataType-specifc classes author: implement the IDataTypeComponent interface. author: author: At this time we use only the type of the data to determine which DataType author: class to use for the requested component. In the future it may become author: useful to include other factors, such as the specific table and column author: being displayed. This info could be used to select a specialized class author: (or a general class using an external resource file) to display table author: and column specific translations of data, such as mapping an integer author: code in the DB into a mnemonic representation (eg. 1='dial-up', 2='cable', 3='DSL'). author:
author: The JTable is needed to allow the components to identify which cell author: is being referred to by a double-click mouse event, which causes author: a popup editing window to be generated. author:
author: Creating new DataType handlers author: Plugins and other code may need to create and install handlers for author: data types that are not included in the standard SQuirreL product. author: This might be needed to handle DBMS-specific data types, author: or to override the standard behavior for a specific data type. author: For example: author:
author:
author: PostgreSQL defines several non-standard data types, such as "bytea", author: "tid", "xid", int2vector", etc. All of these have the same SQL type-code author: of "1111", which means "OTHER". author: The default ContesTab operation on type 1111 is to not display it author: and not allow editing. However, if a plugin is able to define the author: operations on those fields, it can register a handler that will author: display the data appropriately and allow editing on those fields. author: author: If a DBMS defines a standard SQL data type in a non-standard way, author: a plugin for that DBMS may need to override the normal DataType class author: for that data type with another. author: An example would be if a DBMS implemented SQL type SMALLINT, author: which is handled internally as a Short, as an INTEGER, which is author: handled as an Integer. author: In order to correctly read and display values of that type in the ContentsTab, author: the handler for SQL type SMALLINT (=5) should be changed from author: DataTypeShort to DataTypeInteger. author: author: author: Here is how to create and register a DataType handler: author:
author:
author: Using SQuirrel, connect to the DBMS. author: Click on the "Data Types" tab. author: Get the "TYPE_NAME" and "DATA_TYPE" values for the data type author: for which you want to create a handler. author: author: Create a handler for that type of data. author: The handler must implement the IDataTypeComponet interface. author: The files whose names start with "DataType..." author: in the package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent author: (i.e. the same place as this file) author: are examples of how to handle different data types. author: The data must be held in the JTable as a Java object. author: You must first identify what class of that object is. author: It may be your own local class or one of the standard Java classes author: since all of the code outside of the DataType class just treats it as an Object. author: The DataType class that you create must handle all transformations author: between that internal Java class and the Database, author: rendering in a cell, rendering in the Popup editing window author: (which may be the same as in a cell), and export/import with files. author: The DataType class also determines whether or not these verious translations author: are allowed. author: author: As part of the initialization of the application or plugin, author: register the DataType class as the handler for the data type. author: This is done using the static method registerDataType() in this class. author: The first argument is the fully-qualified name of the method, author: and the other two arguments identify the data type. author: For example: author: author: CellComponentFactory.registerDataType( author: "net.sourceforge.squirrel_sql.plugins.postgreSQLPlugin.DataTypeBytea", author: 1111, "bytea"); author:
author: Another example, in the case where a SMALLINT is actually handled author: by the DBMS as an integer: author: author: CellComponentFactory.registerDataType( author: "net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeInteger", author: 5, "SHORT"); author:
author: Once the DataType class is registered, author: that class is called to process that data type in all of the author: associated data type. author: author: author: The DataType registration process does not associate DataType handlers author: with particular DBMSs. Therefore, if two plugins for two different DBMSs author: register exactly the same SQL Type code and data type name, author: one of the databases will not be handled correctly.
|
Method Summary | |
public static boolean | areEqual(ColumnDisplayDefinition colDef, Object newValue, Object oldValue) Determine if the values of two objects are the same. | public static boolean | canDoFileIO(ColumnDisplayDefinition colDef) Say whether or not object can be exported to and imported from
a file. | public static void | exportObject(ColumnDisplayDefinition colDef, FileOutputStream outStream, String text) Given a text string from the Popup, validate that it makes sense
for the given DataType, then write it out to a file in the
appropriate format. | public static String | getClassName(ColumnDisplayDefinition colDef) Return the name of the Java class that is used to represent
this data type within the application. | public static OkJPanel[] | getControlPanels() Get the Control Panels (JPanels containing controls) that let the
user adjust the properties of static properties in specific DataTypes. | public static Object | getDefaultValue(ColumnDisplayDefinition colDef, String dbDefaultValue) Get a default value for the table used to input data for a new row
to be inserted into the DB. | public static DefaultCellEditor | getInCellEditor(JTable table, ColumnDisplayDefinition colDef) Return a DefaultCellEditor using a JTextField with appropriate
handlers to manage the type of input for the cell. | public static JTextArea | getJTextArea(ColumnDisplayDefinition colDef, Object value) Return a JTextArea with appropriate handlers for editing
the type of data in the cell. | public static TableCellRenderer | getTableCellRenderer(ColumnDisplayDefinition colDef) Get a TableCellRenderer for the given column. | public static String | getWhereClauseValue(ColumnDisplayDefinition colDef, Object value, ISQLDatabaseMetaData md) When updating the database, generate a string form of this object value
that can be used in the WHERE clause to match the value in the database. | public static String | importObject(ColumnDisplayDefinition colDef, FileInputStream inStream) Read a file and construct a valid object from its contents. | public static boolean | isEditableInCell(ColumnDisplayDefinition colDef, Object originalValue) Return true if the data type for the column may be edited
within the table cell, false if not. | public static boolean | isEditableInPopup(ColumnDisplayDefinition colDef, Object originalValue) Return true if the data type for the column may be edited
in the popup, false if not. | public static boolean | needToReRead(ColumnDisplayDefinition colDef, Object originalValue) See if a value in a column has been limited in some way and
needs to be re-read before being used for editing. | public static Object | readResultSet(ColumnDisplayDefinition colDef, ResultSet rs, int index, boolean limitDataRead) On input from the DB, read the data from the ResultSet into the appropriate
type of object to be stored in the table cell. | public static Object | readResultWithPluginRegisteredDataType(ResultSet rs, int sqlType, String sqlTypeName, int index) Returns the result for the column at the specified index as determined
by a previously registered plugin DataTypeComponent. | public static void | registerDataTypeFactory(IDataTypeComponentFactory factory, int sqlType, String sqlTypeName) Method for registering a DataTypeComponent factory for a non-standard
SQL type (or for overriding a standard handler). | public static String | renderObject(Object value, ColumnDisplayDefinition colDef) Render value of object as a string for text output. | public static void | setPreparedStatementValue(ColumnDisplayDefinition colDef, PreparedStatement pstmt, Object value, int position) When updating the database, insert the appropriate datatype into the
prepared statment at the given variable position. | public static boolean | useBinaryEditingPanel(ColumnDisplayDefinition colDef) Return the flag from the component saying
whether to do editing in the special binary editing panel
or the component will handle all text input. | public static Object | validateAndConvert(ColumnDisplayDefinition colDef, Object originalValue, String inputValue, StringBuffer messageBuffer) Call the validate and convert method in the appropriate
DataType object. | public static Object | validateAndConvertInPopup(ColumnDisplayDefinition colDef, Object originalValue, String inputValue, StringBuffer messageBuffer) Call the validate and convert method in the appropriate
DataType object. |
canDoFileIO | public static boolean canDoFileIO(ColumnDisplayDefinition colDef)(Code) | | Say whether or not object can be exported to and imported from
a file. We put both export and import together in one test
on the assumption that all conversions can be done both ways.
|
exportObject | public static void exportObject(ColumnDisplayDefinition colDef, FileOutputStream outStream, String text) throws IOException(Code) | | Given a text string from the Popup, validate that it makes sense
for the given DataType, then write it out to a file in the
appropriate format.
Errors are returned by throwing an IOException containing the
cause of the problem as its message.
|
getClassName | public static String getClassName(ColumnDisplayDefinition colDef)(Code) | | Return the name of the Java class that is used to represent
this data type within the application.
|
getControlPanels | public static OkJPanel[] getControlPanels()(Code) | | Get the Control Panels (JPanels containing controls) that let the
user adjust the properties of static properties in specific DataTypes.
The only DataType objects checked for here are:
- those that are registered through the registerDataType method, and
- those that are specifically listed in the variable initialClassNameList
|
getDefaultValue | public static Object getDefaultValue(ColumnDisplayDefinition colDef, String dbDefaultValue)(Code) | | Get a default value for the table used to input data for a new row
to be inserted into the DB.
|
getWhereClauseValue | public static String getWhereClauseValue(ColumnDisplayDefinition colDef, Object value, ISQLDatabaseMetaData md)(Code) | | When updating the database, generate a string form of this object value
that can be used in the WHERE clause to match the value in the database.
A return value of null means that this column cannot be used in the WHERE
clause, while a return of "null" (or "is null", etc) means that the column
can be used in the WHERE clause and the value is actually a null value.
This function must also include the column label so that its output
is of the form:
"columnName = value"
or
"columnName is null"
or whatever is appropriate for this column in the database.
|
isEditableInCell | public static boolean isEditableInCell(ColumnDisplayDefinition colDef, Object originalValue)(Code) | | Return true if the data type for the column may be edited
within the table cell, false if not.
|
isEditableInPopup | public static boolean isEditableInPopup(ColumnDisplayDefinition colDef, Object originalValue)(Code) | | Return true if the data type for the column may be edited
in the popup, false if not.
|
needToReRead | public static boolean needToReRead(ColumnDisplayDefinition colDef, Object originalValue)(Code) | | See if a value in a column has been limited in some way and
needs to be re-read before being used for editing.
For read-only tables this may actually return true since we want
to be able to view the entire contents of the cell even if it was not
completely loaded during the initial table setup.
|
readResultWithPluginRegisteredDataType | public static Object readResultWithPluginRegisteredDataType(ResultSet rs, int sqlType, String sqlTypeName, int index) throws Exception(Code) | | Returns the result for the column at the specified index as determined
by a previously registered plugin DataTypeComponent. Will return null
if the type cannot be handled by any plugin-registered DataTypeComponent.
Parameters: rs - the ResultSet to read Parameters: sqlType - the Java SQL type of the column Parameters: sqlTypeName - the SQL type name of the column Parameters: index - the index of the column that should be read the value as interpreted by the plugin-registeredDataTypeComponent, or null if no plugin DataTypeComponent hasbeen registered for the specified sqlType and sqlTypename. throws: Exception - |
registerDataTypeFactory | public static void registerDataTypeFactory(IDataTypeComponentFactory factory, int sqlType, String sqlTypeName)(Code) | | Method for registering a DataTypeComponent factory for a non-standard
SQL type (or for overriding a standard handler).
|
useBinaryEditingPanel | public static boolean useBinaryEditingPanel(ColumnDisplayDefinition colDef)(Code) | | Return the flag from the component saying
whether to do editing in the special binary editing panel
or the component will handle all text input.
|
|
|