use of org.eclipse.core.commands.common.CommandException in project org.csstudio.display.builder by kasemir.
the class SearchView method configureActions.
/**
* React to selections, button presses, ...
*/
private void configureActions() {
// Start a channel search
search.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
searchForChannels();
}
});
// Channel Table: Allow dragging of PVs with archive
final Table table = channel_table.getTable();
new ControlSystemDragSource(table) {
@Override
public Object getSelection() {
final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection();
// To allow transfer of array, the data must be
// of the actual array type, not Object[]
final Object[] objs = selection.toArray();
final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class);
return channels;
}
};
// Double-clicks should have the same effect as context menu -> Data Browser
getSite().setSelectionProvider(channel_table);
channel_table.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
// casting is needed for RAP
IHandlerService handlerService = getSite().getService(IHandlerService.class);
try {
handlerService.executeCommand("org.csstudio.trends.databrowser3.OpenDataBrowserPopup", null);
} catch (CommandException ex) {
// $NON-NLS-1$
Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex);
}
}
});
// Add context menu for object contributions
final MenuManager menu = new MenuManager();
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
table.setMenu(menu.createContextMenu(table));
getSite().registerContextMenu(menu, channel_table);
}
use of org.eclipse.core.commands.common.CommandException in project egit by eclipse.
the class CommonUtils method runCommand.
/**
* Programatically run command based on it id and given selection
*
* @param commandId
* id of command that should be run
* @param selection
* given selection
* @return {@code true} when command was successfully executed,
* {@code false} otherwise
*/
public static boolean runCommand(String commandId, IStructuredSelection selection) {
ICommandService commandService = CommonUtils.getService(PlatformUI.getWorkbench(), ICommandService.class);
Command cmd = commandService.getCommand(commandId);
if (!cmd.isDefined())
return false;
IHandlerService handlerService = CommonUtils.getService(PlatformUI.getWorkbench(), IHandlerService.class);
EvaluationContext c = null;
if (selection != null) {
c = new EvaluationContext(handlerService.createContextSnapshot(false), selection.toList());
c.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
c.removeVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
}
try {
if (c != null)
handlerService.executeCommandInContext(new ParameterizedCommand(cmd, null), null, c);
else
handlerService.executeCommand(commandId, null);
return true;
} catch (CommandException ignored) {
// Ignored
}
return false;
}
Aggregations