home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / WizardModelSubDbQuerySelect.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  6.6 KB  |  191 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 com.sun.java.swing.DefaultListModel;
  13. import com.sun.java.swing.ImageIcon;
  14. import java.util.Vector;
  15.  
  16. public class WizardModelSubDbQuerySelect extends WizardModelSub {
  17.    WizardSubDbQuery _Wizard;
  18.    WizardPage _joinPage;
  19.    WizardPage _wherePage;
  20.    SubDBQueryData _Data;
  21.    WizardViewSubDbQuerySelect _viewInstance;
  22.    // $FF: synthetic field
  23.    static Class class$asp$wizard$WVPanelDbQuerySelect;
  24.  
  25.    public WizardModelSubDbQuerySelect() {
  26.    }
  27.  
  28.    public WizardModelSubDbQuerySelect(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
  29.       super(wizard, bullet, info, icon, handler);
  30.       this._Wizard = (WizardSubDbQuery)wizard;
  31.       this._Data = this._Wizard.getData();
  32.    }
  33.  
  34.    protected WizardPageView getViewSingleInstance() {
  35.       WizardViewSubDbQuerySelect wizard = (WizardViewSubDbQuerySelect)WizardViewSubDbQuerySelect.getInstance();
  36.       return WizardViewSubDbQuerySelect.getInstance();
  37.    }
  38.  
  39.    public void commit() throws InternalError, ExternalError {
  40.       WizardViewSubDbQuerySelect view = (WizardViewSubDbQuerySelect)this.getViewSingleInstance();
  41.       OrderedListModel olm = view.getFields();
  42.       this._Data.removeAllFields();
  43.  
  44.       for(int i = 0; i < ((DefaultListModel)olm).getSize(); ++i) {
  45.          String strData = ((DefaultListModel)olm).elementAt(i).toString();
  46.          int nIndex = strData.indexOf(".");
  47.          if (nIndex != -1) {
  48.             String strTable = strData.substring(0, nIndex);
  49.             String strField = strData.substring(nIndex + 1);
  50.             this._Data.addField(strTable, strField);
  51.          }
  52.       }
  53.  
  54.       this._Data.updateAllPossibleFields();
  55.    }
  56.  
  57.    public void updateTableComboBox() {
  58.       WizardViewSubDbQuerySelect view = (WizardViewSubDbQuerySelect)((WizardPage)this).getView();
  59.       boolean[] containingSpaceFound = new boolean[1];
  60.       OrderedListModel list = this._Data.getTables(containingSpaceFound);
  61.       if (containingSpaceFound[0]) {
  62.          view.setContainingSpaceWarningVisible(true);
  63.       }
  64.  
  65.       view.setTableComboBoxModel(list);
  66.    }
  67.  
  68.    public void updateAvailableFieldList() {
  69.       WizardViewSubDbQuerySelect view = (WizardViewSubDbQuerySelect)((WizardPage)this).getView();
  70.       OrderedListModel olmAvailFields = new OrderedListModel();
  71.       String selTableName = view.getSelectedTable();
  72.       boolean[] containingSpaceFound = new boolean[1];
  73.       if (selTableName != null && !selTableName.equals("")) {
  74.          DefConnection dc = ((WizardSubDbQuery)((WizardPage)this).getWizard()).getDefConnection();
  75.          SubDBQueryData.setFields(dc, olmAvailFields, selTableName, containingSpaceFound);
  76.          olmAvailFields.setOrdered(true);
  77.       }
  78.  
  79.       if (containingSpaceFound[0]) {
  80.          view.setContainingSpaceWarningVisible(true);
  81.       }
  82.  
  83.       view.setAvailableFieldModel(olmAvailFields);
  84.    }
  85.  
  86.    public void loadView() {
  87.       if (((WizardPage)this).getView() != null) {
  88.          ((WizardViewSubDbQuerySelect)((WizardPage)this).getView()).setContainingSpaceWarningVisible(false);
  89.       }
  90.  
  91.       this.updateTableComboBox();
  92.       this.updateAvailableFieldList();
  93.       this.loadValues();
  94.    }
  95.  
  96.    public void loadValues() {
  97.       Vector fields = this._Data.getFields();
  98.       OrderedListModel olm = new OrderedListModel();
  99.  
  100.       for(int i = 0; i < fields.size(); ++i) {
  101.          SubDBQueryData.FieldOb field = (SubDBQueryData.FieldOb)fields.elementAt(i);
  102.          olm.addElement(field.getTable() + "." + field.getField());
  103.       }
  104.  
  105.       WizardViewSubDbQuerySelect view = (WizardViewSubDbQuerySelect)((WizardPage)this).getView();
  106.       view.setSelectedFields(olm);
  107.    }
  108.  
  109.    public WizardPage createNext() {
  110.       if (this._Wizard.getData().containsMultipleTables()) {
  111.          this._joinPage = new WizardModelSubDbQueryJoin(this._Wizard, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
  112.          return this._joinPage;
  113.       } else {
  114.          this._wherePage = new WizardModelSubDbQueryWhere(this._Wizard, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
  115.          return this._wherePage;
  116.       }
  117.    }
  118.  
  119.    public void validate() throws InternalError, ExternalError {
  120.       super.validate();
  121.       WizardViewSubDbQuerySelect view = (WizardViewSubDbQuerySelect)this.getViewSingleInstance();
  122.       OrderedListModel olm = view.getFields();
  123.       if (((DefaultListModel)olm).size() == 0) {
  124.          String msg = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbQuerySelect != null ? class$asp$wizard$WVPanelDbQuerySelect : (class$asp$wizard$WVPanelDbQuerySelect = class$("asp.wizard.WVPanelDbQuerySelect")), "err.selectfield");
  125.          throw new ExternalError(msg);
  126.       }
  127.    }
  128.  
  129.    public WizardPage getNext() {
  130.       WizardPage result = null;
  131.       if (this._Wizard.getData().containsMultipleTables()) {
  132.          if (this._joinPage == null) {
  133.             this._joinPage = new WizardModelSubDbQueryJoin(this._Wizard, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
  134.          }
  135.  
  136.          this._joinPage.setPrevious(this);
  137.          if (this._wherePage != null) {
  138.             this._joinPage.setNext(this._wherePage);
  139.             this._wherePage.setPrevious(this._joinPage);
  140.          }
  141.  
  142.          result = this._joinPage;
  143.       } else {
  144.          if (this._wherePage == null) {
  145.             WizardPage afterJoin = null;
  146.  
  147.             try {
  148.                if (this._joinPage != null) {
  149.                   afterJoin = this._joinPage.getNext();
  150.                }
  151.             } catch (ExternalError var3) {
  152.             } catch (InternalError var4) {
  153.             }
  154.  
  155.             if (afterJoin != null) {
  156.                this._wherePage = afterJoin;
  157.             } else {
  158.                this._wherePage = new WizardModelSubDbQueryWhere(this._Wizard, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
  159.             }
  160.          }
  161.  
  162.          this._wherePage.setPrevious(this);
  163.          result = this._wherePage;
  164.       }
  165.  
  166.       return result;
  167.    }
  168.  
  169.    public Object handleGetItemToXfer(Object sourceItem) {
  170.       WizardViewSubDbQuerySelect view = (WizardViewSubDbQuerySelect)((WizardPage)this).getView();
  171.       String s = view.getSelectedTable();
  172.       if (s != null && !s.equals("")) {
  173.          StringBuffer sb = new StringBuffer(s);
  174.          sb.append(".");
  175.          sb.append(sourceItem.toString());
  176.          return sb.toString();
  177.       } else {
  178.          return null;
  179.       }
  180.    }
  181.  
  182.    // $FF: synthetic method
  183.    static Class class$(String class$) {
  184.       try {
  185.          return Class.forName(class$);
  186.       } catch (ClassNotFoundException forName) {
  187.          throw new NoClassDefFoundError(((Throwable)forName).getMessage());
  188.       }
  189.    }
  190. }
  191.