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.FilesViewAction;
046: import org.netbeans.jellytools.nodes.Node;
047: import org.netbeans.jemmy.ComponentChooser;
048: import org.netbeans.jemmy.operators.ContainerOperator;
049: import org.netbeans.jemmy.operators.JTreeOperator;
050:
051: /** Operator handling Files TopComponent.<p>
052: * Functionality related to Projects tree is delegated to JTreeOperator (method
053: * tree()) and nodes (method getProjectNode()).<p>
054: *
055: * Example:<p>
056: * <pre>
057: * FilesTabOperator fto = new FilesTabOperator();
058: * // or when Files pane is not already opened
059: * FilesTabOperator fto = FilesTabOperator.invoke();
060: *
061: * // get the tree if needed
062: * JTreeOperator tree = fto.tree();
063: * // work with nodes
064: * Node projectNode = fto.getProjectNode("SampleProject").select();
065: * Node node = new Node(projectNode, "subnode|sub subnode");
066: * </pre>
067: *
068: * @see FilesViewAction
069: */
070: public class FilesTabOperator extends TopComponentOperator {
071:
072: static final String FILES_CAPTION = Bundle.getStringTrimmed(
073: "org.netbeans.modules.project.ui.Bundle",
074: "LBL_projectTab_tc");
075: private static final FilesViewAction viewAction = new FilesViewAction();
076:
077: private JTreeOperator _tree;
078:
079: /** Search for Files TopComponent within all IDE. */
080: public FilesTabOperator() {
081: super (waitTopComponent(null, FILES_CAPTION, 0,
082: new FilesTabSubchooser()));
083: }
084:
085: /** invokes Files and returns new instance of FilesTabOperator
086: * @return new instance of FilesTabOperator */
087: public static FilesTabOperator invoke() {
088: viewAction.perform();
089: return new FilesTabOperator();
090: }
091:
092: /** Getter for Files JTreeOperator
093: * @return JTreeOperator of Projects tree */
094: public JTreeOperator tree() {
095: makeComponentVisible();
096: if (_tree == null) {
097: _tree = new JTreeOperator(this );
098: }
099: return _tree;
100: }
101:
102: /** Gets node representing a project.
103: * @param projectName display name of project
104: * @return Node instance representing the project specified by name
105: */
106: public Node getProjectNode(String projectName) {
107: return new Node(tree(), projectName);
108: }
109:
110: /** Performs verification by accessing all sub-components */
111: public void verify() {
112: tree();
113: }
114:
115: /** SubChooser to determine TopComponent is instance of
116: * org.netbeans.modules.project.ui.ProjectTab
117: * Used in constructor.
118: */
119: private static final class FilesTabSubchooser implements
120: ComponentChooser {
121: public boolean checkComponent(Component comp) {
122: return comp.getClass().getName().endsWith("ProjectTab");
123: }
124:
125: public String getDescription() {
126: return "org.netbeans.modules.project.ui.ProjectTab";
127: }
128: }
129: }
|