@Override protected Control createControl(final Composite parent) { final Control control = super.createControl(parent); control.addTraverseListener( new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { switch (e.keyCode) { case SWT.ARROW_LEFT: case SWT.ARROW_RIGHT: case SWT.ARROW_UP: case SWT.ARROW_DOWN: case SWT.TAB: fireApplyEditorValue(); deactivate(); final Event event = new Event(); event.character = e.character; event.keyCode = e.keyCode; event.stateMask = e.stateMask; parent.notifyListeners(SWT.KeyDown, event); } } }); return control; }
@Override protected Control addLabel(Composite parent) { if (fCreateTargetQuery != null) { Composite firstLine = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginHeight = layout.marginWidth = 0; firstLine.setLayout(layout); firstLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Control label = super.addLabel(firstLine); label.addTraverseListener( new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) { e.detail = SWT.TRAVERSE_NONE; getTreeViewer().getTree().setFocus(); } } }); Button newButton = new Button(firstLine, SWT.PUSH); newButton.setText(fCreateTargetQuery.getNewButtonLabel()); GridData gd = new GridData( GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); gd.widthHint = SWTUtil.getButtonWidthHint(newButton); newButton.setLayoutData(gd); newButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doNewButtonPressed(); } }); return firstLine; } else { return super.addLabel(parent); } }