0001://** Copyright Statement ***************************************************
0002://The Salmon Open Framework for Internet Applications (SOFIA)
0003:// Copyright (C) 1999 - 2002, Salmon LLC
0004://
0005:// This program is free software; you can redistribute it and/or
0006:// modify it under the terms of the GNU General Public License version 2
0007:// as published by the Free Software Foundation;
0008://
0009:// This program is distributed in the hope that it will be useful,
0010:// but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012:// GNU General Public License for more details.
0013://
0014:// You should have received a copy of the GNU General Public License
0015:// along with this program; if not, write to the Free Software
0016:// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0017://
0018:// For more information please visit http://www.salmonllc.com
0019://** End Copyright Statement ***************************************************
0020:package com.salmonllc.ideTools;
0021:
0022://///////////////////////
0023://$Archive: /SOFIA/SourceCode/com/salmonllc/ideTools/ModelDialog.java $
0024://$Author: Dan $
0025://$Revision: 24 $
0026://$Modtime: 9/24/04 2:14p $
0027://///////////////////////
0028:import java.awt.*;
0029:import java.awt.event.ActionEvent;
0030:import java.awt.event.ActionListener;
0031:import java.util.StringTokenizer;
0032:import java.util.Vector;
0033:
0034:import javax.swing.*;
0035:import javax.swing.border.EmptyBorder;
0036:import javax.swing.event.*;
0037:
0038:import com.salmonllc.properties.Props;
0039:import com.salmonllc.sql.*;
0040:import com.salmonllc.util.MessageLog;
0041:import com.salmonllc.util.VectorSort;
0042:
0043:public class ModelDialog extends JDialog implements ActionListener, ListSelectionListener, CaretListener {
0044:
0045: JButton _ok;
0046: JButton _cancel;
0047: JButton _validateButton;
0048: JCheckBox _qbe;
0049: boolean _qbeChecked = false;
0050: JPanel _main;
0051: JPanel _qbePanel;
0052: JList _qbeElements;
0053: JPanel _standardPanel;
0054: JTextField _className, _qbeName, _qbeCols;
0055: JComboBox _tables, _bucketType, _qbeType;
0056: JList _colList, _colsInModel, _colsInSort, _aliases, _joins, _buckets;
0057: Vector _validations = new Vector();
0058: JTextField _colName, _colFormat, _aliasName, _bucketName, _bucketFormat;
0059: JButton _addCol, _delCol;
0060: JButton _addQBE, _delQBE, _clearQBE;
0061: JButton _addOrder, _delOrder;
0062: JButton _addAlias, _delAlias;
0063: JButton _addJoin, _delJoin;
0064: JButton _addBucket, _delBucket;
0065: JButton _qbeColLookup;
0066: JCheckBox _updateable, _sortAscending;
0067: DataDictionary _dd;
0068: Frame _owner;
0069: boolean _clickedCancel = true;
0070: int _buttonHeight = 28;
0071: boolean _remotable = false;
0072: public static final int _qbeTypeInts[] =
0073: {
0074: QBEBuilder.CRITERIA_TYPE_COMPLEX,
0075: QBEBuilder.CRITERIA_TYPE_EQUALS_IGNORE_CASE,
0076: QBEBuilder.CRITERIA_TYPE_STARTS_WITH,
0077: QBEBuilder.CRITERIA_TYPE_STARTS_WITH_IGNORE_CASE,
0078: QBEBuilder.CRITERIA_TYPE_CONTAINS,
0079: QBEBuilder.CRITERIA_TYPE_CONTAINS_IGNORE_CASE,
0080: QBEBuilder.CRITERIA_TYPE_LTE,
0081: QBEBuilder.CRITERIA_TYPE_LT,
0082: QBEBuilder.CRITERIA_TYPE_GTE,
0083: QBEBuilder.CRITERIA_TYPE_GT,
0084: QBEBuilder.CRITERIA_TYPE_EQUALS,
0085: QBEBuilder.CRITERIA_TYPE_NOT_EQUALS,
0086: QBEBuilder.CRITERIA_TYPE_IN,
0087: QBEBuilder.CRITERIA_TYPE_CUSTOM };
0088:
0089: public class QBEType {
0090: public int type;
0091: public QBEType(int type) {
0092: this .type = type;
0093: }
0094: public String toString() {
0095: if (type == QBEBuilder.CRITERIA_TYPE_COMPLEX)
0096: return "Complex";
0097: if (type == QBEBuilder.CRITERIA_TYPE_EQUALS_IGNORE_CASE)
0098: return "Equals Ignore Case";
0099: if (type == QBEBuilder.CRITERIA_TYPE_STARTS_WITH)
0100: return "Starts With";
0101: if (type == QBEBuilder.CRITERIA_TYPE_STARTS_WITH_IGNORE_CASE)
0102: return "Starts With Ignore Case";
0103: if (type == QBEBuilder.CRITERIA_TYPE_CONTAINS)
0104: return "Contains";
0105: if (type == QBEBuilder.CRITERIA_TYPE_CONTAINS_IGNORE_CASE)
0106: return "Contains Ignore Case";
0107: if (type == QBEBuilder.CRITERIA_TYPE_LTE)
0108: return "Less Than or Equal";
0109: if (type == QBEBuilder.CRITERIA_TYPE_LT)
0110: return "Less Than";
0111: if (type == QBEBuilder.CRITERIA_TYPE_GTE)
0112: return "Greater Than or Equal";
0113: if (type == QBEBuilder.CRITERIA_TYPE_GT)
0114: return "Greater Than";
0115: if (type == QBEBuilder.CRITERIA_TYPE_EQUALS)
0116: return "Equal";
0117: if (type == QBEBuilder.CRITERIA_TYPE_NOT_EQUALS)
0118: return "Not Equal";
0119: if (type == QBEBuilder.CRITERIA_TYPE_IN)
0120: return "In";
0121: if (type == QBEBuilder.CRITERIA_TYPE_CUSTOM)
0122: return "Custom";
0123: return null;
0124: }
0125: }
0126:
0127: public class DataType {
0128: public int type;
0129: public DataType(int type) {
0130: this .type = type;
0131: }
0132: public String toString() {
0133: if (type == DataStore.DATATYPE_BYTEARRAY)
0134: return "binary";
0135: else if (type == DataStore.DATATYPE_DATE)
0136: return "date";
0137: else if (type == DataStore.DATATYPE_DATETIME)
0138: return "datetime";
0139: else if (type == DataStore.DATATYPE_DOUBLE)
0140: return "double";
0141: else if (type == DataStore.DATATYPE_FLOAT)
0142: return "float";
0143: else if (type == DataStore.DATATYPE_INT)
0144: return "int";
0145: else if (type == DataStore.DATATYPE_LONG)
0146: return "long";
0147: else if (type == DataStore.DATATYPE_SHORT)
0148: return "short";
0149: else if (type == DataStore.DATATYPE_STRING)
0150: return "string";
0151: else if (type == DataStore.DATATYPE_TIME)
0152: return "time";
0153: else
0154: return "unknown";
0155: }
0156: }
0157:
0158: public class QBECriteriaDef {
0159: public String name, colList;
0160: public QBEType type;
0161: public QBECriteriaDef(String name, QBEType type, String colList) {
0162: this .name = name;
0163: this .type = type;
0164: this .colList = colList;
0165: }
0166: public String toString() {
0167: return name + " | Type: " + type + " | Column List: " + colList;
0168: }
0169: public boolean equals(QBECriteriaDef def) {
0170: return def.name.equals(this .name);
0171: }
0172: }
0173: public class ColumnDef {
0174: public ColumnDefinition def;
0175: public String name, format, alias;
0176: public boolean updateable;
0177: private int DISPLAY_SHORT = 0;
0178: private int DISPLAY_LONG = 1;
0179: private int DISPLAY_FULL = 2;
0180: private int _display = DISPLAY_SHORT;
0181:
0182: public ColumnDef(ColumnDefinition def, boolean displayShort) {
0183: this .def = def;
0184: _display = displayShort ? DISPLAY_SHORT : DISPLAY_LONG;
0185: }
0186:
0187: public ColumnDef(ColumnDefinition def, String name, String alias, String format, boolean updateable) {
0188: this .def = def;
0189: this .name = (name == null || name.length() == 0) ? null : name;
0190: this .format = (format == null || format.length() == 0) ? null : format;
0191: this .alias = (alias == null || alias.length() == 0) ? null : alias;
0192: this .updateable = updateable;
0193: _display = DISPLAY_FULL;
0194:
0195: }
0196: public String toString() {
0197: if (_display == DISPLAY_SHORT)
0198: return def.getColumnName();
0199: else if (_display == DISPLAY_LONG)
0200: return def.getTableName() + "." + def.getColumnName();
0201: else if (_display == DISPLAY_FULL) {
0202: String tab = (alias == null ? def.getTableName() : alias);
0203: String nme = (name == null ? (tab + "." + def.getColumnName()) + " " : (name + " (" + tab + "." + def.getColumnName()) + ") ");
0204: String fmt = (format == null ? "" : " | format:" + format);
0205: String upd = (updateable ? " | update:yes" : "| update:no");
0206: return nme + fmt + upd;
0207: }
0208: return "";
0209:
0210: }
0211: public String getName() {
0212: if (name != null)
0213: return name;
0214: else if (alias != null)
0215: return alias + "." + def.getColumnName();
0216: else
0217: return def.getTableName() + "." + def.getColumnName();
0218: }
0219: }
0220:
0221: public class SortDef {
0222: public ColumnDefinition def;
0223: public String alias;
0224: private boolean sortAscending;
0225:
0226: public SortDef(ColumnDefinition def, String alias, boolean sortAsc) {
0227: this .def = def;
0228: this .alias = alias;
0229: this .sortAscending = sortAsc;
0230: }
0231: public String toString() {
0232: String tab = (alias == null ? def.getTableName() : alias);
0233: String col = def.getColumnName();
0234: String dir = (sortAscending ? " ASC" : " DESC");
0235: return tab + "." + col + dir;
0236: }
0237: public String getDir() {
0238: if (sortAscending)
0239: return "ASC";
0240: else
0241: return "DESC";
0242: }
0243: }
0244: public class AliasDef {
0245: public String table, alias;
0246: public AliasDef(String table, String alias) {
0247: this .table = table;
0248: this .alias = alias;
0249: }
0250: public String toString() {
0251: if (alias == null)
0252: return table;
0253: else
0254: return alias + " (" + table + ")";
0255: }
0256: }
0257: public class BucketDef {
0258: public String name, format;
0259: public DataType datatype;
0260: public BucketDef(String name, String format, DataType type) {
0261: this .name = name;
0262: this .format = format == null || format.length() == 0 ? null : format;
0263: this .datatype = type;
0264: }
0265: public String toString() {
0266: return name + (format == null ? "" : " | format:" + format) + " | datatype:" + datatype.toString();
0267: }
0268: }
0269:
0270: public class JoinDef {
0271: public String leftSide, rightSide;
0272: public boolean outer;
0273: public String toString() {
0274: return leftSide + (outer ? " *= " : " = ") + rightSide;
0275: }
0276:
0277: public void addJoinTerm(JoinDialog.JoinTermDef term) {
0278: if (leftSide == null) {
0279: leftSide = term.left;
0280: rightSide = term.right;
0281: } else {
0282: leftSide += "," + term.left;
0283: rightSide += "," + term.right;
0284: }
0285: outer = term.outer;
0286: }
0287: public void addJoinTerm(JoinTermDef term) {
0288: if (leftSide == null) {
0289: leftSide = term.left;
0290: rightSide = term.right;
0291: } else {
0292: leftSide += "," + term.left;
0293: rightSide += "," + term.right;
0294: }
0295: outer = term.outer;
0296: }
0297:
0298: public boolean usesAlias(String alias) {
0299: String search = alias + ".";
0300: return (leftSide.indexOf(search) > -1 || rightSide.indexOf(search) > -1);
0301: }
0302: }
0303:
0304: public class JoinTermDef {
0305: String left;
0306: String right;
0307: boolean outer;
0308: public JoinTermDef(String left, String right, boolean outer) {
0309: this .left = left;
0310: this .right = right;
0311: this .outer = outer;
0312: }
0313: public String toString() {
0314: return left + (outer ? "*=" : "=") + right;
0315: }
0316: }
0317:
0318: private class Sorter extends VectorSort {
0319: public boolean compare(Object o1, Object o2) {
0320: return ((String) o1).compareTo((String) o2) < 1;
0321: }
0322: }
0323:
0324: public ModelDialog(Frame owner, String classToLoad, int buttonHeight) {
0325: super (owner, "Create a Model", true);
0326: _buttonHeight = buttonHeight;
0327: int buttonWidth = 60;
0328: _owner = owner;
0329: setModal(true);
0330: setResizable(false);
0331: //create a data dictionary object
0332: _dd = new DataDictionary(Props.getSystemProps().getProperty(IDETool.getProjectProperty(Props.IDE_DEFAULT_FRAMEWORK_APP)));
0333: String appName = Props.getSystemProps().getProperty(IDETool.getProjectProperty(Props.IDE_DEFAULT_FRAMEWORK_APP));
0334: IDETool.setPropsPath();
0335: int width = 780;
0336: int height = 570;
0337: Dimension frameBounds = Toolkit.getDefaultToolkit().getScreenSize();
0338: int x = (frameBounds.width - width) / 2;
0339: int y = (frameBounds.height - height) / 2;
0340: setBounds(x, y, width, height);
0341: JPanel box = new JPanel();
0342:
0343: //main box
0344: _main = new JPanel();
0345: _main.setLayout(new BoxLayout(_main, BoxLayout.Y_AXIS));
0346: _main.setBorder(new EmptyBorder(10, 10, 10, 10));
0347: _qbePanel = new JPanel();
0348: _qbePanel.setLayout(new BoxLayout(_qbePanel, BoxLayout.Y_AXIS));
0349: _standardPanel = new JPanel();
0350: _standardPanel.setLayout(new BoxLayout(_standardPanel, BoxLayout.Y_AXIS));
0351:
0352: //row 1, class name
0353: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0354: box.add(DialogComponentFactory.makeLabel("Class Name:", 80));
0355: box.add(_className = DialogComponentFactory.makeTextField(200));
0356: _validateButton = new JButton("Validations");
0357: _validateButton.addActionListener(this );
0358:
0359: box.add(Box.createHorizontalGlue());
0360: box.add(Box.createRigidArea(new Dimension(10, 0)));
0361: box.add(DialogComponentFactory.makeLabel(" QBE:"));
0362: box.add(_qbe = new JCheckBox());
0363: if (IDETool.useDefaultOSLookAndFeel())
0364: box.add(Box.createRigidArea(new Dimension(60, 0)));
0365: else
0366: box.add(Box.createRigidArea(new Dimension(50, 0)));
0367: box.add(_validateButton);
0368: box.add(Box.createRigidArea(new Dimension(15, 0)));
0369: _main.add(box);
0370: _main.add(Box.createRigidArea(new Dimension(0, 5)));
0371:
0372: //row 2, file drop down label, Columns in Data Store Label, Columns in sort label
0373: box = new JPanel();
0374: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0375: box.add(DialogComponentFactory.makeLabel("Tables/Columns in DataBase:", 200));
0376: box.add(Box.createRigidArea(new Dimension(10, 0)));
0377: box.add(DialogComponentFactory.makeLabel("Columns in Model:", 200));
0378: box.add(_addCol = DialogComponentFactory.makeButton("Add", buttonWidth, buttonHeight));
0379: box.add(_delCol = DialogComponentFactory.makeButton("Del", buttonWidth, buttonHeight));
0380: box.add(Box.createRigidArea(new Dimension(10, 0)));
0381: box.add(DialogComponentFactory.makeLabel("Order By:", 80));
0382: box.add(_addOrder = DialogComponentFactory.makeButton("Add", buttonWidth, buttonHeight));
0383: box.add(_delOrder = DialogComponentFactory.makeButton("Del", buttonWidth, buttonHeight));
0384:
0385: box.add(Box.createHorizontalGlue());
0386: _standardPanel.add(box);
0387:
0388: //row 3, name, updatable, format
0389: _standardPanel.add(Box.createRigidArea(new Dimension(0, 5)));
0390: box = new JPanel();
0391: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0392: box.add(_tables = DialogComponentFactory.makeComboBox(200));
0393: box.add(Box.createRigidArea(new Dimension(10, 0)));
0394: box.add(DialogComponentFactory.makeLabel("Name:", 47));
0395: box.add(_colName = DialogComponentFactory.makeTextField(44));
0396: box.add(Box.createRigidArea(new Dimension(2, 0)));
0397: box.add(DialogComponentFactory.makeLabel("Format:", 47));
0398: box.add(Box.createRigidArea(new Dimension(2, 0)));
0399: box.add(_colFormat = DialogComponentFactory.makeTextField(44));
0400: box.add(Box.createRigidArea(new Dimension(2, 0)));
0401: box.add(DialogComponentFactory.makeLabel("Updateable:", 67));
0402: box.add(_updateable = new JCheckBox());
0403: box.add(Box.createRigidArea(new Dimension(105, 0)));
0404: box.add(DialogComponentFactory.makeLabel("Ascending:", 80));
0405: box.add(_sortAscending = new JCheckBox());
0406: box.add(Box.createRigidArea(new Dimension(10, 0)));
0407: box.add(Box.createHorizontalGlue());
0408: _standardPanel.add(box);
0409:
0410: //row 4, Columns, in model, in sort
0411: box = new JPanel();
0412: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0413: box.add(DialogComponentFactory.makeScrollPane(200, 170, _colList = DialogComponentFactory.makeList(new LModel())));
0414: box.add(Box.createRigidArea(new Dimension(10, 0)));
0415: box.add(DialogComponentFactory.makeScrollPane(320, 170, _colsInModel = DialogComponentFactory.makeList(new LModel())));
0416: box.add(Box.createRigidArea(new Dimension(10, 0)));
0417: box.add(DialogComponentFactory.makeScrollPane(200, 170, _colsInSort = DialogComponentFactory.makeList(new LModel())));
0418: box.add(Box.createHorizontalGlue());
0419: _standardPanel.add(Box.createRigidArea(new Dimension(0, 3)));
0420: _standardPanel.add(box);
0421:
0422: //row 5, captions for alias, joins, buckets
0423: _standardPanel.add(Box.createRigidArea(new Dimension(0, 10)));
0424: box = new JPanel();
0425: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0426: box.add(DialogComponentFactory.makeLabel("Aliases:", 80));
0427: box.add(_addAlias = DialogComponentFactory.makeButton("Add", buttonWidth, buttonHeight));
0428: box.add(_delAlias = DialogComponentFactory.makeButton("Del", buttonWidth, buttonHeight));
0429: box.add(Box.createRigidArea(new Dimension(10, 0)));
0430: box.add(DialogComponentFactory.makeLabel("Buckets:", 200));
0431: box.add(_addBucket = DialogComponentFactory.makeButton("Add", buttonWidth, buttonHeight));
0432: box.add(_delBucket = DialogComponentFactory.makeButton("Del", buttonWidth, buttonHeight));
0433: box.add(Box.createRigidArea(new Dimension(10, 0)));
0434: box.add(DialogComponentFactory.makeLabel("Joins:", 80));
0435: box.add(_addJoin = DialogComponentFactory.makeButton("Add", buttonWidth, buttonHeight));
0436: box.add(_delJoin = DialogComponentFactory.makeButton("Del", buttonWidth, buttonHeight));
0437: box.add(Box.createHorizontalGlue());
0438: _standardPanel.add(box);
0439:
0440: //row 6, alias name, bucket name, format, type
0441: _standardPanel.add(Box.createRigidArea(new Dimension(0, 5)));
0442: box = new JPanel();
0443: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0444: box.add(DialogComponentFactory.makeLabel("Name:", 60));
0445: box.add(_aliasName = DialogComponentFactory.makeTextField(140));
0446: box.add(Box.createRigidArea(new Dimension(10, 0)));
0447: box.add(DialogComponentFactory.makeLabel("Name:", 40));
0448: box.add(_bucketName = DialogComponentFactory.makeTextField(60));
0449: box.add(Box.createRigidArea(new Dimension(2, 0)));
0450: box.add(DialogComponentFactory.makeLabel("Format:", 45));
0451: box.add(_bucketFormat = DialogComponentFactory.makeTextField((60)));
0452: box.add(Box.createRigidArea(new Dimension(2, 0)));
0453: box.add(DialogComponentFactory.makeLabel("Type:", 35));
0454: box.add(_bucketType = DialogComponentFactory.makeComboBox((75)));
0455: box.add(Box.createRigidArea(new Dimension(240, 0)));
0456: box.add(Box.createHorizontalGlue());
0457: _standardPanel.add(box);
0458:
0459: //row 7, Alias, Joins, Buckets
0460: box = new JPanel();
0461: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0462: box.add(DialogComponentFactory.makeScrollPane(200, 140, _aliases = DialogComponentFactory.makeList(new LModel())));
0463: box.add(Box.createRigidArea(new Dimension(10, 0)));
0464: box.add(DialogComponentFactory.makeScrollPane(320, 140, _buckets = DialogComponentFactory.makeList(new LModel())));
0465: box.add(Box.createRigidArea(new Dimension(10, 0)));
0466: box.add(DialogComponentFactory.makeScrollPane(200, 140, _joins = DialogComponentFactory.makeList(new LModel())));
0467: box.add(Box.createHorizontalGlue());
0468: _standardPanel.add(Box.createRigidArea(new Dimension(0, 3)));
0469: _standardPanel.add(box);
0470:
0471: //row 2 in qbe, qbe captions
0472: box = new JPanel();
0473: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0474: box.add(Box.createRigidArea(new Dimension(0, 50)));
0475: box.add(DialogComponentFactory.makeLabel("QBE Selection Criteria:", 200));
0476: box.add(Box.createHorizontalGlue());
0477: box.add(_addQBE = DialogComponentFactory.makeButton("Add", buttonWidth, buttonHeight));
0478: box.add(_delQBE = DialogComponentFactory.makeButton("Del", buttonWidth, buttonHeight));
0479: box.add(_clearQBE = DialogComponentFactory.makeButton("Clear Selection", 120, buttonHeight));
0480: box.add(Box.createRigidArea(new Dimension(15, 0)));
0481: _qbePanel.add(box);
0482:
0483: //row 3 in qbe, qbe panel, name, type, column list
0484: _qbePanel.add(Box.createRigidArea(new Dimension(0, 15)));
0485: box = new JPanel();
0486: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0487: box.add(DialogComponentFactory.makeLabel("Criteria Name:", 80));
0488: box.add(_qbeName = DialogComponentFactory.makeTextField(60));
0489: box.add(Box.createRigidArea(new Dimension(10, 0)));
0490: box.add(DialogComponentFactory.makeLabel("Type:", 30));
0491: box.add(_qbeType = DialogComponentFactory.makeComboBox(140));
0492: box.add(Box.createRigidArea(new Dimension(10, 0)));
0493: box.add(DialogComponentFactory.makeLabel("Column List:", 75));
0494: box.add(Box.createRigidArea(new Dimension(2, 0)));
0495: box.add(_qbeCols = DialogComponentFactory.makeTextField(120));
0496: box.add(Box.createRigidArea(new Dimension(2, 0)));
0497: box.add(_qbeColLookup = DialogComponentFactory.makeButton("...", 40, _buttonHeight));
0498: box.add(Box.createRigidArea(new Dimension(15, 0)));
0499: box.add(Box.createHorizontalGlue());
0500: _qbePanel.add(box);
0501:
0502: //row 4 in qbe, list of QBE items
0503: _qbePanel.add(Box.createRigidArea(new Dimension(0, 15)));
0504: box = new JPanel();
0505: box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
0506: box.add(DialogComponentFactory.makeScrollPane(740, 300, _qbeElements = DialogComponentFactory.makeList(new LModel())));
0507: box.add(Box.createRigidArea(new Dimension(15, 0)));
0508: _qbePanel.add(box);
0509: _qbePanel.add(Box.createVerticalGlue());
0510:
0511: //last row, button bar
0512: _ok = new JButton("OK");
0513: _ok.addActionListener(this );
0514: _cancel = new JButton("Cancel");
0515: _cancel.addActionListener(this );
0516: JPanel buttonBar = new JPanel();
0517: buttonBar.setLayout(new BoxLayout(buttonBar, BoxLayout.X_AXIS));
0518: buttonBar.add(_ok);
0519: buttonBar.add(_cancel);
0520:
0521: //add it to the screen
0522: _main.add(_standardPanel);
0523: _main.add(_qbePanel);
0524: _qbePanel.setVisible(false);
0525:
0526: Container cp = getContentPane();
0527: cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
0528: cp.add(_main);
0529: cp.add(Box.createVerticalGlue());
0530: cp.add(buttonBar);
0531: cp.add(Box.createRigidArea(new Dimension(0, 20)));
0532:
0533: //add listeners
0534: _colList.addListSelectionListener(this );
0535: _colsInModel.addListSelectionListener(this );
0536: _colsInSort.addListSelectionListener(this );
0537: _aliases.addListSelectionListener(this );
0538: _buckets.addListSelectionListener(this );
0539: _qbeElements.addListSelectionListener(this );
0540: _joins.addListSelectionListener(this );
0541: _bucketName.addCaretListener(this );
0542: _aliasName.addCaretListener(this );
0543: _qbeName.addCaretListener(this );
0544: _qbeCols.addCaretListener(this );
0545: _tables.addActionListener(this );
0546: _addAlias.addActionListener(this );
0547: _delAlias.addActionListener(this );
0548: _className.addCaretListener(this );
0549: _addOrder.addActionListener(this );
0550: _delOrder.addActionListener(this );
0551: _addCol.addActionListener(this );
0552: _delCol.addActionListener(this );
0553: _addBucket.addActionListener(this );
0554: _delBucket.addActionListener(this );
0555: _addJoin.addActionListener(this );
0556: _delJoin.addActionListener(this );
0557: _qbe.addActionListener(this );
0558: _addQBE.addActionListener(this );
0559: _delQBE.addActionListener(this );
0560: _clearQBE.addActionListener(this );
0561: _qbeColLookup.addActionListener(this );
0562: _qbeElements.addListSelectionListener(this );
0563: _qbeType.addActionListener(this );
0564:
0565: //fill drop downs and init the buttons
0566: enableDisableButtons();
0567: _updateable.setSelected(true);
0568: _sortAscending.setSelected(true);
0569: try {
0570: loadTables();
0571: } catch (Exception ex) {
0572: IDETool.displayError("Error Loading Tables" + ex.getMessage());
0573: return;
0574: }
0575: _bucketType.addItem(new DataType(DataStore.DATATYPE_BYTEARRAY));
0576: _bucketType.addItem(new DataType(DataStore.DATATYPE_DATE));
0577: _bucketType.addItem(new DataType(DataStore.DATATYPE_DATETIME));
0578: _bucketType.addItem(new DataType(DataStore.DATATYPE_DOUBLE));
0579: _bucketType.addItem(new DataType(DataStore.DATATYPE_FLOAT));
0580: _bucketType.addItem(new DataType(DataStore.DATATYPE_INT));
0581: _bucketType.addItem(new DataType(DataStore.DATATYPE_LONG));
0582: _bucketType.addItem(new DataType(DataStore.DATATYPE_SHORT));
0583: _bucketType.addItem(new DataType(DataStore.DATATYPE_STRING));
0584: _bucketType.addItem(new DataType(DataStore.DATATYPE_TIME));
0585:
0586: for (int i = 0; i < _qbeTypeInts.length; i++)
0587: _qbeType.addItem(new QBEType(_qbeTypeInts[i]));
0588:
0589: if (classToLoad != null) {
0590: populateFromModel(classToLoad, appName);
0591: }
0592: setVisible(true);
0593: }
0594: public void actionPerformed(ActionEvent e) {
0595: if (e.getSource() == _qbe) {
0596: _qbeChecked = !_qbeChecked;
0597: _qbePanel.setVisible(_qbeChecked);
0598: _standardPanel.setVisible(!_qbeChecked);
0599: enableDisableButtons();
0600: } else if (e.getSource() == _qbeType) {
0601: int i = _qbeElements.getSelectedIndex();
0602: if (i > -1) {
0603: LModel mod = (LModel)_qbeElements.getModel();
0604: QBECriteriaDef def = (QBECriteriaDef) mod.getElementAt(i);
0605: def.type = (QBEType) _qbeType.getSelectedItem();
0606: _qbeElements.revalidate();
0607: _qbeElements.repaint();
0608: }
0609: }
0610: else if (e.getSource() == _ok) {
0611: _clickedCancel = false;
0612: setVisible(false);
0613: } else if (e.getSource() == _cancel) {
0614: _clickedCancel = true;
0615: setVisible(false);
0616: } else if (e.getSource() == _tables) {
0617: AliasDef def = (AliasDef) _tables.getSelectedItem();
0618: loadColumns(def.table);
0619: enableDisableButtons();
0620: } else if (e.getSource() == _addAlias)
0621: addAlias();
0622: else if (e.getSource() == _delAlias)
0623: deleteAlias();
0624: else if (e.getSource() == _addOrder)
0625: addSort();
0626: else if (e.getSource() == _delOrder)
0627: deleteSort();
0628: else if (e.getSource() == _addCol)
0629: addColumn();
0630: else if (e.getSource() == _delCol)
0631: deleteColumn();
0632: else if (e.getSource() == _addBucket)
0633: addBucket();
0634: else if (e.getSource() == _delBucket)
0635: deleteBucket();
0636: else if (e.getSource() == _addJoin)
0637: addJoin();
0638: else if (e.getSource() == _delJoin)
0639: deleteJoin();
0640: else if (e.getSource() == _validateButton)
0641: doValidations();
0642: else if (e.getSource() == _addQBE)
0643: addQBE();
0644: else if (e.getSource() == _delQBE)
0645: deleteQBE();
0646: else if (e.getSource() == _qbeColLookup)
0647: doColListLookup();
0648: else if (e.getSource() == _clearQBE)
0649: doClearQBE();
0650: }
0651: private void addAlias() {
0652: LModel aliasMod = (LModel) _aliases.getModel();
0653: String table = ((AliasDef) _tables.getSelectedItem()).table;
0654: String alias = _aliasName.getText().trim();
0655: if (alias.length() == 0)
0656: alias = null;
0657:
0658: AliasDef d = new AliasDef(table, alias);
0659: aliasMod.addElement(d);
0660: _aliasName.setText("");
0661:
0662: if (d.alias != null) {
0663: _tables.addItem(d);
0664: _tables.setSelectedItem(d);
0665: }
0666: enableDisableButtons();
0667: }
0668: private void addBucket() {
0669: String name = _bucketName.getText().trim();
0670: String format = _bucketFormat.getText().trim();
0671: DataType dt = (DataType) _bucketType.getSelectedItem();
0672: BucketDef d = new BucketDef(name, format, dt);
0673: ((LModel) _buckets.getModel()).addElement(d);
0674: _bucketName.setText("");
0675: enableDisableButtons();
0676:
0677: }
0678: private void addColumn() {
0679: Object[] vals = _colList.getSelectedValues();
0680: AliasDef alias = (AliasDef) _tables.getSelectedItem();
0681: String name = vals.length > 1 ? null : _colName.getText().trim();
0682: String format = _colFormat.getText().trim();
0683: boolean updable = _updateable.isSelected();
0684: for (int i = 0; i < vals.length; i++) {
0685: ColumnDefinition col = ((ColumnDef) vals[i]).def;
0686: ColumnDef d = new ColumnDef(col, name, alias.alias, format, updable);
0687: ((LModel) _colsInModel.getModel()).addElement(d);
0688: }
0689: _colName.setText("");
0690: enableDisableButtons();
0691: }
0692: private void addQBE() {
0693: QBEType type = (QBEType) _qbeType.getSelectedItem();
0694: QBECriteriaDef def = new QBECriteriaDef(_qbeName.getText().trim(), type, _qbeCols.getText().trim());
0695: LModel mod = ((LModel) _qbeElements.getModel());
0696: _qbeName.setText("");
0697: _qbeCols.setText("");
0698: for (int i = 0; i < mod.getSize(); i++) {
0699: QBECriteriaDef d1 = (QBECriteriaDef) mod.getElementAt(i);
0700: if (d1.equals(def)) {
0701: mod.setElementAt(def, i);
0702: enableDisableButtons();
0703: return;
0704: }
0705: }
0706: mod.addElement(def);
0707: _qbeElements.clearSelection();
0708: enableDisableButtons();
0709: }
0710:
0711: private void addJoin() {
0712: Vector aliases = new Vector();
0713:
0714: LModel mod = (LModel) _colsInModel.getModel();
0715: for (int i = 0; i < mod.getSize(); i++) {
0716: ColumnDef d = (ColumnDef) mod.getElementAt(i);
0717: String table = d.def.getTableName();
0718: String alias = d.alias;
0719: boolean found = false;
0720: for (int j = 0; j < aliases.size(); j++) {
0721: AliasDef def = (AliasDef) aliases.elementAt(j);
0722: if (equals(table, def.table) && equals(alias, def.alias)) {
0723: found = true;
0724: break;
0725: }
0726: }
0727: if (!found)
0728: aliases.add(new AliasDef(table, alias));
0729: }
0730:
0731: mod = (LModel) _aliases.getModel();
0732: for (int i = 0; i < mod.getSize(); i++) {
0733: AliasDef d = (AliasDef) mod.getElementAt(i);
0734: String table = d.table;
0735: String alias = d.alias;
0736: boolean found = false;
0737: for (int j = 0; j < aliases.size(); j++) {
0738: AliasDef def = (AliasDef) aliases.elementAt(j);
0739: if (equals(table, def.table) && equals(alias, def.alias)) {
0740: found = true;
0741: break;
0742: }
0743: }
0744: if (!found)
0745: aliases.add(new AliasDef(table, alias));
0746: }
0747:
0748: AliasDef send[] = new AliasDef[aliases.size()];
0749: aliases.copyInto(send);
0750: JoinDialog d = new JoinDialog(_owner, send, _dd, _buttonHeight);
0751: JoinDialog.JoinTermDef[] res = d.getResult();
0752: if (res.length > 0) {
0753: JoinDef join = new JoinDef();
0754: for (int i = 0; i < res.length; i++)
0755: join.addJoinTerm(res[i]);
0756: ((LModel) _joins.getModel()).addElement(join);
0757: }
0758: d.dispose();
0759: enableDisableButtons();
0760: }
0761: private void doValidations() {
0762: ValidationDialog d = new ValidationDialog(_owner, getValidationRules(), getColumnAndBucketNames(), _dd, _buttonHeight);
0763: if (!d.isClickedCancel()) {
0764: _validations.removeAllElements();
0765: ValidationRuleDefinition def[] = d.getValidationRules();
0766: for (int i = 0; i < def.length; i++)
0767: _validations.add(def[i]);
0768: }
0769: d.dispose();
0770: }
0771: private void doColListLookup() {
0772: ColumnListLookupDialog d = new ColumnListLookupDialog(_owner, _qbeCols.getText(), _dd, _buttonHeight);
0773: if (!d.isClickedCancel())
0774: _qbeCols.setText(d.getColumnList());
0775: d.dispose();
0776: }
0777: private void doClearQBE() {
0778: _qbeElements.clearSelection();
0779: _qbeName.setText("");
0780: _qbeCols.setText("");
0781: _qbeType.setSelectedIndex(0);
0782: }
0783: private void addSort() {
0784: Object[] vals = _colList.getSelectedValues();
0785: AliasDef alias = (AliasDef) _tables.getSelectedItem();
0786: for (int i = 0; i < vals.length; i++) {
0787: ColumnDefinition col = ((ColumnDef) vals[i]).def;
0788: SortDef d = new SortDef(col, alias.alias, _sortAscending.isSelected());
0789: ((LModel) _colsInSort.getModel()).addElement(d);
0790: }
0791: enableDisableButtons();
0792: }
0793: /**
0794: * Called when the caret position is updated.
0795: *
0796: * @param e the caret event
0797: */
0798: public void caretUpdate(CaretEvent e) {
0799: if (_qbeChecked) {
0800: int i = _qbeElements.getSelectedIndex();
0801: if (i > -1) {
0802: LModel mod = (LModel)_qbeElements.getModel();
0803: QBECriteriaDef def = (QBECriteriaDef) mod.getElementAt(i);
0804: if (e.getSource() == _qbeName)
0805: def.name=_qbeName.getText();
0806: else if (e.getSource() == _qbeCols)
0807: def.colList=_qbeCols.getText();
0808: _qbeElements.revalidate();
0809: _qbeElements.repaint();
0810:
0811: }
0812: }
0813: enableDisableButtons();
0814:
0815: }
0816: private void deleteAlias() {
0817: LModel aliasMod = (LModel) _aliases.getModel();
0818: int sel[] = _aliases.getSelectedIndices();
0819: for (int i = sel.length - 1; i > -1; i--) {
0820: AliasDef def = (AliasDef) aliasMod.getElementAt(sel[i]);
0821: aliasMod.remove(sel[i]);
0822: if (def.alias != null) {
0823: for (int j = _tables.getItemCount() - 1; j > -1; j--) {
0824: AliasDef comp = (AliasDef) _tables.getItemAt(j);
0825: if (comp.alias == null)
0826: break;
0827: else if (comp.alias.equals(def.alias)) {
0828: _tables.removeItemAt(j);
0829: break;
0830: }
0831: }
0832: }
0833: }
0834: _aliases.getSelectionModel().clearSelection();
0835: enableDisableButtons();
0836: }
0837: private void deleteBucket() {
0838: LModel bucketMod = (LModel) _buckets.getModel();
0839: int sel[] = _buckets.getSelectedIndices();
0840: for (int i = sel.length - 1; i > -1; i--)
0841: bucketMod.remove(sel[i]);
0842: _buckets.getSelectionModel().clearSelection();
0843: enableDisableButtons();
0844: }
0845:
0846: private void deleteQBE() {
0847: LModel qbeMod = (LModel) _qbeElements.getModel();
0848: int sel[] = _qbeElements.getSelectedIndices();
0849: for (int i = sel.length - 1; i > -1; i--)
0850: qbeMod.remove(sel[i]);
0851: _qbeElements.getSelectionModel().clearSelection();
0852: doClearQBE();
0853: enableDisableButtons();
0854: }
0855: private void deleteColumn() {
0856: LModel colMod = (LModel) _colsInModel.getModel();
0857: int sel[] = _colsInModel.getSelectedIndices();
0858: for (int i = sel.length - 1; i > -1; i--)
0859: colMod.remove(sel[i]);
0860: _colsInModel.getSelectionModel().clearSelection();
0861: enableDisableButtons();
0862: }
0863: private void deleteJoin() {
0864: LModel mod = (LModel) _joins.getModel();
0865: int sel[] = _joins.getSelectedIndices();
0866: for (int i = sel.length - 1; i > -1; i--)
0867: mod.remove(sel[i]);
0868: _joins.getSelectionModel().clearSelection();
0869: enableDisableButtons();
0870: }
0871: private void deleteSort() {
0872: LModel sortMod = (LModel) _colsInSort.getModel();
0873: int sel[] = _colsInSort.getSelectedIndices();
0874: for (int i = sel.length - 1; i > -1; i--)
0875: sortMod.remove(sel[i]);
0876: _colsInSort.getSelectionModel().clearSelection();
0877: enableDisableButtons();
0878: }
0879: private void enableDisableButtons() {
0880: _addCol.setEnabled(_colList.getSelectedIndices().length > 0);
0881: _addOrder.setEnabled(_colList.getSelectedIndices().length > 0);
0882: _addJoin.setEnabled(_colsInModel.getModel().getSize() > 0 || _aliases.getModel().getSize() > 0);
0883: _delOrder.setEnabled(_colsInSort.getSelectedIndices().length > 0 && _colsInSort.getModel().getSize() > 0);
0884: _delJoin.setEnabled(_joins.getSelectedIndices().length > 0 && _joins.getModel().getSize() > 0);
0885: _delBucket.setEnabled(_buckets.getSelectedIndices().length > 0 && _buckets.getModel().getSize() > 0);
0886: _addQBE.setEnabled(_qbeName.getText().trim().length() > 0 && _qbeCols.getText().trim().length() > 0 && _qbeElements.getSelectedIndex() == -1);
0887: _clearQBE.setEnabled(_qbeElements.getSelectedIndex() != -1);
0888: _delQBE.setEnabled(_qbeElements.getSelectedIndices().length > 0 && _qbeElements.getModel().getSize() > 0);
0889: _addBucket.setEnabled(_bucketName.getText().trim().length() > 0);
0890:
0891: if (_qbeChecked) {
0892: _ok.setEnabled(IDETool.isClassNameValid(_className.getText(), true) && (_qbeElements.getModel().getSize() > 0));
0893: _validateButton.setEnabled(_qbeElements.getModel().getSize() > 0);
0894: } else {
0895: _validateButton.setEnabled(_buckets.getModel().getSize() > 0 || _colsInModel.getModel().getSize() > 0);
0896: _ok.setEnabled(IDETool.isClassNameValid(_className.getText(), true) && (_buckets.getModel().getSize() > 0 || _colsInModel.getModel().getSize() > 0));
0897: }
0898:
0899: //add Alias button
0900: _addAlias.setEnabled(true);
0901: String check = _aliasName.getText().trim();
0902: AliasDef sel = (AliasDef) _tables.getSelectedItem();
0903: if (sel == null)
0904: _addAlias.setEnabled(false);
0905: else {
0906: if (check.length() == 0)
0907: check = sel.table;
0908: LModel aliasModel = (LModel) _aliases.getModel();
0909: for (int i = 0; i < aliasModel.getSize(); i++) {
0910: AliasDef comp = (AliasDef) aliasModel.getElementAt(i);
0911: if (comp.alias == null) {
0912: if (check.equals(comp.table)) {
0913: _addAlias.setEnabled(false);
0914: break;
0915: }
0916: } else if (comp.alias.equals(check)) {
0917: if (check.equals(comp.alias)) {
0918: _addAlias.setEnabled(false);
0919: break;
0920: }
0921: }
0922: }
0923: }
0924:
0925: //delete alias
0926: _delAlias.setEnabled(_aliases.getSelectedIndex() != -1 && _aliases.getModel().getSize() > 0);
0927: if (_delAlias.isEnabled()) {
0928: LModel cols = (LModel) _colsInModel.getModel();
0929: LModel sortCols = (LModel) _colsInSort.getModel();
0930: LModel joinCols = (LModel) _joins.getModel();
0931: Object[] selAlias = _aliases.getSelectedValues();
0932: for (int i = 0; i < selAlias.length; i++) {
0933: String alias = ((AliasDef) selAlias[i]).alias;
0934: if (alias != null) {
0935: for (int j = 0; j < cols.getSize(); j++) {
0936: ColumnDef d = (ColumnDef) cols.getElementAt(j);
0937: if (d.alias != null && d.alias.equals(alias)) {
0938: _delAlias.setEnabled(false);
0939: break;
0940: }
0941: }
0942: for (int j = 0; j < sortCols.getSize(); j++) {
0943: SortDef d = (SortDef) sortCols.getElementAt(j);
0944: if (d.alias != null && d.alias.equals(alias)) {
0945: _delAlias.setEnabled(false);
0946: break;
0947: }
0948: }
0949: } else {
0950: alias = ((AliasDef) selAlias[i]).table;
0951: }
0952: for (int j = 0; j < joinCols.getSize(); j++) {
0953: JoinDef d = (JoinDef) joinCols.getElementAt(j);
0954: if (d.usesAlias(alias)) {
0955: _delAlias.setEnabled(false);
0956: break;
0957: }
0958: }
0959: }
0960: }
0961: }
0962: private boolean equals(String val1, String val2) {
0963: if (val1 == null && val2 == null)
0964: return true;
0965: else if (val1 == null && val2 != null)
0966: return false;
0967: else if (val2 == null && val1 != null)
0968: return false;
0969: else
0970: return val1.equals(val2);
0971: }
0972:
0973: /**
0974: * Returns whether or not the model is remotable
0975: */
0976: public boolean isRemotable() {
0977: return _remotable;
0978: }
0979: /**
0980: * get list of aliases
0981: */
0982: public AliasDef[] getAliases() {
0983: LModel l = (LModel) _aliases.getModel();
0984: AliasDef[] ret = new AliasDef[l.getSize()];
0985: for (int i = 0; i < l.getSize(); i++)
0986: ret[i] = (AliasDef) l.getElementAt(i);
0987: return ret;
0988: }
0989: /**
0990: * get list of buckets
0991: */
0992: public BucketDef[] getBuckets() {
0993: LModel l = (LModel) _buckets.getModel();
0994: BucketDef[] ret = new BucketDef[l.getSize()];
0995: for (int i = 0; i < l.getSize(); i++)
0996: ret[i] = (BucketDef) l.getElementAt(i);
0997: return ret;
0998: }
0999: /**
1000: * Return true if the user clicked cancel to close the dialog
1001: */
1002: public boolean getCancelClicked() {
1003: return _clickedCancel;
1004: }
1005: /**
1006: * Get the name of the class to save as
1007: */
1008: public String getClassName() {
1009: return _className.getText().trim();
1010: }
1011: /**
1012: * get list of columns
1013: */
1014: public ColumnDef[] getColumns() {
1015: LModel l = (LModel) _colsInModel.getModel();
1016: ColumnDef[] ret = new ColumnDef[l.getSize()];
1017: for (int i = 0; i < l.getSize(); i++)
1018: ret[i] = (ColumnDef) l.getElementAt(i);
1019: return ret;
1020: }
1021: /**
1022: * get list of joins
1023: */
1024: public JoinDef[] getJoins() {
1025: LModel l = (LModel) _joins.getModel();
1026: JoinDef[] ret = new JoinDef[l.getSize()];
1027: for (int i = 0; i < l.getSize(); i++)
1028: ret[i] = (JoinDef) l.getElementAt(i);
1029: return ret;
1030: }
1031:
1032: /**
1033: * Get a list of validations
1034: */
1035: public ValidationRuleDefinition[] getValidationRules() {
1036: ValidationRuleDefinition[] d = new ValidationRuleDefinition[_validations.size()];
1037: _validations.copyInto(d);
1038: return d;
1039: }
1040:
1041: /**
1042: * Get a list of qbe criteria columns
1043: * @return
1044: */
1045: public QBECriteriaDef[] getQBECriteria() {
1046: LModel l = (LModel) _qbeElements.getModel();
1047: QBECriteriaDef[] ret = new QBECriteriaDef[l.getSize()];
1048: for (int i = 0; i < l.getSize(); i++)
1049: ret[i] = (QBECriteriaDef) l.getElementAt(i);
1050: return ret;
1051:
1052: }
1053:
1054: /**
1055: * Returns true if the model is a qbe datastore
1056: */
1057: public boolean isQBE() {
1058: return _qbeChecked;
1059: }
1060: /**
1061: * get list of columns to sort by
1062: */
1063: public SortDef[] getSortColumns() {
1064: LModel l = (LModel) _colsInSort.getModel();
1065: SortDef[] ret = new SortDef[l.getSize()];
1066: for (int i = 0; i < l.getSize(); i++)
1067: ret[i] = (SortDef) l.getElementAt(i);
1068: return ret;
1069: }
1070: private void loadColumns(String tableName) {
1071: if (tableName != null) {
1072: Vector v = _dd.getColumns(tableName);
1073: Vector mod = new Vector(v.size());
1074: for (int i = 0; i < v.size(); i++) {
1075: ColumnDefinition def = (ColumnDefinition) v.elementAt(i);
1076: mod.add(new ColumnDef(def, true));
1077: }
1078: _colList.setModel(new LModel(mod));
1079: }
1080: }
1081: private void loadTables() {
1082: Vector v = _dd.getTableNames();
1083: for (int i = 0; i < v.size(); i++) {
1084: _tables.addItem(new AliasDef((String) v.elementAt(i), null));
1085: }
1086: }
1087: private void populateFromModel(String model, String appName) {
1088: try {
1089: DataStoreBuffer d = DataStore.constructDataStore(model, appName);
1090: if (d == null) {
1091: IDETool.displayError("Error parsing model. Make sure the class extends com.salmonllc.sql.DataStoreBuffer and has compiled correctly!", true);
1092:
1093: }
1094: if (d instanceof Remotable)
1095: _remotable = true;
1096:
1097: _className.setText(model);
1098: if (d instanceof QBEBuilder) {
1099: _qbeChecked = true;
1100: //criteria Elements
1101: QBEBuilder ds = (QBEBuilder) d;
1102: QBEBuilder.CriteriaElement ele[] = ds.getCriteriaElements();
1103: for (int i = 0; i < ele.length; i++) {
1104: //String name = ds.getColumnName(i);
1105: QBECriteriaDef def = new QBECriteriaDef(ele[i].bucketName, new QBEType(ele[i].type), ele[i].columnList);
1106: ((LModel) _qbeElements.getModel()).addElement(def);
1107: }
1108:
1109: //validations
1110: for (int i = 0; i < ele.length; i++) {
1111: String name = ele[i].bucketName;
1112: ValidationRule rules[] = ds.getValidationRulesForColumn(i);
1113: if (rules != null) {
1114: for (int j = 0; j < rules.length; j++) {
1115: if (rules[j].getDsExpression() == null) {
1116: ValidationRuleDefinition def = new ValidationRuleDefinition();
1117: def.columnName = name;
1118: def.rule = rules[j];
1119: _validations.add(def);
1120: }
1121: }
1122: }
1123:
1124: }
1125: } else if (d instanceof DataStore) {
1126: _qbeChecked = false;
1127:
1128: DataStore ds = (DataStore) d;
1129:
1130: //first do the aliases
1131: for (int i = 0; i < ds.getAliasCount(); i++) {
1132: AliasDef def = new AliasDef(ds.getTable(i), ds.getAlias(i));
1133: ((LModel) _aliases.getModel()).addElement(def);
1134: if (def.alias != null)
1135: _tables.addItem(def);
1136: }
1137:
1138: //then the columns and buckets
1139: for (int i = 0; i < ds.getColumnCount(); i++) {
1140: if (ds.getColumnTableName(i) == null && ds.getColumnDBColumnName(i) == null) {
1141: DataType dt = new DataType(ds.getColumnDataType(i));
1142: String internalName = ds.getColumnInternalName(i);
1143: String format = ds.getFormat(i);
1144: BucketDef bd = new BucketDef(internalName, format, dt);
1145: ((LModel) _buckets.getModel()).addElement(bd);
1146: continue;
1147: }
1148: String tableName = ds.getColumnTableName(i);
1149: String aliasName = null;
1150: for (int j = 0; j < ds.getAliasCount(); j++) {
1151: if (ds.getAlias(j) != null && ds.getAlias(j).equals(tableName)) {
1152: tableName = ds.getTable(j);
1153: aliasName = ds.getAlias(j);
1154: }
1155: }
1156: ColumnDefinition cDef = new ColumnDefinition(tableName, ds.getColumnDBColumnName(i), ds.getColumnDataType(i), ds.isColumnPrimaryKey(i));
1157:
1158: String internalName = ds.getColumnInternalName(i);
1159: if (internalName.equals(ds.getColumnDatabaseName(i)))
1160: internalName = null;
1161:
1162: ColumnDef def = new ColumnDef(cDef, internalName, aliasName, ds.getFormat(i), ds.isUpdateable(i));
1163:
1164: ((LModel) _colsInModel.getModel()).addElement(def);
1165:
1166: }
1167:
1168: //order by
1169: String orderBy = ds.getOrderBy();
1170: if (orderBy != null) {
1171: StringTokenizer st = new StringTokenizer(orderBy, ",");
1172: while (st.hasMoreTokens()) {
1173: String tok = st.nextToken();
1174: String col = null;
1175: String tab = null;
1176: String dir = "A";
1177: String alias = null;
1178: int pos = tok.indexOf(" ");
1179: if (pos > -1) {
1180: dir = tok.substring(pos).trim().toUpperCase();
1181: col = tok.substring(0, pos).trim();
1182: }
1183: else
1184: {
1185: col = tok;
1186: }
1187: pos = col.indexOf(".");
1188: if (pos > -1) {
1189: tab = col.substring(0, pos);
1190: col = col.substring(pos + 1);
1191: }
1192: if (tab == null)
1193: tab = ds.getDefaultTable();
1194:
1195: for (int j = 0; j < ds.getAliasCount(); j++)
1196: if (ds.getAlias(j) != null && ds.getAlias(j).equals(tab))
1197: alias = ds.getAlias(j);
1198:
1199: ColumnDefinition def = new ColumnDefinition(tab, col, 0, false);
1200: SortDef sd = new SortDef(def, alias, dir.startsWith("A"));
1201: ((LModel) _colsInSort.getModel()).addElement(sd);
1202:
1203: }
1204: }
1205:
1206: //joins
1207: for (int i = 0; i < ds.getJoinCount(); i++) {
1208: JoinDef jd = new JoinDef();
1209: boolean outer = ds.getJoinOuter(i);
1210: for (int j = 0; j < ds.getJoinColumnCount(i); j++) {
1211: String left = ds.getJoinLeftColumn(i, j);
1212: String right = ds.getJoinRightColumn(i, j);
1213: JoinTermDef jtd = new JoinTermDef(left, right, outer);
1214: jd.addJoinTerm(jtd);
1215: }
1216: ((LModel) _joins.getModel()).addElement(jd);
1217: }
1218:
1219: //validations
1220: for (int i = 0; i < ds.getColumnCount(); i++) {
1221: String name = ds.getColumnInternalName(i);
1222: ValidationRule rules[] = ds.getValidationRulesForColumn(i);
1223: if (rules != null) {
1224: for (int j = 0; j < rules.length; j++) {
1225: if (rules[j].getDsExpression() == null) {
1226: ValidationRuleDefinition def = new ValidationRuleDefinition();
1227: def.columnName = name;
1228: def.rule = rules[j];
1229: _validations.add(def);
1230: }
1231: }
1232: }
1233:
1234: }
1235: }
1236: _qbe.getModel().setSelected(_qbeChecked);
1237: _qbePanel.setVisible(_qbeChecked);
1238: _standardPanel.setVisible(!_qbeChecked);
1239: enableDisableButtons();
1240: } catch (Exception e) {
1241: MessageLog.writeErrorMessage("populateFromModel", e, this );
1242: IDETool.displayError("Error, class must extend com.salmonllc.sql.DataStoreBuffer!", true);
1243:
1244: }
1245: }
1246: /**
1247: * Reset the cancel clicked status button
1248: */
1249: public void resetCancel() {
1250: _clickedCancel = true;
1251: }
1252: /**
1253: * Called whenever the value of the selection changes.
1254: * @param e the event that characterizes the change.
1255: */
1256: public void valueChanged(ListSelectionEvent e) {
1257: if (e.getSource() == _qbeElements) {
1258: Object o[] = _qbeElements.getSelectedValues();
1259: if (o.length > 0) {
1260: QBECriteriaDef def = (QBECriteriaDef) o[0];
1261: _qbeName.setText(def.name);
1262: _qbeCols.setText(def.colList);
1263: ComboBoxModel mod =_qbeType.getModel();
1264: for (int i = 0; i < mod.getSize(); i++) {
1265: if (((QBEType)mod.getElementAt(i)).type == def.type.type) {
1266: _qbeType.setSelectedIndex(i);
1267: break;
1268: }
1269: }
1270: }
1271: }
1272: enableDisableButtons();
1273: }
1274:
1275: /**
1276: * Returns the names of all the columns and buckets in the model
1277: */
1278: public String[] getColumnAndBucketNames() {
1279: Sorter st = new Sorter();
1280: if (_qbeChecked) {
1281: QBECriteriaDef criteriaDef[] = getQBECriteria();
1282: for (int i = 0; i < criteriaDef.length; i++)
1283: st.add(criteriaDef[i].name);
1284: } else {
1285: ColumnDef columns[] = getColumns();
1286: BucketDef buckets[] = getBuckets();
1287: for (int i = 0; i < columns.length; i++)
1288: st.add(columns[i].getName());
1289: for (int i = 0; i < buckets.length; i++)
1290: st.add(buckets[i].name);
1291: st.sort();
1292: }
1293: String ret[] = new String[st.size()];
1294: st.copyInto(ret);
1295: return ret;
1296:
1297: }
1298:}
|