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.test.java.gui.customizers;

import junit.textui.TestRunner;
import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.ExplorerOperator;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.RepositoryTabOperator;
import org.netbeans.jellytools.modules.java.ClassCustomizerOperator;
import org.netbeans.jellytools.modules.java.NewIdentifierOperator;
import org.netbeans.jellytools.nodes.JavaNode;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.test.java.Utilities;

public class ClassCustomizer extends JellyTestCase {
    
    private static final String NAME_TEST_FILE = "TestFile";
    private static final String NAME_TEST_RENAMED = "TestClass";
    private static final String NAME_TEST_INTERFACE = "TestInterface";
    private static final String NAME_DATA_DIR = "org/netbeans/test/java/gui/customizers/data/";
    
    /** Need to be defined because of JUnit */
    public ClassCustomizer(String name) {
        super(name);
    }
    
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new ClassCustomizer("testAddClass"));
        suite.addTest(new ClassCustomizer("testAddInterface"));
        suite.addTest(new ClassCustomizer("testCustomizeClass"));
        suite.addTest(new ClassCustomizer("testCustomizeInterface"));
        return suite;
    }
    
    /** Use for execution inside IDE */
    public static void main(java.lang.String[] args) {
        // run whole suite
        junit.textui.TestRunner.run(suite());
        // run only selected test case
        //TestRunner.run(new ClassCustomizer("testCustomizeInterface"));
    }
    
    /** setUp method  */
    public void setUp() {
        System.out.println("########  "+getName()+"  #######");
        RepositoryTabOperator.invoke();
    }
    
    /** tearDown method */
    public void tearDown() {
    }
    
    public void testCustomizeClass() {
        //create test file
        Utilities.copyToSampleDir(NAME_DATA_DIR +  NAME_TEST_FILE + ".java");
        
        customizeClass();
        
        ref(Utilities.getAsString(NAME_TEST_RENAMED + ".java"));
        
        Utilities.saveAll();
        Utilities.delete(NAME_TEST_RENAMED + ".java");
        compareReferenceFiles();
    }
    
    private void customizeClass() {
        //add class
        ExplorerOperator explorerOperator = new ExplorerOperator();
        explorerOperator.selectPageFilesystems();
        Node repositoryRootNode = explorerOperator.repositoryTab().getRootNode();
        JavaNode testFile = new JavaNode(repositoryRootNode, Utilities.getSampleDir().getDisplayName()+"|"+NAME_TEST_FILE + "|class " + NAME_TEST_FILE);
        testFile.select();
        testFile.performPopupActionNoBlock(Bundle.getString("org.openide.actions.Bundle", "Customize"));
        
        //customize it
        final ClassCustomizerOperator classCustomizer = new ClassCustomizerOperator(Bundle.getString("org.netbeans.core.Bundle", "CTL_Customizer_dialog_title"));
        classCustomizer.typeName(NAME_TEST_RENAMED);
        classCustomizer.typeSuperClass("javax.swing.JComponent");
        classCustomizer.selectAccess("public");
        classCustomizer.checkFinal(true);
        classCustomizer.checkAbstract(true);
        Thread thread = new Thread( new java.lang.Runnable() {
            public void run() {
                classCustomizer.add();
            }
        });
        thread.start();
        
        NewIdentifierOperator identifier = new NewIdentifierOperator();
        identifier.setNewName("java.lang.Runnable");
        identifier.oK();
        
        classCustomizer.closeByButton();
    }
    
    public void testCustomizeInterface() {
        //create test file
        Utilities.copyToSampleDir(NAME_DATA_DIR +  NAME_TEST_INTERFACE + ".java");
        
        customizeInterface();
        
        ref(Utilities.getAsString(NAME_TEST_INTERFACE + ".java"));
        
        Utilities.saveAll();
        Utilities.delete(NAME_TEST_INTERFACE + ".java");
        compareReferenceFiles();
    }
    
    private void customizeInterface() {
        //add class
        ExplorerOperator explorerOperator = new ExplorerOperator();
        explorerOperator.selectPageFilesystems();
        Node repositoryRootNode = explorerOperator.repositoryTab().getRootNode();
        JavaNode testFile = new JavaNode(repositoryRootNode, Utilities.getSampleDir().getDisplayName()+"|"+NAME_TEST_INTERFACE + "|interface " + NAME_TEST_INTERFACE);
        testFile.select();
        testFile.performPopupActionNoBlock(Bundle.getString("org.openide.actions.Bundle", "Customize"));
        
        //customize it
        final ClassCustomizerOperator classCustomizer = new ClassCustomizerOperator(Bundle.getString("org.netbeans.core.Bundle", "CTL_Customizer_dialog_title"));
        classCustomizer.typeName(NAME_TEST_INTERFACE);
        classCustomizer.cboAccess().selectItem("");
        classCustomizer.checkAbstract(true);
        Thread thread = new Thread( new java.lang.Runnable() {
            public void run() {
                classCustomizer.add();
            }
        });
        thread.start();
        
        NewIdentifierOperator identifier = new NewIdentifierOperator();
        identifier.setNewName("java.lang.Runnable");
        identifier.oK();
        
        classCustomizer.closeByButton();
    }
    public void testAddClass() {
        //create test file
        Utilities.copyToSampleDir(NAME_DATA_DIR +  NAME_TEST_FILE + ".java");
        
        addClass();
        
        ref(Utilities.getAsString(NAME_TEST_FILE + ".java"));
        
        Utilities.saveAll();
        Utilities.delete(NAME_TEST_FILE + ".java");
        compareReferenceFiles();
    }
    
    /** testName method */
    public void testAddInterface() {
        //create test file
        Utilities.copyToSampleDir(NAME_DATA_DIR +  NAME_TEST_FILE + ".java");
        
        addInterface();
        
        ref(Utilities.getAsString(NAME_TEST_FILE + ".java"));
        
        Utilities.saveAll();
        Utilities.delete(NAME_TEST_FILE + ".java");
        compareReferenceFiles();
    }
    
    private void addInterface() {
        //add class
        ExplorerOperator explorerOperator = new ExplorerOperator();
        explorerOperator.selectPageFilesystems();
        Node repositoryRootNode = explorerOperator.repositoryTab().getRootNode();
        JavaNode testFile = new JavaNode(repositoryRootNode, Utilities.getSampleDir().getDisplayName()+"|"+NAME_TEST_FILE);
        testFile.select();
        testFile.performPopupActionNoBlock(Bundle.getString("org.openide.src.nodes.Bundle", "LAB_Add") + '|' + Bundle.getString("org.openide.src.nodes.Bundle", "CTL_Interface"));
        
        //customize it
        final ClassCustomizerOperator classCustomizer = new ClassCustomizerOperator(Bundle.getString("org.netbeans.modules.java.Bundle", "TITLE_CREATE_INTERFACE"));
        classCustomizer.typeName("MyInterface");
        classCustomizer.selectAccess("public");
        classCustomizer.checkAbstract(true);
        Thread thread = new Thread( new java.lang.Runnable() {
            public void run() {
                classCustomizer.add();
            }
        });
        thread.start();
        
        NewIdentifierOperator identifier = new NewIdentifierOperator();
        identifier.setNewName("java.lang.Runnable");
        identifier.oK();
        
        classCustomizer.oK();
    }
    

    private void addClass() {
        //add class
        ExplorerOperator explorerOperator = new ExplorerOperator();
        explorerOperator.selectPageFilesystems();
        Node repositoryRootNode = explorerOperator.repositoryTab().getRootNode();
        JavaNode testFile = new JavaNode(repositoryRootNode, Utilities.getSampleDir().getDisplayName()+"|"+NAME_TEST_FILE);
        testFile.select();
        testFile.performPopupActionNoBlock(Bundle.getString("org.openide.src.nodes.Bundle", "LAB_Add") + '|' + Bundle.getString("org.openide.src.nodes.Bundle", "CTL_Class"));
        
        //customize it
        final ClassCustomizerOperator classCustomizer = new ClassCustomizerOperator(Bundle.getString("org.netbeans.modules.java.Bundle", "TITLE_CREATE_CLASS"));
        classCustomizer.typeName("MyClass");
        classCustomizer.typeSuperClass("javax.swing.JComponent");
        classCustomizer.selectAccess("public");
        classCustomizer.checkFinal(true);
        classCustomizer.checkAbstract(true);
        Thread thread = new Thread( new java.lang.Runnable() {
            public void run() {
                classCustomizer.add();
            }
        });
        thread.start();
        
        NewIdentifierOperator identifier = new NewIdentifierOperator();
        identifier.setNewName("java.lang.Runnable");
        identifier.oK();
        
        classCustomizer.oK();
    }
}
... 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.