Example #1
0
  public static void selectTabbedPropertyView(final SWTBot viewerBot, final String tabeText) {
    viewerBot.sleep(
        1000); // DO NOT REMOVE ME //TODO : find a way to remove bot.sleep, can save almost one
               // minute
    UIThreadRunnable.syncExec(
        new VoidResult() {

          /*
           * (non-Javadoc)
           * @see org.eclipse.swtbot.swt.finder.results.VoidResult#run()
           */
          @Override
          @SuppressWarnings("restriction")
          public void run() {
            try {
              final List<? extends Widget> widgets =
                  viewerBot
                      .getFinder()
                      .findControls(WidgetMatcherFactory.widgetOfType(TabbedPropertyList.class));
              Assert.assertTrue(
                  "No widget of type " + TabbedPropertyList.class.getName() + " has been found",
                  widgets.size() > 0);
              final TabbedPropertyList tabbedPropertyList = (TabbedPropertyList) widgets.get(0);
              final StringBuilder availableTabbedPropertySection = new StringBuilder("");
              int i = 0;
              boolean found = false;
              ListElement currentTab;
              final Method selectMethod =
                  TabbedPropertyList.class.getDeclaredMethod("select", new Class[] {int.class});
              selectMethod.setAccessible(true);
              do {
                currentTab =
                    (org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyList
                            .ListElement)
                        tabbedPropertyList.getElementAt(i);
                if (currentTab != null) {
                  final String label = currentTab.getTabItem().getText();
                  availableTabbedPropertySection.append(label);
                  if (label.equals(tabeText)) {
                    found = true;
                    selectMethod.invoke(tabbedPropertyList, i);
                  }
                }
                i++;
              } while (currentTab != null && !found);
              if (!found) {
                throw new WidgetNotFoundException(
                    "Can't find a tab item with "
                        + tabeText
                        + " label. Only found: "
                        + availableTabbedPropertySection.toString());
              }
            } catch (final Exception ex) {
              BonitaStudioLog.error(ex);
              throw new WidgetNotFoundException(
                  "Can't find a tab item with " + tabeText + " label");
            }
          }
        });
  }
  /**
   * Clicks the context menu matching the text.
   *
   * @param text the text on the context menu.
   * @throws WidgetNotFoundException if the widget is not found.
   */
  public static void clickContextMenu(final AbstractSWTBot<?> bot, final String... texts) {

    // show
    final MenuItem menuItem =
        UIThreadRunnable.syncExec(
            new WidgetResult<MenuItem>() {
              public MenuItem run() {
                MenuItem menuItem = null;
                Control control = (Control) bot.widget;

                // MenuDetectEvent added by Stefan Schaefer
                Event event = new Event();
                control.notifyListeners(SWT.MenuDetect, event);
                if (!event.doit) {
                  return null;
                }

                Menu menu = control.getMenu();
                for (String text : texts) {
                  Matcher<?> matcher = allOf(instanceOf(MenuItem.class), withMnemonic(text));
                  menuItem = show(menu, matcher);
                  if (menuItem != null) {
                    menu = menuItem.getMenu();
                  } else {
                    hide(menu);
                    break;
                  }
                }

                return menuItem;
              }
            });
    if (menuItem == null) {
      throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(texts));
    }

    // click
    click(menuItem);

    // hide
    UIThreadRunnable.syncExec(
        new VoidResult() {
          public void run() {
            hide(menuItem.getParent());
          }
        });
  }
 protected Shell[] findShells() {
   return UIThreadRunnable.syncExec(
       new ArrayResult<Shell>() {
         public Shell[] run() {
           return parent.getShells();
         }
       });
 }
 /** focus on this edit part */
 public void focus() {
   UIThreadRunnable.syncExec(
       new VoidResult() {
         public void run() {
           graphicalEditor.graphicalViewer.setFocus(part);
         }
       });
 }
 /** get the parent, or null if this is the root edit part. */
 public SWTBotGefEditPart parent() {
   return UIThreadRunnable.syncExec(
       new Result<SWTBotGefEditPart>() {
         public SWTBotGefEditPart run() {
           return graphicalEditor.createEditPart(part.getParent());
         }
       });
 }
 public Boolean enabled() {
   return UIThreadRunnable.syncExec(
       display,
       new Result<Boolean>() {
         public Boolean run() {
           return Button.super.isEnabled();
         }
       });
 }
 public String getText() {
   return UIThreadRunnable.syncExec(
       display,
       new Result<String>() {
         public String run() {
           return Button.super.getText();
         }
       });
 }
Example #8
0
 public SWTBotTreeColumn(final TreeColumn w) throws WidgetNotFoundException {
   super(w);
   parent =
       UIThreadRunnable.syncExec(
           new WidgetResult<Tree>() {
             public Tree run() {
               return w.getParent();
             }
           });
 }
 public Button select(final boolean selected) {
   UIThreadRunnable.syncExec(
       display,
       new VoidResult() {
         public void run() {
           Button.this.setSelection(selected);
         }
       });
   return this;
 }
 public Button image(final Image image) {
   UIThreadRunnable.syncExec(
       display,
       new VoidResult() {
         public void run() {
           Button.super.setImage(image);
         }
       });
   return this;
 }
 public Button enabled(final boolean value) {
   UIThreadRunnable.syncExec(
       display,
       new VoidResult() {
         public void run() {
           Button.super.setEnabled(value);
         }
       });
   return this;
 }
 protected void closeAllEditors() {
   syncExec(
       new VoidResult() {
         @Override
         public void run() {
           IWorkbenchPage page =
               PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
           page.closeAllEditors(false);
         }
       });
 }
Example #13
0
 public static SWTBotTreeColumn getColumn(final Tree tree, final int index) {
   TreeColumn treeColumn =
       UIThreadRunnable.syncExec(
           tree.getDisplay(),
           new WidgetResult<TreeColumn>() {
             public TreeColumn run() {
               return tree.getColumn(index);
             }
           });
   return new SWTBotTreeColumn(treeColumn);
 }
 public static Button add_Button(final Composite target, final int style) {
   return UIThreadRunnable.syncExec(
       target.getDisplay(),
       new Result<Button>() {
         public Button run() {
           Button button = new Button(target, style);
           target.layout(true);
           return button;
         }
       });
 }
Example #15
0
  /**
   * Clicks the context menu matching the text.
   *
   * @param text the text on the context menu.
   * @throws WidgetNotFoundException if the widget is not found.
   */
  public static void clickContextMenu(final AbstractSWTBot<?> bot, final String... texts) {

    // show
    final MenuItem menuItem =
        UIThreadRunnable.syncExec(
            new WidgetResult<MenuItem>() {
              public MenuItem run() {
                MenuItem menuItem = null;
                Control control = (Control) bot.widget;
                Menu menu = control.getMenu();
                for (String text : texts) {
                  @SuppressWarnings("unchecked")
                  Matcher<?> matcher = allOf(instanceOf(MenuItem.class), withMnemonic(text));
                  menuItem = show(menu, matcher);
                  if (menuItem != null) {
                    menu = menuItem.getMenu();
                  } else {
                    hide(menu);
                    break;
                  }
                }

                return menuItem;
              }
            });
    if (menuItem == null) {
      throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(texts));
    }

    // click
    click(menuItem);

    // hide
    UIThreadRunnable.syncExec(
        new VoidResult() {
          public void run() {
            hide(menuItem.getParent());
          }
        });
  }
    private StructuredSelection getEventsTableSelection() {
      return UIThreadRunnable.syncExec(
          new Result<StructuredSelection>() {

            @Override
            public StructuredSelection run() {
              SWTBotEditor eventsEditor = SWTBotUtils.activeEventsEditor(fBot);
              TmfEventsEditor part = (TmfEventsEditor) eventsEditor.getReference().getPart(false);
              StructuredSelection selection = (StructuredSelection) part.getSelection();
              return selection;
            }
          });
    }
 public void setText(final String text) {
   if (text != null)
     UIThreadRunnable.syncExec(
         display,
         new VoidResult() {
           public void run() {
             Button.super.setText(text);
             Button.this
                 .getParent()
                 .layout(true); // need to see if there is a better to way to refresh the contents
           }
         });
 }
 private void openGraphitiTestPerspective() {
   syncExec(
       new VoidResult() {
         @Override
         public void run() {
           SWTBotPerspective p =
               bot.perspectiveById(
                   "org.eclipse.graphiti.examples.common.perspective.GFPerspective");
           p.activate();
           bot.activeShell().widget.setMaximized(true);
         }
       });
 }
Example #19
0
 /**
  * Get the children of this edit part.
  *
  * @return the edit part's children
  */
 @SuppressWarnings("unchecked")
 public List<SWTBotGefEditPart> children() {
   return UIThreadRunnable.syncExec(
       new Result<List<SWTBotGefEditPart>>() {
         public List<SWTBotGefEditPart> run() {
           List<SWTBotGefEditPart> children = new ArrayList<SWTBotGefEditPart>();
           for (org.eclipse.gef.EditPart child :
               ((List<org.eclipse.gef.EditPart>) part.getChildren())) {
             children.add(graphicalEditor.createEditPart(child));
           }
           return children;
         }
       });
 }
  /**
   * Applies Open On (F3) on textToSelect within editor with editorTitle and checks if
   * expectedOpenedFileName was opened
   *
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @param expectedOpenedFileName
   */
  public static SWTBotEditor checkOpenOnFileIsOpened(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex,
      String expectedOpenedFileName) {

    SWTBotEclipseEditor sourceEditor =
        SWTJBTExt.selectTextInSourcePane(
            bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex);

    bot.sleep(Timing.time3S());

    sourceEditor.setFocus();
    // process UI Events
    UIThreadRunnable.syncExec(
        new VoidResult() {
          @Override
          public void run() {}
        });
    bot.sleep(Timing.time3S());
    new SWTUtilExt(bot).waitForNonIgnoredJobs();

    KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_F3);
    // process UI Events
    UIThreadRunnable.syncExec(
        new VoidResult() {
          @Override
          public void run() {}
        });
    bot.sleep(Timing.time3S());
    new SWTUtilExt(bot).waitForNonIgnoredJobs();

    return checkActiveEditorTitle(bot, expectedOpenedFileName);
  }
Example #21
0
 @SuppressWarnings("unchecked")
 public List<SWTBotGefConnectionEditPart> targetConnections() {
   return UIThreadRunnable.syncExec(
       new Result<List<SWTBotGefConnectionEditPart>>() {
         public List<SWTBotGefConnectionEditPart> run() {
           List<SWTBotGefConnectionEditPart> connections =
               new ArrayList<SWTBotGefConnectionEditPart>();
           List<org.eclipse.gef.ConnectionEditPart> targetConnections =
               ((GraphicalEditPart) part).getTargetConnections();
           for (org.eclipse.gef.ConnectionEditPart c : targetConnections) {
             connections.add(graphicalEditor.createEditPart(c));
           }
           return connections;
         }
       });
 }
  private SWTBotMenu nodeContextMenu(
      final SWTBotTree tree, SWTBotTreeItem item, final String... menu) {
    assert menu.length > 0;
    ContextMenuHelper.prepareTreeItemForContextMenu(tree, item);
    return UIThreadRunnable.syncExec(
        new Result<SWTBotMenu>() {

          public SWTBotMenu run() {
            SWTBotMenu m = new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, menu[0], false));
            for (int i = 1; i < menu.length; i++) {
              m = m.menu(menu[i]);
            }
            return m;
          }
        });
  }
  public Button onClick(final Runnable runnable) {
    if (runnable != null)
      UIThreadRunnable.syncExec(
          display,
          new VoidResult() {
            public void run() {
              Button.this.addListener(
                  SWT.Selection,
                  new Listener() {
                    public void handleEvent(Event event) {
                      runnable.run();
                    }
                  });
            }
          });

    return this;
  }
Example #24
0
 public static StagingViewTester openStagingView() throws Exception {
   SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
   UIThreadRunnable.syncExec(
       new VoidResult() {
         public void run() {
           try {
             PlatformUI.getWorkbench()
                 .getActiveWorkbenchWindow()
                 .getActivePage()
                 .showView(StagingView.VIEW_ID);
           } catch (Exception e) {
             throw new WidgetNotFoundException(e.getMessage(), e);
           }
         }
       });
   SWTBotView view = workbenchBot.viewById(StagingView.VIEW_ID);
   return new StagingViewTester(view);
 }
 /** @param diagramEditor */
 protected void shutdownEditor(final DiagramEditor diagramEditor) {
   syncExec(
       new VoidResult() {
         @Override
         public void run() {
           // Using SWTBot yields an exception since a keyboard layout file for DE is not
           // available.
           //				bot.activeShell().pressShortcut(SWT.NONE, SWT.ESC);
           try {
             Robot r = new Robot();
             r.keyPress(SWT.ESC);
             r.keyRelease(SWT.ESC);
           } catch (AWTException e) {
             e.printStackTrace();
           }
           diagramEditor.doSave(null);
           closeEditor(diagramEditor);
         }
       });
 }
Example #26
0
  /**
   * Invokes method
   *
   * @param object
   * @param methodName
   * @return
   */
  public static Object invokeMethod(final Object object, String methodName) {

    final Method method;
    try {
      method = object.getClass().getMethod(methodName, new Class[0]);
    } catch (Exception e) {
      throw new RuntimeException("Cannot get method : " + e.getMessage());
    }
    Widget widget = null;
    final Object result;
    if (object instanceof Widget) {
      widget = (Widget) object;
      result =
          UIThreadRunnable.syncExec(
              widget.getDisplay(),
              new Result<Object>() {
                public Object run() {
                  Object o = null;
                  try {
                    o = method.invoke(object, new Object[0]);
                  } catch (Exception e) {
                    try {
                      throw new RuntimeException("Cannot invoke method : " + e.getMessage());
                    } catch (Exception e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                    }
                  }
                  return o;
                }
              });
    } else
      try {
        result = method.invoke(object, new Object[0]);
      } catch (Exception e) {
        throw new RuntimeException("Cannot invoke method : " + e.getMessage());
      }

    return result;
  }
  /**
   * Choose Run On Server menu for specified project
   *
   * @param bot
   * @param projectName
   */
  public static void runProjectOnServer(SWTWorkbenchBot bot, String projectName) {

    SWTBotTree packageExplorerTree = eclipse.showView(ViewType.PACKAGE_EXPLORER).tree();

    packageExplorerTree.setFocus();
    SWTBotTreeItem packageExplorerTreeItem = packageExplorerTree.getTreeItem(projectName);

    packageExplorerTreeItem.select();
    packageExplorerTreeItem.click();
    // Search for Menu Item with Run on Server substring within label
    final SWTBotMenu menuRunAs = bot.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();
      bot.shell(IDELabel.Shell.RUN_ON_SERVER).activate();
      bot.button(IDELabel.Button.FINISH).click();
      SWTUtilExt swtUtil = new SWTUtilExt(bot);
      swtUtil.waitForAll(10 * 1000L);
    } else {
      throw new WidgetNotFoundException("Unable to find Menu Item with Label 'Run on Server'");
    }
  }
Example #28
0
 /**
  * find descendants that match.
  *
  * @param matcher the matcher that matches against {@link org.eclipse.gef.EditPart}
  * @return a list of matches or an empty list if there are none
  */
 @SuppressWarnings("unchecked")
 public List<SWTBotGefEditPart> descendants(final Matcher<? extends EditPart> matcher) {
   return UIThreadRunnable.syncExec(
       new Result<List<SWTBotGefEditPart>>() {
         public List<SWTBotGefEditPart> run() {
           List<SWTBotGefEditPart> descendants = new ArrayList<SWTBotGefEditPart>();
           Stack<SWTBotGefEditPart> parts = new Stack<SWTBotGefEditPart>();
           parts.push(SWTBotGefEditPart.this);
           while (!parts.isEmpty()) {
             SWTBotGefEditPart part = parts.pop();
             for (org.eclipse.gef.EditPart child :
                 ((List<org.eclipse.gef.EditPart>) part.part.getChildren())) {
               SWTBotGefEditPart childPart = graphicalEditor.createEditPart(child);
               if (matcher.matches(child)) {
                 descendants.add(childPart);
               }
               parts.push(childPart);
             }
           }
           return descendants;
         }
       });
 }
  protected void closeEditor(final DiagramEditor diagramEditor) {

    if (diagramEditor == null) {
      return;
    }

    final IWorkbenchPage workbenchPage = diagramEditor.getEditorSite().getPage();

    if (Display.getCurrent() == null) {

      syncExec(
          new VoidResult() {
            @Override
            public void run() {
              if (diagramEditor != null) {
                workbenchPage.closeEditor(diagramEditor, false);
              }
            }
          });
    } else {
      workbenchPage.closeEditor(diagramEditor, false);
    }
  }
  protected DiagramEditor openDiagram(final String type) {
    final DiagramEditorHolder deh = new DiagramEditorHolder();
    syncExec(
        new VoidResult() {
          @Override
          public void run() {

            /**/
            final Diagram newDiagram = createDiagram(type);
            assertTrue("create diagram does not work", newDiagram != null);

            //				assertEditingDomainSave(getTransactionalEditingDomain());

            // use TestUtil to open editor since this waits for late
            // initialization
            DiagramEditor diagramEditor =
                (DiagramEditor)
                    GraphitiUiInternal.getWorkbenchService()
                        .openDiagramEditor(newDiagram, getTransactionalEditingDomain(), false);
            deh.setDiagramEditor(diagramEditor);
          }
        });
    DiagramEditor diagramEditor = deh.getDiagramEditor();
    if (ITestConstants.DIAGRAM_TYPE_ID_SKETCH.equals(type)) {
      IFeatureProvider featureProvider =
          diagramEditor.getDiagramTypeProvider().getFeatureProvider();
      if (featureProvider instanceof ConfigurableFeatureProviderWrapper) {
        ConfigurableFeatureProviderWrapper fpw =
            (ConfigurableFeatureProviderWrapper) featureProvider;
        IFeatureProvider innerFeatureProvider = fpw.getInnerFeatureProvider();
        if (innerFeatureProvider instanceof SketchFeatureProvider) {
          ((SketchFeatureProvider) innerFeatureProvider).setTestMode(true);
        }
      }
    }
    return diagramEditor;
  }