use of org.eclipse.core.commands.Command in project gfm_viewer by satyagraha.
the class Online method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// update toggled state
final Command command = event.getCommand();
final boolean state = !HandlerUtil.toggleCommandState(command);
LOGGER.fine("state: " + state);
return null;
}
use of org.eclipse.core.commands.Command in project dbeaver by serge-rider.
the class ActionUtils method findCommandDescription.
@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly) {
String commandName = null;
String shortcut = null;
ICommandService commandService = serviceLocator.getService(ICommandService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
if (command != null && command.isDefined()) {
try {
commandName = command.getName();
} catch (NotDefinedException e) {
log.debug(e);
}
}
}
IBindingService bindingService = serviceLocator.getService(IBindingService.class);
if (bindingService != null) {
TriggerSequence sequence = null;
for (Binding b : bindingService.getBindings()) {
ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
if (parameterizedCommand != null && commandId.equals(parameterizedCommand.getId())) {
sequence = b.getTriggerSequence();
}
}
if (sequence == null) {
sequence = bindingService.getBestActiveBindingFor(commandId);
}
if (sequence != null) {
shortcut = sequence.format();
}
}
if (shortcutOnly) {
return shortcut == null ? "?" : shortcut;
}
if (shortcut == null) {
return commandName;
}
if (commandName == null) {
return shortcut;
}
return commandName + " (" + shortcut + ")";
}
use of org.eclipse.core.commands.Command in project dbeaver by serge-rider.
the class ActionUtils method runCommand.
public static void runCommand(String commandId, ISelection selection, IServiceLocator serviceLocator) {
if (commandId != null) {
try {
ICommandService commandService = serviceLocator.getService(ICommandService.class);
IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
boolean needContextPatch = false;
if (selection != null) {
needContextPatch = true;
if (serviceLocator instanceof IWorkbenchSite) {
final ISelection curSelection = ((IWorkbenchSite) serviceLocator).getSelectionProvider().getSelection();
if (curSelection instanceof IStructuredSelection && selection instanceof IStructuredSelection) {
if (((IStructuredSelection) curSelection).size() == ((IStructuredSelection) selection).size() && ((IStructuredSelection) curSelection).getFirstElement() == ((IStructuredSelection) selection).getFirstElement()) {
// The same selection
needContextPatch = false;
}
}
}
}
if (selection != null && needContextPatch) {
// Create new eval context
IEvaluationContext context = new EvaluationContext(handlerService.createContextSnapshot(false), selection);
if (serviceLocator instanceof IWorkbenchPartSite) {
context.addVariable(ISources.ACTIVE_PART_NAME, ((IWorkbenchPartSite) serviceLocator).getPart());
}
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
ParameterizedCommand pc = new ParameterizedCommand(command, null);
handlerService.executeCommandInContext(pc, null, context);
} else if (command != null && command.isEnabled()) {
handlerService.executeCommand(commandId, null);
}
}
} catch (Exception e) {
log.error("Can't execute command '" + commandId + "'", e);
}
}
}
use of org.eclipse.core.commands.Command in project eclipse.platform.text by eclipse.
the class EditorTest method testGenericEditorHasWordWrap.
@Test
public void testGenericEditorHasWordWrap() throws Exception {
this.editor.setFocus();
final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
Assert.assertFalse(editorTextWidget.getWordWrap());
Assert.assertFalse(this.editor.isWordWrapEnabled());
// Toggle word wrap
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.WORD_WRAP);
Assert.assertTrue(wordWrapCommand.isDefined());
Assert.assertTrue(wordWrapCommand.isEnabled());
Assert.assertTrue(wordWrapCommand.isHandled());
PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
//
Assert.assertTrue(editorTextWidget.getWordWrap());
Assert.assertTrue(this.editor.isWordWrapEnabled());
}
use of org.eclipse.core.commands.Command in project eclipse.platform.text by eclipse.
the class EditorTest method testGenericEditorCanUseBlockSelection.
@Test
public void testGenericEditorCanUseBlockSelection() throws Exception {
this.editor.setFocus();
Assert.assertFalse(this.editor.isBlockSelectionModeEnabled());
// Toggle word wrap
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.BLOCK_SELECTION_MODE);
Assert.assertTrue(wordWrapCommand.isDefined());
Assert.assertTrue(wordWrapCommand.isEnabled());
Assert.assertTrue(wordWrapCommand.isHandled());
PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
//
Assert.assertTrue(this.editor.isBlockSelectionModeEnabled());
}
Aggregations