コード例 #1
0
  /**
   * Expands the entry. Takes care that all attributes and child entries are initialized so that
   * there are no pending background actions and event notifications. This is necessary to avoid
   * race conditions.
   *
   * @param bot the bot
   * @param entry the entry to expand
   * @param nextName the name of the entry that must become visible, may be null
   * @throws Exception the exception
   */
  public static void expandEntry(
      final SWTWorkbenchBot bot, final SWTBotTreeItem entry, final String nextName) {
    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            entry.expand();
          }
        });

    bot.waitUntil(
        new DefaultCondition() {
          public boolean test() throws Exception {
            if (nextName != null) {
              String adjustedNodeName = nextName != null ? adjustNodeName(entry, nextName) : null;
              SWTBotTreeItem node = entry.getNode(adjustedNodeName);
              if (node == null) {
                return false;
              }
            }
            return !entry.getNodes().contains("Fetching Entries...");
          }

          public String getFailureMessage() {
            return "Could not find entry " + entry.getText() + " -> " + nextName;
          }
        });
  }
コード例 #2
0
  private void expand(final SWTBotTreeItem entry, boolean wait, final String nextNode) {
    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            entry.expand();
          }
        });

    if (wait) {
      bot.waitUntil(
          new DefaultCondition() {
            public boolean test() throws Exception {
              //                    if ( nextNode != null )
              //                    {
              //                        String adjustedNodeName = nextNode != null ? adjustNodeName(
              // entry, nextNode ) : null;
              //                        SWTBotTreeItem node = entry.getNode( adjustedNodeName );
              //                        if ( node == null )
              //                        {
              //                            return false;
              //                        }
              //                    }
              return !entry.getNodes().contains("Fetching Entries...")
                  && !entry.getNodes().contains("Opening Connection...");
            }

            public String getFailureMessage() {
              return "Could not find entry " + entry.getText() + " -> " + nextNode;
            }
          });
    }
  }
コード例 #3
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");
            }
          }
        });
  }
コード例 #4
0
  /**
   * Clicks a button asynchronously and waits till the given condition is fulfilled.
   *
   * @param bot the SWT bot
   * @param button the button to click
   * @param waitCondition the condition to wait for, may be null
   * @throws TimeoutException
   */
  public static void asyncClick(
      final SWTWorkbenchBot bot, final SWTBotButton button, final ICondition waitCondition)
      throws TimeoutException {
    bot.waitUntil(
        new DefaultCondition() {
          public boolean test() throws Exception {
            return button.isEnabled();
          }

          public String getFailureMessage() {
            return "Button isn't enabled.";
          }
        });

    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            button.click();
          }
        });

    if (waitCondition != null) {
      bot.waitUntil(waitCondition);
    }
  }
コード例 #5
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;

                // 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());
          }
        });
  }
コード例 #6
0
 /** 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());
         }
       });
 }
コード例 #7
0
 protected Shell[] findShells() {
   return UIThreadRunnable.syncExec(
       new ArrayResult<Shell>() {
         public Shell[] run() {
           return parent.getShells();
         }
       });
 }
コード例 #8
0
 /** focus on this edit part */
 public void focus() {
   UIThreadRunnable.syncExec(
       new VoidResult() {
         public void run() {
           graphicalEditor.graphicalViewer.setFocus(part);
         }
       });
 }
コード例 #9
0
 public String getText() {
   return UIThreadRunnable.syncExec(
       display,
       new Result<String>() {
         public String run() {
           return Button.super.getText();
         }
       });
 }
コード例 #10
0
 /** click on the edit part at the specified location */
 public SWTBotGefEditPart click(final Point location) {
   UIThreadRunnable.asyncExec(
       new VoidResult() {
         public void run() {
           graphicalEditor.getCanvas().mouseEnterLeftClickAndExit(location.x, location.y);
         }
       });
   return this;
 }
コード例 #11
0
 public Boolean enabled() {
   return UIThreadRunnable.syncExec(
       display,
       new Result<Boolean>() {
         public Boolean run() {
           return Button.super.isEnabled();
         }
       });
 }
コード例 #12
0
ファイル: SWTBotTreeColumn.java プロジェクト: jlulwd/egit
 public SWTBotTreeColumn(final TreeColumn w) throws WidgetNotFoundException {
   super(w);
   parent =
       UIThreadRunnable.syncExec(
           new WidgetResult<Tree>() {
             public Tree run() {
               return w.getParent();
             }
           });
 }
コード例 #13
0
 public Button enabled(final boolean value) {
   UIThreadRunnable.syncExec(
       display,
       new VoidResult() {
         public void run() {
           Button.super.setEnabled(value);
         }
       });
   return this;
 }
コード例 #14
0
 public Button image(final Image image) {
   UIThreadRunnable.syncExec(
       display,
       new VoidResult() {
         public void run() {
           Button.super.setImage(image);
         }
       });
   return this;
 }
コード例 #15
0
 public Button select(final boolean selected) {
   UIThreadRunnable.syncExec(
       display,
       new VoidResult() {
         public void run() {
           Button.this.setSelection(selected);
         }
       });
   return this;
 }
コード例 #16
0
 /** double click on the edit part. */
 public SWTBotGefEditPart doubleClick() {
   final Rectangle bounds = getBounds();
   UIThreadRunnable.asyncExec(
       new VoidResult() {
         public void run() {
           graphicalEditor.getCanvas().mouseMoveDoubleClick(bounds.x, bounds.y);
         }
       });
   return this;
 }
コード例 #17
0
 public SWTBotGefEditPart activateDirectEdit(final Object feature) {
   UIThreadRunnable.asyncExec(
       new VoidResult() {
         public void run() {
           DirectEditRequest request = new DirectEditRequest();
           if (feature != null) request.setDirectEditFeature(feature);
           part().performRequest(request);
         }
       });
   return this;
 }
コード例 #18
0
 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;
         }
       });
 }
コード例 #19
0
ファイル: SWTBotTreeColumn.java プロジェクト: jlulwd/egit
 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);
 }
コード例 #20
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());
          }
        });
  }
コード例 #21
0
    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;
            }
          });
    }
コード例 #22
0
 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
           }
         });
 }
コード例 #23
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;
         }
       });
 }
コード例 #24
0
ファイル: SDKPreferenceBot.java プロジェクト: nuxeo/nuxeo-ide
 public void addSDK(final File home) throws IOException {
   final SDKInfo info = SDKInfo.loadSDK(home);
   UIThreadRunnable.asyncExec(
       SWTUtils.display(),
       new VoidResult() {
         @Override
         public void run() {
           SDKTableWidget w =
               (SDKTableWidget) sdks.widget.getData("org.eclipse.swtbot.widget.owner");
           CheckboxTableViewer v = w.getViewer();
           v.add(info);
         }
       });
 }
コード例 #25
0
  /**
   * 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);
  }
コード例 #26
0
  @Override
  public void synchronizeOnActivityQueue(JID jid, long timeout) throws RemoteException {

    ISarosSession session = this.session;
    IActivityListener listener = this.listener;

    // this is too lazy, but ok for testing purposes

    if (session == null) throw new IllegalStateException("no session running");

    if (listener == null) throw new IllegalStateException("no session running");

    final CountDownLatch swtThreadSync = new CountDownLatch(1);

    UIThreadRunnable.asyncExec(
        new VoidResult() {
          @Override
          public void run() {
            swtThreadSync.countDown();
          }
        });

    try {
      if (!swtThreadSync.await(
          SarosSWTBotPreferences.SAROS_DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)) {
        LOG.warn("could not synchronize on the SWT EDT");
      }
    } catch (InterruptedException e1) {
      Thread.currentThread().interrupt();
    }

    int id = RANDOM.nextInt();

    NOPActivity activity = new NOPActivity(session.getLocalUser(), session.getUser(jid), id);

    CountDownLatch latch = new CountDownLatch(1);

    synchronizeRequests.put(id, latch);
    listener.created(activity);

    try {
      if (!latch.await(timeout, TimeUnit.MILLISECONDS))
        throw new TimeoutException("no reply from " + jid);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    } finally {
      synchronizeRequests.remove(id);
    }
  }
コード例 #27
0
  /**
   * Clicks a tree item asynchronously and waits till the given condition is fulfilled.
   *
   * @param bot the SWT bot
   * @param item the tree item to click
   * @param waitCondition the condition to wait for, may be null
   * @throws TimeoutException the timeout exception
   */
  public static void asyncClick(
      final SWTWorkbenchBot bot, final SWTBotTreeItem item, final ICondition waitCondition)
      throws TimeoutException {
    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            item.click();
          }
        });

    if (waitCondition != null) {
      bot.waitUntil(waitCondition);
    }
  }
コード例 #28
0
  private static void click(final MenuItem menuItem) {
    final Event event = new Event();
    event.time = (int) System.currentTimeMillis();
    event.widget = menuItem;
    event.display = menuItem.getDisplay();
    event.type = SWT.Selection;

    UIThreadRunnable.asyncExec(
        menuItem.getDisplay(),
        new VoidResult() {
          public void run() {
            menuItem.notifyListeners(SWT.Selection, event);
          }
        });
  }
コード例 #29
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;
         }
       });
 }
コード例 #30
0
  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;
          }
        });
  }