alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.jellytools.modules.db;

import org.netbeans.jemmy.operators.*;
import org.netbeans.jellytools.*;
import org.netbeans.jellytools.properties.PropertySheetOperator;

/** Class implementing all necessary methods for handling "Connect" NbDialog.
 *
 * @author ms113234
 * @version 1.0
 */
public class ConnectDialogOperator extends NbDialogOperator {

    /** Creates new ConnectDialogOperator that can handle it.
     */
    public ConnectDialogOperator() {
        super("Connect");
    }

    private JTabbedPaneOperator _tbpDatabaseConnect;
    private String _selectPageBasicSetting = "Basic setting";
    private JLabelOperator _lblUserName;
    private JLabelOperator _lblPassword;
    private JCheckBoxOperator _cbRememberPasswordDuringThisSession;
    private JPasswordFieldOperator _txtPassword;
    private JTextFieldOperator _txtUserName;
    private JProgressBarOperator _prbConnectionProgressBar;
    private String _selectPageAdvanced = "Advanced";
    private JTextAreaOperator _txtSchemaPanelDescription;
    private JLabelOperator _lblSelectSchema;
    private JComboBoxOperator _cboSelectSchema;

    private JButtonOperator _btGetSchemas;
    private JProgressBarOperator _prbConnectionProgressBar2;


    //******************************
    // Subcomponents definition part
    //******************************

    /** Tries to find null JTabbedPane in this dialog.
     * @return JTabbedPaneOperator
     */
    public JTabbedPaneOperator tbpDatabaseConnect() {
        if (_tbpDatabaseConnect==null) {
            _tbpDatabaseConnect = new JTabbedPaneOperator(this);
        }
        return _tbpDatabaseConnect;
    }

    /** Tries to find "User name:" JLabel in this dialog.
     * @return JLabelOperator
     */
    public JLabelOperator lblUserName() {
        if (_lblUserName==null) {
            _lblUserName = new JLabelOperator(selectPageBasicSetting(), "User name:");
        }
        selectPageBasicSetting();
        return _lblUserName;
    }

    /** Tries to find "Password:" JLabel in this dialog.
     * @return JLabelOperator
     */
    public JLabelOperator lblPassword() {
        if (_lblPassword==null) {
            _lblPassword = new JLabelOperator(selectPageBasicSetting(), "Password:");
        }
        selectPageBasicSetting();
        return _lblPassword;
    }

    /** Tries to find "Remember password during this session" JCheckBox in this dialog.
     * @return JCheckBoxOperator
     */
    public JCheckBoxOperator cbRememberPasswordDuringThisSession() {
        if (_cbRememberPasswordDuringThisSession==null) {
            _cbRememberPasswordDuringThisSession = new JCheckBoxOperator(selectPageBasicSetting(), "Remember password during this session");
        }
        selectPageBasicSetting();
        return _cbRememberPasswordDuringThisSession;
    }

    /** Tries to find null JPasswordField in this dialog.
     * @return JPasswordFieldOperator
     */
    public JPasswordFieldOperator txtPassword() {
        if (_txtPassword==null) {
            _txtPassword = new JPasswordFieldOperator(selectPageBasicSetting());
        }
        selectPageBasicSetting();
        return _txtPassword;
    }

    /** Tries to find null JTextField in this dialog.
     * @return JTextFieldOperator
     */
    public JTextFieldOperator txtUserName() {
        if (_txtUserName==null) {
            _txtUserName = new JTextFieldOperator(selectPageBasicSetting(), 1);
        }
        selectPageBasicSetting();
        return _txtUserName;
    }

    /** Tries to find null JProgressBar in this dialog.
     * @return JProgressBarOperator
     */
    public JProgressBarOperator prbConnectionProgressBar() {
        if (_prbConnectionProgressBar==null) {
            _prbConnectionProgressBar = new JProgressBarOperator(selectPageBasicSetting());
        }
        selectPageBasicSetting();
        return _prbConnectionProgressBar;
    }

    /** Tries to find null JTextArea in this dialog.
     * @return JTextAreaOperator
     */
    public JTextAreaOperator txtSchemaPanelDescription() {
        if (_txtSchemaPanelDescription==null) {
            _txtSchemaPanelDescription = new JTextAreaOperator(selectPageAdvanced());
        }
        selectPageAdvanced();
        return _txtSchemaPanelDescription;
    }

    /** Tries to find "Select schema:" JLabel in this dialog.
     * @return JLabelOperator
     */
    public JLabelOperator lblSelectSchema() {
        if (_lblSelectSchema==null) {
            _lblSelectSchema = new JLabelOperator(selectPageAdvanced(), "Select schema:");
        }
        selectPageAdvanced();
        return _lblSelectSchema;
    }

    /** Tries to find null JComboBox in this dialog.
     * @return JComboBoxOperator
     */
    public JComboBoxOperator cboSelectSchema() {
        if (_cboSelectSchema==null) {
            _cboSelectSchema = new JComboBoxOperator(selectPageAdvanced());
        }
        selectPageAdvanced();
        return _cboSelectSchema;
    }

    /** Tries to find "Get Schemas" JButton in this dialog.
     * @return JButtonOperator
     */
    public JButtonOperator btGetSchemas() {
        if (_btGetSchemas==null) {
            _btGetSchemas = new JButtonOperator(selectPageAdvanced(), "Get Schemas");
        }
        selectPageAdvanced();
        return _btGetSchemas;
    }

    /** Tries to find null JProgressBar in this dialog.
     * @return JProgressBarOperator
     */
    public JProgressBarOperator prbConnectionProgressBar2() {
        if (_prbConnectionProgressBar2==null) {
            _prbConnectionProgressBar2 = new JProgressBarOperator(selectPageAdvanced());
        }
        selectPageAdvanced();
        return _prbConnectionProgressBar2;
    }


    //****************************************
    // Low-level functionality definition part
    //****************************************

    /** changes current selected tab
     * @param tabName String tab name */
    public void selectDatabaseConnectPage(String tabName) {
        tbpDatabaseConnect().selectPage(tabName);
    }

    /** changes current selected tab to "Basic setting"
     * @return JTabbedPaneOperator of parent tabbed pane
     */
    public JTabbedPaneOperator selectPageBasicSetting() {
        tbpDatabaseConnect().selectPage(_selectPageBasicSetting);
        return tbpDatabaseConnect();
    }

    /** checks or unchecks given JCheckBox
     * @param state boolean requested state
     */
    public void checkRememberPasswordDuringThisSession(boolean state) {
        if (cbRememberPasswordDuringThisSession().isSelected()!=state) {
            cbRememberPasswordDuringThisSession().push();
        }
    }

    /** sets text for txtPassword
     * @param text String text
     */
    public void setPassword(String text) {
        txtPassword().setText(text);
    }

    /** types text for txtPassword
     * @param text String text
     */
    public void typePassword(String text) {
        txtPassword().typeText(text);
    }

    /** gets text for txtUserName
     * @return String text
     */
    public String getUserName() {
        return txtUserName().getText();
    }

    /** sets text for txtUserName
     * @param text String text
     */
    public void setUserName(String text) {
        txtUserName().setText(text);
    }

    /** types text for txtUserName
     * @param text String text
     */
    public void typeUserName(String text) {
        txtUserName().typeText(text);
    }

    /** changes current selected tab to "Advanced"
     * @return JTabbedPaneOperator of parent tabbed pane
     */
    public JTabbedPaneOperator selectPageAdvanced() {
        tbpDatabaseConnect().selectPage(_selectPageAdvanced);
        return tbpDatabaseConnect();
    }

    /** gets text for txtSchemaPanelDescription
     * @return String text
     */
    public String getSchemaPanelDescription() {
        return txtSchemaPanelDescription().getText();
    }

    /** sets text for txtSchemaPanelDescription
     * @param text String text
     */
    public void setSchemaPanelDescription(String text) {
        txtSchemaPanelDescription().setText(text);
    }

    /** types text for txtSchemaPanelDescription
     * @param text String text
     */
    public void typeSchemaPanelDescription(String text) {
        txtSchemaPanelDescription().typeText(text);
    }

    /** returns selected item for cboSelectSchema
     * @return String item
     */
    public String getSelectedSelectSchema() {
        return cboSelectSchema().getSelectedItem().toString();
    }

    /** selects item for cboSelectSchema
     * @param item String item
     */
    public void selectSelectSchema(String item) {
        cboSelectSchema().selectItem(item);
    }

    /** clicks on "Get Schemas" JButton
     */
    public void getSchemas() {
        btGetSchemas().push();
        prbConnectionProgressBar2().waitValue("Connection established");
    }

    /**
     * get name of the selected tab within JTabbedPane (added, not generated)
     * @return name of the selected tab
     */
    public String getSelectedTab() {
        return this.tbpDatabaseConnect().getTitleAt(this.tbpDatabaseConnect().getSelectedIndex());
    }

    //*****************************************
    // High-level functionality definition part
    //*****************************************

    /** Performs verification of ConnectDialogOperator by accessing all its components.
     */
    public void verify() {
        tbpDatabaseConnect();
        lblUserName();
        lblPassword();
        cbRememberPasswordDuringThisSession();
        txtPassword();
        txtUserName();
        prbConnectionProgressBar();
        txtSchemaPanelDescription();
        lblSelectSchema();
        cboSelectSchema();
        btGetSchemas();
        prbConnectionProgressBar2();
    }

    /** Performs simple test of ConnectDialogOperator
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        new ConnectDialogOperator().verify();
        System.out.println("ConnectDialogOperator verification finished.");
    }
}

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.