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-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.jellytools.modules.db;

import org.netbeans.jemmy.operators.*;

/** Class implementing all necessary methods for handling "ConnectOperator" NbDialog.
 *
 * @author Patrik Knakal
 * @version 1.0
 */
public class ConnectOperator extends JDialogOperator {

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

    private JTabbedPaneOperator _tbpJTabbedPane;
    private JTextFieldOperator _txtUserName;
    private JPasswordFieldOperator _txtPassword;
    private JCheckBoxOperator _cbRememberPasswordDuringThisSession;
    private JComboBoxOperator _cboSelectSchema;
    /*
    public static final String ITEM_PBPUBLIC = "PBPUBLIC";
    public static final String ITEM_POINTBASE = "POINTBASE";
    */
    private JButtonOperator _btOK;
    private JButtonOperator _btCancel;


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

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

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

    /** 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 "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 JComboBox in this dialog.
     * @return JComboBoxOperator
     */
    public JComboBoxOperator cboSelectSchema() {
        if (_cboSelectSchema==null) {
            _cboSelectSchema = new JComboBoxOperator(selectPageAdvanced());
        }
        selectPageAdvanced();
        return _cboSelectSchema;
    }

    /** Tries to find "OK" JButton in this dialog.
     * @return JButtonOperator
     */
    public JButtonOperator btOK() {
        if (_btOK==null) {
            _btOK = new JButtonOperator(this, "OK");
        }
        return _btOK;
    }

    /** Tries to find "Cancel" JButton in this dialog.
     * @return JButtonOperator
     */
    public JButtonOperator btCancel() {
        if (_btCancel==null) {
            _btCancel = new JButtonOperator(this, "Cancel");
        }
        return _btCancel;
    }


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

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


    /**
     * changes current selected tab ... non blocking operation (added, not generated)
     * @param tabName String tab name
     */
    public void selectJTabbedPanePageNoBlock(String tabName) {
        final String tabNameTmp = tabName;
        new Thread(
                   new Runnable() {
                       public void run() {
                           tbpJTabbedPane().selectPage(tabNameTmp);
                       }
                   }).start();
    }


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


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

    /** 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);
    }

    /** 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);
    }

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

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

    /** 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);
    }

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

    /** clicks on "OK" JButton
     */
    public void oK() {
        btOK().push();
    }


    /**
     * clicks on "OK" JButton ... non blocking operation (added, not generated)
     */
    public void oKNoBlock() {
        btOK().pushNoBlock();
    }


    /** clicks on "Cancel" JButton
     */
    public void cancel() {
        btCancel().push();
    }


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

    /** Performs verification of ConnectOperator by accessing all its components.
     */
    public void verify() {
        tbpJTabbedPane();
        txtUserName();
        txtPassword();
        cbRememberPasswordDuringThisSession();
        cboSelectSchema();
        btOK();
        btCancel();
    }

    /** Performs simple test of ConnectOperator
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        new ConnectOperator().verify();
        System.out.println("ConnectOperator 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.