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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039: package org.netbeans.jellytools;
040:
041: import java.awt.Component;
042: import java.awt.Container;
043: import java.io.File;
044: import javax.swing.JRadioButton;
045: import org.netbeans.jellytools.actions.ActionNoBlock;
046: import org.netbeans.jemmy.ComponentChooser;
047: import org.netbeans.jemmy.JemmyException;
048: import org.netbeans.jemmy.JemmyProperties;
049: import org.netbeans.jemmy.operators.JButtonOperator;
050: import org.netbeans.jemmy.operators.JCheckBoxOperator;
051: import org.netbeans.jemmy.operators.JFileChooserOperator;
052: import org.netbeans.jemmy.operators.JRadioButtonOperator;
053: import org.netbeans.jemmy.operators.JTabbedPaneOperator;
054: import org.netbeans.jemmy.operators.JTableOperator;
055: import org.netbeans.jemmy.operators.JTextAreaOperator;
056: import org.netbeans.jemmy.operators.JTextFieldOperator;
057:
058: /**
059: * Handle Plugins dialog which is opened from main menu "Tools|Plugins".
060: * This dialog shows list of installed plugins and also list of available
061: * plugins. Plugins can be installed, uninstalled, activated and deactivated.
062: * <p>
063: * Usage:<br>
064: * <pre>
065: * pluginsOper = PluginsOperator.invoke();
066: * pluginsOper.install("My Plugin");
067: * pluginsOper.close();
068: * </pre>
069: *
070: * @author Jiri.Skrivanek@sun.com
071: */
072: public class PluginsOperator extends NbDialogOperator {
073:
074: // "Plugins"
075: private static final String TITLE = Bundle.getString(
076: "org.netbeans.modules.autoupdate.ui.actions.Bundle",
077: "PluginManager_Panel_Name");
078: // "Tools"
079: private static final String TOOLS_ITEM = Bundle.getStringTrimmed(
080: "org.netbeans.core.Bundle", "Menu/Tools");
081: // "Plugins"
082: private static final String PLUGINS_ITEM = Bundle.getStringTrimmed(
083: "org.netbeans.modules.autoupdate.ui.actions.Bundle",
084: "PluginManagerAction_Name");
085: // "Installed"
086: private static final String INSTALLED_LABEL = Bundle
087: .getStringTrimmed(
088: "org.netbeans.modules.autoupdate.ui.Bundle",
089: "PluginManagerUI_UnitTab_Installed_Title");
090: // "Available Plugins"
091: private static final String AVAILABLE_PLUGINS_LABEL = Bundle
092: .getStringTrimmed(
093: "org.netbeans.modules.autoupdate.ui.Bundle",
094: "PluginManagerUI_UnitTab_Available_Title");
095: private JTabbedPaneOperator _tabbedPane;
096:
097: /** Waits for Plugins dialog and waits until initial refresh is finished. */
098: public PluginsOperator() {
099: super (TITLE);
100: tabbedPane();
101: waitTabEnabled(INSTALLED_LABEL);
102: // this works around when Available Plugins tab is not enabled by default
103: if (!tabbedPane().isEnabledAt(
104: tabbedPane().waitPage(AVAILABLE_PLUGINS_LABEL))) {
105: selectInstalled();
106: reloadCatalog();
107: selectAvailablePlugins();
108: }
109: }
110:
111: /** Invokes Plugins dialog from main menu "Tools|Plugins".
112: * @return instance of PluginsOperator
113: */
114: public static PluginsOperator invoke() {
115: new ActionNoBlock(TOOLS_ITEM + "|" + PLUGINS_ITEM, null)
116: .perform();
117: // increase timeout to 120 seconds
118: long oldTime = JemmyProperties
119: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
120: JemmyProperties.setCurrentTimeout(
121: "DialogWaiter.WaitDialogTimeout", 120000);
122: try {
123: return new PluginsOperator();
124: } finally {
125: JemmyProperties.setCurrentTimeout(
126: "DialogWaiter.WaitDialogTimeout", oldTime);
127: }
128: }
129:
130: /** Wait for JTabbedPane.
131: * @return JTabbedPaneOperator
132: */
133: public JTabbedPaneOperator tabbedPane() {
134: if (_tabbedPane == null) {
135: _tabbedPane = new JTabbedPaneOperator(this );
136: _tabbedPane.getTimeouts().setTimeout(
137: "ComponentOperator.WaitComponentEnabledTimeout",
138: 120000);
139: _tabbedPane.getTimeouts().setTimeout(
140: "ComponentOperator.WaitStateTimeout", 120000);
141: }
142: _tabbedPane.wtComponentEnabled();
143: return _tabbedPane;
144: }
145:
146: /** Tries to find JTable in selected tab.
147: * @return JTableOperator instance
148: */
149: public JTableOperator table() {
150: return new JTableOperator(this );
151: }
152:
153: /** Switches to Updates tab and finds "Update" JButton.
154: * @return JButtonOperator
155: */
156: public JButtonOperator btUpdate() {
157: selectUpdates();
158: return new JButtonOperator(this , Bundle.getStringTrimmed(
159: "org.netbeans.modules.autoupdate.ui.Bundle",
160: "UnitTab_bTabAction_Name_UPDATE"));
161: }
162:
163: /** Tries to find "Install" JButton in this dialog.
164: * @return JButtonOperator
165: */
166: public JButtonOperator btInstall() {
167: return new JButtonOperator(this , Bundle.getStringTrimmed(
168: "org.netbeans.modules.autoupdate.ui.Bundle",
169: "UnitTab_bTabAction_Name_AVAILABLE"));
170: }
171:
172: /** Tries to find "Reload Catalog" JButton in this dialog.
173: * @return JButtonOperator
174: */
175: public JButtonOperator btReloadCatalog() {
176: // do not cache it because it is on more tabs
177: return new JButtonOperator(this , Bundle.getStringTrimmed(
178: "org.netbeans.modules.autoupdate.ui.Bundle",
179: "UnitTab_ReloadAction"));
180: }
181:
182: /** Tries to find "Add Plugins..." JButton in this dialog.
183: * @return JButtonOperator
184: */
185: public JButtonOperator btAddPlugins() {
186: selectDownloaded();
187: return new JButtonOperator(this , Bundle.getStringTrimmed(
188: "org.netbeans.modules.autoupdate.ui.Bundle",
189: "UnitTab_bAddLocallyDownloads_Name"));
190: }
191:
192: /** Switches to Installed tab and finds "Deactivate" JButton.
193: * @return JButtonOperator
194: */
195: public JButtonOperator btDeactivate() {
196: selectInstalled();
197: return new JButtonOperator(this , Bundle.getStringTrimmed(
198: "org.netbeans.modules.autoupdate.ui.Bundle",
199: "UnitTab_DeactivateAction"));
200: }
201:
202: /** Switches to Installed tab and finds "Uninstall" JButton.
203: * @return JButtonOperator
204: */
205: public JButtonOperator btUninstall() {
206: selectInstalled();
207: return new JButtonOperator(this , Bundle.getStringTrimmed(
208: "org.netbeans.modules.autoupdate.ui.Bundle",
209: "InstalledTableModel_Columns_Uninstall"));
210: }
211:
212: /** Finds search text field. */
213: public JTextFieldOperator txtSearch() {
214: return new JTextFieldOperator(this );
215: }
216:
217: /** Waits for "NetBeans IDE Installer" dialog.
218: * @return WizardOperator instance
219: */
220: public WizardOperator installer() {
221: // "NetBeans IDE Installer"
222: String installerTitle = Bundle.getString(
223: "org.netbeans.modules.autoupdate.ui.Bundle",
224: "UninstallUnitWizard_Title");
225: return new WizardOperator(installerTitle);
226: }
227:
228: /** Changes current selected tab to "Updates"
229: * @return JTabbedPaneOperator instance
230: */
231: public JTabbedPaneOperator selectUpdates() {
232: String updatesTitle = Bundle.getStringTrimmed(
233: "org.netbeans.modules.autoupdate.ui.Bundle",
234: "PluginManagerUI_UnitTab_Update_Title");
235: return selectTab(updatesTitle);
236: }
237:
238: /** Changes current selected tab to "Available Plugins"
239: * @return JTabbedPaneOperator instance
240: */
241: public JTabbedPaneOperator selectAvailablePlugins() {
242: return selectTab(AVAILABLE_PLUGINS_LABEL);
243: }
244:
245: /** Changes current selected tab to "Downloaded"
246: * @return JTabbedPaneOperator of parent tabbed pane
247: */
248: public JTabbedPaneOperator selectDownloaded() {
249: String downloadedTitle = Bundle.getString(
250: "org.netbeans.modules.autoupdate.ui.Bundle",
251: "PluginManagerUI_UnitTab_Local_Title");
252: return selectTab(downloadedTitle);
253: }
254:
255: /** Changes current selected tab to "Installed"
256: * @return JTabbedPaneOperator instance
257: */
258: public JTabbedPaneOperator selectInstalled() {
259: return selectTab(INSTALLED_LABEL);
260: }
261:
262: /** Changes current selected tab to "Settings"
263: * @return JTabbedPaneOperator instance
264: */
265: public JTabbedPaneOperator selectSettings() {
266: String settingsTitle = Bundle.getStringTrimmed(
267: "org.netbeans.modules.autoupdate.ui.Bundle",
268: "SettingsTab_displayName");
269: return selectTab(settingsTitle);
270: }
271:
272: /** Changes current selected tab to one specified in argument.
273: * @return JTabbedPaneOperator instance
274: */
275: public JTabbedPaneOperator selectTab(String tabName) {
276: waitTabEnabled(tabName);
277: tabbedPane().selectPage(tabName);
278: return tabbedPane();
279: }
280:
281: /** Waits until specified tab is enabled.
282: * @param tabName name of tab
283: */
284: public void waitTabEnabled(final String tabName) {
285: final int installedIndex = tabbedPane().waitPage(tabName);
286: tabbedPane().waitState(new ComponentChooser() {
287:
288: public boolean checkComponent(Component comp) {
289: return tabbedPane().isEnabledAt(installedIndex);
290: }
291:
292: public String getDescription() {
293: return "page " + tabName + " enabled";// NOI18N
294: }
295: });
296: }
297:
298: /** Switches to Updates tab and clicks "Update" button. */
299: public void update() {
300: btUpdate().pushNoBlock();
301: }
302:
303: /** Clicks "Install" button. */
304: public void install() {
305: btInstall().pushNoBlock();
306: }
307:
308: /** Switches to Installed tab and clicks "Uninstall" button. */
309: public void uninstall() {
310: btUninstall().pushNoBlock();
311: }
312:
313: /** Switches to Installed tab and clicks "Deactivate" button. */
314: public void deactivate() {
315: btDeactivate().pushNoBlock();
316: }
317:
318: /** Type given text into search text field and waits until row count of
319: * table is changed.
320: * @param text text to be searched for
321: */
322: public void search(String text) {
323: final int rowCount = table().getRowCount();
324: txtSearch().setText(text);
325: table().waitState(new ComponentChooser() {
326:
327: public boolean checkComponent(Component comp) {
328: return table().getRowCount() != rowCount;
329: }
330:
331: public String getDescription() {
332: return "table changed row count";// NOI18N
333: }
334: });
335: }
336:
337: /** Clicks "Reload Catalog" button and wait until tabbed pane is again enabled. */
338: public void reloadCatalog() {
339: btReloadCatalog().push();
340: tabbedPane();
341: }
342:
343: /** Switches to Downloaded tab and clicks "Add Plugins" button. */
344: public void addPlugins() {
345: btAddPlugins().pushNoBlock();
346: }
347:
348: /** Selects plugin in the table.
349: * @param pluginName name of plugin to be selected
350: */
351: public void selectPlugin(String pluginName) {
352: selectPlugins(new String[] { pluginName });
353: }
354:
355: /** Selects plugins in the table.
356: * @param pluginNames array of plugin names to be selected
357: */
358: public void selectPlugins(String[] pluginNames) {
359: JTableOperator tableOper = table();
360: for (int i = 0; i < pluginNames.length; i++) {
361: String name = pluginNames[i];
362: int row = tableOper.findCellRow(name,
363: new DefaultStringComparator(true, true), 1, 0);
364: if (row == -1) {
365: throw new JemmyException("Plugin " + name
366: + " not found.");
367: }
368: tableOper.selectCell(row, 1);
369: tableOper.clickOnCell(row, 0);
370: }
371: }
372:
373: /** Adds plugin specified by its NBM path to the list at Downloaded tab.
374: * @param nbmPath absolute path to nbm file
375: */
376: public void addPlugin(String nbmPath) {
377: addPlugins();
378: JFileChooserOperator fileChooserOp = new JFileChooserOperator();
379: fileChooserOp.setSelectedFile(new File(nbmPath));
380: fileChooserOp.approve();
381: tabbedPane();
382: }
383:
384: /** Installs given plugin. It switches to Available Plugins tab, selects
385: * desired plugin, click Install button and finish installation.
386: * @param pluginName
387: */
388: public void install(String pluginName) {
389: install(new String[] { pluginName });
390: }
391:
392: /** Installs given plugins. It switches to Available Plugins tab, selects
393: * desired plugins, click Install button and finish installation.
394: * @param pluginNames array of plugin names to be installed
395: */
396: public void install(String[] pluginNames) {
397: selectAvailablePlugins();
398: selectPlugins(pluginNames);
399: install();
400: finishInstall();
401: }
402:
403: /** Finish installation of selected plugins. Do the following:
404: * <ul>
405: * <li>waits for "NetBeans IDE Installer" dialog</li>
406: * <li>in "NetBeans IDE Installer" dialog click Next</li>
407: * <li>click "I accept..." check box</li>
408: * <li>click Install button</li>
409: * <li>wait until message that plugins were successfully installed appears</li>
410: * <li>if restart is not needed wait until the module is turned on (message in main window status bar)</li>
411: * <li>click Finish button to dismiss the dialog</li>
412: * </ul>
413: */
414: public void finishInstall() {
415: WizardOperator installerOper = installer();
416: installerOper.next();
417: // "I accept the terms..."
418: String acceptLabel = Bundle.getStringTrimmed(
419: "org.netbeans.modules.autoupdate.ui.wizards.Bundle",
420: "LicenseApprovalPanel.cbAccept.text");
421: JCheckBoxOperator acceptCheckboxOper = new JCheckBoxOperator(
422: installerOper, acceptLabel);
423: if (!acceptCheckboxOper.isEnabled()) {
424: // wait until licence is shown and dialog is re-created
425: acceptCheckboxOper.waitComponentShowing(false);
426: // find check box again
427: acceptCheckboxOper = new JCheckBoxOperator(installerOper,
428: acceptLabel);
429: }
430: acceptCheckboxOper.push();
431: // "Install"
432: String installInDialogLabel = Bundle.getStringTrimmed(
433: "org.netbeans.modules.autoupdate.ui.wizards.Bundle",
434: "InstallUnitWizardModel_Buttons_Install");
435: new JButtonOperator(installerOper, installInDialogLabel).push();
436: // "The NetBeans IDE Installer has successfully installed the following plugins:"
437: String installedLabel = Bundle.getString(
438: "org.netbeans.modules.autoupdate.ui.wizards.Bundle",
439: "InstallStep_InstallDone_Text");
440: JemmyProperties.setCurrentTimeout(
441: "ComponentOperator.WaitComponentTimeout", 120000);
442: new JTextAreaOperator(installerOper, installedLabel);
443: // "Restart IDE Now"
444: String restartNowLabel = Bundle.getStringTrimmed(
445: "org.netbeans.modules.autoupdate.ui.wizards.Bundle",
446: "InstallUnitWizardModel_Buttons_RestartNow");
447: JRadioButton restartButton = JRadioButtonOperator
448: .findJRadioButton(
449: (Container) installerOper.getSource(),
450: restartNowLabel, true, true);
451: if (restartButton == null) {
452: // check Status line
453: // "Turning on modules...done."
454: String turningOnLabel = Bundle.getString(
455: "org.netbeans.core.startup.Bundle",
456: "MSG_finish_enable_modules");
457: // increase timeout to 120 seconds
458: MainWindowOperator.getDefault().getTimeouts().setTimeout(
459: "Waiter.WaitingTime", 120000);
460: MainWindowOperator.getDefault().waitStatusText(
461: turningOnLabel);
462: }
463: installerOper.finish();
464: }
465: }
|