home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / WizardModelSubDbQueryWhere.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  8.1 KB  |  204 lines

  1. package asp.wizard;
  2.  
  3. import asp.netobjects.nfx.ui.OrderedListModel;
  4. import asp.netobjects.nfx.util.ExceptionHandler;
  5. import asp.netobjects.nfx.util.ExternalError;
  6. import asp.netobjects.nfx.util.InternalError;
  7. import asp.netobjects.nfx.wizard.Wizard;
  8. import asp.netobjects.nfx.wizard.WizardPage;
  9. import asp.netobjects.nfx.wizard.WizardPageView;
  10. import asp.util.ResourceUtil;
  11. import asp.wizard.def.DefConnection;
  12. import asp.wizard.util.UiUtil;
  13. import com.sun.java.swing.DefaultListModel;
  14. import com.sun.java.swing.ImageIcon;
  15. import com.sun.java.swing.table.DefaultTableModel;
  16. import java.sql.Connection;
  17. import java.text.MessageFormat;
  18. import java.util.Vector;
  19.  
  20. public class WizardModelSubDbQueryWhere extends WizardModelSub {
  21.    // $FF: synthetic field
  22.    static Class class$asp$wizard$WVPanelDbQueryWhere;
  23.  
  24.    public WizardModelSubDbQueryWhere() {
  25.       super.dmCanFinish = true;
  26.    }
  27.  
  28.    public WizardModelSubDbQueryWhere(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
  29.       super(wizard, bullet, info, icon, handler);
  30.       super.dmCanFinish = true;
  31.    }
  32.  
  33.    protected WizardPageView getViewSingleInstance() {
  34.       return WizardViewSubDbQueryWhere.getInstance();
  35.    }
  36.  
  37.    public WizardPage createNext() throws InternalError, ExternalError {
  38.       Wizard wizard = ((WizardPage)this).getWizard();
  39.       return new WizardModelSubDbQuerySort(wizard, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
  40.    }
  41.  
  42.    public void loadView() {
  43.       WizardViewSubDbQueryWhere view = (WizardViewSubDbQueryWhere)this.getViewSingleInstance();
  44.       view.setSuffixes(this.getSuffixes());
  45.       view.setOperators(this.getOperators());
  46.       view.setPrefixes(this.getPrefixes());
  47.       OrderedListModel olm = this.getAllFields();
  48.       UiUtil.populateCombo(view.getcboLhs(), olm);
  49.       UiUtil.populateCombo(view.getcboRhs(), olm);
  50.       WizardSubDbQuery wizard = (WizardSubDbQuery)((WizardPage)this).getWizard();
  51.       SubDBQueryData data = wizard.getData();
  52.       data.removeUnsupportedWheres();
  53.       Vector wheres = data.getWheres();
  54.       DefaultTableModel whereData = view.getWhereData();
  55.  
  56.       while(whereData.getRowCount() > 0) {
  57.          whereData.removeRow(0);
  58.       }
  59.  
  60.       whereData.setNumRows(wheres.size());
  61.  
  62.       for(int i = 0; i < wheres.size(); ++i) {
  63.          SubDBQueryData.WhereOb where = (SubDBQueryData.WhereOb)wheres.elementAt(i);
  64.          whereData.setValueAt(where.getPrefix(), i, 0);
  65.          whereData.setValueAt(where.getField(), i, 1);
  66.          whereData.setValueAt(where.getFilter(), i, 2);
  67.          whereData.setValueAt(where.getValue(), i, 3);
  68.          whereData.setValueAt(where.getSuffix(), i, 4);
  69.       }
  70.  
  71.       if (view.getWhereData().getRowCount() == 0) {
  72.          view.addRow();
  73.       }
  74.  
  75.    }
  76.  
  77.    public Vector getSuffixes() {
  78.       String test = " |)";
  79.       Vector result = UiUtil.strToVector(test);
  80.       return result;
  81.    }
  82.  
  83.    public Vector getOperators() {
  84.       String test = "=|<|>|<=|>=";
  85.       Vector result = UiUtil.strToVector(test);
  86.       return result;
  87.    }
  88.  
  89.    public Vector getPrefixes() {
  90.       String test = " |and |or |and (|or (|(|)";
  91.       Vector result = UiUtil.strToVector(test);
  92.       return result;
  93.    }
  94.  
  95.    public void validate() throws InternalError, ExternalError {
  96.       super.validate();
  97.       WizardViewSubDbQueryWhere view = (WizardViewSubDbQueryWhere)this.getViewSingleInstance();
  98.       WVPanelDbQueryWhere panel = (WVPanelDbQueryWhere)view.getMainPanel();
  99.       WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
  100.       SubDBQueryData data = wizard.getData();
  101.       DefaultTableModel whereData = view.getWhereData();
  102.       new String();
  103.  
  104.       for(int i = 0; i < whereData.getRowCount(); ++i) {
  105.          String strPrefix = (String)whereData.getValueAt(i, 0);
  106.          String strField = (String)whereData.getValueAt(i, 1);
  107.          String strFilter = (String)whereData.getValueAt(i, 2);
  108.          String strValue = (String)whereData.getValueAt(i, 3);
  109.          String strSuffix = (String)whereData.getValueAt(i, 4);
  110.          if ((strField != null || strField != null || strFilter != null || strValue != null || strSuffix != null) && (strField == null || strField.trim().compareTo("") == 0 || strValue == null || strValue.trim().compareTo("") == 0 || strFilter == null || strFilter.trim().compareTo("") == 0)) {
  111.             String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbQueryWhere != null ? class$asp$wizard$WVPanelDbQueryWhere : (class$asp$wizard$WVPanelDbQueryWhere = class$("asp.wizard.WVPanelDbQueryWhere")), "err.incomplete");
  112.             Object[] args = new Object[]{new Integer(i + 1)};
  113.             String msg = MessageFormat.format(err, args);
  114.             throw new ExternalError(msg);
  115.          }
  116.       }
  117.  
  118.    }
  119.  
  120.    public void commit() throws InternalError, ExternalError {
  121.       WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
  122.       SubDBQueryData data = wizard.getData();
  123.       WizardViewSubDbQueryWhere view = (WizardViewSubDbQueryWhere)this.getViewSingleInstance();
  124.       DefaultTableModel whereData = view.getWhereData();
  125.       new String();
  126.       data.removeAllWheres();
  127.  
  128.       for(int i = 0; i < whereData.getRowCount(); ++i) {
  129.          String strPrefix = (String)whereData.getValueAt(i, 0);
  130.          String strField = (String)whereData.getValueAt(i, 1);
  131.          String strFilter = (String)whereData.getValueAt(i, 2);
  132.          String strValue = (String)whereData.getValueAt(i, 3);
  133.          String strSuffix = (String)whereData.getValueAt(i, 4);
  134.          if (strField != null || strField != null || strFilter != null || strValue != null || strSuffix != null) {
  135.             data.addWhere(strPrefix, strField, strFilter, strValue, strSuffix);
  136.          }
  137.       }
  138.  
  139.    }
  140.  
  141.    protected int matchParens(String s) {
  142.       int nLeft = 0;
  143.       int nRight = 0;
  144.  
  145.       for(int i = 0; i < s.length(); ++i) {
  146.          if (s.charAt(i) == '(') {
  147.             ++nLeft;
  148.          }
  149.  
  150.          if (s.charAt(i) == ')') {
  151.             ++nRight;
  152.          }
  153.       }
  154.  
  155.       if (nLeft < nRight) {
  156.          return -1;
  157.       } else if (nLeft > nRight) {
  158.          return 1;
  159.       } else {
  160.          return 0;
  161.       }
  162.    }
  163.  
  164.    public OrderedListModel getAllFields() {
  165.       OrderedListModel result = new OrderedListModel();
  166.       WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
  167.       OrderedListModel tables = wizard.getData().getSelectedTables();
  168.  
  169.       for(int i = 0; i < ((DefaultListModel)tables).size(); ++i) {
  170.          OrderedListModel olm = this.getFields(((DefaultListModel)tables).elementAt(i).toString());
  171.  
  172.          for(int j = 0; j < ((DefaultListModel)olm).size(); ++j) {
  173.             result.addElement(((DefaultListModel)tables).elementAt(i).toString() + "." + ((DefaultListModel)olm).elementAt(j).toString());
  174.          }
  175.       }
  176.  
  177.       return result;
  178.    }
  179.  
  180.    protected OrderedListModel getFields(String strTable) {
  181.       OrderedListModel olm = new OrderedListModel();
  182.  
  183.       try {
  184.          WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
  185.          DefConnection dc = wizard.getDefConnection();
  186.          WizDbManager wdbm = WizDbManager.getInstance();
  187.          Connection conn = wdbm.getConnection(dc.getDSNName(), dc.getUserName(), dc.getPassword());
  188.          WizDbManager.getFields(conn, strTable, olm, true, (boolean[])null);
  189.       } catch (Exception var7) {
  190.       }
  191.  
  192.       return olm;
  193.    }
  194.  
  195.    // $FF: synthetic method
  196.    static Class class$(String class$) {
  197.       try {
  198.          return Class.forName(class$);
  199.       } catch (ClassNotFoundException forName) {
  200.          throw new NoClassDefFoundError(((Throwable)forName).getMessage());
  201.       }
  202.    }
  203. }
  204.