Search in sources :

Example 76 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cubrid-manager by CUBRID.

the class CommonUITool method registerCopyPasteContextMenu.

/**
	 *
	 * Register context menu for styled text
	 *
	 * @param text StyledText
	 * @param isEditable boolean
	 */
public static void registerCopyPasteContextMenu(final StyledText text, final boolean isEditable, final boolean isCopiable) {
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (isCopiable) {
                IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
                if (copyAction instanceof CopyAction) {
                    manager.add(copyAction);
                    if (!copyAction.isEnabled()) {
                        FocusAction.changeActionStatus(copyAction, text);
                    }
                }
                IAction copyAllAction = ActionManager.getInstance().getAction(CopyAllAction.ID);
                if (copyAllAction instanceof CopyAllAction) {
                    manager.add(copyAllAction);
                    if (!copyAllAction.isEnabled()) {
                        FocusAction.changeActionStatus(copyAllAction, text);
                    }
                }
            }
            if (!isEditable) {
                return;
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction instanceof PasteAction) {
                manager.add(pasteAction);
                if (!pasteAction.isEnabled()) {
                    FocusAction.changeActionStatus(pasteAction, text);
                }
            }
        }
    });
    Menu contextMenu = menuManager.createContextMenu(text);
    text.setMenu(contextMenu);
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (!copyAction.isEnabled()) {
                FocusAction.changeActionStatus(copyAction, text);
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction != null && !pasteAction.isEnabled()) {
                FocusAction.changeActionStatus(pasteAction, text);
            }
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) IAction(org.eclipse.jface.action.IAction) CopyAction(com.cubrid.common.ui.query.action.CopyAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CopyAllAction(com.cubrid.common.ui.query.action.CopyAllAction) FocusEvent(org.eclipse.swt.events.FocusEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) PasteAction(com.cubrid.common.ui.query.action.PasteAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 77 with FocusEvent

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

the class ResultsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    parent.setLayout(new GridLayout(1, true));
    filter = new Text(parent, SWT.FILL);
    filter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    TextUtils.setToDefault(filter, FILTER_DEFAULT);
    filter.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if ("".equals(filter.getText())) {
                TextUtils.setToDefault(filter, FILTER_DEFAULT);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            TextUtils.makeEditable(filter);
        }
    });
    filter.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            viewer.refresh();
        }
    });
    return parent;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) KeyAdapter(org.eclipse.swt.events.KeyAdapter) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 78 with FocusEvent

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

the class ToolBarControl method createControl.

@Override
protected Control createControl(Composite parent) {
    final Text searchBox = new Text(parent, SWT.FILL | SWT.BORDER);
    TextUtils.setToDefault(searchBox, "{OpenGrok");
    searchBox.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!disableFocusLostEvent) {
                TextUtils.setToDefault(searchBox, "{OpenGrok");
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            TextUtils.makeEditable(searchBox);
        }
    });
    searchBox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                doSearch();
            } else if (e.keyCode == SWT.ARROW_UP) {
                historyIndex++;
                if (historyIndex > history.size()) {
                    historyIndex = history.size();
                }
                if (historyIndex >= 0 && history.size() >= historyIndex) {
                    searchBox.setText(history.get(historyIndex - 1));
                }
            } else if (e.keyCode == SWT.ARROW_DOWN) {
                historyIndex--;
                if (historyIndex < 0) {
                    historyIndex = 0;
                } else if (history.size() > historyIndex) {
                    searchBox.setText(history.get(historyIndex));
                }
            } else if ((e.stateMask & SWT.CTRL) == SWT.CTRL && e.keyCode == 'v') {
                searchBox.setText("");
                searchBox.paste();
                if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT) {
                    doSearch();
                }
            } else if (e.stateMask == SWT.CTRL && e.keyCode == 'c') {
                searchBox.copy();
            }
        }

        private void doSearch() {
            String text = searchBox.getText();
            if (text != null && !"".equals(text)) {
                history.add(0, text);
                historyIndex = 0;
                Rectangle bounds = searchBox.getBounds();
                Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
                topLeft = searchBox.getShell().toDisplay(topLeft);
                final ResultsDialog dialog = new ResultsDialog(Display.getCurrent().getActiveShell(), text, topLeft);
                Query query = new Query(text);
                disableFocusLostEvent = true;
                query.run(dialog);
                disableFocusLostEvent = false;
            }
        }
    });
    return parent;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Query(org.opensolaris.opengrok.egrok.query.Query) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 79 with FocusEvent

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

the class TabbedFolderPageEditor method createControl.

@Override
public void createControl(Composite parent) {
    editor = editorDescriptor.createEditor();
    final IWorkbenchPartSite ownerSite = this.mainEditor.getSite();
    if (ownerSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart ownerMultiPageEditor = ((MultiPageEditorSite) ownerSite).getMultiPageEditor();
        nestedEditorSite = new TabbedFolderPageEditorSite(ownerMultiPageEditor, editor);
        // We need it to tell owner editor about dirty state change
        if (ownerMultiPageEditor instanceof IPropertyChangeReflector) {
            editor.addPropertyListener(new IPropertyListener() {

                @Override
                public void propertyChanged(Object source, int propId) {
                    ((IPropertyChangeReflector) ownerMultiPageEditor).handlePropertyChange(propId);
                }
            });
        }
    } else {
        nestedEditorSite = new SubEditorSite(mainEditor.getEditorSite());
    }
    try {
        editor.init(nestedEditorSite, editorDescriptor.getNestedEditorInput(mainEditor.getEditorInput()));
    } catch (PartInitException e) {
        UIUtils.showErrorDialog(parent.getShell(), "Create SQL viewer", null, e);
    }
    editor.createPartControl(parent);
    if (editor instanceof ISingleControlEditor) {
        // Use focus to active selection provider and contributed actions
        Control editorControl = ((ISingleControlEditor) editor).getEditorControl();
        assert editorControl != null;
        editorControl.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                ISelectionProvider selectionProvider = editor.getSite().getSelectionProvider();
                mainEditor.getSite().setSelectionProvider(selectionProvider);
                if (actionContributor != null) {
                    actionContributor.setActiveEditor(editor);
                }
                activateNestedSite(true);
            }

            @Override
            public void focusLost(FocusEvent e) {
                activateNestedSite(false);
                if (actionContributor != null) {
                    actionContributor.setActiveEditor(null);
                }
            }
        });
    }
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (editor != null) {
                editor.dispose();
                editor = null;
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) Control(org.eclipse.swt.widgets.Control) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) FocusListener(org.eclipse.swt.events.FocusListener)

Example 80 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cubrid-manager by CUBRID.

the class GeneralInfoPage method createLogVolumeGroup.

/**
	 * Create log volume information group
	 *
	 * @param parent the parent composite
	 */
private void createLogVolumeGroup(Composite parent) {
    Group logVolumeGroup = new Group(parent, SWT.NONE);
    logVolumeGroup.setText(Messages.grpLogVolInfo);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    logVolumeGroup.setLayout(layout);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    logVolumeGroup.setLayoutData(gridData);
    if (CompatibleUtil.isSupportLogPageSize(server.getServerInfo())) {
        Label logPageSizeLabel = new Label(logVolumeGroup, SWT.LEFT | SWT.WRAP);
        logPageSizeLabel.setText(Messages.lblLogPageSize);
        gridData = new GridData();
        gridData.widthHint = 150;
        logPageSizeLabel.setLayoutData(gridData);
        logPageSizeCombo = new Combo(logVolumeGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 3;
        logPageSizeCombo.setLayoutData(gridData);
        logPageSizeCombo.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                valid();
            }
        });
    }
    Label logSizeLabel = new Label(logVolumeGroup, SWT.LEFT | SWT.WRAP);
    logSizeLabel.setText(Messages.lblVolSize);
    gridData = new GridData();
    gridData.widthHint = 150;
    logSizeLabel.setLayoutData(gridData);
    logVolumeSizeText = new Text(logVolumeGroup, SWT.BORDER);
    logVolumeSizeText.setTextLimit(20);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    logVolumeSizeText.setLayoutData(gridData);
    logVolumeSizeText.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent event) {
            logVolumeSizeText.addModifyListener(GeneralInfoPage.this);
        }

        public void focusLost(FocusEvent event) {
            logVolumeSizeText.removeModifyListener(GeneralInfoPage.this);
        }
    });
    Label logVolumePathLabel = new Label(logVolumeGroup, SWT.LEFT | SWT.WRAP);
    logVolumePathLabel.setText(Messages.lblLogVolPath);
    gridData = new GridData();
    gridData.widthHint = 150;
    logVolumePathLabel.setLayoutData(gridData);
    logVolumePathText = new Text(logVolumeGroup, SWT.BORDER);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    logVolumePathText.setLayoutData(gridData);
    Button selectDirectoryButton = new Button(logVolumeGroup, SWT.NONE);
    selectDirectoryButton.setText(Messages.btnBrowse);
    selectDirectoryButton.setLayoutData(CommonUITool.createGridData(1, 1, 80, -1));
    selectDirectoryButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            if (databasePath != null && databasePath.trim().length() > 0) {
                dlg.setFilterPath(databasePath);
            }
            dlg.setText(Messages.msgSelectDir);
            dlg.setMessage(Messages.msgSelectDir);
            String dir = dlg.open();
            if (dir != null) {
                logVolumePathText.setText(dir);
            }
        }
    });
    ServerInfo serverInfo = server.getServerInfo();
    if (serverInfo != null && !serverInfo.isLocalServer()) {
        selectDirectoryButton.setEnabled(false);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)115 FocusAdapter (org.eclipse.swt.events.FocusAdapter)64 SelectionEvent (org.eclipse.swt.events.SelectionEvent)54 FocusListener (org.eclipse.swt.events.FocusListener)47 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)42 GridData (org.eclipse.swt.layout.GridData)38 Composite (org.eclipse.swt.widgets.Composite)34 Text (org.eclipse.swt.widgets.Text)33 GridLayout (org.eclipse.swt.layout.GridLayout)32 Label (org.eclipse.swt.widgets.Label)26 Menu (org.eclipse.swt.widgets.Menu)22 KeyEvent (org.eclipse.swt.events.KeyEvent)21 Button (org.eclipse.swt.widgets.Button)21 Point (org.eclipse.swt.graphics.Point)20 ModifyEvent (org.eclipse.swt.events.ModifyEvent)19 MenuManager (org.eclipse.jface.action.MenuManager)18 ModifyListener (org.eclipse.swt.events.ModifyListener)18 Combo (org.eclipse.swt.widgets.Combo)17 Group (org.eclipse.swt.widgets.Group)17 SelectionListener (org.eclipse.swt.events.SelectionListener)15