home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 183 / dpcs0503.iso / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / WizardViewDbList3.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  7.8 KB  |  213 lines

  1. package asp.wizard;
  2.  
  3. import com.sun.java.swing.ButtonModel;
  4. import com.sun.java.swing.JComponent;
  5. import com.sun.java.swing.JList;
  6. import com.sun.java.swing.JTable;
  7. import com.sun.java.swing.table.DefaultTableModel;
  8. import com.sun.java.swing.table.TableColumn;
  9. import com.sun.java.swing.table.TableColumnModel;
  10. import java.awt.Component;
  11. import java.awt.Container;
  12. import java.awt.Insets;
  13. import java.util.Enumeration;
  14. import java.util.TooManyListenersException;
  15. import java.util.Vector;
  16.  
  17. public class WizardViewDbList3 extends WizardViewAbstract {
  18.    public static final int COLFIELDNAME = 0;
  19.    public static final int COLFIELDTYPE = 1;
  20.    public static final int COLFIELDLABEL = 2;
  21.    public static final int LINK_TO_LIST = 1000;
  22.    public static final int LINK_TO_DETAIL = 1001;
  23.    private static WizardViewAbstract _instance = null;
  24.    private WVPanelDbListLink _mainPanel;
  25.    private TableColumn _columnAlias;
  26.    private boolean _initFieldSpecColWidths = false;
  27.  
  28.    public WizardViewDbList3() {
  29.       JTable table = this._mainPanel.getFieldSpecTable();
  30.       TableColumnModel tcm = table.getColumnModel();
  31.       this._columnAlias = tcm.getColumn(2);
  32.       tcm.removeColumn(this._columnAlias);
  33.    }
  34.  
  35.    public static WizardViewAbstract getInstance() {
  36.       if (_instance == null) {
  37.          _instance = new WizardViewDbList3();
  38.       }
  39.  
  40.       return _instance;
  41.    }
  42.  
  43.    protected void createMainPanel() {
  44.       this._mainPanel = new WVPanelDbListLink();
  45.       this.initListeners();
  46.    }
  47.  
  48.    public WVPanelBase getMainPanel() {
  49.       return this._mainPanel;
  50.    }
  51.  
  52.    public int getSeqTemplateId() {
  53.       int result = -1;
  54.       ButtonModel buttonModel = this._mainPanel._btgTemplates.getSelection();
  55.       if (buttonModel != null) {
  56.          String actionCommand = buttonModel.getActionCommand();
  57.          if (actionCommand.equals("radiobutton.linktodetail")) {
  58.             result = 1;
  59.          } else if (actionCommand.equals("radiobutton.linktolist")) {
  60.             result = 0;
  61.          }
  62.       }
  63.  
  64.       return result;
  65.    }
  66.  
  67.    private void resizeColumnsEqually(JTable table) {
  68.       TableColumnModel tcm = table.getColumnModel();
  69.       Container cont = ((Component)table).getParent();
  70.       Insets insets = cont.getInsets();
  71.       int width = ((Component)cont).getSize().width - insets.left - insets.right - 2;
  72.       int colWidth = width / tcm.getColumnCount();
  73.  
  74.       for(int i = 0; i < tcm.getColumnCount(); ++i) {
  75.          tcm.getColumn(i).setWidth(colWidth);
  76.       }
  77.  
  78.       ((Container)table).invalidate();
  79.       Container rootContainer = ((JComponent)table).getTopLevelAncestor();
  80.       if (rootContainer != null) {
  81.          rootContainer.validate();
  82.       }
  83.  
  84.       ((Component)this).repaint();
  85.    }
  86.  
  87.    public void updateFieldSpecTableColumnsVisibility() {
  88.       JTable table = this._mainPanel.getFieldSpecTable();
  89.       TableColumnModel tcm = table.getColumnModel();
  90.       boolean show = this.getLinkOption() == 1000;
  91.       if (show && this._columnAlias != null) {
  92.          tcm.addColumn(this._columnAlias);
  93.          this._columnAlias = null;
  94.          this.resizeColumnsEqually(table);
  95.       } else if (!show && this._columnAlias == null) {
  96.          this._columnAlias = tcm.getColumn(2);
  97.          tcm.removeColumn(this._columnAlias);
  98.          this.resizeColumnsEqually(table);
  99.       }
  100.  
  101.    }
  102.  
  103.    protected void initListeners() {
  104.       try {
  105.          this._mainPanel._l2tFieldSpec.addXferItemListener(new 1(this));
  106.       } catch (TooManyListenersException e) {
  107.          System.err.println(((Throwable)e).getMessage());
  108.       }
  109.  
  110.       this._mainPanel._rdbLinkToDetail.addActionListener(new 2(this));
  111.       this._mainPanel._rdbLinkToList.addActionListener(new 3(this));
  112.       this._mainPanel.getFieldSpecTable().addComponentListener(new 4(this));
  113.    }
  114.  
  115.    public void setDataType(Vector list) {
  116.       Enumeration values = list.elements();
  117.       this._mainPanel._cboDataType.removeAllItems();
  118.  
  119.       while(values.hasMoreElements()) {
  120.          this._mainPanel._cboDataType.addItem((String)values.nextElement());
  121.       }
  122.  
  123.    }
  124.  
  125.    public void setHyperlinkField(int hyperlinkField) {
  126.       if (hyperlinkField < this._mainPanel._cboList.getItemCount()) {
  127.          this._mainPanel._cboList.setSelectedIndex(hyperlinkField);
  128.       } else {
  129.          this._mainPanel._cboList.setSelectedIndex(0);
  130.       }
  131.  
  132.    }
  133.  
  134.    public int getHyperlinkField() {
  135.       return this._mainPanel._cboList.getSelectedIndex();
  136.    }
  137.  
  138.    public void setHyperlinkPage(int hyperlinkPage) {
  139.    }
  140.  
  141.    public int getHyperlinkPage() {
  142.       return 1;
  143.    }
  144.  
  145.    public DefaultTableModel getKeyFields() {
  146.       return (DefaultTableModel)this._mainPanel.getFieldSpecTable().getModel();
  147.    }
  148.  
  149.    public void setKeyFields(DefaultTableModel KFCollection) {
  150.       this._mainPanel.getFieldSpecTable().setModel(KFCollection);
  151.    }
  152.  
  153.    public JTable getFieldSpecTable() {
  154.       return this._mainPanel.getFieldSpecTable();
  155.    }
  156.  
  157.    public JList getFieldList() {
  158.       return this._mainPanel.getFieldList();
  159.    }
  160.  
  161.    public void setHLFieldList(String[] list) {
  162.       this._mainPanel._cboList.removeAllItems();
  163.  
  164.       for(int i = 0; i < list.length; ++i) {
  165.          this._mainPanel._cboList.addItem(list[i]);
  166.       }
  167.  
  168.    }
  169.  
  170.    public int getLinkOption() {
  171.       int result = 1001;
  172.       ButtonModel selModel = this._mainPanel._btgTemplates.getSelection();
  173.       if (selModel == this._mainPanel._rdbLinkToList.getModel()) {
  174.          result = 1000;
  175.       }
  176.  
  177.       return result;
  178.    }
  179.  
  180.    public void setLinkOption(int option) {
  181.       if (option == 1000) {
  182.          this._mainPanel._btgTemplates.setSelected(this._mainPanel._rdbLinkToList.getModel(), true);
  183.       } else if (option == 1001) {
  184.          this._mainPanel._btgTemplates.setSelected(this._mainPanel._rdbLinkToDetail.getModel(), true);
  185.       }
  186.  
  187.    }
  188.  
  189.    public void commit() {
  190.       this._mainPanel._l2tFieldSpec.commitChanges();
  191.    }
  192.  
  193.    // $FF: synthetic method
  194.    static boolean access$0(WizardViewDbList3 $0) {
  195.       return $0._initFieldSpecColWidths;
  196.    }
  197.  
  198.    // $FF: synthetic method
  199.    static WVPanelDbListLink access$1(WizardViewDbList3 $0) {
  200.       return $0._mainPanel;
  201.    }
  202.  
  203.    // $FF: synthetic method
  204.    static void access$2(WizardViewDbList3 $0, JTable $1) {
  205.       $0.resizeColumnsEqually($1);
  206.    }
  207.  
  208.    // $FF: synthetic method
  209.    static void access$3(WizardViewDbList3 $0, boolean $1) {
  210.       $0._initFieldSpecColWidths = $1;
  211.    }
  212. }
  213.