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: package org.netbeans.jellytools.modules.web;
042:
043: import java.awt.Component;
044: import javax.swing.JComboBox;
045: import javax.swing.JTextArea;
046: import javax.swing.JTextField;
047: import org.netbeans.jellytools.Bundle;
048: import org.netbeans.jellytools.NewFileWizardOperator;
049: import org.netbeans.jellytools.WizardOperator;
050: import org.netbeans.jemmy.operators.*;
051:
052: /**
053: * Handle "Name And Location" panel of the New JSP File wizard.<br>
054: * Usage:
055: * <pre>
056: * NewFileWizardOperator wop = NewFileWizardOperator.invoke();
057: * wop.selectCategory("Web");
058: * wop.selectFileType("JSP");
059: * wop.next();
060: * NewJspFileNameStepOperator op = new NewJspFileNameStepOperator();
061: * op.setJspFileName("index1");
062: * op.finish();
063: * </pre>
064: *
065: * @author Martin.Schovanek@sun.com
066: */
067: public class NewJspFileNameStepOperator extends WizardOperator {
068: private JLabelOperator _lblNameAndLocation;
069: private JLabelOperator _lblJSPFileName;
070: private JTextFieldOperator _txtJSPFileName;
071: private JLabelOperator _lblProject;
072: private JTextFieldOperator _txtProject;
073: private JLabelOperator _lblLocation;
074: private JComboBoxOperator _cboLocation;
075: private JLabelOperator _lblFolder;
076: private JTextFieldOperator _txtFolder;
077: private JButtonOperator _btBrowse;
078: private JLabelOperator _lblCreatedFile;
079: private JTextFieldOperator _txtCreatedFile;
080: private JLabelOperator _lblOptions;
081: private JRadioButtonOperator _rbJSPFileStandardSyntax;
082: private JRadioButtonOperator _rbJSPDocumentXMLSyntax;
083: private JCheckBoxOperator _cbCreateAsAJSPSegment;
084: private JLabelOperator _lblDescription;
085: private JTextAreaOperator _txtDescription;
086:
087: private static final String JSP_FILE = Bundle.getStringTrimmed(
088: "org.netbeans.modules.web.wizards.Bundle", "TITLE_JspFile");
089: private static final String NEW = Bundle.getStringTrimmed(
090: "org.netbeans.modules.project.ui.Bundle",
091: "LBL_NewFileWizard_Subtitle");
092:
093: /**
094: * Creates new NewJspFileNameStepOperator that can handle it.
095: */
096: public NewJspFileNameStepOperator() {
097: super (Bundle.getStringTrimmed(
098: "org.netbeans.modules.project.ui.Bundle",
099: "LBL_NewFileWizard_MessageFormat", new Object[] { NEW,
100: JSP_FILE }));
101: }
102:
103: /** Invokes dialog from main menu "File|New..." and selects Web/JSP template.
104: * @return instance of NewJspFileNameStepOperator
105: */
106: public static final NewJspFileNameStepOperator invoke() {
107: NewFileWizardOperator wizarOperator = NewFileWizardOperator
108: .invoke();
109: wizarOperator.selectCategory(Bundle.getStringTrimmed(
110: "org.netbeans.modules.web.core.Bundle",
111: "Templates/JSP_Servlet"));
112: wizarOperator.selectFileType(Bundle.getStringTrimmed(
113: "org.netbeans.modules.web.core.Bundle",
114: "Templates/JSP_Servlet/JSP.jsp"));
115: wizarOperator.next();
116: return new NewJspFileNameStepOperator();
117: }
118:
119: //******************************
120: // Subcomponents definition part
121: //******************************
122:
123: /** Tries to find "Name and Location" JLabel in this dialog.
124: * @return JLabelOperator
125: */
126: public JLabelOperator lblNameAndLocation() {
127: if (_lblNameAndLocation == null) {
128: _lblNameAndLocation = new JLabelOperator(this , Bundle
129: .getStringTrimmed(
130: "org.netbeans.modules.web.wizards.Bundle",
131: "TITLE_name_location"));
132: }
133: return _lblNameAndLocation;
134: }
135:
136: /** Tries to find "JSP File Name:" JLabel in this dialog.
137: * @return JLabelOperator
138: */
139: public JLabelOperator lblJSPFileName() {
140: if (_lblJSPFileName == null) {
141: _lblJSPFileName = new JLabelOperator(this , Bundle
142: .getStringTrimmed(
143: "org.netbeans.modules.web.wizards.Bundle",
144: "LBL_JspName"));
145: }
146: return _lblJSPFileName;
147: }
148:
149: /** Tries to find null JTextField in this dialog.
150: * @return JTextFieldOperator
151: */
152: public JTextFieldOperator txtJSPFileName() {
153: if (_txtJSPFileName == null) {
154: Component comp = lblJSPFileName().getLabelFor();
155: if (comp != null) {
156: _txtJSPFileName = new JTextFieldOperator(
157: (JTextField) comp);
158: } else {
159: _txtJSPFileName = new JTextFieldOperator(this );
160: }
161: }
162: return _txtJSPFileName;
163: }
164:
165: /** Tries to find "Project:" JLabel in this dialog.
166: * @return JLabelOperator
167: */
168: public JLabelOperator lblProject() {
169: if (_lblProject == null) {
170: _lblProject = new JLabelOperator(this , Bundle
171: .getStringTrimmed(
172: "org.netbeans.modules.web.wizards.Bundle",
173: "LBL_Project"));
174: }
175: return _lblProject;
176: }
177:
178: /** Tries to find null JTextField in this dialog.
179: * @return JTextFieldOperator
180: */
181: public JTextFieldOperator txtProject() {
182: if (_txtProject == null) {
183: Component comp = lblProject().getLabelFor();
184: if (comp != null) {
185: _txtProject = new JTextFieldOperator((JTextField) comp);
186: } else {
187: _txtProject = new JTextFieldOperator(this , 1);
188: }
189: }
190: return _txtProject;
191: }
192:
193: /** Tries to find "Location:" JLabel in this dialog.
194: * @return JLabelOperator
195: */
196: public JLabelOperator lblLocation() {
197: if (_lblLocation == null) {
198: _lblLocation = new JLabelOperator(this , Bundle
199: .getStringTrimmed(
200: "org.netbeans.modules.web.wizards.Bundle",
201: "LBL_Location"));
202: }
203: return _lblLocation;
204: }
205:
206: /** Tries to find null JComboBox in this dialog.
207: * @return JComboBoxOperator
208: */
209: public JComboBoxOperator cboLocation() {
210: if (_cboLocation == null) {
211: Component comp = lblLocation().getLabelFor();
212: if (comp != null) {
213: _cboLocation = new JComboBoxOperator((JComboBox) comp);
214: } else {
215: _cboLocation = new JComboBoxOperator(this );
216: }
217: }
218: return _cboLocation;
219: }
220:
221: /** Tries to find "Folder:" JLabel in this dialog.
222: * @return JLabelOperator
223: */
224: public JLabelOperator lblFolder() {
225: if (_lblFolder == null) {
226: _lblFolder = new JLabelOperator(this , Bundle
227: .getStringTrimmed(
228: "org.netbeans.modules.web.wizards.Bundle",
229: "LBL_Folder"));
230: }
231: return _lblFolder;
232: }
233:
234: /** Tries to find null JTextField in this dialog.
235: * @return JTextFieldOperator
236: */
237: public JTextFieldOperator txtFolder() {
238: if (_txtFolder == null) {
239: Component comp = lblFolder().getLabelFor();
240: if (comp != null) {
241: _txtFolder = new JTextFieldOperator((JTextField) comp);
242: } else {
243: _txtFolder = new JTextFieldOperator(this , 2);
244: }
245: }
246: return _txtFolder;
247: }
248:
249: /** Tries to find "Browse..." JButton in this dialog.
250: * @return JButtonOperator
251: */
252: public JButtonOperator btBrowse() {
253: if (_btBrowse == null) {
254: _btBrowse = new JButtonOperator(this , Bundle
255: .getStringTrimmed(
256: "org.netbeans.modules.web.wizards.Bundle",
257: "LBL_Browse"));
258: }
259: return _btBrowse;
260: }
261:
262: /** Tries to find "Created File:" JLabel in this dialog.
263: * @return JLabelOperator
264: */
265: public JLabelOperator lblCreatedFile() {
266: if (_lblCreatedFile == null) {
267: _lblCreatedFile = new JLabelOperator(this , Bundle
268: .getStringTrimmed(
269: "org.netbeans.modules.web.wizards.Bundle",
270: "LBL_CreatedFile"));
271: }
272: return _lblCreatedFile;
273: }
274:
275: /** Tries to find null JTextField in this dialog.
276: * @return JTextFieldOperator
277: */
278: public JTextFieldOperator txtCreatedFile() {
279: if (_txtCreatedFile == null) {
280: Component comp = lblCreatedFile().getLabelFor();
281: if (comp != null) {
282: _txtCreatedFile = new JTextFieldOperator(
283: (JTextField) comp);
284: } else {
285: _txtCreatedFile = new JTextFieldOperator(this , 3);
286: }
287: }
288: return _txtCreatedFile;
289: }
290:
291: /** Tries to find "Options:" JLabel in this dialog.
292: * @return JLabelOperator
293: */
294: public JLabelOperator lblOptions() {
295: if (_lblOptions == null) {
296: _lblOptions = new JLabelOperator(this , Bundle
297: .getStringTrimmed(
298: "org.netbeans.modules.web.wizards.Bundle",
299: "LBL_Options"));
300: }
301: return _lblOptions;
302: }
303:
304: /** Tries to find "JSP File (Standard Syntax)" JRadioButton in this dialog.
305: * @return JRadioButtonOperator
306: */
307: public JRadioButtonOperator rbJSPFileStandardSyntax() {
308: if (_rbJSPFileStandardSyntax == null) {
309: _rbJSPFileStandardSyntax = new JRadioButtonOperator(this ,
310: Bundle.getStringTrimmed(
311: "org.netbeans.modules.web.wizards.Bundle",
312: "OPT_JspSyntax"));
313: }
314: return _rbJSPFileStandardSyntax;
315: }
316:
317: /** Tries to find "JSP Document (XML Syntax)" JRadioButton in this dialog.
318: * @return JRadioButtonOperator
319: */
320: public JRadioButtonOperator rbJSPDocumentXMLSyntax() {
321: if (_rbJSPDocumentXMLSyntax == null) {
322: _rbJSPDocumentXMLSyntax = new JRadioButtonOperator(this ,
323: Bundle.getStringTrimmed(
324: "org.netbeans.modules.web.wizards.Bundle",
325: "OPT_XmlSyntax"));
326: }
327: return _rbJSPDocumentXMLSyntax;
328: }
329:
330: /** Tries to find "Create as a JSP Segment" JCheckBox in this dialog.
331: * @return JCheckBoxOperator
332: */
333: public JCheckBoxOperator cbCreateAsAJSPSegment() {
334: if (_cbCreateAsAJSPSegment == null) {
335: _cbCreateAsAJSPSegment = new JCheckBoxOperator(this , Bundle
336: .getStringTrimmed(
337: "org.netbeans.modules.web.wizards.Bundle",
338: "OPT_JspSegment"));
339: }
340: return _cbCreateAsAJSPSegment;
341: }
342:
343: /** Tries to find "Description:" JLabel in this dialog.
344: * @return JLabelOperator
345: */
346: public JLabelOperator lblDescription() {
347: if (_lblDescription == null) {
348: _lblDescription = new JLabelOperator(this , Bundle
349: .getStringTrimmed(
350: "org.netbeans.modules.web.wizards.Bundle",
351: "LBL_description"));
352: }
353: return _lblDescription;
354: }
355:
356: /** Tries to find null JTextArea in this dialog.
357: * @return JTextAreaOperator
358: */
359: public JTextAreaOperator txtDescription() {
360: if (_txtDescription == null) {
361: Component comp = lblDescription().getLabelFor();
362: if (comp != null) {
363: _txtDescription = new JTextAreaOperator(
364: (JTextArea) comp);
365: } else {
366: _txtDescription = new JTextAreaOperator(this );
367: }
368: }
369: return _txtDescription;
370: }
371:
372: //****************************************
373: // Low-level functionality definition part
374: //****************************************
375:
376: /** gets text for txtJSPFileName
377: * @return String text
378: */
379: public String getJSPFileName() {
380: return txtJSPFileName().getText();
381: }
382:
383: /** sets text for txtJSPFileName
384: * @param text String text
385: */
386: public void setJSPFileName(String text) {
387: txtJSPFileName().setText(text);
388: }
389:
390: /** types text for txtJSPFileName
391: * @param text String text
392: */
393: public void typeJSPFileName(String text) {
394: txtJSPFileName().typeText(text);
395: }
396:
397: /** gets text for txtProject
398: * @return String text
399: */
400: public String getProject() {
401: return txtProject().getText();
402: }
403:
404: /** sets text for txtProject
405: * @param text String text
406: */
407: public void setProject(String text) {
408: txtProject().setText(text);
409: }
410:
411: /** types text for txtProject
412: * @param text String text
413: */
414: public void typeProject(String text) {
415: txtProject().typeText(text);
416: }
417:
418: /** returns selected item for cboLocation
419: * @return String item
420: */
421: public String getSelectedLocation() {
422: return cboLocation().getSelectedItem().toString();
423: }
424:
425: /** selects item for cboLocation
426: * @param item String item
427: */
428: public void selectLocation(String item) {
429: cboLocation().selectItem(item);
430: }
431:
432: /** gets text for txtFolder
433: * @return String text
434: */
435: public String getFolder() {
436: return txtFolder().getText();
437: }
438:
439: /** sets text for txtFolder
440: * @param text String text
441: */
442: public void setFolder(String text) {
443: txtFolder().setText(text);
444: }
445:
446: /** types text for txtFolder
447: * @param text String text
448: */
449: public void typeFolder(String text) {
450: txtFolder().typeText(text);
451: }
452:
453: /** clicks on "Browse..." JButton
454: */
455: public void browse() {
456: btBrowse().push();
457: }
458:
459: /** gets text for txtCreatedFile
460: * @return String text
461: */
462: public String getCreatedFile() {
463: return txtCreatedFile().getText();
464: }
465:
466: /** sets text for txtCreatedFile
467: * @param text String text
468: */
469: public void setCreatedFile(String text) {
470: txtCreatedFile().setText(text);
471: }
472:
473: /** types text for txtCreatedFile
474: * @param text String text
475: */
476: public void typeCreatedFile(String text) {
477: txtCreatedFile().typeText(text);
478: }
479:
480: /** clicks on "JSP File (Standard Syntax)" JRadioButton
481: */
482: public void jSPFileStandardSyntax() {
483: rbJSPFileStandardSyntax().push();
484: }
485:
486: /** clicks on "JSP Document (XML Syntax)" JRadioButton
487: */
488: public void jSPDocumentXMLSyntax() {
489: rbJSPDocumentXMLSyntax().push();
490: }
491:
492: /** checks or unchecks given JCheckBox
493: * @param state boolean requested state
494: */
495: public void checkCreateAsAJSPSegment(boolean state) {
496: if (cbCreateAsAJSPSegment().isSelected() != state) {
497: cbCreateAsAJSPSegment().push();
498: }
499: }
500:
501: /** gets text for txtDescription
502: * @return String text
503: */
504: public String getDescription() {
505: return txtDescription().getText();
506: }
507:
508: /** sets text for txtDescription
509: * @param text String text
510: */
511: public void setDescription(String text) {
512: txtDescription().setText(text);
513: }
514:
515: /** types text for txtDescription
516: * @param text String text
517: */
518: public void typeDescription(String text) {
519: txtDescription().typeText(text);
520: }
521:
522: //*****************************************
523: // High-level functionality definition part
524: //*****************************************
525:
526: /**
527: * Performs verification of NewJspFileNameStepOperator by accessing all its components.
528: */
529: public void verify() {
530: lblNameAndLocation();
531: lblJSPFileName();
532: txtJSPFileName();
533: lblProject();
534: txtProject();
535: lblLocation();
536: cboLocation();
537: lblFolder();
538: txtFolder();
539: btBrowse();
540: lblCreatedFile();
541: txtCreatedFile();
542: lblOptions();
543: rbJSPFileStandardSyntax();
544: rbJSPDocumentXMLSyntax();
545: cbCreateAsAJSPSegment();
546: lblDescription();
547: txtDescription();
548: }
549: }
|