Search in sources :

Example 1 with IMultiController

use of org.jkiss.dbeaver.ui.data.IMultiController 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)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 IContextActivation (org.eclipse.ui.contexts.IContextActivation)1 IContextService (org.eclipse.ui.contexts.IContextService)1 IMultiController (org.jkiss.dbeaver.ui.data.IMultiController)1