org.eclipse.swtbot.swt.finder.results.Result Java Examples

The following examples show how to use org.eclipse.swtbot.swt.finder.results.Result. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShellUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests if a shell with a specific type of data contained (e.g. Window).
 * 
 * @param bot
 *          to use
 * @param clazz
 *          class of data contained to check for
 */
@SuppressWarnings("rawtypes")
public static void assertShellWithDataTypeVisible(final SWTWorkbenchBot bot, final Class clazz) {
  bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() {
    @SuppressWarnings("unchecked")
    public boolean matches(final Object item) {
      return UIThreadRunnable.syncExec(new Result<Boolean>() {
        public Boolean run() {
          if (item instanceof Shell) {
            Object shellData = ((Shell) item).getData();
            if (shellData != null) {
              return clazz.isAssignableFrom(shellData.getClass());
            }
          }
          return false;
        }
      });
    }

    public void describeTo(final Description description) {
      description.appendText("Shell for " + clazz.getName());
    }
  }));
}
 
Example #2
Source File: PatternLatencyTableViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Get the table associated to the view
 */
private void getTable() {
    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertNotNull(viewPart);
    if (!(viewPart instanceof PatternLatencyTableView)) {
        fail("Could not instanciate view");
    }
    fLatencyView = (PatternLatencyTableView) viewPart;
    fTable = fLatencyView.getSegmentStoreViewer();
    assertNotNull(fTable);
}
 
Example #3
Source File: ChartMakerDialogTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private List<IDataChartDescriptor<?, ?>> getDescriptors(int tblIndex) {
    SWTBotTable table = fBot.table(tblIndex);

    List<IDataChartDescriptor<?, ?>> items = UIThreadRunnable.syncExec((Result<@Nullable List<IDataChartDescriptor<?, ?>>>) () -> {
        List<IDataChartDescriptor<?, ?>> list = new ArrayList<>();
        for (TableItem item : table.widget.getItems()) {
            Object data = item.getData();
            if (data instanceof IDataChartDescriptor<?, ?>) {
                IDataChartDescriptor<?, ?> desc = (IDataChartDescriptor<?, ?>) data;
                list.add(desc);
            }
        }
        return list;
    });
    assertNotNull(items);
    return items;
}
 
Example #4
Source File: PatternDensityViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Set the density viewer
 *
 * @throws SecurityException
 *             If a security manager is present and any the wrong class is
 *             loaded or the class loader is not the same as its ancestor's
 *             loader.
 *
 * @throws NoSuchFieldException
 *             Field not available
 * @throws IllegalAccessException
 *             Field is inaccessible
 * @throws IllegalArgumentException
 *             the object is not the correct class type
 */
public void setDensityViewer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertNotNull(viewPart);
    if (!(viewPart instanceof PatternDensityView)) {
        fail("Could not instanciate view");
    }
    fDensityView = (PatternDensityView) viewPart;

    /*
     * Use reflection to access the table viewer
     */
    final Field field = AbstractSegmentStoreDensityView.class.getDeclaredField("fTableViewer");
    field.setAccessible(true);
    fDensityViewer = (AbstractSegmentStoreTableViewer) field.get(fDensityView);
    fDensityChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class));
    assertNotNull(fDensityViewer);
}
 
Example #5
Source File: FlameGraphTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open a flamegraph
 */
@Before
public void before() {
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.openView(FLAMEGRAPH_ID);
    SWTBotView view = fBot.viewById(FLAMEGRAPH_ID);
    assertNotNull(view);
    fView = view;
    FlameGraphView flamegraph = UIThreadRunnable.syncExec((Result<FlameGraphView>) () -> {
        IViewPart viewRef = fView.getViewReference().getView(true);
        return (viewRef instanceof FlameGraphView) ? (FlameGraphView) viewRef : null;
    });
    assertNotNull(flamegraph);
    fTimeGraphViewer = flamegraph.getTimeGraphViewer();
    assertNotNull(fTimeGraphViewer);
    SWTBotUtils.maximize(flamegraph);
    fFg = flamegraph;
}
 
Example #6
Source File: CallGraphDensityViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Setup for the test
 */
@Before
public void before() {
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.openView(CALLGRAPHDENSITY_ID);
    SWTBotView view = fBot.viewById(CALLGRAPHDENSITY_ID);
    assertNotNull(view);
    fView = view;
    CallGraphDensityView funcDensityView = UIThreadRunnable.syncExec((Result<CallGraphDensityView>) () -> {
        IViewPart viewRef = fView.getViewReference().getView(true);
        return (viewRef instanceof CallGraphDensityView) ? (CallGraphDensityView) viewRef : null;
    });
    assertNotNull(funcDensityView);
    fTableBot = fView.bot().table();
    assertNotNull(fTableBot);
    fDensityViewer = funcDensityView.getDensityViewer();
    assertNotNull(fDensityViewer);
    fLatch = new CountDownLatch(1);
    fDensityViewer.removeDataListener(fSyncListener);
    fDensityViewer.addDataListener(fSyncListener);
    fTableViewer = funcDensityView.getTableViewer();
    assertNotNull(fTableViewer);
    SWTBotUtils.maximize(funcDensityView);
    fFuncDensityView = funcDensityView;
    fDensityViewer.setNbPoints(100);
}
 
Example #7
Source File: SystemCallLatencyStatisticsTableAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Opens a latency table
 */
@Before
public void createTree() {
    /*
     * Open latency view
     */
    SWTBotUtils.openView(PRIMARY_VIEW_ID, SECONDARY_VIEW_ID);
    SWTWorkbenchBot bot = new SWTWorkbenchBot();
    SWTBotView viewBot = bot.viewById(PRIMARY_VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertTrue("Could not instanciate view", viewPart instanceof SegmentStoreStatisticsView);
    fTreeBot = viewBot.bot().tree();
    assertNotNull(fTreeBot);
}
 
Example #8
Source File: SystemCallLatencyTableAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected AbstractSegmentStoreTableView openTable() {
    /*
     * Open latency view
     */
    SWTBotUtils.openView(PRIMARY_VIEW_ID, SECONDARY_VIEW_ID);
    SWTBotView viewBot = fBot.viewById(PRIMARY_VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertTrue("Could not instanciate view", viewPart instanceof SegmentStoreTableView);
    return (SegmentStoreTableView) viewPart;
}
 
Example #9
Source File: SegmentTableTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create the table viewer to test
 *
 * @return the table viewer bot
 */
protected AbstractSegmentStoreTableView openTable() {
    AbstractSegmentStoreTableView tableView = getTableView();
    if (tableView != null) {
        return tableView;
    }
    IViewPart vp = null;
    final IWorkbench workbench = PlatformUI.getWorkbench();
    vp = UIThreadRunnable.syncExec((Result<IViewPart>) () -> {
        try {
            return workbench.getActiveWorkbenchWindow().getActivePage().showView(TestSegmentStoreTableView.ID);
        } catch (PartInitException e) {
            return null;
        }
    });
    assertNotNull(vp);
    assertTrue(vp instanceof TestSegmentStoreTableView);
    TestSegmentStoreTableView testSegmentStoreTableView = (TestSegmentStoreTableView) vp;
    testSegmentStoreTableView.setTest(this);
    fTableView = testSegmentStoreTableView;

    return fTableView;
}
 
Example #10
Source File: SWTBotTimeGraph.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Set the name space width
 *
 * @param nameSpace the name space width
 */
public void setNameSpace(int nameSpace) {
    int x = widget.getTimeDataProvider().getNameSpace();
    Rectangle bounds = syncExec(new Result<Rectangle>() {
        @Override
        public Rectangle run() {
            return widget.getBounds();
        }
    });
    int y = bounds.y + bounds.height / 2;
    notify(SWT.MouseEnter);
    notify(SWT.MouseMove, createMouseEvent(x, y, 0, SWT.NONE, 0));
    notify(SWT.Activate);
    notify(SWT.FocusIn);
    notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
    notify(SWT.DragDetect, createMouseEvent(nameSpace, y, 0, SWT.NONE, 0));
    notify(SWT.MouseMove, createMouseEvent(nameSpace, y, 1, SWT.BUTTON1, 1));
    notify(SWT.MouseUp, createMouseEvent(nameSpace, y, 1, SWT.BUTTON1, 1));
    notify(SWT.MouseMove, createMouseEvent(0, y, 0, SWT.NONE, 0));
    notify(SWT.MouseExit);
    notify(SWT.Deactivate);
    notify(SWT.FocusOut);
}
 
Example #11
Source File: ImageHelper.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets a screen grab of the rectangle r; the way to access a given pixel is
 * <code>pixel = rect.width * y + x;</code>
 *
 * @param rect
 *            the area to grab in display relative coordinates (top left is the
 *            origin)
 * @return an ImageHelper, cannot be null
 */
public static ImageHelper grabImage(final Rectangle rect) {
    return UIThreadRunnable.syncExec(new Result<ImageHelper>() {
        @Override
        public ImageHelper run() {
            try {
                // note: awt is explicitly called until we can use SWT to
                // replace it.
                java.awt.Robot rb = new java.awt.Robot();
                java.awt.image.BufferedImage bi = rb.createScreenCapture(new java.awt.Rectangle(rect.x, rect.y, rect.width, rect.height));
                return new ImageHelper(bi.getRGB(0, 0, rect.width, rect.height, null, 0, rect.width), rect);
            } catch (AWTException e) {
            }
            return new ImageHelper(new int[0], new Rectangle(0, 0, 0, 0));
        }
    });
}
 
Example #12
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 type id (eg: org.eclipse.linuxtools.btf.trace)
 * @param delay
 *            delay and wait for jobs
 */
public static void openTrace(final String projectName, final String tracePath, final String traceType, boolean delay) {
    IStatus status = UIThreadRunnable.syncExec(new Result<IStatus>() {
        @Override
        public IStatus run() {
            try {
                IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
                TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
                return TmfOpenTraceHelper.openTraceFromPath(destinationFolder, tracePath, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), traceType);
            } catch (CoreException e) {
                return new Status(IStatus.ERROR, "", e.getMessage(), e);
            }
        }
    });
    if (!status.isOK()) {
        fail(status.getMessage());
    }

    if (delay) {
        delay(1000);
        WaitUtils.waitForJobs();
    }
}
 
Example #13
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Press the shortcut specified by the given keys. The method returns when
 * the key events have been received by the focus control.
 *
 * @param keyboard
 *            the keyboard
 * @param keys
 *            the keys to press
 */
public static void pressShortcut(Keyboard keyboard, KeyStroke... keys) {
    Control focusControl = UIThreadRunnable.syncExec(new Result<Control>() {
        @Override
        public Control run() {
            return Display.getCurrent().getFocusControl();
        }
    });
    pressShortcut(focusControl, () -> keyboard.pressShortcut(keys), keys);
}
 
Example #14
Source File: SWTBotTimeGraphEntry.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the time in the entry for a given X point
 *
 * @param x
 *            the x point
 * @return the time or {@code null} or {@code -1} if it is out of bounds
 */
public Long getTimeForPoint(int x) {
    return UIThreadRunnable.syncExec((Result<@Nullable Long>) () -> {
        Rectangle bounds = widget.getBounds();
        Point p = new Point(x, bounds.y + bounds.height / 2);
        if (!bounds.contains(p)) {
            return null;
        }
        return widget.getTimeAtX(x);
    });
}
 
Example #15
Source File: TimeGraphViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private Rectangle getBounds() {
    return UIThreadRunnable.syncExec((Result<Rectangle>) () -> {
        Control control = fTimeGraph.widget;
        Rectangle ctrlRelativeBounds = control.getBounds();
        Point res = control.toDisplay(new Point(fTimeGraph.getNameSpace(), 0));
        ctrlRelativeBounds.width -= fTimeGraph.getNameSpace();
        ctrlRelativeBounds.x = res.x;
        ctrlRelativeBounds.y = res.y;
        return ctrlRelativeBounds;
    });
}
 
Example #16
Source File: SWTBotTimeGraphEntry.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the coordinates of a point for a specified time
 *
 * @param time
 *            the time to get the equivalent Point of.
 * @return the point at the time
 */
public Point getPointForTime(long time) {
    return UIThreadRunnable.syncExec((Result<Point>) () -> {
        ITimeDataProvider timeDataProvider = widget.getTimeDataProvider();
        if (timeDataProvider.getTime0() > time || timeDataProvider.getTime1() < time) {
            return null;
        }
        int x = widget.getXForTime(time);
        Rectangle bounds = widget.getItemBounds(fEntry);
        int y = bounds.y + bounds.height / 2;
        return new Point(x, y);
    });
}
 
Example #17
Source File: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the {@link SWTBotMenu}s available on the given widget bot.
 *
 * @param widgetBot
 *          the bot representing the widget, whose {@link SWTBotMenu}s should be returned
 * @return the {@link SWTBotMenu}s on the given widget bot
 */
public static List<SWTBotMenu> getContextMenuItems(final AbstractSWTBot<? extends Control> widgetBot) {
  return UIThreadRunnable.syncExec(new Result<List<SWTBotMenu>>() {
    @Override
    public List<SWTBotMenu> run() {
      List<SWTBotMenu> menuItems = Lists.newArrayList();
      for (MenuItem menuItem : new ContextMenuFinder(widgetBot.widget).findMenus(widgetBot.widget.getShell(), WidgetMatcherFactory.widgetOfType(MenuItem.class), true)) {
        menuItems.add(new SWTBotMenu(menuItem));
      }
      return menuItems;
    }
  });
}
 
Example #18
Source File: FontEventEditorTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static FontData getFont(final SWTBotStyledText rawText) {
    return UIThreadRunnable.syncExec(new Result<FontData>() {
        @Override
        public FontData run() {
            return rawText.widget.getFont().getFontData()[0];
        }
    });
}
 
Example #19
Source File: SystemCallLatencyDensityViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Opens a latency table
 *
 * @throws SecurityException
 *             If a security manager is present and any the wrong class is
 *             loaded or the class loader is not the same as its ancestor's
 *             loader.
 *
 * @throws NoSuchFieldException
 *             Field not available
 * @throws IllegalAccessException
 *             Field is inaccessible
 * @throws IllegalArgumentException
 *             the object is not the correct class type
 *
 *
 */
@Before
public void createDensityViewer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    /*
     * Open latency view
     */
    SWTBotUtils.openView(VIEW_ID);
    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertNotNull(viewPart);
    if (!(viewPart instanceof SystemCallLatencyDensityView)) {
        fail("Could not instanciate view");
    }
    fDensityView = (SystemCallLatencyDensityView) viewPart;

    /*
     * Use reflection to access the table viewer
     */
    final Field field = AbstractSegmentStoreDensityView.class.getDeclaredField("fTableViewer");
    field.setAccessible(true);
    fDensityViewer = (AbstractSegmentStoreTableViewer) field.get(fDensityView);
    fDensityChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class));
    assertNotNull(fDensityViewer);
}
 
Example #20
Source File: LamiChartViewerTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Execute the LAMI analyses and return the viewBot corresponding to the
 * newly opened view. To avoid tests interracting with each other, it is
 * preferable to use the returned view bot in a try finally statement and
 * make sure the view is closed at the end of the test.
 *
 * @param analysis
 *            The analysis to execute
 * @return The view bot
 */
private SWTBotView executeAnalysis(LamiAnalyses analysis) {
    // Open the LAMI analysis
    SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
    SWTBotTreeItem externalAnalyses = SWTBotUtils.getTraceProjectItem(fBot, tracesFolder, TRACE.getPath(), "External Analyses", analysis.getAnalysis().getName());
    assertNotNull(externalAnalyses);
    fBot.waitUntil(isLamiAnalysisEnabled(externalAnalyses));
    externalAnalyses.doubleClick();

    fBot.shell("External Analysis Parameters").activate();
    fBot.button("OK").click();
    WaitUtils.waitForJobs();

    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    viewBot.setFocus();
    final @Nullable LamiReportView lamiView = UIThreadRunnable.syncExec((Result<@Nullable LamiReportView>) () -> {
        IViewPart viewRef = viewBot.getViewReference().getView(true);
        return (viewRef instanceof LamiReportView) ? (LamiReportView) viewRef : null;
    });
    assertNotNull(lamiView);
    SWTBotUtils.maximize(lamiView);
    fViewBot = viewBot;

    fCurrentTab = lamiView.getCurrentSelectedPage();

    return viewBot;
}
 
Example #21
Source File: ResourcesViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static int getXForTime(TimeGraphControl timeGraph, long time) {
    return UIThreadRunnable.syncExec(new Result<Integer>() {
        @Override
        public Integer run() {
            return timeGraph.getXForTime(time);
        }
    });
}
 
Example #22
Source File: ResourcesViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static Point getSize(Control control) {
    return UIThreadRunnable.syncExec(new Result<Point>() {
        @Override
        public Point run() {
            return control.getSize();
        }
    });
}
 
Example #23
Source File: SwtBotTreeActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean doesTreeItemHaveText(final TreeItem widget) {
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      TreeItem[] items = widget.getItems();
      for (TreeItem item : items) {
        if (item.getText() == null || item.getText().length() == 0) {
          return false;
        }
      }
      return true;
    }
  });
}
 
Example #24
Source File: SwtBotTreeActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper method to check whether a given tree is expanded which can be called from any thread.
 */
public static boolean isTreeExpanded(final TreeItem tree) {
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      return tree.getExpanded();
    }
  });
}
 
Example #25
Source File: MaterialsDatabaseTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
public void maximize() {
	syncExec(new Result<Object>() {
		@Override
		public Object run() {
			widget.setMaximized(true);
			return null;
		}
	});

}
 
Example #26
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the bounds of a widget in display coordinates
 *
 * @param bot
 *            the widget bot
 * @return the widget bounds, in display coordinates
 */
public static Rectangle getBoundsToDisplay(AbstractSWTBot<?> bot) {
    if (bot.widget instanceof Control) {
        final Control control = checkNotNull((Control) bot.widget);
        return UIThreadRunnable.syncExec(new Result<Rectangle>() {
            @Override
            public Rectangle run() {
                Point location = control.toDisplay(0, 0);
                Point size = control.getSize();
                return new Rectangle(location.x, location.y, size.x, size.y);
            }
        });
    }
    throw new IllegalArgumentException(bot +" is not a Control widget");
}
 
Example #27
Source File: FixedDefaultWorkbench.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
private IWorkbenchWindow getActiveWorkbenchWindow() {
  return UIThreadRunnable.syncExec(bot.getDisplay(), new Result<IWorkbenchWindow>() {
    @Override
    public IWorkbenchWindow run() {
      return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    }
  });
}
 
Example #28
Source File: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the disabled {@link SWTBotMenu}s on the given widget bot.
 *
 * @param widgetBot
 *          the bot representing the widget, whose disabled {@link SWTBotMenu}s should be returned
 * @return the disabled {@link SWTBotMenu}s on the given widget bot
 */
public static List<SWTBotMenu> getDisabledContextMenuItems(final AbstractSWTBot<? extends Control> widgetBot) {
  return UIThreadRunnable.syncExec(new Result<List<SWTBotMenu>>() {
    @Override
    public List<SWTBotMenu> run() {
      List<SWTBotMenu> disabledMenuItems = Lists.newArrayList();
      for (MenuItem menuItem : new ContextMenuFinder(widgetBot.widget).findMenus(widgetBot.widget.getShell(), WidgetMatcherFactory.widgetOfType(MenuItem.class), true)) {
        if (!menuItem.isEnabled()) {
          disabledMenuItems.add(new SWTBotMenu(menuItem));
        }
      }
      return disabledMenuItems;
    }
  });
}
 
Example #29
Source File: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Whether the context menu with the given labels is enabled.
 *
 * @param widgetBot
 *          the bot representing the widget on which it should be checked, whether the context menu
 *          with the given labels is enabled
 * @param labels
 *          the labels on the context menus
 * @return {@code true} if the context menu is enabled, else {@code false}
 * @throw {@link WidgetNotFoundException} if the context menu could not be found
 */
public static boolean isEnabled(final AbstractSWTBot<? extends Control> widgetBot, final String... labels) {
  final MenuItem menuItem = getContextMenuItem(widgetBot, labels);
  if (menuItem == null) {
    throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(labels));
  }
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      return menuItem.isEnabled();
    }
  });
}
 
Example #30
Source File: DragAndDropUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Rectangle absoluteLocation() {
  return UIThreadRunnable.syncExec(new Result<Rectangle>() {
    @Override
    public Rectangle run() {
      return display.map(widget.getParent(), null, widget.getBounds());
    }
  });
}