Search in sources :

Example 1 with FocusListener

use of org.eclipse.swt.events.FocusListener 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 2 with FocusListener

use of org.eclipse.swt.events.FocusListener 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 3 with FocusListener

use of org.eclipse.swt.events.FocusListener 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)

Example 4 with FocusListener

use of org.eclipse.swt.events.FocusListener in project translationstudio8 by heartsome.

the class NatTable method initInternalListener.

protected void initInternalListener() {
    modeSupport = new ModeSupport(this);
    modeSupport.registerModeEventHandler(Mode.NORMAL_MODE, new ConfigurableModeEventHandler(modeSupport, this));
    modeSupport.switchMode(Mode.NORMAL_MODE);
    addPaintListener(this);
    addFocusListener(new FocusListener() {

        public void focusLost(final FocusEvent arg0) {
            redraw();
        }

        public void focusGained(final FocusEvent arg0) {
            redraw();
        }
    });
    addListener(SWT.Resize, new Listener() {

        public void handleEvent(final Event e) {
            doCommand(new ClientAreaResizeCommand(NatTable.this));
        }
    });
}
Also used : ModeSupport(net.sourceforge.nattable.ui.mode.ModeSupport) PaintListener(org.eclipse.swt.events.PaintListener) ILayerListener(net.sourceforge.nattable.layer.ILayerListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) ClientAreaResizeCommand(net.sourceforge.nattable.grid.command.ClientAreaResizeCommand) ConfigurableModeEventHandler(net.sourceforge.nattable.ui.mode.ConfigurableModeEventHandler) IVisualChangeEvent(net.sourceforge.nattable.layer.event.IVisualChangeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) ILayerEvent(net.sourceforge.nattable.layer.event.ILayerEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 5 with FocusListener

use of org.eclipse.swt.events.FocusListener in project translationstudio8 by heartsome.

the class CustomFilterDialog method setGray.

/**
	 * 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒
	 * @param text
	 *            Text控件
	 * @param initTxt
	 *            灰色提醒字符串
	 */
private void setGray(final Text text, final String initTxt) {
    text.setForeground(gray);
    text.setText(initTxt);
    text.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent arg0) {
            if (text.getText().trim().equals("")) {
                if (!text.getForeground().equals(gray)) {
                    text.setForeground(gray);
                }
                text.setText(initTxt);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }

        public void focusGained(FocusEvent arg0) {
            if (text.getText().trim().equals(initTxt)) {
                text.setText("");
                text.setForeground(black);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }
    });
}
Also used : FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)40 FocusListener (org.eclipse.swt.events.FocusListener)40 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 GridData (org.eclipse.swt.layout.GridData)13 GridLayout (org.eclipse.swt.layout.GridLayout)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 Text (org.eclipse.swt.widgets.Text)9 ControlEvent (org.eclipse.swt.events.ControlEvent)7 ControlListener (org.eclipse.swt.events.ControlListener)7 SashForm (org.eclipse.swt.custom.SashForm)6 KeyEvent (org.eclipse.swt.events.KeyEvent)6 Composite (org.eclipse.swt.widgets.Composite)6 StyledText (org.eclipse.swt.custom.StyledText)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)5 DisposeListener (org.eclipse.swt.events.DisposeListener)5 Button (org.eclipse.swt.widgets.Button)5 Label (org.eclipse.swt.widgets.Label)5 Table (org.eclipse.swt.widgets.Table)5 TableViewer (org.eclipse.jface.viewers.TableViewer)4 KeyListener (org.eclipse.swt.events.KeyListener)4