Search in sources :

Example 1 with Varchar

use of easik.database.types.Varchar in project fql by CategoricalData.

the class AttributeUI method getTabs.

/**
 * Returns the tabs for the page; we separate the options into rough
 * categories: numeric, string, date/time, and other (for boolean/custom).
 *
 * @return
 */
@Override
public List<OptionTab> getTabs() {
    LinkedList<OptionTab> tabs = new LinkedList<>();
    EasikType currentType = (_att != null) ? _att.getType() : null;
    JPanel pInts = new JPanel(), pFloats = new JPanel(), pChars = new JPanel(), pTS = new JPanel(), pCustom = new JPanel();
    pInts.setLayout(new BoxLayout(pInts, BoxLayout.Y_AXIS));
    pFloats.setLayout(new BoxLayout(pFloats, BoxLayout.Y_AXIS));
    pChars.setLayout(new BoxLayout(pChars, BoxLayout.Y_AXIS));
    pTS.setLayout(new BoxLayout(pTS, BoxLayout.Y_AXIS));
    pCustom.setLayout(new BoxLayout(pCustom, BoxLayout.Y_AXIS));
    OptionTab numeric = new OptionTab("Numeric");
    OptionTab text = new OptionTab("Character/data");
    OptionTab datetime = new OptionTab("Date/time");
    OptionTab other = new OptionTab("Other");
    types = new ButtonGroup();
    types.add(tInt = new JRadioButton("INTEGER"));
    tInt.setToolTipText("An integer value field (usually a 32-bit int) that stores integer values from -2147483648 to 2147483647");
    if (currentType instanceof Int) {
        tInt.setSelected(true);
        numeric.setInitial(true);
    }
    types.add(tSmallInt = new JRadioButton("SMALLINT"));
    tSmallInt.setToolTipText("An integer value field (usually a 16-bit int) that stores integer values from (at least) -32768 to 32767");
    if (currentType instanceof SmallInt) {
        tSmallInt.setSelected(true);
        numeric.setInitial(true);
    }
    types.add(tBigInt = new JRadioButton("BIGINT"));
    tBigInt.setToolTipText("<html>An integer value field (usually a 64-bit int) that stores integer values from -9223372036854775808<br>to 9223372036854775807");
    if (currentType instanceof BigInt) {
        tBigInt.setSelected(true);
        numeric.setInitial(true);
    }
    pInts.add(tInt);
    pInts.add(tSmallInt);
    pInts.add(tBigInt);
    numeric.addOption(new Option("Integers", pInts));
    types.add(tDouble = new JRadioButton("DOUBLE PRECISION"));
    tDouble.setToolTipText("<html>A floating point value with at least 15 digits of precision (typically a standard 64-bit<br>floating-point value with 53 bits of precision).");
    if (currentType instanceof DoublePrecision) {
        tDouble.setSelected(true);
        numeric.setInitial(true);
    }
    types.add(tFloat = new JRadioButton("FLOAT"));
    tFloat.setToolTipText("<html>A floating point value with at least 6 digits of precision (typically a standard 32-bit<br>floating-point value with 24 bits of precision).  This is sometimes known as a REAL, but a REAL is<br>also sometimes an alias for a DOUBLE PRECISION.");
    if (currentType instanceof easik.database.types.Float) {
        tFloat.setSelected(true);
        numeric.setInitial(true);
    }
    pFloats.add(tDouble);
    pFloats.add(tFloat);
    numeric.addOption(new Option("Floating-point", pFloats));
    types.add(tDecimal = new JRadioButton("NUMERIC"));
    // We allow a max precision of 38, since that seems to be the lowest
    // maximum (in MS SQL and Oracle)
    // Pg supports up to 1000, and MySQL supports up to 63.
    // *Any* default here doesn't make much sense; 10,2 is an arbitrary
    // choice.
    // This default allows anything from 0.00 to 99,999,999.99
    int defPrec = 10, defScale = 2;
    if (currentType instanceof Decimal) {
        tDecimal.setSelected(true);
        numeric.setInitial(true);
        Decimal d = (Decimal) currentType;
        defPrec = d.getPrecision();
        defScale = d.getScale();
    }
    _decPrec = new JSpinner(new SpinnerNumberModel(defPrec, 1, 38, 1));
    // The scale limits, for most databases, are 0 <= scale <= precision.
    // Oracle, however
    // permits the scale to be larger than the precision. We don't.
    _decScale = new JSpinner(new SpinnerNumberModel(defScale, 0, 38, 1));
    // Add a change listener to update the scale maximum to the current
    // precision value:
    _decPrec.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            int scaleMax = ((SpinnerNumberModel) _decPrec.getModel()).getNumber().intValue();
            ((SpinnerNumberModel) _decScale.getModel()).setMaximum(scaleMax);
            if (((SpinnerNumberModel) _decScale.getModel()).getNumber().intValue() > scaleMax) {
                _decScale.setValue(new Integer(scaleMax));
            }
        }
    });
    JPanel decPanel = new JPanel();
    decPanel.setLayout(new BoxLayout(decPanel, BoxLayout.X_AXIS));
    decPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    decPanel.add(tDecimal);
    decPanel.add(new JLabel("(Precision: "));
    decPanel.add(JUtils.fixWidth(JUtils.fixHeight(_decPrec)));
    decPanel.add(new JLabel(", Scale: "));
    decPanel.add(JUtils.fixWidth(JUtils.fixHeight(_decScale)));
    decPanel.add(new JLabel(")"));
    decPanel.setToolTipText("<html>A fixed-point numeric type.  Also known as DECIMAL.<br><br>This type is substantially slower than integer and floating-point types, but guarantees precision<br>for the range of values it supports.  The \"precision\" value is the total number of digits storable, <br>and the \"scale\" is the number of digits stored after the decimal point.  '12345.67' has precision 7<br>and scale 2.");
    tDecimal.setToolTipText(decPanel.getToolTipText());
    numeric.addOption(new Option("Fixed-point", decPanel));
    types.add(tVarchar = new JRadioButton("VARCHAR"));
    int vcs = 255;
    if (currentType instanceof Varchar) {
        tVarchar.setSelected(true);
        text.setInitial(true);
        vcs = ((Varchar) currentType).getSize();
    }
    _varcharSize = new JSpinner(new SpinnerNumberModel(vcs, 1, 255, 1));
    JPanel vcPanel = new JPanel();
    vcPanel.setLayout(new BoxLayout(vcPanel, BoxLayout.X_AXIS));
    vcPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    vcPanel.add(tVarchar);
    vcPanel.add(new JLabel("Size: "));
    vcPanel.add(JUtils.fixHeight(JUtils.fixWidth(_varcharSize)));
    vcPanel.setToolTipText("<html>Stores a string of characters of up to \"size\" characters.  Unlike a CHAR, a VARCHAR column is<br>typically stored using the minimum storage space required, while a CHAR field pads shorter strings<br>to always store values of \"size\" length.");
    tVarchar.setToolTipText(vcPanel.getToolTipText());
    pChars.add(vcPanel);
    types.add(tChar = new JRadioButton("CHAR"));
    int cs = 255;
    if (currentType instanceof Char) {
        tChar.setSelected(true);
        text.setInitial(true);
        cs = ((Char) currentType).getSize();
    }
    _charSize = new JSpinner(new SpinnerNumberModel(cs, 1, 255, 1));
    JPanel cPanel = new JPanel();
    cPanel.setLayout(new BoxLayout(cPanel, BoxLayout.X_AXIS));
    cPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    cPanel.add(tChar);
    cPanel.add(new JLabel("Size: "));
    cPanel.add(JUtils.fixHeight(JUtils.fixWidth(_charSize)));
    cPanel.setToolTipText("<html>Stores a string of characters of up to \"size\" characters.  Unlike a VARCHAR, a CHAR column is<br>typically padded up to the specified size to make it a fixed-width column (the padding is removed on<br>retrieval).  Note that some databases implicitly convert CHAR columns to VARCHAR if other<br>variable-width columns exist in the table.");
    tChar.setToolTipText(cPanel.getToolTipText());
    pChars.add(cPanel);
    text.addOption(new Option("Characters", pChars));
    types.add(tText = new JRadioButton("TEXT (stores up to 4GB)"));
    tText.setToolTipText("Stores large amounts of text data.  Also known as a CLOB.");
    if (currentType instanceof Text) {
        tText.setSelected(true);
        text.setInitial(true);
    }
    text.addOption(new Option("Text data", tText));
    types.add(tBlob = new JRadioButton("BLOB (stores up to 4GB)"));
    tBlob.setToolTipText("Stores large amounts of binary data (bytes).  Will result in a BYTEA under PostgreSQL.");
    if (currentType instanceof Blob) {
        tBlob.setSelected(true);
        text.setInitial(true);
    }
    text.addOption(new Option("Binary data", tBlob));
    types.add(tDate = new JRadioButton("DATE"));
    tDate.setToolTipText("A date field that does not include a time, such as '2008/07/14'");
    if (currentType instanceof Date) {
        tDate.setSelected(true);
        datetime.setInitial(true);
    }
    datetime.addOption(new Option("Date only", tDate));
    types.add(tTime = new JRadioButton("TIME"));
    tTime.setToolTipText("A field that stores just a time (e.g. '12:13:14')");
    if (currentType instanceof Time) {
        tTime.setSelected(true);
        datetime.setInitial(true);
    }
    datetime.addOption(new Option("Time only", tTime));
    types.add(tTimestamp = new JRadioButton("TIMESTAMP (date and time)"));
    tTimestamp.setToolTipText("<html>A field that stores a date and time (e.g. '2008/07/14 12:13:14').  Note that this is converted to a<br>DATETIME when using MySQL.");
    if (currentType instanceof Timestamp) {
        tTimestamp.setSelected(true);
        datetime.setInitial(true);
    }
    pTS.add(tTimestamp);
    datetime.addOption(new Option("Date & time", pTS));
    types.add(tBoolean = new JRadioButton("BOOLEAN"));
    tBoolean.setToolTipText("<html>A column that stores true/false values.  Note that this type may be converted to a small integer<br>type by databases (such as MySQL) that do not fully support BOOLEAN data types");
    if (currentType instanceof easik.database.types.Boolean) {
        tBoolean.setSelected(true);
        other.setInitial(true);
    }
    other.addOption(new Option("Boolean", tBoolean));
    types.add(tCustom = new JRadioButton("Custom type:"));
    if (currentType instanceof Custom) {
        tCustom.setSelected(true);
        other.setInitial(true);
        _custom = JUtils.textField(((Custom) currentType).getCustom());
    } else {
        _custom = JUtils.textField("");
    }
    JPanel custPanel = new JPanel();
    custPanel.setLayout(new BoxLayout(custPanel, BoxLayout.X_AXIS));
    custPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    custPanel.setToolTipText("<html>Any SQL type supported by the SQL db that will be exported to can be entered here.  No<br>verification of this field is performed: you must ensure that what you specify here is a valid type<br>for the SQL db type you will be using!");
    tCustom.setToolTipText(custPanel.getToolTipText());
    _custom.setToolTipText(custPanel.getToolTipText());
    custPanel.add(tCustom);
    custPanel.add(_custom);
    other.addOption(new Option("Custom:", custPanel));
    tabs.add(numeric);
    tabs.add(text);
    tabs.add(datetime);
    tabs.add(other);
    return tabs;
}
Also used : JPanel(javax.swing.JPanel) JRadioButton(javax.swing.JRadioButton) BoxLayout(javax.swing.BoxLayout) Time(easik.database.types.Time) Timestamp(easik.database.types.Timestamp) BigInt(easik.database.types.BigInt) SmallInt(easik.database.types.SmallInt) Int(easik.database.types.Int) Varchar(easik.database.types.Varchar) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Decimal(easik.database.types.Decimal) Char(easik.database.types.Char) EasikType(easik.database.types.EasikType) ChangeListener(javax.swing.event.ChangeListener) Blob(easik.database.types.Blob) JLabel(javax.swing.JLabel) Text(easik.database.types.Text) Custom(easik.database.types.Custom) LinkedList(java.util.LinkedList) Date(easik.database.types.Date) OptionTab(easik.ui.OptionTab) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) BigInt(easik.database.types.BigInt) JSpinner(javax.swing.JSpinner) SmallInt(easik.database.types.SmallInt) Option(easik.ui.Option) DoublePrecision(easik.database.types.DoublePrecision)

Aggregations

BigInt (easik.database.types.BigInt)1 Blob (easik.database.types.Blob)1 Char (easik.database.types.Char)1 Custom (easik.database.types.Custom)1 Date (easik.database.types.Date)1 Decimal (easik.database.types.Decimal)1 DoublePrecision (easik.database.types.DoublePrecision)1 EasikType (easik.database.types.EasikType)1 Int (easik.database.types.Int)1 SmallInt (easik.database.types.SmallInt)1 Text (easik.database.types.Text)1 Time (easik.database.types.Time)1 Timestamp (easik.database.types.Timestamp)1 Varchar (easik.database.types.Varchar)1 Option (easik.ui.Option)1 OptionTab (easik.ui.OptionTab)1 LinkedList (java.util.LinkedList)1 BoxLayout (javax.swing.BoxLayout)1 ButtonGroup (javax.swing.ButtonGroup)1 JLabel (javax.swing.JLabel)1