Search in sources :

Example 1 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cogtool by cogtool.

the class ActionSet method createTransitionName.

private Text createTransitionName(Composite parent, String txt) {
    final Text name = new Text(parent, SWT.BORDER);
    final NameInfo info = new NameInfo(txt);
    // Note that we have to use a VerifyListener to prevent editing the
    // contents of the Text, as SWT has made the rather surprising decision
    // that setting its editable field to false also
    // takes away our ability to select and navigate in the field, and copy
    // its contents. Grr.
    name.addVerifyListener(new VerifyListener() {

        public void verifyText(VerifyEvent evt) {
            // the user's trying to modify an already populated Text. Yuk.
            switch(transitionNameState) {
                case NORMAL:
                    info.fullName = evt.text;
                    evt.text = SWTStringUtil.insertEllipsis(info.fullName, name.getSize().x, StringUtil.EQUAL, name.getFont());
                    break;
                case HAS_FOCUS:
                    evt.doit = false;
                    break;
                case GAINING_FOCUS:
                    break;
            }
        }
    });
    name.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent evt) {
            transitionNameState = TransitionNameState.GAINING_FOCUS;
            name.setText(info.fullName);
            transitionNameState = TransitionNameState.HAS_FOCUS;
        }

        @Override
        public void focusLost(FocusEvent evt) {
            transitionNameState = TransitionNameState.NORMAL;
            name.setText(info.fullName);
        }
    });
    name.setText(txt);
    return name;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) VerifyListener(org.eclipse.swt.events.VerifyListener) ManagedText(edu.cmu.cs.hcii.cogtool.util.ManagedText) Text(org.eclipse.swt.widgets.Text) VerifyEvent(org.eclipse.swt.events.VerifyEvent) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 2 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project dbeaver by serge-rider.

the class CustomCheckboxCellEditor method createControl.

@Override
protected Control createControl(Composite parent) {
    checkBox = new Button(parent, SWT.CHECK);
    checkBox.setFont(parent.getFont());
    checkBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            applyEditorValue();
            // This is needed for MacOS
            fireApplyEditorValue();
        }
    });
    checkBox.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            CustomCheckboxCellEditor.this.focusLost();
        }
    });
    return checkBox;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 3 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project dbeaver by serge-rider.

the class BaseValueEditor method initInlineControl.

protected void initInlineControl(final Control inlineControl) {
    boolean isInline = (valueController.getEditType() == IValueController.EditType.INLINE);
    if (isInline && UIUtils.isInDialog(inlineControl)) {
    //isInline = false;
    }
    UIUtils.enableHostEditorKeyBindingsSupport(valueController.getValueSite(), inlineControl);
    //            if (!isInline) {
    //                inlineControl.setBackground(valueController.getEditPlaceholder().getBackground());
    //            }
    final IContextService contextService = valueController.getValueSite().getService(IContextService.class);
    inlineControl.addFocusListener(new FocusListener() {

        private IContextActivation activationEditor;

        @Override
        public void focusGained(FocusEvent e) {
            if (contextService != null) {
                activationEditor = contextService.activateContext(RESULTS_EDIT_CONTEXT_ID);
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            contextService.deactivateContext(activationEditor);
            activationEditor = null;
        }
    });
    if (isInline) {
        inlineControl.setFont(valueController.getEditPlaceholder().getFont());
        inlineControl.setFocus();
        if (valueController instanceof IMultiController) {
            // In dialog it also should handle all standard stuff because we have params dialog
            inlineControl.addTraverseListener(new TraverseListener() {

                @Override
                public void keyTraversed(TraverseEvent e) {
                    if (e.detail == SWT.TRAVERSE_RETURN) {
                        saveValue();
                        ((IMultiController) valueController).closeInlineEditor();
                        e.doit = false;
                        e.detail = SWT.TRAVERSE_NONE;
                    } else if (e.detail == SWT.TRAVERSE_ESCAPE) {
                        ((IMultiController) valueController).closeInlineEditor();
                        e.doit = false;
                        e.detail = SWT.TRAVERSE_NONE;
                    } else if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
                        saveValue();
                        ((IMultiController) valueController).nextInlineEditor(e.detail == SWT.TRAVERSE_TAB_NEXT);
                        e.doit = false;
                        e.detail = SWT.TRAVERSE_NONE;
                    }
                }
            });
            if (!UIUtils.isInDialog(inlineControl)) {
                addAutoSaveSupport(inlineControl);
            }
        }
    }
    final ControlModifyListener modifyListener = new ControlModifyListener();
    control.addListener(SWT.Modify, modifyListener);
    control.addListener(SWT.Selection, modifyListener);
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) IContextActivation(org.eclipse.ui.contexts.IContextActivation) TraverseListener(org.eclipse.swt.events.TraverseListener) IContextService(org.eclipse.ui.contexts.IContextService) IMultiController(org.jkiss.dbeaver.ui.data.IMultiController) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 4 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project dbeaver by serge-rider.

the class SQLEditorNested method createPartControl.

@Override
public void createPartControl(Composite parent) {
    pageControl = new EditorPageControl(parent, SWT.SHEET);
    boolean hasCompiler = getCompileCommandId() != null;
    if (hasCompiler) {
        editorSash = new SashForm(pageControl.createContentContainer(), SWT.VERTICAL | SWT.SMOOTH);
        super.createPartControl(editorSash);
        editorControl = editorSash.getChildren()[0];
        compileLog = new ObjectCompilerLogViewer(editorSash, false);
    } else {
        super.createPartControl(pageControl.createContentContainer());
    }
    // Create new or substitute progress control
    pageControl.createOrSubstituteProgressPanel(getSite());
    pageControl.setInfo("Source");
    if (hasCompiler) {
        editorSash.setWeights(new int[] { 70, 30 });
        editorSash.setMaximizedControl(editorControl);
    }
    // Use focus to activate page control
    final Control editorControl = getEditorControl();
    assert editorControl != null;
    editorControl.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            if (pageControl != null && !pageControl.isDisposed()) {
                pageControl.activate(true);
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            if (pageControl != null && !pageControl.isDisposed()) {
                pageControl.activate(false);
            }
        }
    });
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) Control(org.eclipse.swt.widgets.Control) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 5 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project dbeaver by serge-rider.

the class TabbedFolderPageNode method createControl.

@Override
public void createControl(Composite parent) {
    itemControl = new ItemListControl(parent, SWT.SHEET, mainEditor.getSite(), node, metaNode);
    //itemControl.getLayout().marginHeight = 0;
    //itemControl.getLayout().marginWidth = 0;
    ProgressPageControl progressControl = null;
    if (mainEditor instanceof IProgressControlProvider) {
        progressControl = ((IProgressControlProvider) mainEditor).getProgressControl();
    }
    if (progressControl != null) {
        itemControl.substituteProgressPanel(progressControl);
    } else {
        itemControl.createProgressPanel();
    }
    parent.layout();
    // Activate items control on focus
    itemControl.getItemsViewer().getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            // Update selection provider and selection
            final ISelectionProvider selectionProvider = itemControl.getSelectionProvider();
            if (mainEditor.getSite().getSelectionProvider() != selectionProvider) {
                mainEditor.getSite().setSelectionProvider(selectionProvider);
                selectionProvider.setSelection(selectionProvider.getSelection());
            }
            itemControl.activate(true);
            // We need it to update search actions and other contributions provided by node editor
            if (mainEditor.getSite() instanceof MultiPageEditorSite) {
                MultiPageEditorPart multiPageEditor = ((MultiPageEditorSite) mainEditor.getSite()).getMultiPageEditor();
                if (multiPageEditor.getSelectedPage() != mainEditor) {
                    multiPageEditor.setActiveEditor(mainEditor);
                }
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            itemControl.activate(false);
        }
    });
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) ItemListControl(org.jkiss.dbeaver.ui.controls.itemlist.ItemListControl) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)98 FocusAdapter (org.eclipse.swt.events.FocusAdapter)55 SelectionEvent (org.eclipse.swt.events.SelectionEvent)50 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)42 FocusListener (org.eclipse.swt.events.FocusListener)40 GridData (org.eclipse.swt.layout.GridData)34 Text (org.eclipse.swt.widgets.Text)30 GridLayout (org.eclipse.swt.layout.GridLayout)29 Composite (org.eclipse.swt.widgets.Composite)28 Label (org.eclipse.swt.widgets.Label)23 Menu (org.eclipse.swt.widgets.Menu)21 Button (org.eclipse.swt.widgets.Button)19 MenuManager (org.eclipse.jface.action.MenuManager)18 ModifyEvent (org.eclipse.swt.events.ModifyEvent)17 ModifyListener (org.eclipse.swt.events.ModifyListener)17 Group (org.eclipse.swt.widgets.Group)17 Point (org.eclipse.swt.graphics.Point)16 Combo (org.eclipse.swt.widgets.Combo)15 MenuItem (org.eclipse.swt.widgets.MenuItem)15 KeyEvent (org.eclipse.swt.events.KeyEvent)12