Java Doc for CellComponentFactory.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » fw » datasetviewer » cellcomponent » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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.



    Field Summary
    static  HashMap<ColumnDisplayDefinition, IDataTypeComponent>_colDataTypeObjects
        
    static  HashMap<String, IDataTypeComponentFactory>_pluginDataTypeFactories
        
    static  JTable_table
        


    Method Summary
    public static  booleanareEqual(ColumnDisplayDefinition colDef, Object newValue, Object oldValue)
         Determine if the values of two objects are the same.
    public static  booleancanDoFileIO(ColumnDisplayDefinition colDef)
         Say whether or not object can be exported to and imported from a file.
    public static  voidexportObject(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  StringgetClassName(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  ObjectgetDefaultValue(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  DefaultCellEditorgetInCellEditor(JTable table, ColumnDisplayDefinition colDef)
         Return a DefaultCellEditor using a JTextField with appropriate handlers to manage the type of input for the cell.
    public static  JTextAreagetJTextArea(ColumnDisplayDefinition colDef, Object value)
         Return a JTextArea with appropriate handlers for editing the type of data in the cell.
    public static  TableCellRenderergetTableCellRenderer(ColumnDisplayDefinition colDef)
         Get a TableCellRenderer for the given column.
    public static  StringgetWhereClauseValue(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  StringimportObject(ColumnDisplayDefinition colDef, FileInputStream inStream)
         Read a file and construct a valid object from its contents.
    public static  booleanisEditableInCell(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  booleanisEditableInPopup(ColumnDisplayDefinition colDef, Object originalValue)
         Return true if the data type for the column may be edited in the popup, false if not.
    public static  booleanneedToReRead(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  ObjectreadResultSet(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  ObjectreadResultWithPluginRegisteredDataType(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  voidregisterDataTypeFactory(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  StringrenderObject(Object value, ColumnDisplayDefinition colDef)
         Render value of object as a string for text output.
    public static  voidsetPreparedStatementValue(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  booleanuseBinaryEditingPanel(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  ObjectvalidateAndConvert(ColumnDisplayDefinition colDef, Object originalValue, String inputValue, StringBuffer messageBuffer)
         Call the validate and convert method in the appropriate DataType object.
    public static  ObjectvalidateAndConvertInPopup(ColumnDisplayDefinition colDef, Object originalValue, String inputValue, StringBuffer messageBuffer)
         Call the validate and convert method in the appropriate DataType object.

    Field Detail
    _colDataTypeObjects
    static HashMap<ColumnDisplayDefinition, IDataTypeComponent> _colDataTypeObjects(Code)



    _pluginDataTypeFactories
    static HashMap<String, IDataTypeComponentFactory> _pluginDataTypeFactories(Code)



    _table
    static JTable _table(Code)





    Method Detail
    areEqual
    public static boolean areEqual(ColumnDisplayDefinition colDef, Object newValue, Object oldValue)(Code)
    Determine if the values of two objects are the same.



    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.



    getInCellEditor
    public static DefaultCellEditor getInCellEditor(JTable table, ColumnDisplayDefinition colDef)(Code)
    Return a DefaultCellEditor using a JTextField with appropriate handlers to manage the type of input for the cell.



    getJTextArea
    public static JTextArea getJTextArea(ColumnDisplayDefinition colDef, Object value)(Code)
    Return a JTextArea with appropriate handlers for editing the type of data in the cell.



    getTableCellRenderer
    public static TableCellRenderer getTableCellRenderer(ColumnDisplayDefinition colDef)(Code)
    Get a TableCellRenderer for the given column.



    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.



    importObject
    public static String importObject(ColumnDisplayDefinition colDef, FileInputStream inStream) throws IOException(Code)
    Read a file and construct a valid object from its contents. Errors are returned by throwing an IOException containing the cause of the problem as its message.



    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.



    readResultSet
    public static Object readResultSet(ColumnDisplayDefinition colDef, ResultSet rs, int index, boolean limitDataRead) throws java.sql.SQLException(Code)
    On input from the DB, read the data from the ResultSet into the appropriate type of object to be stored in the table cell.



    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).



    renderObject
    public static String renderObject(Object value, ColumnDisplayDefinition colDef)(Code)
    Render value of object as a string for text output. Used by Text version of table.



    setPreparedStatementValue
    public static void setPreparedStatementValue(ColumnDisplayDefinition colDef, PreparedStatement pstmt, Object value, int position) throws java.sql.SQLException(Code)
    When updating the database, insert the appropriate datatype into the prepared statment at the given variable position.



    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.



    validateAndConvert
    public static Object validateAndConvert(ColumnDisplayDefinition colDef, Object originalValue, String inputValue, StringBuffer messageBuffer)(Code)
    Call the validate and convert method in the appropriate DataType object.



    validateAndConvertInPopup
    public static Object validateAndConvertInPopup(ColumnDisplayDefinition colDef, Object originalValue, String inputValue, StringBuffer messageBuffer)(Code)
    Call the validate and convert method in the appropriate DataType object.



    Methods inherited from java.lang.Object
    native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
    public boolean equals(Object obj)(Code)(Java Doc)
    protected void finalize() throws Throwable(Code)(Java Doc)
    final native public Class getClass()(Code)(Java Doc)
    native public int hashCode()(Code)(Java Doc)
    final native public void notify()(Code)(Java Doc)
    final native public void notifyAll()(Code)(Java Doc)
    public String toString()(Code)(Java Doc)
    final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
    final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
    final public void wait() throws InterruptedException(Code)(Java Doc)

    www.java2java.com | Contact Us
    Copyright 2009 - 12 Demo Source and Support. All rights reserved.
    All other trademarks are property of their respective owners.