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-2008 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.actions.DocumentsAction;
045: import org.netbeans.jemmy.operators.JButtonOperator;
046: import org.netbeans.jemmy.operators.JListOperator;
047: import org.netbeans.jemmy.operators.JTextAreaOperator;
048:
049: /**
050: * Handle the dialog which is open from main menu "Window|Documents...".
051: * This dialog shows list of all opened documents and it enables to close
052: * or save selected documents. You can also activate one of documents.
053: * <p>
054: * Usage:<br>
055: * <pre>
056: DocumentsDialogOperator ddo = DocumentsDialogOperator.invoke();
057: ddo.selectDocument("MyDocument");
058: ddo.activate();
059: ddo = DocumentsDialogOperator.invoke();
060: ddo.selectDocuments(new int[] {0, 3, 4});
061: ddo.closeDocuments();
062: ddo.close();
063: * </pre>
064: *
065: * @author Jiri.Skrivanek@sun.com
066: * @see org.netbeans.jellytools.actions.DocumentsAction
067: */
068: public class DocumentsDialogOperator extends NbDialogOperator {
069:
070: private JButtonOperator _btClose;
071: private JButtonOperator _btActivate;
072: private JButtonOperator _btCloseDocuments;
073: private JButtonOperator _btSaveDocuments;
074: private JTextAreaOperator _txtDescription;
075: private JListOperator _lstDocuments;
076:
077: private static final String title = Bundle.getString(
078: "org.netbeans.core.windows.view.ui.Bundle",
079: "CTL_DocumentsTitle");
080:
081: /** Waits until dialog with title Documents is found. */
082: public DocumentsDialogOperator() {
083: super (title);
084: }
085:
086: /** Invokes dialog from main menu "Windows|Documents...".
087: * @return instance of DocumentsDialogOperator
088: */
089: public static DocumentsDialogOperator invoke() {
090: new DocumentsAction().perform();
091: return new DocumentsDialogOperator();
092: }
093:
094: /** Returns operator of "Switch to Document" button.
095: * @return JButtonOperator instance of "Switch to Document" button
096: */
097: public JButtonOperator btSwitchToDocument() {
098: if (_btActivate == null) {
099: String switchCaption = Bundle.getStringTrimmed(
100: "org.netbeans.core.windows.view.ui.Bundle",
101: "LBL_Activate");
102: _btActivate = new JButtonOperator(this , switchCaption);
103: }
104: return _btActivate;
105: }
106:
107: /** Returns operator of "Close Document(s)" button.
108: * @return JButtonOperator instance of "Close Document(s)" button
109: */
110: public JButtonOperator btCloseDocuments() {
111: if (_btCloseDocuments == null) {
112: String closeDocumentsCaption = Bundle.getStringTrimmed(
113: "org.netbeans.core.windows.view.ui.Bundle",
114: "LBL_CloseDocuments");
115: _btCloseDocuments = new JButtonOperator(this ,
116: closeDocumentsCaption);
117: }
118: return _btCloseDocuments;
119: }
120:
121: /** Returns operator of "Save Document(s)" button.
122: * @return JButtonOperator instance of "Save Document(s)" button
123: */
124: public JButtonOperator btSaveDocuments() {
125: if (_btSaveDocuments == null) {
126: String saveDocumentsCaption = Bundle.getStringTrimmed(
127: "org.netbeans.core.windows.view.ui.Bundle",
128: "LBL_SaveDocuments");
129: _btSaveDocuments = new JButtonOperator(this ,
130: saveDocumentsCaption);
131: }
132: return _btSaveDocuments;
133: }
134:
135: /** Returns operator of "Close" button.
136: * @return JButtonOperator instance of "Close" button
137: */
138: @Override
139: public JButtonOperator btClose() {
140: if (_btClose == null) {
141: String closeCaption = Bundle.getStringTrimmed(
142: "org.netbeans.core.windows.services.Bundle",
143: "CLOSED_OPTION_CAPTION");
144: // need to set exact matching comparator becouse Close button can
145: // be mistaken for Close Document(s) button
146: StringComparator oldComparator = this .getComparator();
147: this .setComparator(new DefaultStringComparator(true, true));
148: _btClose = new JButtonOperator(this , closeCaption);
149: this .setComparator(oldComparator);
150: }
151: return _btClose;
152: }
153:
154: /** Returns operator of "Description" text area.
155: * @return JTextAreaOperator instance of "Description" text area
156: */
157: public JTextAreaOperator txtDescription() {
158: if (_txtDescription == null) {
159: _txtDescription = new JTextAreaOperator(this );
160: }
161: return _txtDescription;
162: }
163:
164: /** Returns operator of list of documents.
165: * @return JListOperator instance of list of documents
166: */
167: public JListOperator lstDocuments() {
168: if (_lstDocuments == null) {
169: _lstDocuments = new JListOperator(this );
170: }
171: return _lstDocuments;
172: }
173:
174: /** Pushes "Switch to Document" button. It closes the dialog and focuses selected
175: * document in the editor area.
176: */
177: public void switchToDocument() {
178: btSwitchToDocument().push();
179: }
180:
181: /** Pushes "Close Document(s)" button. */
182: public void closeDocuments() {
183: btCloseDocuments().push();
184: }
185:
186: /** Pushes "Save Document(s)" button. */
187: public void saveDocuments() {
188: btSaveDocuments().push();
189: }
190:
191: /** Returns description text.
192: * @return description text.
193: */
194: public String getDescription() {
195: return txtDescription().getText();
196: }
197:
198: /** Selects document with given name in the list.
199: * @param name name of document to be selected
200: */
201: public void selectDocument(String name) {
202: lstDocuments().selectItem(name);
203: }
204:
205: /** Selects index-th document in the list.
206: * @param index index of document to be selected
207: */
208: public void selectDocument(int index) {
209: lstDocuments().selectItem(index);
210: }
211:
212: /** Selects documents with given names in the list.
213: * @param names names of document to be selected
214: */
215: public void selectDocuments(String[] names) {
216: lstDocuments().selectItem(names);
217: }
218:
219: /** Selects documents with given indexes in the list.
220: * @param indexes indexes of documents to be selected
221: */
222: public void selectDocuments(int[] indexes) {
223: lstDocuments().selectItems(indexes);
224: }
225:
226: /** Performs verification by accessing all sub-components */
227: public void verify() {
228: btSwitchToDocument();
229: btCloseDocuments();
230: btSaveDocuments();
231: btClose();
232: txtDescription();
233: lstDocuments();
234: }
235: }
|