private SWTBotGefViewer activateTool(final Pattern labelMatcher, final int index) throws WidgetNotFoundException {
final WidgetNotFoundException[] exception = new WidgetNotFoundException[1];
UIThreadRunnable.syncExec(new VoidResult() {
public void run() {
final EditDomain editDomain = getEditDomain();
final List<PaletteEntry> entries = new PaletteFinder(editDomain).findEntries(new ToolEntryLabelMatcher(labelMatcher));
if (entries.size() > 0) {
final PaletteEntry paletteEntry = entries.get(index);
if (paletteEntry instanceof ToolEntry) {
editDomain.getPaletteViewer().setActiveTool((ToolEntry) paletteEntry);
} else {
exception[0] = new WidgetNotFoundException(String.format("%s is not a tool entry, it's a %s", labelMatcher
.toString(), paletteEntry.getClass().getName()));
}
} else {