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.
 */

/*
 * File PropertiesEditorOperator.java
 *
 * Created on 24.9.02 18:18
 *
 * Description :
 *
 * This is operator used in autometed tests for netBenas dev. version. Operator has been
 * writed in Jelly2 ( see testtools.netbeans.org )
 *
 *
 */


package org.netbeans.properties.jelly2tests.operators;


import java.util.*;
import javax.swing.*;
import org.netbeans.jellytools.*;
import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.actions.*;
import org.netbeans.jellytools.nodes.*;
import org.netbeans.jellytools.properties.*;
import org.netbeans.jellytools.properties.editors.StringCustomEditorOperator;
import org.netbeans.jemmy.*;
import org.netbeans.jemmy.operators.*;


/** Class implementing all necessary methods for handling Property sheet in Editor window.
 * This class is used for automated tests of properties module.
 * @author Petr Felenda ( e-mail petr.felenda@sun.com )
 * @version 1
 */
public class PropertiesEditorOperator {
    
    /*
     * declaration of members variables
     */
    private final String TITLE_ADD_LOCALE_DIALOG = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "CTL_NewLocaleTitle");    // String : New Locale
    private final String TITLE_NEW_PROPERTY_DIALOG = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "CTL_NewPropertyTitle");    // String : New Property
    private final String TITLE_HELP_DIALOG = "Help";
    private final String TITLE_ERROR_DIALOG = Bundle.getStringTrimmed("org.openide.Bundle", "NTF_ErrorTitle");  // String : Error
    private final String TITLE_SAVE_QUESTION_DIALOG = Bundle.getStringTrimmed("org.openide.text.Bundle", "LBL_SaveFile_Title");    // String : Question
    private final String TITLE_QUESTION_DIALOG = "Question";    // String : Question
    private final String TITLE_CUSTOMIZE_LOCALES_DIALOG = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "CTL_Customizer_dialog_title");  // String : Customizer Dialog
    private final String TITLE_CUSTOMIZE_PROPERTIES_DIALOG = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "CTL_Customizer_dialog_title");   // The same string as last one
    private final String TITLE_DIALOG_CONFIRM_OBJECT_DELETION = Bundle.getStringTrimmed("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle");    // String : Confirm Object deletion
    private final String TITLE_DELETE_MORE_LOCALES_CONFIRMATION_DIALOG = Bundle.getStringTrimmed("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectsTitle");    // String : Confirm Multiple Object Deletion
    private final String TITLE_WELCOME = Bundle.getStringTrimmed("org.netbeans.modules.welcome.Bundle", "LBL_Tab_Title"); // String Welcome
    private final String TITLE_PROPERTIES_WINDOW_TABLE = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "CTL_FMT_GlobalProperties");  // String : Properties of
    private final String TITLE_PROPERTIES_WINDOW_TAB = Bundle.getStringTrimmed("org.openide.nodes.Bundle", "Properties");    // String : Properties
    
    private final String BUTTON_NAME_NEW_PROPERTY = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "LBL_AddPropertyButton"); // String : New Property
    private final String BUTTON_NAME_REMOVE_PROPERTY = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "LBL_RemovePropertyButton");   // String : Remove Property
    private final String BUTTON_NAME_REMOVE_LOCALE = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "CTL_RemoveLocale");   // String : Remove Locale
    private final String BUTTON_NAME_ADD_LOCALE = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "CTL_AddLocale"); // String : Add Locale
    private final String BUTTON_NAME_ADD_KEY = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "CTL_AddKey");   // String : Add Key
    private final String BUTTON_NAME_REMOVE_KEY = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "CTL_RemoveKey"); // String : Remove Key
    private final String BUTTON_NAME_YES = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "YES_OPTION_CAPTION");   // String : Yes
    private final String BUTTON_NAME_NO = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "NO_OPTION_CAPTION"); // String : No
    private final String BUTTON_NAME_DISCARD = "Discard";
    
    private final String POPUP_MENU_ADD_LOCALE = Bundle.getStringTrimmed("org.openide.actions.Bundle", "NewArg")+Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "LAB_NewLocaleAction");   // String : Add Locale...
    private final String POPUP_MENU_CUSTOMIZE = Bundle.getStringTrimmed("org.openide.actions.Bundle", "Customize");    // String : Customize
    private final String POPUP_MENU_ADD_PROPERTY = Bundle.getStringTrimmed("org.openide.actions.Bundle", "NewArg")+Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "LAB_NewPropertyAction");  // String : Add Property
    private final String POPUP_MENU_DELETE_LOCALE = Bundle.getStringTrimmed("org.openide.actions.Bundle", "Delete");;   // String : Delete
    private final String POPUP_MENU_EDIT = Bundle.getStringTrimmed("org.openide.actions.Bundle", "Edit");  // String : Edit
    
    private final String LABEL_KEY = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "LBL_KeyLabel"); // String : Key
    private final String LABLE_VALUE = Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "LBL_ValueLabel"); // String : Value
    private final String RESOURCE_BUNDLE_COMMENT = " Sample ResourceBundle properties file\n\n";
    
    private final String EXCEPTION_TEXT = "Text typing";
    
    private final String WIZARD_TREE_STRING = Bundle.getStringTrimmed("org.netbeans.modules.text.Bundle", "Templates/Other")+"|"+Bundle.getStringTrimmed("org.netbeans.modules.properties.Bundle", "Templates/Other/properties.properties"); // String : "Other|Properties File";
    
    
    /** This constructor only creates operator's object and then does nothing. */
    public PropertiesEditorOperator() {
    }
    
    
    /** This method opens file in editor. There is used popup menu in explorer.
* Usage :
* FilesystemNode filesystemNode = new FilesystemNode(
* System.getProperty("netbeans.user") +
* File.separator +
* "sampledir");
*
* openExistedPropertiesFile(filesystemNode.getPath()+"|"+"myFile");
* @param filePath of existed file in explorer ( without extension ) */ public void openExistedPropertiesFile(String filePath) { new OpenAction().performPopup(new FilesystemNode(filePath)); new EventTool().waitNoEvent(2500); } /** This method opens file in editor. There is used popup menu in explorer for this action. * @param filesystemNode of mounted directory ( without extension ) * @param filePath of file in explorer tree */ public void openExistedPropetiesFileInClassicEditor(FilesystemNode filesystemNode, String filePath) { new EditAction().performPopup(new Node(filesystemNode,filePath)); } /** It creates new property file. There is used popup menu from explorer. * @param filesystemNode node of tree, where file will be created * @param filePath of file without extension */ public void createNewPropertiesFile(FilesystemNode filesystemNode, String filePath) { NewWizardOperator newWizard = NewWizardOperator.invoke(filesystemNode, this.WIZARD_TREE_STRING); new NewObjectNameStepOperator().setName(filePath); newWizard.finish(); } /** It clicks to the 'New property' button in properties editor ( table view ) */ public void propertiesEditorClickNewPropertyButton(String fileName) { JButtonOperator jButtonOperator = new JButtonOperator(new TopComponentOperator(fileName),this.BUTTON_NAME_NEW_PROPERTY); jButtonOperator.pushNoBlock(); new EventTool().waitNoEvent(250); } /** This pushs 'Remove property' button in properties editor form. */ public void propertiesEditorClickRemovePropertyButton(String fileName) { JButtonOperator jButtonOperator = new JButtonOperator(new TopComponentOperator(fileName),this.BUTTON_NAME_REMOVE_PROPERTY); jButtonOperator.pushNoBlock(); } /** This opens popup menu over tab in properties file and chooses close item from it. */ public void propertiesEditorCloseFromTabPane() throws Exception { throw new Exception("Do not use this method. Not defined in Operator yet"); } /** This deletes properties file from disk. There is used popup menu in Explorer. * @param filesystemNode of tree, where file is stored ( without file name ) * @param filePath of file to delete */ public void deletePropertiesFileFromExplorer(FilesystemNode filesystemNode, String filePath) { PropertiesNode propNode = new PropertiesNode(filesystemNode, filePath); propNode.delete(); new NbDialogOperator(this.TITLE_DIALOG_CONFIRM_OBJECT_DELETION).yes(); } /** This closes properties file. There is used popup menu in Explorer. * @param filesystemNode of tree, where file is stored ( without file name ) * @param filePath of file to delete */ public void closePropertiesFile(String fileName) { TopComponentOperator tco = new TopComponentOperator(fileName); tco.close(); //new NbDialogOperator(this.TITLE_SAVE_QUESTION_DIALOG).btNo(); } /** This fill three textafields in 'New property' dialog. * @param key which will be filled to appeared dialog 'New property' * @param value of key, which will be filled to appeared dialog 'New property' * @param comment of key, which will be filles to appeared dialog 'New property' * @throws Exception is throws if appeared */ public void newPropertyDialogFill(String fileName, String key, String value, String comment) throws Exception { new EventTool().waitNoEvent(250); boolean finished = false; do { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_NEW_PROPERTY_DIALOG); ContainerOperator containerOperator = new ContainerOperator(nbDialogOperator); int limit = 0; try { JTextFieldOperator jTextFieldOperator = null; if ( key != null ) { jTextFieldOperator = new JTextFieldOperator(containerOperator, 0); jTextFieldOperator.typeText(key); } if ( value != null ){ jTextFieldOperator = new JTextFieldOperator(containerOperator, 1); jTextFieldOperator.typeText(value); } if ( comment != null ){ jTextFieldOperator = new JTextFieldOperator(containerOperator, 2); jTextFieldOperator.typeText(comment); } finished = true; } catch ( TimeoutExpiredException ex) { //if ( ex.getMessage().equals(this.EXCEPTION_TEXT) == false ) // throw new Exception(ex.getMessage()); // if problems occurs then use this code to wake up dialog anyway // close the dialog and open it anyway newPropertyDialogClickCancelButton(); propertiesEditorClickNewPropertyButton(fileName); } JButtonOperator bo = new JButtonOperator(containerOperator); bo.requestFocus(); if ( limit++ >= 3 ) finished = true; } while ( finished == false ); } /** This closes 'New property' dialog. There is used close button for this action in * this dialog. ( dialog must be open ) */ public void newPropertyDialogClickCloseButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_NEW_PROPERTY_DIALOG); //nbDialogOperator.btOK().requestFocus(); //nbDialogOperator.btOK().pushNoBlock(); nbDialogOperator.ok(); System.out.println(">> Ok button pushed"); } /** This closes dialog as in previous method, but there is used no block action for closing dialog. */ public void newPropertyDialogClickOkButtonNoBlock() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_NEW_PROPERTY_DIALOG); //nbDialogOperator.btOK().pushNoBlock(); nbDialogOperator.ok(); } /** There will be found adequte key in property sheet and then will be checked value and comment. If kye will not found then method fail. * @param key which will be compared with key in properties file * @param value of key which will be compared with value in properties file * @param comment of key witch will be compared with comment in propertiies file * @param rowOfCheckedProperty is number of compared propererty in properties file (row position >=0) * @param localeCount is count of locales in properties file, new file has 1 locale (default) * @param rowCount is count of rows (properties) in properties file * @throws Exception if an appeared */ public void checkPropertiesInSheet(String fileName, String key, String value, String comment, int rowOfCheckedProperty, int localeCount, int rowCount) throws Exception { if ( key == null ) key = ""; if ( value == null ) value = ""; if ( comment == null ) comment = ""; // Checking texfields ( Comment and Key ) under table. // ================================================== TopComponentOperator tco = new TopComponentOperator(fileName); JTable jTable = JTableOperator.findJTable(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser("")); if ( rowOfCheckedProperty == 1 ) { // first row is not normal bacause there is comment of file in it + comment of the property comment = this.RESOURCE_BUNDLE_COMMENT.concat(comment); } // click to key field in table // WA the next two rows are work around of jemmy because the action clickOnCell+waitEmpty is not // WA the same as user event called from mouse, keyboard new JTableOperator(jTable).clickOnCell(rowOfCheckedProperty-1 ,1); new EventTool().waitNoEvent(500); // END OF WA new JTableOperator(jTable).clickOnCell(rowOfCheckedProperty-1 ,0); JTextArea jTextArea = JTextAreaOperator.findJTextArea(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),0); if ( jTextArea == null ) System.out.println("> Comment textarea is null"); else { System.out.println("> Comment textarea is found."); if ( ! jTextArea.getText().equals(comment) ) { System.out.println("textarea == string : \""+jTextArea.getText()+"\" == \""+comment+"\""); throw new Exception("Comment is not equal to the specified string. (comparing in textarea under the table)"); } else System.out.println("> Comment is Ok in textarea under the table."); } if ( rowCount == 0 ) { // if label == key then compare key else comapre value JLabel jLabel = JLabelOperator.findJLabel(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),1); String label = jLabel.getText(); System.out.println("> label = "+label); if ( this.LABEL_KEY.equals(label) ) { jTextArea = JTextAreaOperator.findJTextArea(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),1); if ( jTextArea == null ) System.out.println("> Key textarea is null"); else { System.out.println("> Key textarea is found."); if ( ! jTextArea.getText().equals(key) ) { System.out.println("textarea == string : "+jTextArea.getText()+" == "+key); throw new Exception("Key is not equal to the specified string. (comparing in textarea under the table)"); } else System.out.println("> Key is Ok in textarea under the table."); } } else if ( this.LABLE_VALUE.equals(label) ) { jTextArea = JTextAreaOperator.findJTextArea(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),1); if ( jTextArea == null ) System.out.println("> Value textarea is null"); else { System.out.println("> Value textarea is found."); if ( ! jTextArea.getText().equals(value) ) { System.out.println("textarea == string : "+jTextArea.getText()+" == "+value); throw new Exception("Value is not equal to the specified string. (comparing in textarea under the table)"); } else System.out.println("> Value is Ok in textarea under the table."); } } else throw new Exception("Label of Key or Value textarea is corrupted!"); } else { System.out.println("More rows in table (rows>0)"); // comapre key and then compare value System.out.println(">Click to row"+rowOfCheckedProperty); // click to value field in table new JTableOperator(jTable).clickOnCell(rowOfCheckedProperty-1,1); jTextArea = JTextAreaOperator.findJTextArea(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),1); if ( jTextArea == null ) System.out.println("> Value textarea is null"); else { System.out.println("> Value textarea is found."); if ( ! jTextArea.getText().equals(value) ) { System.out.println("textarea == string : "+jTextArea.getText()+" == "+value); throw new Exception("Value is not equal to the specified string. (comparing in textarea under the table)"); } else System.out.println("> Value is Ok in textarea under the table."); } // click to key fild in table new JTableOperator(jTable).clickOnCell(rowOfCheckedProperty-1 ,0); jTextArea = JTextAreaOperator.findJTextArea(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),1); if ( jTextArea == null ) System.out.println("> Key textarea is null"); else { System.out.println("> Key textarea is found."); if ( ! jTextArea.getText().equals(key) ) { System.out.println("textarea == string : "+jTextArea.getText()+" == "+key); throw new Exception("Key is not equal to the specified string. (comparing in textarea under the table)"); } else System.out.println("> Key is Ok in textarea under the table."); } } // Checking table new EventTool().waitNoEvent(250); // find in table if any key which matchs to the parametr int index = -1; if ( jTable != null ) { if ( jTable.getRowCount() == rowCount && rowCount == 0 ) { System.out.println("> There is no rows in table. (OK)"); return; } else if ( rowCount == 0 ) System.out.println("> Table shouldn't have any row!(There is "+jTable.getRowCount()+" rows)"); if ( key != null ) for ( int ii = 0; ii < jTable.getModel().getRowCount(); ii++) { // check if is the key in properties file more times new EventTool().waitNoEvent(250); if ( index >= 0 && jTable.getModel().getValueAt(ii,0).toString().equals(key) == true ) { throw new Exception("The added key is more times in properties sheet."); } if ( index == -1 && jTable.getModel().getValueAt(ii,0).toString().toString().equals(key) == true ) { index = ii; // check value of property if is equal to the value if ( jTable.getModel().getValueAt(ii,1).toString().toString().equals(value) == false ) throw new Exception("Value doesn't match. "+ ii +" - ("+ value + " not equals "+ jTable.getCellEditor(ii, 1).getCellEditorValue().toString() ); // check comment new JTableOperator(jTable).clickOnCell(ii,0); new EventTool().waitNoEvent(250); // check comment of property if is equal to the comment if ( new JTextAreaOperator(new ContainerOperator(tco.getContainer(ComponentSearcher.getTrueChooser(""))),0).getText().equals(comment) == false ) throw new Exception("Comment doesn't match. "+ ii +" : \n>"+ comment + "< not equals with : >"+ new JTextAreaOperator(new ContainerOperator(tco.getContainer(ComponentSearcher.getTrueChooser(""))),0).getText()+"<\n" ); if ( ii+1 != rowOfCheckedProperty ) throw new Exception("Property is not in the right row in property sheet."); } } if ( index < 0 && rowOfCheckedProperty >= 0) throw new Exception("Key not found in properties sheet"); if ( localeCount >= 0 && localeCount != jTable.getModel().getColumnCount() - 1 ) { int locales = jTable.getModel().getColumnCount()-1; throw new Exception("Count of locales (columns-1) doesn't match. ("+ localeCount +"<>"+ locales +")"); } if ( rowCount >= 0 && rowCount != jTable.getModel().getRowCount() ) throw new Exception("Count of properties (rows) doesn't match. ("+rowCount+"<>"+jTable.getModel().getRowCount()+")"); } else throw new Exception("Cann't find JTable in Editor Window"); } /** This method check pleces of keys, values and comments in properties file (in * text mode) * @throws Exception if an appeared */ public void checkPropertiesFileIntegrityInClassicEditor(String fileName) throws Exception { // open properties file in classic editor and them chek spaces, comments, keys, values // and their positions EditorOperator eo = new EditorOperator(fileName); String content = eo.getText(); StringTokenizer strT = new StringTokenizer(content,"\n",true); String row = ""; try { for ( int ii = 0; ii < strT.countTokens(); ii++ ) { // comment of file if ( ii == 0 ) { row = strT.nextToken(); if ( row.charAt(0) != '#' ) throw new Exception("Structure of properties file has been corrupted"); // end row row = strT.nextToken(); try { // free row or end of file row = strT.nextToken(); } catch ( NoSuchElementException ex ) { // no properties in file return; } } // comment of property row = strT.nextToken(); // comment of property if ( row.charAt(0) != '#' ) throw new Exception("Structure of properties file has been corrupted"); // end row row = strT.nextToken(); // key and value of property row = strT.nextToken(); StringTokenizer strT2 = new StringTokenizer(row); String key = strT2.nextToken("=\n"); String value = strT2.nextToken("=\n"); if ( key == null || value == null ) throw new Exception("Structure of properties file has been corrupted"); } } catch ( NoSuchElementException ex ) { throw new Exception("Structure of properties file has been corrupted"); } } /** It clicks on 'Help' button in 'New property' dialog. */ public void newPropertyDialogClickHelpButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_NEW_PROPERTY_DIALOG); nbDialogOperator.help(); } /** Closes 'Help' window. */ public void closeHelp() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_HELP_DIALOG); nbDialogOperator.close(); } /** Closes 'Error' dialog. This dialog appeared after property is added with existed key. (Key which * exists in properties file) */ public void errorDialogClickOkButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_ERROR_DIALOG); nbDialogOperator.ok(); } /** Closes 'New property' dialog. There is used 'Cancel' button. */ public void newPropertyDialogClickCancelButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_NEW_PROPERTY_DIALOG); nbDialogOperator.cancel(); } /** This selectes row in sheet of properties in properties editor. * @param rowNumber is number of row in property sheet * @throws Exception if an appeared */ public void selectPropertiesFileItem(String fileName, int rowNumber) throws Exception { TopComponentOperator tco = new TopComponentOperator(fileName); JTable jTable = JTableOperator.findJTable(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser("")); new EventTool().waitNoEvent(250); // find in table if any key match to the parametr if ( jTable != null ) { JTableOperator jTableOperator = new JTableOperator(jTable); jTableOperator.getTimeouts().setTimeout("JScrollBarOperator.WholeScrollTimeout", 240000); jTableOperator.clickOnCell(rowNumber,1); return; } throw new Exception("Info : Cannot select item id properties table."); } /** There will be counted rows in property sheet in properties editor. * @return counts of rows in property sheet * * @throws Exception if an appeared */ public int getPropertiesFileItemsCount(String fileName) throws Exception { TopComponentOperator tco = new TopComponentOperator(fileName); JTable jTable = JTableOperator.findJTable(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser("")); new EventTool().waitNoEvent(250); // find in table if any key match to the parametr if ( jTable != null ) return jTable.getModel().getRowCount(); return -1; } /** Clicks to button 'Ok' in Quiestion dialog. This dialog appeared after pushing 'Remove Property' button. */ public void questionDialogClickOkButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_SAVE_QUESTION_DIALOG); nbDialogOperator.ok(); } public void questionDialogClickDiscardButton() { QuestionDialogOperator qdo = new QuestionDialogOperator(TITLE_QUESTION_DIALOG); JButtonOperator jbo = new JButtonOperator(qdo,BUTTON_NAME_DISCARD); jbo.pushNoBlock(); } /** Clicks to 'Cancel' button in 'Question' dialog. This dialog appeared after pushing 'Remove Property' button in * properties editor. */ public void questionDialogClickCancelButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_SAVE_QUESTION_DIALOG); nbDialogOperator.cancel(); } /** Method createNewPropertiesFileToClassicEditor() * @param filesystemNode is node of filesystem in which is file located in Explorer * @param fileName is name of file */ public void createNewPropertiesFileAndOpenInClassicEditor(FilesystemNode filesystemNode, String fileName) { // create new file NewWizardOperator newWizard = NewWizardOperator.invoke(filesystemNode, this.WIZARD_TREE_STRING); new NewObjectNameStepOperator().setName(fileName); newWizard.finish(); new EventTool().waitNoEvent(250); // close Properties Editor TopComponentOperator tco = new TopComponentOperator(fileName); tco.close(); // There is problem while writing tests becasuse we must have opened some source files. //new EditorWindowOperator().close(); /* JTabbedPaneOperator jTabbedPaneOperator = new EditorWindowOperator().tbpEditorTabbedPane(); if ( jTabbedPaneOperator != null && jTabbedPaneOperator.findPage(this.TITLE_WELCOME) < 0 ) { CloseViewAction cva = new CloseViewAction(); //jTabbedPaneOperator.selectPage(fileName); cva.performPopup(jTabbedPaneOperator); } else { // close whole editor becase there is no tabs in editor new EditorWindowOperator().close(); } */ // open classic editor from popup menu in Explorer window //ExplorerOperator explorerOperator = new ExplorerOperator(); RepositoryTabOperator eplorer = new RepositoryTabOperator(); new FilesystemNode(filesystemNode.getPath().concat("|").concat(fileName)).performPopupAction(this.POPUP_MENU_EDIT); } /** Open 'Add Locale..' dialog and do nothing * @param filesystemNode is node of filesystem in which is file located in Explorer * @param filePath is path to file in tree in Explorer */ public void openAddLocaleDialogFromExplorer(FilesystemNode filesystemNode,String filePath) { new ActionNoBlock(null,this.POPUP_MENU_ADD_LOCALE).performPopup(new Node(filesystemNode,filePath)); } /** Fills values to 'Add Locale...' dialog. ( use null values if nothig to be filed ) * @param languageCode is Language Code e.g. cs, de, en or other staff * @param countryCode is Country Code e.g. CZ, DE, US or other stuff * @param variant is variant of locale, this should be empty or should will have value e.g. EURO * @param filesystemNode is node of tree in explorer * @param fileName is name of file * @throws Exception if an appeared */ public void addLocaleDialogFill(String languageCode, String countryCode, String variant, FilesystemNode filesystemNode, String fileName) throws Exception { new EventTool().waitNoEvent(250); boolean finished = false; do { try { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_ADD_LOCALE_DIALOG); //ContainerOperator containerOperator = new ContainerOperator(nbDialogOperator); JComboBoxOperator jComboBoxOperator; jComboBoxOperator = new JComboBoxOperator(nbDialogOperator, 0); if ( languageCode != null ) { jComboBoxOperator.typeText(languageCode); } else { jComboBoxOperator.typeText(""); } jComboBoxOperator = new JComboBoxOperator(nbDialogOperator, 1); if ( countryCode != null ){ jComboBoxOperator.typeText(countryCode); } else { jComboBoxOperator.typeText(""); } jComboBoxOperator = new JComboBoxOperator(nbDialogOperator, 2); if ( variant != null ){ jComboBoxOperator.typeText(variant); } else { jComboBoxOperator.typeText(""); } finished = true; System.out.println("Set languge: "+new JComboBoxOperator(nbDialogOperator, 0).getTextField().getText()); System.out.println("Set country: "+new JComboBoxOperator(nbDialogOperator, 1).getTextField().getText()); //nbDialogOperator.ge } catch ( TimeoutExpiredException ex) { if ( ex.getMessage().equals(this.EXCEPTION_TEXT) == false ) throw new Exception(ex.getMessage()); // if problems occurs then use this code to wake up dialog anyway // close the dialog and open it anyway addLocaleDialogClickCancelButton(); openAddLocaleDialogFromExplorer(filesystemNode, fileName); } } while ( finished == false ); new EventTool().waitNoEvent(250); } /** Clicks to 'Help' button in 'Add Locale...' dialog. */ public void addLocaleDialogClickHelpButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_ADD_LOCALE_DIALOG); nbDialogOperator.help(); } /** Clicks to 'Ok' button in 'Add Locale...' dialog. */ public void addLocaleDialogClickOkButtonNoBlock() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_ADD_LOCALE_DIALOG); //nbDialogOperator.btOK().requestFocus(); //nbDialogOperator.btOK().pushNoBlock(); nbDialogOperator.ok(); } /** Clicks to 'Cancel' button in 'Add Locale...' dialog. */ public void addLocaleDialogClickCancelButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_ADD_LOCALE_DIALOG); nbDialogOperator.cancel(); } /** Opens Customizer dialog. * @param filesystemNode node of filesystem in tree in explorer * @param path to the object you can customize */ public void openCustomizeLocalesDialogFromExplorer(FilesystemNode filesystemNode,String path) { new ActionNoBlock(null,this.POPUP_MENU_CUSTOMIZE).performPopup(new Node(filesystemNode,path)); } /** Clicks to 'Add Locale...' button in customizer. */ public void customizeLocalesDialogClickAddLocaleButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_LOCALES_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_ADD_LOCALE); jButtonOperator.pushNoBlock(); } /** Clicks to 'Remove Locale' button in customizer. */ public void customizeLocalesDialogClickRemoveLocaleButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_LOCALES_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_REMOVE_LOCALE); jButtonOperator.pushNoBlock(); } /** Clicks to 'Help' button in customizer. */ public void customizeLocalesDialogClickHelpButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_LOCALES_DIALOG); //nbDialogOperator.btHelp().pushNoBlock(); nbDialogOperator.help(); } /** Clicks to 'Close' button in customizer. */ public void customizeLocalesDialogClickCloseButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_LOCALES_DIALOG); //nbDialogOperator.btClose().pushNoBlock(); nbDialogOperator.close(); } /** Selects focus adequate to locale in customizer * @param row of locale you wish to select */ public void customizeLocalesDialogSelectLocale(int row) { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_LOCALES_DIALOG); JListOperator jListOperator = new JListOperator( new ContainerOperator(nbDialogOperator) ); jListOperator.selectItem(row-1); } /** This checks if has been selected 'Remove Locale' button. * @return true if locale button has been selected */ public boolean customizeLocalesDialogIsEnabledRemoveLocaleButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_LOCALES_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_REMOVE_LOCALE); return jButtonOperator.isEnabled(); } /** Opens 'Add Property' dialog from explorer. * @param filesystemNode is node of tree in explorer * @param path of file in tree in explorer */ public void openAddPropertyDialogFromExplorer(FilesystemNode filesystemNode, String path) { new ActionNoBlock(null,this.POPUP_MENU_ADD_PROPERTY).performPopup(new Node(filesystemNode,path)); } public void openCustomizePropertiesDialogFromExplorer(FilesystemNode fileNode, String path) { new ActionNoBlock(null,this.POPUP_MENU_CUSTOMIZE).performPopup(new Node(fileNode,path)); } public void customizePropertiesDialogClickHelpButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_PROPERTIES_DIALOG); //nbDialogOperator.btHelp().pushNoBlock(); nbDialogOperator.help(); } public void customizePropertiesDialogClickCloseButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_PROPERTIES_DIALOG); //nbDialogOperator.btClose().pushNoBlock(); nbDialogOperator.close(); } public void customizePropertiesDialogClickAddKeyButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_PROPERTIES_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_ADD_KEY); jButtonOperator.pushNoBlock(); } public void customizePropertiesDialogClickRemovePropertyButton(){ NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_PROPERTIES_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_REMOVE_KEY); jButtonOperator.requestFocus(); jButtonOperator.pushNoBlock(); } public boolean customizePropertiesDialogIsEnableRemovePropertyButton() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_PROPERTIES_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_REMOVE_KEY); return jButtonOperator.isEnabled(); } public void customizePropertiesDialogSelectProperty(int row) { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_CUSTOMIZE_PROPERTIES_DIALOG); JListOperator jListOperator = new JListOperator( new ContainerOperator(nbDialogOperator) ); jListOperator.selectItem(row-1); } public void deleteLocaleFromExplorer(FilesystemNode fileNode, String path) { new ActionNoBlock(null,this.POPUP_MENU_DELETE_LOCALE).performPopup(new Node(fileNode,path)); } public void confirmationDeleteteLocaleDialogClickYes() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_DIALOG_CONFIRM_OBJECT_DELETION); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_YES); jButtonOperator.pushNoBlock(); } public void confirmationDeleteteMoreLocalesDialogClickYes() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_DELETE_MORE_LOCALES_CONFIRMATION_DIALOG); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_YES); jButtonOperator.pushNoBlock(); } public void confirmationDeleteteLocaleDialogClickNo() { NbDialogOperator nbDialogOperator = new NbDialogOperator(this.TITLE_DIALOG_CONFIRM_OBJECT_DELETION); JButtonOperator jButtonOperator = new JButtonOperator( new ContainerOperator(nbDialogOperator),this.BUTTON_NAME_NO); jButtonOperator.pushNoBlock(); } public int checkEditorTabCount() { return -1; } public void deleteMoreLocalesInExplorer(String[] Languages, String[] Countres, String[] Varians, FilesystemNode fileNode, String path_to_group) { Node[] nodes = new Node[Languages.length]; for ( int ii = 0; ii < Languages.length; ii++ ) { String path = path_to_group.concat("|").concat(Languages[ii]).concat("_").concat(Countres[ii]); System.out.println(">> path = "+ path); nodes[ii] = new Node(fileNode, path); } new DeleteAction().performPopup(nodes); } public void explorerSelectPath(String treePath, FilesystemNode filesystemNode) { Node node = new Node(filesystemNode,treePath); node.select(); } public void propertiesWindowChangeProperty(String objectName, String propertyName, String newValue) { PropertySheetOperator.invoke(); PropertySheetOperator pso = new PropertySheetOperator(this.TITLE_PROPERTIES_WINDOW_TABLE.concat(objectName)); //PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, this.TITLE_PROPERTIES_WINDOW_TAB); StringProperty pr = new StringProperty(pso, propertyName); pr.setValue(newValue); new EventTool().waitNoEvent(250); /* StringCustomEditorOperator stringCustomizerEditorOperator = pr.setinvokeCustomizer(); stringCustomizerEditorOperator.setStringValue(newValue); new EventTool().waitNoEvent(250); stringCustomizerEditorOperator.btOK().requestFocus(); new EventTool().waitNoEvent(250); stringCustomizerEditorOperator.btOK().pushNoBlock(); new EventTool().waitNoEvent(250);*/ } public void checkLocalesInExplorer(java.lang.String[] locales, FilesystemNode filesystemNode, java.lang.String fileName) throws Exception { new EventTool().waitNoEvent(300); org.openide.filesystems.FileSystem fileSytem = org.openide.filesystems.Repository.getDefault().findFileSystem(filesystemNode.getPath()); Node node = new Node(filesystemNode,fileName); String[] strs = node.getChildren(); if ( strs.length != locales.length ) { throw new Exception("> There is bad count of locales in Explorer window. ("+strs.length+"<>"+locales.length+")"); } for ( int ii = 0 ; ii < locales.length; ii++) if ( strs[ii].compareTo(locales[ii]) != 0 ) throw new Exception("> There is bad locale name in Explorer window. ("+strs[ii]+"<>"+locales[ii]+")"); } public boolean existsFileInExplorer() { return true; } public void requestFocusEditorPane(String nameOfTab) { TopComponentOperator tco = new TopComponentOperator(nameOfTab); tco.requestFocus(); /*EditorWindowOperator ewo = new EditorWindowOperator(); EditorOperator eo = ewo.getEditor(nameOfTab); eo.requestFocus();*/ } public void tableViewClickTo(String fileName, int row, int column) { TopComponentOperator tco = new TopComponentOperator(fileName); JTable jTable = JTableOperator.findJTable(tco.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser("")); new JTableOperator(jTable).clickOnCell(row,column); } public boolean existsFileInEditor(java.lang.String fileName) { TopComponentOperator tco = new TopComponentOperator(fileName); //EditorOperator ewo = new EditorOperator(fileName); return true; } }
... 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.