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 org.netbeans.jellytools.nodes.Node;
045:
046: import org.netbeans.jemmy.JemmyException;
047: import org.netbeans.jemmy.Timeouts;
048: import org.netbeans.jemmy.Waitable;
049: import org.netbeans.jemmy.Waiter;
050: import org.netbeans.jemmy.operators.JButtonOperator;
051: import org.netbeans.jemmy.operators.JTreeOperator;
052:
053: /**
054: * Provides access to the "Search Results" view. <p>
055: * Usage:<br>
056: * <pre>
057: * SearchResultsOperator sro = new SearchResultsOperator();
058: * sro.openResult("MyClass|myMethod");
059: * </pre><p>
060: * Timeouts used:<br>
061: * SearchResultsOperator.SearchTime - maximum time for search to be performed.
062: */
063: public class SearchResultsOperator extends TopComponentOperator {
064:
065: private static final long SEARCH_TIME = 600000;
066:
067: private static final String TITLE = Bundle.getString(
068: "org.netbeans.modules.search.Bundle",
069: "TITLE_SEARCH_RESULTS");
070: /** Used to temporary store default comparator */
071: private static StringComparator oldComparator;
072: private JButtonOperator _btStop;
073: private JButtonOperator _btShowDetails;
074: private JButtonOperator _btModifySearch;
075: private JTreeOperator _treeResult;
076:
077: /**
078: * Waits for view opened.
079: */
080: public SearchResultsOperator() {
081: // "Search Results"
082: super (TITLE);
083: }
084:
085: static {
086: Timeouts.initDefault("SearchResultsOperator.SearchTime",
087: SEARCH_TIME);
088: }
089:
090: //component access
091: /**
092: * returns operator for "Stop Search" button.
093: * @return JButtonOperator instance
094: */
095: public JButtonOperator btStopSearch() {
096: if (_btStop == null) {
097: _btStop = new JButtonOperator(this , Bundle
098: .getStringTrimmed(
099: "org.netbeans.modules.search.Bundle",
100: "TEXT_BUTTON_STOP"));
101: }
102: return _btStop;
103: }
104:
105: /**
106: * Returns operator for "Show Details" button.
107: * @return JButtonOperator instance
108: */
109: public JButtonOperator btShowDetails() {
110: if (_btShowDetails == null) {
111: _btShowDetails = new JButtonOperator(this , Bundle
112: .getStringTrimmed(
113: "org.netbeans.modules.search.Bundle",
114: "TEXT_BUTTON_FILL"));
115: }
116: return _btShowDetails;
117: }
118:
119: /**
120: * Returns operator for "Modify Search" button.
121: * @return JButtonOperator instance
122: */
123: public JButtonOperator btModifySearch() {
124: if (_btModifySearch == null) {
125: _btModifySearch = new JButtonOperator(this , Bundle
126: .getStringTrimmed(
127: "org.netbeans.modules.search.Bundle",
128: "TEXT_BUTTON_CUSTOMIZE"));
129: }
130: return _btModifySearch;
131: }
132:
133: /**
134: * Returns operator for search result tree.
135: * @return JTreeOperator instance
136: */
137: public JTreeOperator treeResult() {
138: if (_treeResult == null) {
139: _treeResult = new JTreeOperator(this );
140: }
141: return _treeResult;
142: }
143:
144: //shortcuts
145:
146: /**
147: * Selects a path in the results tree
148: * @param path path to requested result (e.g. "MyClass|myMethod")
149: */
150: public void selectResult(String path) {
151: new Node(treeResult(), path).select();
152: }
153:
154: /**
155: * Double clicks on the specified path in the results tree. It opens file
156: * in editor.
157: * @param path path to requested result (e.g. "MyClass|myMethod")
158: */
159: public void openResult(String path) {
160: treeResult().clickOnPath(
161: new Node(treeResult(), path).getTreePath(), 2);
162: }
163:
164: /**
165: * Pushes "Stop Search" button.
166: */
167: public void stopSearch() {
168: btStopSearch().push();
169: }
170:
171: /**
172: * Pushes "Show Details" button and returns {@link OutputTabOperator} from output window.
173: * @return OutputTabOperator instance
174: */
175: public OutputTabOperator showDetails() {
176: btShowDetails().push();
177: return new OutputTabOperator(TITLE);
178: }
179:
180: /**
181: * Pushes "Modify Search" button. and return {@link FindInFilesOperator}
182: * @return FindInFilesOperator instance
183: */
184: public FindInFilesOperator modifySearch() {
185: btModifySearch().pushNoBlock();
186: return new FindInFilesOperator();
187: }
188:
189: /**
190: * Waits until search is finished.
191: */
192: public void waitEndOfSearch() {
193: Waiter waiter = new Waiter(new Waitable() {
194: public Object actionProduced(Object param) {
195: return (btStopSearch().isEnabled() ? null : "");
196: }
197:
198: public String getDescription() {
199: return "Wait for a search to be finished";
200: }
201: });
202: waiter.getTimeouts().setTimeout(
203: "Waiter.WaitingTime",
204: getTimeouts().getTimeout(
205: "SearchResultsOperator.SearchTime"));
206: try {
207: waiter.waitAction(null);
208: } catch (InterruptedException e) {
209: throw (new JemmyException("Waiting has been interrupted", e));
210: }
211: }
212:
213: /** Performs verification by accessing all sub-components */
214: public void verify() {
215: btStopSearch();
216: btShowDetails();
217: btModifySearch();
218: treeResult();
219: }
220: }
|