Update of /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18051
Modified Files:
DataTypeUnknown.java
Log Message:
handle options locally
Index: DataTypeUnknown.java
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeUnknown.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DataTypeUnknown.java 7 Apr 2004 02:47:47 -0000 1.5
--- DataTypeUnknown.java 17 May 2004 15:29:32 -0000 1.6
***************
*** 27,32 ****
--- 27,34 ----
import javax.swing.JTextField;
import javax.swing.JTextArea;
+ import javax.swing.JCheckBox;
import javax.swing.SwingUtilities;
import javax.swing.text.JTextComponent;
+ import javax.swing.BorderFactory;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
***************
*** 35,41 ****
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
import net.sourceforge.squirrel_sql.fw.datasetviewer.CellDataPopup;
- //??import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IDataTypeComponent;
import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
import net.sourceforge.squirrel_sql.fw.datasetviewer.LargeResultSetObjectInfo;
/**
--- 37,43 ----
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
import net.sourceforge.squirrel_sql.fw.datasetviewer.CellDataPopup;
import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
import net.sourceforge.squirrel_sql.fw.datasetviewer.LargeResultSetObjectInfo;
+ import net.sourceforge.squirrel_sql.fw.gui.OkJPanel;
/**
***************
*** 96,99 ****
--- 98,122 ----
+
+ /**
+ * Name of this class, which is needed because the class name is needed
+ * by the static method getControlPanel, so we cannot use something
+ * like getClass() to find this name.
+ */
+ private static final String thisClassName =
+ "net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeUnknown";
+
+ /*
+ * Properties settable by the user
+ */
+ // flag for whether we have already loaded the properties or not
+ private static boolean propertiesAlreadyLoaded = false;
+
+
+ /** Read the contents of Other from Result sets when first loading the tables. */
+ private static boolean _readUnknown = false;
+
+
+
/**
* Constructor - save the data needed by this data type.
***************
*** 103,106 ****
--- 126,157 ----
_colDef = colDef;
_isNullable = colDef.isNullable();
+
+ loadProperties();
+ }
+
+ /** Internal function to get the user-settable properties from the DTProperties,
+ * if they exist, and to ensure that defaults are set if the properties have
+ * not yet been created.
+ * <P>
+ * This method may be called from different places depending on whether
+ * an instance of this class is created before the user brings up the Session
+ * Properties window. In either case, the data is static and is set only
+ * the first time we are called.
+ */
+ private static void loadProperties() {
+
+ //set the property values
+ // Note: this may have already been done by another instance of
+ // this DataType created to handle a different column.
+ if (propertiesAlreadyLoaded == false) {
+ // get parameters previously set by user, or set default values
+ _readUnknown = false; // set to the default
+ String readUnknownString = DTProperties.get(
+ thisClassName, "readUnknown");
+ if (readUnknownString != null && readUnknownString.equals("true"))
+ _readUnknown = true;
+
+ propertiesAlreadyLoaded = true;
+ }
}
***************
*** 274,278 ****
String data = null;
! if (largeObjInfo.getReadAllOther())
{
// Running getObject on a java class attempts
--- 325,329 ----
String data = null;
! if (_readUnknown)
{
// Running getObject on a java class attempts
***************
*** 415,417 ****
--- 466,559 ----
throw new IOException("Can not export data type OTHER");
}
+
+
+
+ /*
+ * Property change control panel
+ */
+
+ /**
+ * Generate a JPanel containing controls that allow the user
+ * to adjust the properties for this DataType.
+ * All properties are static accross all instances of this DataType.
+ * However, the class may choose to apply the information differentially,
+ * such as keeping a list (also entered by the user) of table/column names
+ * for which certain properties should be used.
+ * <P>
+ * This is called ONLY if there is at least one property entered into the DTProperties
+ * for this class.
+ * <P>
+ * Since this method is called by reflection on the Method object derived from this class,
+ * it does not need to be included in the Interface.
+ * It would be nice to include this in the Interface for consistancy, documentation, etc,
+ * but the Interface does not seem to like static methods.
+ */
+ public static OkJPanel getControlPanel() {
+
+ /*
+ * If you add this method to one of the standard DataTypes in the
+ * fw/datasetviewer/cellcomponent directory, you must also add the name
+ * of that DataType class to the list in CellComponentFactory, method
+ * getControlPanels, variable named initialClassNameList.
+ * If the class is being registered with the factory using registerDataType,
+ * then you should not include the class name in the list (it will be found
+ * automatically), but if the DataType is part of the case statement in the
+ * factory method getDataTypeObject, then it does need to be explicitly listed
+ * in the getControlPanels method also.
+ */
+
+ // if this panel is called before any instances of the class have been
+ // created, we need to load the properties from the DTProperties.
+ loadProperties();
+
+ return new UnknownOkJPanel();
+ }
+
+
+
+ /**
+ * Inner class that extends OkJPanel so that we can call the ok()
+ * method to save the data when the user is happy with it.
+ */
+ private static class UnknownOkJPanel extends OkJPanel {
+ /*
+ * GUI components - need to be here because they need to be
+ * accessible from the event handlers to alter each other's state.
+ */
+ // check box for whether to read contents during table load or not
+ private JCheckBox _showUnknownChk = new JCheckBox(
+ "Read contents when table is first loaded and display as string");
+
+
+ public UnknownOkJPanel() {
+
+ /* set up the controls */
+ // checkbox for read/not-read on table load
+ _showUnknownChk.setSelected(_readUnknown);
+
+ /*
+ * Create the panel and add the GUI items to it
+ */
+
+ setBorder(BorderFactory.createTitledBorder(
+ "Unknown DataTypes (non-standard SQL type codes)"));
+
+ add(_showUnknownChk);
+
+ } // end of constructor for inner class
+
+
+ /**
+ * User has clicked OK in the surrounding JPanel,
+ * so save the current state of all variables
+ */
+ public void ok() {
+ // get the values from the controls and set them in the static properties
+ _readUnknown = _showUnknownChk.isSelected();
+ DTProperties.put(
+ thisClassName,
+ "readUnknown", Boolean.toString(_readUnknown));
+ }
+
+ } // end of inner class
}
|