use of org.eclipse.swt.events.TraverseListener in project eclipse.platform.text by eclipse.
the class FindReplaceDialog method createContents.
@Override
protected Control createContents(Composite parent) {
Composite panel = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.makeColumnsEqualWidth = true;
panel.setLayout(layout);
setGridData(panel, SWT.FILL, true, SWT.FILL, true);
ScrolledComposite scrolled = new ScrolledComposite(panel, SWT.V_SCROLL);
setGridData(scrolled, SWT.FILL, true, SWT.FILL, true);
Composite mainArea = new Composite(scrolled, SWT.NONE);
setGridData(mainArea, SWT.FILL, true, SWT.FILL, true);
mainArea.setLayout(new GridLayout(1, true));
Composite inputPanel = createInputPanel(mainArea);
setGridData(inputPanel, SWT.FILL, true, SWT.TOP, false);
Composite configPanel = createConfigPanel(mainArea);
setGridData(configPanel, SWT.FILL, true, SWT.TOP, true);
scrolled.setContent(mainArea);
scrolled.setExpandHorizontal(true);
scrolled.setExpandVertical(true);
scrolled.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
scrolled.setMinHeight(mainArea.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
}
});
Composite buttonPanelB = createButtonSection(panel);
setGridData(buttonPanelB, SWT.RIGHT, true, SWT.BOTTOM, false);
Composite statusBar = createStatusAndCloseButton(panel);
setGridData(statusBar, SWT.FILL, true, SWT.BOTTOM, false);
panel.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
if (!Util.isMac()) {
Control controlWithFocus = getShell().getDisplay().getFocusControl();
if (controlWithFocus != null && (controlWithFocus.getStyle() & SWT.PUSH) == SWT.PUSH)
return;
}
Event event = new Event();
event.type = SWT.Selection;
event.stateMask = e.stateMask;
fFindNextButton.notifyListeners(SWT.Selection, event);
e.doit = false;
} else if (e.detail == SWT.TRAVERSE_MNEMONIC) {
Character mnemonic = Character.valueOf(Character.toLowerCase(e.character));
if (fMnemonicButtonMap.containsKey(mnemonic)) {
Button button = fMnemonicButtonMap.get(mnemonic);
if ((fFindField.isFocusControl() || fReplaceField.isFocusControl() || (button.getStyle() & SWT.PUSH) != 0) && button.isEnabled()) {
Event event = new Event();
event.type = SWT.Selection;
event.stateMask = e.stateMask;
if ((button.getStyle() & SWT.RADIO) != 0) {
Composite buttonParent = button.getParent();
if (buttonParent != null) {
Control[] children = buttonParent.getChildren();
for (int i = 0; i < children.length; i++) ((Button) children[i]).setSelection(false);
}
button.setSelection(true);
} else {
button.setSelection(!button.getSelection());
}
button.notifyListeners(SWT.Selection, event);
e.detail = SWT.TRAVERSE_NONE;
e.doit = true;
}
}
}
}
});
updateButtonState();
applyDialogFont(panel);
return panel;
}
use of org.eclipse.swt.events.TraverseListener in project eclipse.platform.text by eclipse.
the class ContentAssistant method install.
protected void install() {
fLayoutManager = new LayoutManager();
fInternalListener = new InternalListener();
AdditionalInfoController controller = null;
if (fInformationControlCreator != null)
controller = new AdditionalInfoController(fInformationControlCreator, OpenStrategy.getPostSelectionDelay());
fContextInfoPopup = fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
fProposalPopup = fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller, fAsynchronous);
fProposalPopup.setSorter(fSorter);
registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT));
registerHandler(SELECT_PREVIOUS_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_PREVIOUS));
if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) {
fContentAssistSubjectControlShell = fContentAssistSubjectControlAdapter.getControl().getShell();
fCASCSTraverseListener = new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE && isProposalPopupActive())
e.doit = false;
}
};
fContentAssistSubjectControlShell.addTraverseListener(fCASCSTraverseListener);
}
manageAutoActivation(fIsAutoActivated);
}
Aggregations