use of org.eclipse.core.commands.Command in project gfm_viewer by satyagraha.
the class ViewerSupportDefault method isLinked.
@Override
public boolean isLinked() {
LOGGER.fine("");
Command command = commandService.getCommand(GFM_VIEWER_PLUGIN_LINKED);
State state = command.getState(RegistryToggleState.STATE_ID);
return (Boolean) state.getValue();
}
use of org.eclipse.core.commands.Command in project gfm_viewer by satyagraha.
the class Linked 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 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);
}
}
}
Aggregations