001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.jellytools;
043:
044: import java.awt.Component;
045: import org.netbeans.jellytools.actions.RuntimeViewAction;
046: import org.netbeans.jellytools.nodes.Node;
047: import org.netbeans.jemmy.ComponentChooser;
048: import org.netbeans.jemmy.operators.JTreeOperator;
049:
050: /** Operator handling Runtime TopComponent.<p>
051: * Functionality related to Runtime tree is delegated to JTreeOperator (method
052: * tree()) and nodes (method getRootNode()).<p>
053: * Example:<p>
054: * <pre>
055: * RuntimeTabOperator rto = RuntimeTabOperator.invoke();
056: * // or when Runtime pane is already opened
057: * //RuntimeTabOperator rto = new RuntimeTabOperator();
058: *
059: * // get the tree if needed
060: * JTreeOperator tree = rto.tree();
061: * // work with nodes
062: * rto.getRootNode().select();
063: * Node node = new Node(rto.getRootNode(), "subnode|sub subnode");
064: * </pre>
065: *
066: * @see RuntimeViewAction
067: */
068: public class RuntimeTabOperator extends TopComponentOperator {
069:
070: static final String RUNTIME_CAPTION = Bundle.getString(
071: "org.netbeans.core.Bundle", "UI/Runtime");
072: private static final RuntimeViewAction viewAction = new RuntimeViewAction();
073:
074: private JTreeOperator _tree;
075:
076: /** Search for Runtime TopComponent through all IDE. */
077: public RuntimeTabOperator() {
078: super (waitTopComponent(null, RUNTIME_CAPTION, 0,
079: new RuntimeTabSubchooser()));
080: }
081:
082: /** invokes Runtime and returns new instance of RuntimeTabOperator
083: * @return new instance of RuntimeTabOperator */
084: public static RuntimeTabOperator invoke() {
085: viewAction.perform();
086: return new RuntimeTabOperator();
087: }
088:
089: /** getter for Runtime JTreeOperator
090: * @return JTreeOperator of Runtime tree */
091: public JTreeOperator tree() {
092: makeComponentVisible();
093: if (_tree == null) {
094: _tree = new JTreeOperator(this );
095: }
096: return _tree;
097: }
098:
099: /** getter for Runtime root node
100: * @return RuntimeRootNode */
101: public Node getRootNode() {
102: return new Node(tree(), "");
103: }
104:
105: /** Performs verification by accessing all sub-components */
106: public void verify() {
107: tree();
108: }
109:
110: /** SubChooser to determine TopComponent is instance of
111: * org.netbeans.core.NbMainExplorer$MainTab
112: * Used in constructor.
113: */
114: private static final class RuntimeTabSubchooser implements
115: ComponentChooser {
116: public boolean checkComponent(Component comp) {
117: return comp.getClass().getName().endsWith("MainTab");
118: }
119:
120: public String getDescription() {
121: return "org.netbeans.core.NbMainExplorer$MainTab";
122: }
123: }
124: }
|