home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard;
-
- import asp.netobjects.nfx.ui.OrderedListModel;
- import asp.netobjects.nfx.util.ExceptionHandler;
- import asp.netobjects.nfx.util.ExternalError;
- import asp.netobjects.nfx.util.InternalError;
- import asp.netobjects.nfx.wizard.Wizard;
- import asp.netobjects.nfx.wizard.WizardPage;
- import asp.netobjects.nfx.wizard.WizardPageView;
- import asp.util.ResourceUtil;
- import asp.wizard.def.DefConnection;
- import asp.wizard.util.UiUtil;
- import com.sun.java.swing.DefaultListModel;
- import com.sun.java.swing.ImageIcon;
- import com.sun.java.swing.table.DefaultTableModel;
- import java.sql.Connection;
- import java.text.MessageFormat;
- import java.util.Vector;
-
- public class WizardModelSubDbQueryWhere extends WizardModelSub {
- // $FF: synthetic field
- static Class class$asp$wizard$WVPanelDbQueryWhere;
-
- public WizardModelSubDbQueryWhere() {
- super.dmCanFinish = true;
- }
-
- public WizardModelSubDbQueryWhere(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
- super(wizard, bullet, info, icon, handler);
- super.dmCanFinish = true;
- }
-
- protected WizardPageView getViewSingleInstance() {
- return WizardViewSubDbQueryWhere.getInstance();
- }
-
- public WizardPage createNext() throws InternalError, ExternalError {
- Wizard wizard = ((WizardPage)this).getWizard();
- return new WizardModelSubDbQuerySort(wizard, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
- }
-
- public void loadView() {
- WizardViewSubDbQueryWhere view = (WizardViewSubDbQueryWhere)this.getViewSingleInstance();
- view.setSuffixes(this.getSuffixes());
- view.setOperators(this.getOperators());
- view.setPrefixes(this.getPrefixes());
- OrderedListModel olm = this.getAllFields();
- UiUtil.populateCombo(view.getcboLhs(), olm);
- UiUtil.populateCombo(view.getcboRhs(), olm);
- WizardSubDbQuery wizard = (WizardSubDbQuery)((WizardPage)this).getWizard();
- SubDBQueryData data = wizard.getData();
- data.removeUnsupportedWheres();
- Vector wheres = data.getWheres();
- DefaultTableModel whereData = view.getWhereData();
-
- while(whereData.getRowCount() > 0) {
- whereData.removeRow(0);
- }
-
- whereData.setNumRows(wheres.size());
-
- for(int i = 0; i < wheres.size(); ++i) {
- SubDBQueryData.WhereOb where = (SubDBQueryData.WhereOb)wheres.elementAt(i);
- whereData.setValueAt(where.getPrefix(), i, 0);
- whereData.setValueAt(where.getField(), i, 1);
- whereData.setValueAt(where.getFilter(), i, 2);
- whereData.setValueAt(where.getValue(), i, 3);
- whereData.setValueAt(where.getSuffix(), i, 4);
- }
-
- if (view.getWhereData().getRowCount() == 0) {
- view.addRow();
- }
-
- }
-
- public Vector getSuffixes() {
- String test = " |)";
- Vector result = UiUtil.strToVector(test);
- return result;
- }
-
- public Vector getOperators() {
- String test = "=|<|>|<=|>=";
- Vector result = UiUtil.strToVector(test);
- return result;
- }
-
- public Vector getPrefixes() {
- String test = " |and |or |and (|or (|(|)";
- Vector result = UiUtil.strToVector(test);
- return result;
- }
-
- public void validate() throws InternalError, ExternalError {
- super.validate();
- WizardViewSubDbQueryWhere view = (WizardViewSubDbQueryWhere)this.getViewSingleInstance();
- WVPanelDbQueryWhere panel = (WVPanelDbQueryWhere)view.getMainPanel();
- WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
- SubDBQueryData data = wizard.getData();
- DefaultTableModel whereData = view.getWhereData();
- new String();
-
- for(int i = 0; i < whereData.getRowCount(); ++i) {
- String strPrefix = (String)whereData.getValueAt(i, 0);
- String strField = (String)whereData.getValueAt(i, 1);
- String strFilter = (String)whereData.getValueAt(i, 2);
- String strValue = (String)whereData.getValueAt(i, 3);
- String strSuffix = (String)whereData.getValueAt(i, 4);
- 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)) {
- 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");
- Object[] args = new Object[]{new Integer(i + 1)};
- String msg = MessageFormat.format(err, args);
- throw new ExternalError(msg);
- }
- }
-
- }
-
- public void commit() throws InternalError, ExternalError {
- WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
- SubDBQueryData data = wizard.getData();
- WizardViewSubDbQueryWhere view = (WizardViewSubDbQueryWhere)this.getViewSingleInstance();
- DefaultTableModel whereData = view.getWhereData();
- new String();
- data.removeAllWheres();
-
- for(int i = 0; i < whereData.getRowCount(); ++i) {
- String strPrefix = (String)whereData.getValueAt(i, 0);
- String strField = (String)whereData.getValueAt(i, 1);
- String strFilter = (String)whereData.getValueAt(i, 2);
- String strValue = (String)whereData.getValueAt(i, 3);
- String strSuffix = (String)whereData.getValueAt(i, 4);
- if (strField != null || strField != null || strFilter != null || strValue != null || strSuffix != null) {
- data.addWhere(strPrefix, strField, strFilter, strValue, strSuffix);
- }
- }
-
- }
-
- protected int matchParens(String s) {
- int nLeft = 0;
- int nRight = 0;
-
- for(int i = 0; i < s.length(); ++i) {
- if (s.charAt(i) == '(') {
- ++nLeft;
- }
-
- if (s.charAt(i) == ')') {
- ++nRight;
- }
- }
-
- if (nLeft < nRight) {
- return -1;
- } else if (nLeft > nRight) {
- return 1;
- } else {
- return 0;
- }
- }
-
- public OrderedListModel getAllFields() {
- OrderedListModel result = new OrderedListModel();
- WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
- OrderedListModel tables = wizard.getData().getSelectedTables();
-
- for(int i = 0; i < ((DefaultListModel)tables).size(); ++i) {
- OrderedListModel olm = this.getFields(((DefaultListModel)tables).elementAt(i).toString());
-
- for(int j = 0; j < ((DefaultListModel)olm).size(); ++j) {
- result.addElement(((DefaultListModel)tables).elementAt(i).toString() + "." + ((DefaultListModel)olm).elementAt(j).toString());
- }
- }
-
- return result;
- }
-
- protected OrderedListModel getFields(String strTable) {
- OrderedListModel olm = new OrderedListModel();
-
- try {
- WizardSubDbQuery wizard = WizardSubDbQuery.getInstance();
- DefConnection dc = wizard.getDefConnection();
- WizDbManager wdbm = WizDbManager.getInstance();
- Connection conn = wdbm.getConnection(dc.getDSNName(), dc.getUserName(), dc.getPassword());
- WizDbManager.getFields(conn, strTable, olm, true, (boolean[])null);
- } catch (Exception var7) {
- }
-
- return olm;
- }
-
- // $FF: synthetic method
- static Class class$(String class$) {
- try {
- return Class.forName(class$);
- } catch (ClassNotFoundException forName) {
- throw new NoClassDefFoundError(((Throwable)forName).getMessage());
- }
- }
- }
-