gridLayout.marginWidth = 0;
root.setLayout(gridLayout);
ICommandService service =
(ICommandService) getWorkbenchWindow().getService(ICommandService.class);
final Command cmd = service.getCommand("net.sf.logsaw.ui.commands.GoToPageCommand"); //$NON-NLS-1$
text = new Text(root, SWT.BORDER | SWT.RIGHT);
text.addKeyListener(new KeyAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
*/
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CR) {
try {
int pageNumber = Integer.valueOf(text.getText().trim());
IHandlerService service =
(IHandlerService) getWorkbenchWindow().getService(IHandlerService.class);
Parameterization param = new Parameterization(
cmd.getParameter("net.sf.logsaw.ui.commands.GoToPageCommand.pageNumber"), Integer.toString(pageNumber)); //$NON-NLS-1$
ParameterizedCommand paraCmd = new ParameterizedCommand(cmd, new Parameterization[] {param});
service.executeCommand(paraCmd, null);
} catch (NumberFormatException e1) {
// nadda
} catch (CommandException e1) {
// Log and show error
UIPlugin.logAndShowError(new CoreException(
new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID,
NLS.bind(Messages.GoToPageContribution_error_failedToExecuteCommand,
new Object[] {e1.getLocalizedMessage()}), e1)), false);
}
}
}
});
label = new Label(root, SWT.NONE);
// This number format is used for label and text field
nf = new DecimalFormat();
nf.setGroupingUsed(false);
nf.setParseIntegerOnly(true);
if (cmd != null) {
updateState(cmd.isEnabled());
cmd.addCommandListener(new ICommandListener() {
/* (non-Javadoc)
* @see org.eclipse.core.commands.ICommandListener#commandChanged(org.eclipse.core.commands.CommandEvent)
*/
@Override