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-2007 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.modules.visualweb.gravy;
043:
044: import java.awt.Rectangle;
045: import java.lang.reflect.InvocationTargetException;
046: import javax.swing.table.JTableHeader;
047: import javax.swing.tree.TreePath;
048: import org.netbeans.modules.visualweb.gravy.Util;
049: import org.netbeans.jemmy.EventTool;
050: import org.netbeans.jemmy.JemmyException;
051: import org.netbeans.jemmy.Timeouts;
052: import org.netbeans.jemmy.operators.ComponentOperator;
053: import org.netbeans.jemmy.operators.JButtonOperator;
054: import org.netbeans.jemmy.operators.JComboBoxOperator;
055: import org.netbeans.jemmy.operators.Operator;
056: import org.netbeans.jemmy.operators.JRadioButtonOperator;
057:
058: /**
059: * Provides access to the Options window and it's subcomponents.
060: * Use PropertySheet class to access properties.
061: * treeTable() method returns TreeTable operator for
062: * options list accessing.
063: */
064: public class OptionsOperator extends NbDialogOperator {
065:
066: /**
067: * Constant used for indication of project property definition level
068: * (first column after ">>").
069: */
070: public static final int PROJECT_LEVEL = 2;
071:
072: /**
073: * Constant used for indication of user property definition level
074: * (second column after ">>").
075: */
076: public static final int USER_LEVEL = 3;
077:
078: /**
079: * Constant used for indication of default property definition level
080: * (third column after ">>").
081: */
082: public static final int DEFAULT_LEVEL = 4;
083:
084: private static final long BEFORE_EDITING_TIMEOUT = 2000;
085:
086: private static int DEFINE_HERE = 0;
087:
088: private JRadioButtonOperator _rbBasic;
089: private JButtonOperator _btAdvanced;
090: private JButtonOperator _btClose;
091: private JButtonOperator _btHelp;
092: private TreeTableOperator _treeTable;
093:
094: /**
095: * Waits for the Options window opened
096: */
097: public OptionsOperator() {
098: super (getTitleToFind());
099: setComparator(oldComparator);
100: setDefaultStringComparator(oldComparator);
101: }
102:
103: private static StringComparator oldComparator;
104:
105: /** Method to set exactly matching comparator to be used in constructor.
106: * @return "Options" - title of window to be found
107: */
108: private static String getTitleToFind() {
109: oldComparator = Operator.getDefaultStringComparator();
110: DefaultStringComparator comparator = new DefaultStringComparator(
111: true, true);
112: setDefaultStringComparator(comparator);
113: return Bundle.getString("org.netbeans.core.Bundle",
114: "UI/Services");
115: }
116:
117: /**
118: * Invoces Options window by the menu operation.
119: * @return OptionsOperator instance
120: */
121: public static OptionsOperator invoke() {
122: // invokeAction.perform();
123: Util.getMainMenu().pushMenu("Tools|Options");
124: return new OptionsOperator();
125: }
126:
127: static {
128: Timeouts.initDefault("OptionsOperator.BeforeEditingTimeout",
129: BEFORE_EDITING_TIMEOUT);
130: }
131:
132: //subcomponents
133:
134: //******************************
135: // Subcomponents definition part
136: //******************************
137:
138: /** Tries to find " Basic" JRadioButton in this dialog.
139: * @return JRadioButtonOperator
140: */
141: public JRadioButtonOperator rbBasic() {
142: if (_rbBasic == null) {
143: _rbBasic = new JRadioButtonOperator(
144: this ,
145: java.util.ResourceBundle
146: .getBundle(
147: "com.sun.rave.extension.core.actions.Bundle")
148: .getString("CTL_basic_button").trim());
149: }
150: return _rbBasic;
151: }
152:
153: /** Tries to find " Advanced" JRadioButton in this dialog.
154: * @return JRadioButtonOperator
155: */
156: public JButtonOperator rbAdvanced() {
157: if (_btAdvanced == null) {
158: _btAdvanced = new JButtonOperator(this , "Advanced Options");
159: //new JRadioButtonOperator(this, java.util.ResourceBundle.getBundle("com.sun.rave.extension.core.actions.Bundle").getString("CTL_advanced_button").trim());
160: }
161: return _btAdvanced;
162: }
163:
164: /** Tries to find "Close" JButton in this dialog.
165: * @return JButtonOperator
166: */
167: public JButtonOperator btClose() {
168: if (_btClose == null) {
169: _btClose = new JButtonOperator(this , Bundle
170: .getStringTrimmed(
171: "org.netbeans.core.actions.Bundle",
172: "CTL_close_button"));
173: }
174: return _btClose;
175: }
176:
177: /** Tries to find "Help" JButton in this dialog.
178: * @return JButtonOperator
179: */
180: public JButtonOperator btHelp() {
181: if (_btHelp == null) {
182: _btHelp = new JButtonOperator(this , "Help"
183: /* TODO: change literal string to Bundle.getStringTrimmed(
184: "org.netbeans.core.actions.Bundle", "CTL_help_button")*/);
185: }
186: return _btHelp;
187: }
188:
189: //****************************************
190: // Low-level functionality definition part
191: //****************************************
192:
193: /** Implements switching to Basic mode
194: * clicks on " Basic" JRadioButton
195: */
196: public void basic() {
197: rbBasic().push();
198: }
199:
200: /** Implements switching to Basic mode
201: * clicks on " Advanced" JRadioButton
202: */
203: public void advanced() {
204: rbAdvanced().push();
205: }
206:
207: /** clicks on "Close" JButton
208: */
209: public void close() {
210: btClose().pushNoBlock();
211: }
212:
213: /** clicks on "Help" JButton
214: */
215: public void help() {
216: btHelp().push();
217: }
218:
219: /** Getter for table containing property list and
220: * property definition levels.
221: * @return TreeTableOperator instance
222: */
223: public TreeTableOperator treeTable() {
224: if (_treeTable == null) {
225: _treeTable = new TreeTableOperator(this );
226: }
227: return _treeTable;
228: }
229:
230: //shortcuts
231: /** Selects an option in the options tree.
232: * @param optionPath Path to the option in left (tree-like) column.
233: * @return row index of selected node (starts at 0)
234: */
235: public int selectOption(String optionPath) {
236: TreePath path = treeTable().tree().findPath(optionPath, "|");
237: if (!treeTable().tree().isPathSelected(path)) {
238: treeTable().tree().selectPath(path);
239: }
240: int result = treeTable().tree().getRowForPath(path);
241: treeTable().scrollToCell(result, 0);
242: new EventTool().waitNoEvent(500);
243: return (result);
244: }
245:
246: /** Selects an option in the options tree, waits for property sheet
247: * corresponding to selected node and returns instance of PropertySheetOperator.
248: * @param optionPath Path to the option in left (tree-like) column.
249: * @return PropertySheetOperator of selected option
250: */
251: /*public PropertySheetOperator getPropertySheet(String optionPath) {
252: selectOption(optionPath);
253: // wait for property sheet corresponding with selected node
254: final String nodeName = treeTable().tree().getSelectionPath().getLastPathComponent().toString();
255: try {
256: return (PropertySheetOperator)new Waiter(new Waitable() {
257: public Object actionProduced(Object optionsOper) {
258: PropertySheetOperator pso = new PropertySheetOperator((OptionsOperator)optionsOper);//this);
259: return pso.getDescriptionHeader().equals(nodeName) ? pso: null;
260: }
261: public String getDescription() {
262: return("Wait Property sheet for \""+nodeName+"\" is showing.");
263: }
264: }
265: ).waitAction(this);
266: } catch (InterruptedException e) {
267: throw new JemmyException("Interrupted.", e);
268: }
269: }*/
270:
271: //definition levels
272: /**
273: * Shows definition levels column by clicking on the "<<" table
274: * column title.
275: */
276: public void showLevels() {
277: if (treeTable().getColumnCount() == 2) {
278: clickOnSecondHeader();
279: }
280: }
281:
282: /**
283: * Hides definition levels column by clicking on the ">>" table
284: * column title.
285: */
286: public void hideLevels() {
287: if (treeTable().getColumnCount() > 2) {
288: clickOnSecondHeader();
289: }
290: }
291:
292: /**
293: * Sets definition level for the option.
294: * @param optionPath Path to the option in left (tree-like) column.
295: * @param level One of the PROJECT_LEVEL, USER_LEVEL or DEFAULT_LEVEL
296: */
297: /*public void setLevel(String optionPath, final int level) {
298: showLevels();
299: int curLevel = getLevel(optionPath);
300: getOutput().printLine("Setting " + level + " level for \"" +
301: optionPath + "\" option. \nCurrent level: " + curLevel);
302: final int row = selectOption(optionPath);
303: if(level > curLevel) {
304: produceNoBlocking(new NoBlockingAction("Setting property definition level") {
305: public Object doAction(Object param) {
306: setLevel(row, level);
307: return(null);
308: }
309: });
310: JDialogOperator question = new JDialogOperator(Bundle.getString("org.openide.Bundle",
311: "NTF_QuestionTitle"));
312: new JButtonOperator(question, Bundle.getString("org.openide.Bundle",
313: "CTL_YES")).push();
314: } else if(level < curLevel) {
315: setLevel(row, level);
316: }
317: }*/
318:
319: /**
320: * Gets definition level for the option.
321: * @param optionPath Path to the option in left (tree-like) column.
322: * @return level One of the PROJECT_LEVEL, USER_LEVEL or DEFAULT_LEVEL
323: */
324: public int getLevel(String optionPath) {
325: int row = selectOption(optionPath);
326: if (getValue(row, PROJECT_LEVEL) == DEFINE_HERE) {
327: return PROJECT_LEVEL;
328: } else if (getValue(row, USER_LEVEL) == DEFINE_HERE) {
329: return USER_LEVEL;
330: } else if (getValue(row, DEFAULT_LEVEL) == DEFINE_HERE) {
331: return DEFAULT_LEVEL;
332: }
333: return -1;
334: }
335:
336: /** Make an option to be difined on the project level.
337: * @param optionPath Path to the option in left (tree-like) column.
338: */
339: /*public void setProjectLevel(String optionPath) {
340: setLevel(optionPath, PROJECT_LEVEL);
341: }*/
342:
343: /** Make an option to be difined on the user level.
344: * @param optionPath Path to the option in left (tree-like) column.
345: */
346: /*public void setUserLevel(String optionPath) {
347: setLevel(optionPath, USER_LEVEL);
348: }*/
349:
350: /** Make an option to be difined on the default level.
351: * @param optionPath Path to the option in left (tree-like) column.
352: */
353: /*public void setDefaultLevel(String optionPath) {
354: setLevel(optionPath, DEFAULT_LEVEL);
355: }*/
356:
357: //protected
358: /** Sets a level for the row index.
359: * @param row row index in the table
360: * @param level level value
361: */
362: protected void setLevel(int row, int level) {
363: if (level == PROJECT_LEVEL) {
364: defineHere(row, level);
365: } else if (level == USER_LEVEL) {
366: defineHere(row, level);
367: } else if (level == DEFAULT_LEVEL) {
368: revertLevel(row, level);
369: }
370: }
371:
372: /** Gets a value of the level definition mark.
373: * @param row row index in the table
374: * @param column column index in the table
375: * @return value of the level definition mark
376: */
377: protected int getValue(int row, int column) {
378: /* TODO: ab153207, commented FileStateProperty was not found
379: try {
380: FileStateProperty property = ((FileStateProperty)treeTable().getValueAt(row, column));
381: return(((Integer)property.getValue()).intValue());
382: } catch(IllegalAccessException e) {
383: throw new JemmyException("Can not access value!", e);
384: } catch(InvocationTargetException e) {
385: throw new JemmyException("Can not access value!", e);
386: }*/
387: return 0;
388: }
389:
390: /** Chooses "Revert Def" from the combobox.
391: * @param row row index in the table
392: * @param colIndex column index in the table
393: */
394: protected void revertLevel(final int row, final int colIndex) {
395: editLevel(row, colIndex, Bundle.getString(
396: "org.netbeans.core.projects.Bundle",
397: "LBL_action_revert"));
398: }
399:
400: /** Chooses "Define Here" from the combobox.
401: * @param row row index in the table
402: * @param colIndex column index in the table
403: */
404: protected void defineHere(int row, int colIndex) {
405: editLevel(row, colIndex, Bundle.getString(
406: "org.netbeans.core.projects.Bundle",
407: "LBL_action_define"));
408: }
409:
410: /**
411: * Causes table editing and chooses a value in the combobox.
412: * @param rowIndex Row index.
413: * @param colIndex Column index. One of the columns containing
414: * level definition marks.
415: * @param value String value to be choosed in the combobox.
416: */
417: protected void editLevel(int rowIndex, int colIndex, String value) {
418: //Point pnt = treeTable().getPointToClick(rowIndex, colIndex);
419: treeTable().clickOnCell(rowIndex, colIndex);
420: JComboBoxOperator combo = new JComboBoxOperator(treeTable());
421: getTimeouts().sleep("OptionsOperator.BeforeEditingTimeout");
422: combo.selectItem(value);
423: }
424:
425: /**
426: * Clicks on "<<" column header.
427: */
428: protected void clickOnSecondHeader() {
429: JTableHeader header = treeTable().getTableHeader();
430: Rectangle rect = header.getHeaderRect(1);
431: new ComponentOperator(header).clickMouse(rect.x + rect.width
432: / 2, rect.y + rect.height / 2, 1);
433: }
434:
435: /** Performs verification by accessing all sub-components */
436: public void verify() {
437: btClose();
438: btHelp();
439: treeTable().verify();
440: }
441: }
|