Search in sources :

Example 31 with TraverseListener

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;
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TraverseListener(org.eclipse.swt.events.TraverseListener) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 32 with TraverseListener

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);
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener)

Aggregations

TraverseListener (org.eclipse.swt.events.TraverseListener)32 TraverseEvent (org.eclipse.swt.events.TraverseEvent)30 FocusEvent (org.eclipse.swt.events.FocusEvent)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 FocusAdapter (org.eclipse.swt.events.FocusAdapter)9 Point (org.eclipse.swt.graphics.Point)9 Button (org.eclipse.swt.widgets.Button)9 MouseEvent (org.eclipse.swt.events.MouseEvent)8 Text (org.eclipse.swt.widgets.Text)8 KeyEvent (org.eclipse.swt.events.KeyEvent)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 StyledText (org.eclipse.swt.custom.StyledText)6 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 ModifyListener (org.eclipse.swt.events.ModifyListener)6 Composite (org.eclipse.swt.widgets.Composite)6 Control (org.eclipse.swt.widgets.Control)6 Label (org.eclipse.swt.widgets.Label)6 MouseAdapter (org.eclipse.swt.events.MouseAdapter)5 MouseListener (org.eclipse.swt.events.MouseListener)5 GridData (org.eclipse.swt.layout.GridData)5