ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.swtbot.tests / src / org / eclipse / linuxtools / tmf / ui / swtbot / tests / SWTBotUtil.java
index e52e239c2bc8bddb5b9446cdd4edcdb133a23265..55224d9c67f5c8d4ab802db8967817b077b43708 100644 (file)
@@ -18,19 +18,37 @@ import static org.junit.Assert.fail;
 import java.util.List;
 
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
 import org.eclipse.linuxtools.tmf.ui.views.TracingPerspectiveFactory;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPageLayout;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.WorkbenchException;
+import org.hamcrest.Matcher;
 
 /**
  * SWTBot Helper functions
@@ -84,6 +102,45 @@ public abstract class SWTBotUtil {
         SWTBotUtil.waitForJobs();
     }
 
+    /**
+     * Deletes a tracing project
+     *
+     * @param projectName
+     *            the name of the tracing project
+     * @param bot
+     *            the workbench bot
+     */
+    public static void deleteProject(String projectName, SWTWorkbenchBot bot) {
+        // Wait for any analysis to complete because it might create
+        // supplementary files
+        SWTBotUtil.waitForJobs();
+        try {
+            ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).refreshLocal(IResource.DEPTH_INFINITE, null);
+        } catch (CoreException e) {
+        }
+
+        SWTBotUtil.waitForJobs();
+
+        final SWTBotView projectViewBot = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
+        projectViewBot.setFocus();
+
+        SWTBotTree treeBot = projectViewBot.bot().tree();
+        SWTBotTreeItem treeItem = treeBot.getTreeItem(projectName);
+        SWTBotMenu contextMenu = treeItem.contextMenu("Delete");
+        contextMenu.click();
+
+        bot.shell("Delete Resources").setFocus();
+        final SWTBotCheckBox checkBox = bot.checkBox();
+        bot.waitUntil(Conditions.widgetIsEnabled(checkBox));
+        checkBox.click();
+
+        final SWTBotButton okButton = bot.button("OK");
+        bot.waitUntil(Conditions.widgetIsEnabled(okButton));
+        okButton.click();
+
+        SWTBotUtil.waitForJobs();
+    }
+
     /**
      * Focus on the main window
      *
@@ -153,4 +210,66 @@ public abstract class SWTBotUtil {
         }
 
     }
+
+    /**
+     * Open a trace, this does not perform any validation though
+     *
+     * @param projectName
+     *            The project name
+     * @param tracePath
+     *            the path of the trace file (absolute or relative)
+     * @param traceType
+     *            the trace canonical string (eg:
+     *            org.eclipse.linuxtools.btf.trace)
+     */
+    public static void openTrace(final String projectName, final String tracePath, final String traceType) {
+        final Exception exception[] = new Exception[1];
+        exception[0] = null;
+        UIThreadRunnable.syncExec(new VoidResult() {
+            @Override
+            public void run() {
+                try {
+                    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+                    TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
+                    TmfOpenTraceHelper.openTraceFromPath(destinationFolder, tracePath, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), traceType);
+                } catch (CoreException e) {
+                    exception[0] = e;
+                }
+            }
+        });
+        if (exception[0] != null) {
+            fail(exception[0].getMessage());
+        }
+
+        delay(1000);
+        waitForJobs();
+    }
+
+    /**
+     * Opens an editor and sets focus to the editor
+     *
+     * @param bot
+     *            the workbench bot
+     * @param editorName
+     *            the editor name
+     * @return the corresponding SWTBotEditor
+     */
+    public static SWTBotEditor openEditor(SWTWorkbenchBot bot, String editorName) {
+        Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(editorName);
+        final SWTBotEditor editorBot = bot.editor(matcher);
+        IEditorPart iep = editorBot.getReference().getEditor(true);
+        final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
+        editorBot.show();
+        UIThreadRunnable.syncExec(new VoidResult() {
+            @Override
+            public void run() {
+                tmfEd.setFocus();
+            }
+        });
+
+        SWTBotUtil.waitForJobs();
+        SWTBotUtil.delay(1000);
+        assertNotNull(tmfEd);
+        return editorBot;
+    }
 }
This page took 0.025928 seconds and 5 git commands to generate.