Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,49 +295,58 @@ public final boolean executeCommand(final ParameterizedCommand parameterizedComm
final EHandlerService handlerService = getHandlerService();
final Command command = parameterizedCommand.getCommand();

final IEclipseContext staticContext = createContext(trigger);

final boolean commandDefined = command.isDefined();
// boolean commandEnabled;
boolean commandHandled = false;

try {
// commandEnabled = handlerService.canExecute(parameterizedCommand, staticContext);
Object obj = HandlerServiceImpl.lookUpHandler(context, command.getId());
if (obj != null) {
if (obj instanceof IHandler) {
commandHandled = ((IHandler) obj).isHandled();
} else {
commandHandled = true;
}
// commandEnabled = handlerService.canExecute(parameterizedCommand,
// staticContext);
Object obj = HandlerServiceImpl.lookUpHandler(context, command.getId());
if (obj != null) {
if (obj instanceof IHandler handler) {
commandHandled = handler.isHandled();
} else {
commandHandled = true;
}
}

if (isTracingEnabled()) {
logger.trace("Command " + parameterizedCommand + ", defined: " + commandDefined + ", handled: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ commandHandled + " in " + describe(context)); //$NON-NLS-1$
}
if (isTracingEnabled()) {
logger.trace("Command " + parameterizedCommand + ", defined: " + commandDefined + ", handled: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ commandHandled + " in " + describe(context)); //$NON-NLS-1$
}

final IEclipseContext staticContext = createContext(trigger);
if (trigger.widget instanceof Browser) {
getDisplay()
.asyncExec(() -> handleCommandExecution(parameterizedCommand, handlerService, staticContext, obj));
} else {
handleCommandExecution(parameterizedCommand, handlerService, staticContext, obj);
}
return (commandDefined && commandHandled);
}

private void handleCommandExecution(final ParameterizedCommand parameterizedCommand,
final EHandlerService handlerService, final IEclipseContext staticContext, Object handler) {
try {
handlerService.executeHandler(parameterizedCommand, staticContext);
final Object commandException = staticContext.get(HandlerServiceImpl.HANDLER_EXCEPTION);
if (commandException instanceof CommandException) {
commandHandled = false;
if (commandException instanceof ExecutionException) {
if (logger != null) {
logger.error((Throwable) commandException,
"Execution exception for: " + parameterizedCommand + " in " //$NON-NLS-1$//$NON-NLS-2$
+ describe(context));
}
} else if (isTracingEnabled()) {
logger.trace((Throwable) commandException,
"Command exception for: " + parameterizedCommand + " in " //$NON-NLS-1$ //$NON-NLS-2$
logger.trace((Throwable) commandException, "Command exception for: " + parameterizedCommand + " in " //$NON-NLS-1$ //$NON-NLS-2$
+ describe(context));
if (handlerService instanceof HandlerServiceImpl serviceImpl) {
IEclipseContext serviceContext = serviceImpl.getContext();
if (serviceContext != null) {
StringBuilder sb = new StringBuilder("\n\tExecution context: "); //$NON-NLS-1$
sb.append(describe(serviceContext));
sb.append("\n\tHandler: "); //$NON-NLS-1$
sb.append(obj);
sb.append(handler);
logger.trace(sb.toString());
}
}
Expand All @@ -352,17 +361,16 @@ public final boolean executeCommand(final ParameterizedCommand parameterizedComm
}
}
}
/*
* Now that the command has executed (and had the opportunity to use the remembered
* state of the dialog), it is safe to delete that information.
*/
if (keyAssistDialog != null) {
keyAssistDialog.clearRememberedState();
}
} finally {
staticContext.dispose();
}
return (commandDefined && commandHandled);
/*
* Now that the command has executed (and had the opportunity to use the
* remembered state of the dialog), it is safe to delete that information.
*/
if (keyAssistDialog != null) {
keyAssistDialog.clearRememberedState();
}
}

private boolean isTracingEnabled() {
Expand Down
Loading