Author: lzoubek(a)redhat.com
Date: 2010-04-14 07:56:02 -0400 (Wed, 14 Apr 2010)
New Revision: 21465
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotScaleExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotBrowserExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProjectExplorer.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java
Log:
improoved SWTBot extensions, code formating
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -17,6 +17,7 @@
import org.apache.log4j.Logger;
import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.widgets.Scale;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
@@ -27,6 +28,7 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.jboss.tools.ui.bot.ext.parts.SWTBotBrowserExt;
import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotScaleExt;
/**
* Extended version of SWTWorkbenchBot, logging added
@@ -107,4 +109,18 @@
}
}
+ public SWTBotScaleExt scale() {
+ return scale(0);
+ }
+ @SuppressWarnings("unchecked")
+ public SWTBotScaleExt scale(int index) {
+ try {
+ List<Scale> bsrs = (List<Scale>) widgets(widgetOfType(Scale.class));
+ return new SWTBotScaleExt(bsrs.get(0));
+ } catch (WidgetNotFoundException ex) {
+ throw new WidgetNotFoundException(
+ "Could not find widget of type Browser", ex);
+ }
+ }
+
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -1,7 +1,6 @@
package org.jboss.tools.ui.bot.ext;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses;
-import static org.eclipse.swtbot.swt.finder.waits.Conditions.waitForShell;
import java.util.Iterator;
@@ -12,7 +11,6 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
-import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
@@ -25,9 +23,7 @@
import org.jboss.tools.ui.bot.ext.gen.INewObject;
import org.jboss.tools.ui.bot.ext.gen.IPerspective;
import org.jboss.tools.ui.bot.ext.gen.IPreference;
-import org.jboss.tools.ui.bot.ext.gen.IServer;
import org.jboss.tools.ui.bot.ext.gen.IView;
-import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.ServerServer;
/**
* this class represents
@@ -52,6 +48,7 @@
try {
viewObj = bot.viewByTitle(view.getName());
viewObj.setFocus();
+ viewObj.show();
return viewObj;
} catch (WidgetNotFoundException ex) {
}
@@ -62,6 +59,7 @@
bot.button("OK").click();
viewObj = bot.viewByTitle(view.getName());
viewObj.setFocus();
+ viewObj.show();
return viewObj;
}
/**
@@ -251,8 +249,18 @@
return;
} catch (TimeoutException ex) {
if (System.currentTimeMillis()-time>timeout) {
- log.error("Shell '"+activeShellStr+"' probably hanged up
(480s timeout), returning, expect upcomming errors");
- return;
+ log.error("Shell '"+activeShellStr+"' probably hanged up
(480s timeout), returning, forcing to close it, expect errors");
+ try {
+ bot.activeShell().close();
+ activeShell.close();
+ bot.waitUntil(shellCloses(activeShell));
+ log.info("Shell '"+activeShellStr+"' was forced to
close.");
+ return;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw new WidgetNotFoundException("Shell '"+activeShellStr+"'
did not close after timeout", ex);
}
log.warn("Shell '" + activeShellStr + "' is still
opened");
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -27,6 +27,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
@@ -134,8 +135,19 @@
}
}
-
/**
+ * closes all editor tabs
+ * @param save changes?
+ */
+ public void closeAllEditors(boolean save) {
+ for (SWTBotEditor e : bot.editors()) {
+ if (save) {
+ e.save();
+ }
+ e.close();
+ }
+ }
+ /**
* Wait for named running jobs with defined TIMEOUT
*/
public void waitForJobs(String... jobNames) {
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotBrowserExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotBrowserExt.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotBrowserExt.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -8,7 +8,6 @@
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
@@ -124,6 +123,21 @@
}
});
}
+ public void forward() {
+ UIThreadRunnable.syncExec(new VoidResult() {
+ public void run() {
+ pl.setDone(false);
+ widget.addProgressListener(pl);
+ if (widget.isForwardEnabled()) {
+ if (!widget.forward()) {
+ pl.setDone(true);
+ widget.removeProgressListener(pl);
+ }
+ }
+
+ }
+ });
+ }
/**
* loads given URI into browser, page is loaded asynchronously (see {@link
#isPageLoaded()})
*
@@ -146,7 +160,8 @@
/**
*
* @return true by default or when page was completely loaded by browser
- * = asynchronous page load invoked by {@link #goURL(String)} was finished
+ * i.e asynchronous page load invoked by {@link #goURL(String)} was finished
+ * returns false only when browser is loading the page
*/
public boolean isPageLoaded() {
return pl.isDone();
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotScaleExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotScaleExt.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotScaleExt.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -0,0 +1,104 @@
+package org.jboss.tools.ui.bot.ext.parts;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Scale;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.results.IntResult;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.utils.MessageFormat;
+import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
+/**
+ * SWTBot Scale component (very similar to slider, can be found for example in 'New
Web Service' wizard)
+ * @author lzoubek
+ *
+ */
+public class SWTBotScaleExt extends AbstractSWTBotControl<Scale> {
+
+ public SWTBotScaleExt(Scale w) throws WidgetNotFoundException {
+ super(w);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Return the current value of the slider.
+ *
+ * @return the current selection in the slider.
+ */
+ public int getSelection() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getSelection();
+ }
+ });
+ }
+
+ /**
+ * Set the selection to the specified value.
+ *
+ * @param value the value to set into the slider.
+ */
+ public void setSelection(final int value) {
+ log.debug(MessageFormat.format("Setting selection on {0} to {1}", this,
value)); //$NON-NLS-1$
+ waitForEnabled();
+ asyncExec(new VoidResult() {
+ public void run() {
+ widget.setSelection(value);
+ }
+ });
+ notify(SWT.Selection);
+ log.debug(MessageFormat.format("Set selection on {0} to {1}", this, value));
//$NON-NLS-1$
+ }
+
+ /**
+ * Return the maximum value the slider will accept.
+ *
+ * @return the maximum of the slider.
+ */
+ public int getMaximum() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getMaximum();
+ }
+ });
+ }
+
+ /**
+ * Return the minimum value the slider will accept.
+ *
+ * @return the minimum of the slider.
+ */
+ public int getMinimum() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getMinimum();
+ }
+ });
+ }
+
+ /**
+ * Return the increment of the slider.
+ *
+ * @return the increment of the slider.
+ */
+ public int getIncrement() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getIncrement();
+ }
+ });
+ }
+
+ /**
+ * Return the page increment of the slider.
+ *
+ * @return the increment of the slider.
+ */
+ public int getPageIncrement() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getPageIncrement();
+ }
+ });
+ }
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotScaleExt.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -0,0 +1,201 @@
+package org.jboss.tools.ui.bot.ext.view;
+
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.WidgetResult;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
+import org.jboss.tools.ui.bot.ext.SWTOpenExt;
+import org.jboss.tools.ui.bot.ext.SWTUtilExt;
+import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.ui.bot.ext.gen.IView;
+import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+/**
+ * base class for explorer-like helper components
+ * @author lzoubek
+ *
+ */
+public abstract class ExplorerBase extends SWTBotExt {
+ /**
+ * view object representing current view, MUST be defined in derived constructor (for
use, see {@link SWTOpenExt#viewOpen(IView)}
+ */
+ protected IView viewObject;
+ protected final SWTOpenExt open;
+ Logger log = Logger.getLogger(ExplorerBase.class);
+ public ExplorerBase() {
+ open = new SWTOpenExt(this);
+ }
+
+ /**
+ * shows Explorer view
+ */
+ public void show() {
+ open.viewOpen(viewObject);
+ }
+ /*
+ * Selects given project in Package Explorer
+ */
+ public void selectProject(String projectName) {
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ viewBot.tree().expandNode(projectName).select();
+ }
+ /**
+ * Selects Tree Item within Package Explorer
+ * @param treeItemText
+ * @param path
+ * @return
+ */
+ public SWTBotTreeItem selectTreeItem(String treeItemText, String[] path) {
+ return
SWTEclipseExt.getTreeItemOnPath(viewByTitle(viewObject.getName()).bot().tree(),
+ treeItemText, path)
+ .select();
+ }
+ /**
+ * deletes given project from workspace
+ * @param projectName
+ * @param fileSystem if true, project will be also deleted from file-system
+ */
+ public void deleteProject(String projectName, boolean fileSystem) {
+ log.info("Deleting project '"+projectName+"'");
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ SWTBotTreeItem item = viewBot.tree().expandNode(projectName);
+ ContextMenuHelper.prepareTreeItemForContextMenu(viewBot.tree(), item);
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(viewBot.tree(), IDELabel.Menu.DELETE,
false)).click();
+ shell("Delete Resources").activate();
+ if (fileSystem) {
+ checkBox().click();
+ }
+ open.finish(this,IDELabel.Button.OK);
+ new SWTUtilExt(this).waitForNonIgnoredJobs();
+ }
+ /**
+ * deletes all projects from workspace
+ */
+ public void deleteAllProjects() {
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ List<String> items = new Vector<String>();
+ for (SWTBotTreeItem ti : viewBot.tree().getAllItems()) {
+ items.add(ti.getText());
+ }
+ for (String proj : items) {
+ try {
+ viewBot.tree().expandNode(proj);
+ viewBot.tree().select(proj);
+ // try to select project in tree (in some cases, when one project is deleted,
+ // the other item in tree (not being a project) is auto-deleted)
+
+ } catch (WidgetNotFoundException ex) {
+ log.warn("Attempted to delete non-existing project
'"+proj+"'");
+ continue;
+ }
+ deleteProject(proj,true);
+ }
+ }
+ /**
+ * opens file (selects in tree and doubleclicks)
+ * @param projectName
+ * @param path to file
+ * @return editor with opened file
+ */
+ public SWTBotEditor openFile(String projectName, String... path) {
+ SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
+ viewByTitle(IDELabel.View.PROJECT_EXPLORER).show();
+ viewByTitle(IDELabel.View.PROJECT_EXPLORER).setFocus();
+ SWTBotTree tree = viewBot.tree();
+ SWTBotTreeItem item = tree.expandNode(projectName);
+ StringBuilder builder = new StringBuilder(projectName);
+ // Go through path
+ for (String nodeName : path) {
+ item = item.expandNode(nodeName);
+ builder.append("/" + nodeName);
+ }
+ item.select().doubleClick();
+ log.info("File Opened:" + builder.toString());
+ SWTBotEditor editor = activeEditor();
+ return editor;
+ }
+ /**
+ * runs given project on Server (uses default server, the first one) server MUST be
running
+ * @param projectName
+ */
+ public void runOnServer(String projectName) {
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ SWTBotTreeItem item = viewBot.tree().expandNode(projectName);
+ ContextMenuHelper.prepareTreeItemForContextMenu(viewBot.tree(), item);
+ final SWTBotMenu menuRunAs =
viewBot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.RUN_AS);
+ final MenuItem menuItem = UIThreadRunnable
+ .syncExec(new WidgetResult<MenuItem>() {
+ public MenuItem run() {
+ int menuItemIndex = 0;
+ MenuItem menuItem = null;
+ final MenuItem[] menuItems = menuRunAs.widget.getMenu().getItems();
+ while (menuItem == null && menuItemIndex < menuItems.length){
+ if (menuItems[menuItemIndex].getText().indexOf("Run on Server")
> - 1){
+ menuItem = menuItems[menuItemIndex];
+ }
+ else{
+ menuItemIndex++;
+ }
+ }
+ return menuItem;
+ }
+ });
+ if (menuItem != null){
+ new SWTBotMenu(menuItem).click();
+ shell(IDELabel.Shell.RUN_ON_SERVER).activate();
+ open.finish(this);
+ new SWTUtilExt(this).waitForAll(Timing.time3S());
+ }
+ else{
+ throw new WidgetNotFoundException("Unable to find Menu Item with Label
'Run on Server'");
+ }
+
+ }
+ /**
+ * true if resource described by parameters exists in ProjectExplorer
+ * @param projectName project name
+ * @param resource path (e.g. 'Project' 'src'
'org.jbosstools.test' 'MyClass.java')
+ * @return
+ */
+ public boolean existsResource(String... resource) {
+
+ try {
+ SWTBot viewBot = viewByTitle(viewObject.getName()).bot();
+ SWTBotTreeItem ancestor = viewBot.tree().getTreeItem(resource[0]);
+ viewBot.tree().expandNode(resource[0]);
+ for (int i=1;i<resource.length;i++) {
+ ancestor = getItem(ancestor, resource[i]);
+ if (ancestor == null) {
+ return false;
+ }
+ }
+ return true;
+ }
+ catch (WidgetNotFoundException ex) {
+ ex.printStackTrace();
+ return false;
+ }
+ }
+ private SWTBotTreeItem getItem(SWTBotTreeItem ancestor, String name) {
+ try {
+ return ancestor.expandNode(name);
+ }
+ catch (WidgetNotFoundException ex) {
+ return null;
+ }
+ }
+
+
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ExplorerBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -1,36 +1,15 @@
package org.jboss.tools.ui.bot.ext.view;
-import org.eclipse.swtbot.swt.finder.SWTBot;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
-import org.jboss.tools.ui.bot.ext.SWTBotExt;
-import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
-import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.JavaPackageExplorer;
/**
* Class provides bot routines related to Package Explorer View
* @author jpeterka
*
*/
-public class PackageExplorer extends SWTBotExt {
-
- /*
- * Selects project in Package Explorer
- */
- public void selectProject(String projectName) {
- SWTBot viewBot = viewByTitle(IDELabel.View.PACKAGE_EXPLORER).bot();
- viewBot.tree().expandNode(projectName).select();
- }
+public class PackageExplorer extends ExplorerBase {
- /**
- * Selects Tree Item within Package Explorer
- * @param treeItemText
- * @param path
- * @return
- */
- public SWTBotTreeItem selectTreeItem(String treeItemText, String[] path) {
- return
SWTEclipseExt.getTreeItemOnPath(viewByTitle(IDELabel.View.PACKAGE_EXPLORER).bot().tree(),
- treeItemText, path)
- .select();
- }
-
+ public PackageExplorer() {
+ viewObject = JavaPackageExplorer.LABEL;
+ }
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProjectExplorer.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProjectExplorer.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ProjectExplorer.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -10,215 +10,17 @@
******************************************************************************/
package org.jboss.tools.ui.bot.ext.view;
-import static org.jboss.tools.ui.bot.ext.SWTTestExt.eclipse;
-
-import java.util.List;
-import java.util.Vector;
-
-import org.apache.log4j.Logger;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
-import org.eclipse.swtbot.swt.finder.SWTBot;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
-import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
-import org.eclipse.swtbot.swt.finder.results.WidgetResult;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
-import org.jboss.tools.ui.bot.ext.SWTBotExt;
-import org.jboss.tools.ui.bot.ext.SWTOpenExt;
-import org.jboss.tools.ui.bot.ext.SWTUtilExt;
-import org.jboss.tools.ui.bot.ext.Timing;
-import org.jboss.tools.ui.bot.ext.gen.ActionItem;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.View;
-import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.ServerServer;
-import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.ServerServers;
-import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
-import org.jboss.tools.ui.bot.ext.types.IDELabel;
-import org.jboss.tools.ui.bot.ext.types.ViewType;
/**
- * Eclipse project type enum
+ * Eclipse project explorer helper component
*
- * @author jpeterka
+ * @author jpeterka & lzoubek
*
*/
-public class ProjectExplorer extends SWTBotExt {
+public class ProjectExplorer extends ExplorerBase {
- Logger log = Logger.getLogger(ProjectExplorer.class);
- private final SWTOpenExt open;
public ProjectExplorer() {
- open = new SWTOpenExt(this);
+ viewObject = View.GeneralProjectExplorer.LABEL;
}
- /**
- * shows Project Explorer view
- */
- public void show() {
- open.viewOpen(ActionItem.View.GeneralProjectExplorer.LABEL);
- }
- public void removeProjectFromServers(String projectName){
-
- SWTBot bot = open.viewOpen(View.ServerServers.LABEL).bot();
- SWTBotTree serverTree = bot.tree();
- // Expand All
- for (SWTBotTreeItem serverTreeItem : serverTree.getAllItems()){
- serverTreeItem.expand();
- // if JSF Test Project is deployed to server remove it
- SWTBotTreeItem[] serverTreeItemChildren = serverTreeItem.getItems();
- if (serverTreeItemChildren != null && serverTreeItemChildren.length >
0){
- int itemIndex = 0;
- boolean found = false;
- do{
- String treeItemlabel = serverTreeItemChildren[itemIndex].getText();
- found = treeItemlabel.startsWith(projectName);
- } while (!found && ++itemIndex < serverTreeItemChildren.length);
- // Server Tree Item has Child with Text equal to JSF TEst Project
- if (found){
- log.info("Found project to be removed from server: " +
serverTreeItemChildren[itemIndex].getText());
-
ContextMenuHelper.prepareTreeItemForContextMenu(serverTree,serverTreeItemChildren[itemIndex]);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(serverTree,
IDELabel.Menu.REMOVE, false)).click();
- bot.shell("Server").activate();
- open.finish(this, IDELabel.Button.OK);
- log.info("Removed project from server: " +
serverTreeItemChildren[itemIndex].getText());
- }
- }
- }
- }
- /**
- * runs given project on Server (uses default server, the first one) server MUST be
running
- * @param projectName
- */
- public void runOnServer(String projectName) {
- SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
- SWTBotTreeItem item = viewBot.tree().expandNode(projectName);
- ContextMenuHelper.prepareTreeItemForContextMenu(viewBot.tree(), item);
- final SWTBotMenu menuRunAs =
viewBot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.RUN_AS);
- final MenuItem menuItem = UIThreadRunnable
- .syncExec(new WidgetResult<MenuItem>() {
- public MenuItem run() {
- int menuItemIndex = 0;
- MenuItem menuItem = null;
- final MenuItem[] menuItems = menuRunAs.widget.getMenu().getItems();
- while (menuItem == null && menuItemIndex < menuItems.length){
- if (menuItems[menuItemIndex].getText().indexOf("Run on Server")
> - 1){
- menuItem = menuItems[menuItemIndex];
- }
- else{
- menuItemIndex++;
- }
- }
- return menuItem;
- }
- });
- if (menuItem != null){
- new SWTBotMenu(menuItem).click();
- shell(IDELabel.Shell.RUN_ON_SERVER).activate();
- new SWTOpenExt(this).finish(this);
- SWTUtilExt swtUtil = new SWTUtilExt(this);
- swtUtil.waitForNonIgnoredJobs();
- swtUtil.waitForAll(Timing.time3S());
- }
- else{
- throw new WidgetNotFoundException("Unable to find Menu Item with Label
'Run on Server'");
- }
-
- }
- public SWTBotEditor openFile(String projectName, String... path) {
- SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
-
- viewByTitle(IDELabel.View.PROJECT_EXPLORER).show();
- viewByTitle(IDELabel.View.PROJECT_EXPLORER).setFocus();
- SWTBotTree tree = viewBot.tree();
- SWTBotTreeItem item = tree.expandNode(projectName);
- StringBuilder builder = new StringBuilder(projectName);
- // Go through path
- for (String nodeName : path) {
- item = item.expandNode(nodeName);
- builder.append("/" + nodeName);
- }
-
- item.select().doubleClick();
- log.info("File Opened:" + builder.toString());
-
- SWTBotEditor editor = activeEditor();
- return editor;
- }
- public void deleteAllProjects() {
- SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
- List<String> items = new Vector<String>();
- for (SWTBotTreeItem ti : viewBot.tree().getAllItems()) {
- items.add(ti.getText());
- }
- for (String proj : items) {
- try {
- viewBot.tree().expandNode(proj);
- viewBot.tree().select(proj);
- // try to select project in tree (in some cases, when one project is deleted,
- // the other item in tree (not being a project) is auto-deleted)
-
- } catch (WidgetNotFoundException ex) {
- log.warn("Attempted to delete non-existing project
'"+proj+"'");
- continue;
- }
- deleteProject(proj,true);
- }
- }
- /**
- * deletes given project from workspace
- * @param projectName
- * @param fileSystem if true, project will be also deleted from filesystem
- */
- public void deleteProject(String projectName, boolean fileSystem) {
- SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
- SWTBotTreeItem item = viewBot.tree().expandNode(projectName);
- ContextMenuHelper.prepareTreeItemForContextMenu(viewBot.tree(), item);
- new SWTBotMenu(ContextMenuHelper.getContextMenu(viewBot.tree(), IDELabel.Menu.DELETE,
false)).click();
- shell("Delete Resources").activate();
- if (fileSystem) {
- checkBox().click();
- }
- new SWTOpenExt(this).finish(this,IDELabel.Button.OK);
- new SWTUtilExt(this).waitForNonIgnoredJobs();
-
- }
- /*
- * Selects given project in Package Explorer
- */
- public void selectProject(String projectName) {
- SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
- viewBot.tree().expandNode(projectName).select();
- }
- /**
- * true if resource described by parameters exists in ProjectExplorer
- * @param projectName project name
- * @param resource path (e.g. 'Project' 'src'
'org.jbosstools.test' 'MyClass.java')
- * @return
- */
- public boolean existsResource(String... resource) {
-
- try {
- SWTBot viewBot = viewByTitle(IDELabel.View.PROJECT_EXPLORER).bot();
- SWTBotTreeItem ancestor = viewBot.tree().getTreeItem(resource[0]);
- viewBot.tree().expandNode(resource[0]);
- for (int i=1;i<resource.length;i++) {
- ancestor = getItem(ancestor, resource[i]);
- if (ancestor == null) {
- return false;
- }
- }
- return true;
- }
- catch (WidgetNotFoundException ex) {
- ex.printStackTrace();
- return false;
- }
- }
- private SWTBotTreeItem getItem(SWTBotTreeItem ancestor, String name) {
- try {
- return ancestor.expandNode(name);
- }
- catch (WidgetNotFoundException ex) {
- return null;
- }
- }
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java 2010-04-14
11:52:35 UTC (rev 21464)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ServersView.java 2010-04-14
11:56:02 UTC (rev 21465)
@@ -12,6 +12,7 @@
import org.jboss.tools.ui.bot.ext.SWTUtilExt;
import org.jboss.tools.ui.bot.ext.Timing;
import org.jboss.tools.ui.bot.ext.gen.ActionItem;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem.View;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.View.ServerServers;
import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
@@ -101,4 +102,43 @@
}
return null;
}
+ /**
+ * removes project with given name from all servers
+ * @param projectName
+ */
+ public void removeProjectFromServers(String projectName){
+
+ SWTBot bot = open.viewOpen(View.ServerServers.LABEL).bot();
+ SWTBotTree serverTree = bot.tree();
+ // Expand All
+ for (SWTBotTreeItem serverTreeItem : serverTree.getAllItems()){
+ serverTreeItem.expand();
+ // if JSF Test Project is deployed to server remove it
+ SWTBotTreeItem[] serverTreeItemChildren = serverTreeItem.getItems();
+ if (serverTreeItemChildren != null && serverTreeItemChildren.length >
0){
+ int itemIndex = 0;
+ boolean found = false;
+ do{
+ String treeItemlabel = serverTreeItemChildren[itemIndex].getText();
+ found = treeItemlabel.startsWith(projectName);
+ } while (!found && ++itemIndex < serverTreeItemChildren.length);
+ // Server Tree Item has Child with Text equal to JSF TEst Project
+ if (found){
+ log.info("Found project to be removed from server: " +
serverTreeItemChildren[itemIndex].getText());
+
ContextMenuHelper.prepareTreeItemForContextMenu(serverTree,serverTreeItemChildren[itemIndex]);
+ new SWTBotMenu(ContextMenuHelper.getContextMenu(serverTree,
IDELabel.Menu.REMOVE, false)).click();
+ bot.shell("Server").activate();
+ open.finish(this, IDELabel.Button.OK);
+ log.info("Removed project from server: " +
serverTreeItemChildren[itemIndex].getText());
+ new SWTUtilExt(this).waitForNonIgnoredJobs();
+ } else {
+ log.info("Project '"+projectName+"' not found on any
server");
+ }
+ }
+ }
+ }
+ /**
+ * removes project with given name from all servers
+ * @param projectName
+ */
}