Search in sources :

Example 61 with KeyEvent

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

the class EditProcedureDialog method createProcedureSettingComposite.

/**
	 * Create the procedure setting composite
	 *
	 * @return the composite
	 */
private Composite createProcedureSettingComposite() {
    final Composite composite = new Composite(tabFolder, SWT.LEFT | SWT.WRAP);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layoutComp;
    layoutComp = new GridLayout();
    layoutComp.marginWidth = 10;
    layoutComp.marginHeight = 10;
    layoutComp.numColumns = 2;
    composite.setLayout(layoutComp);
    final Label functionNameLabel = new Label(composite, SWT.NONE);
    functionNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    functionNameLabel.setText(Messages.lblProcedureName);
    procNameText = new Text(composite, SWT.BORDER);
    procNameText.setTextLimit(ValidateUtil.MAX_SCHEMA_NAME_LENGTH);
    procNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    procNameText.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {

        public void keyPressed(KeyEvent event) {
        }

        public void keyReleased(KeyEvent event) {
            if (StringUtil.isEmpty(procNameText.getText())) {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
                return;
            }
            getButton(IDialogConstants.OK_ID).setEnabled(true);
        }
    });
    if (isCommentSupport) {
        final Label procDescriptionLabel = new Label(composite, SWT.NONE);
        procDescriptionLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        procDescriptionLabel.setText(Messages.lblProcedureDescription);
        procDescriptionText = new Text(composite, SWT.BORDER);
        procDescriptionText.setTextLimit(ValidateUtil.MAX_DB_OBJECT_COMMENT);
        procDescriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    }
    final String[] userColumnNameArr = isCommentSupport ? new String[] { Messages.tblColProcedureParamName, Messages.tblColProcedureParamType, Messages.tblColProcedureJavaParamType, Messages.tblColProcedureModel, Messages.tblColProcedureMemo } : new String[] { Messages.tblColProcedureParamName, Messages.tblColProcedureParamType, Messages.tblColProcedureJavaParamType, Messages.tblColProcedureModel };
    procParamsTableViewer = CommonUITool.createCommonTableViewer(composite, null, userColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 6, 4, -1, 200));
    procParamsTable = procParamsTableViewer.getTable();
    procParamsTableViewer.getTable().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
        }

        public void widgetSelected(SelectionEvent event) {
            if (procParamsTableViewer.getTable().getSelectionCount() > 0) {
                getButton(BUTTON_EDIT_ID).setEnabled(true);
                getButton(BUTTON_UP_ID).setEnabled(true);
                getButton(BUTTON_DOWN_ID).setEnabled(true);
                getButton(BUTTON_DROP_ID).setEnabled(true);
            }
        }
    });
    procParamsTableViewer.setInput(procParamsListData);
    procParamsTable.setLinesVisible(true);
    procParamsTable.setHeaderVisible(true);
    procParamsTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
        // setBtnEnableDisable();
        }
    });
    barComp = new Composite(composite, SWT.NONE);
    final GridData gdbarComp = new GridData(GridData.FILL_HORIZONTAL);
    gdbarComp.horizontalSpan = 2;
    barComp.setLayoutData(gdbarComp);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 10;
    layout.marginHeight = 10;
    barComp.setLayout(layout);
    final Label javaNameLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
    javaNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    javaNameLabel.setText(Messages.lblJavaFunctionName);
    javaNameText = new Text(composite, SWT.BORDER);
    GridData gdJavaNameText = new GridData(GridData.FILL_HORIZONTAL);
    javaNameText.setLayoutData(gdJavaNameText);
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 62 with KeyEvent

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

the class ReformatColumnsAliasDialog method createContents.

protected void createContents() {
    shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    shell.setLayout(gridLayout);
    shell.setSize(450, 100);
    shell.setText(Messages.reformatTableAliasTitle);
    final Composite composite = new Composite(shell, SWT.NONE);
    final GridData gdComposite = new GridData(SWT.FILL, SWT.FILL, true, true);
    gdComposite.heightHint = 0;
    gdComposite.widthHint = 296;
    composite.setLayoutData(gdComposite);
    composite.setLayout(new GridLayout());
    sqlComp = getActiveSQLEditorComposite();
    if (sqlComp == null) {
        close();
        return;
    }
    final Composite group = new Composite(composite, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayoutGroup = new GridLayout();
    gridLayoutGroup.marginHeight = 0;
    gridLayoutGroup.numColumns = 1;
    group.setLayout(gridLayoutGroup);
    {
        final Label findWhatLabel = new Label(group, SWT.NONE);
        String msg = Messages.reformatTableAliasMessage;
        findWhatLabel.setText(msg);
        aliasText = new Text(group, SWT.BORDER);
        final GridData gdFind = new GridData(SWT.FILL, SWT.CENTER, true, false);
        aliasText.setLayoutData(gdFind);
        aliasText.addKeyListener(new KeyListener() {

            public void keyReleased(KeyEvent e) {
            }

            public void keyPressed(KeyEvent e) {
                if (e.keyCode == SWT.CR) {
                    submit();
                }
            }
        });
    }
    final Composite composite1 = new Composite(shell, SWT.NONE);
    final GridData gdComposite1 = new GridData(SWT.RIGHT, SWT.FILL, false, false);
    composite1.setLayoutData(gdComposite1);
    final GridLayout gridLayoutGroup2 = new GridLayout();
    gridLayoutGroup2.marginHeight = 0;
    gridLayoutGroup2.numColumns = 2;
    composite1.setLayout(gridLayoutGroup2);
    new Label(composite1, SWT.NONE);
    new Label(composite1, SWT.NONE);
    final Button findBtn = new Button(composite1, SWT.NONE);
    final GridData gdFindBtn = new GridData(SWT.FILL, SWT.CENTER, false, false);
    findBtn.setLayoutData(gdFindBtn);
    findBtn.setText(Messages.reformatTableAliasBtn);
    findBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            submit();
        }
    });
    final Button closeBtn = new Button(composite1, SWT.NONE);
    final GridData gdCloseBtn = new GridData(SWT.FILL, SWT.CENTER, false, false);
    closeBtn.setLayoutData(gdCloseBtn);
    closeBtn.setText(Messages.reformatTableAliasCancelBtn);
    closeBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            close();
        }
    });
    aliasText.addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR) {
                submit();
            }
        }

        public void keyPressed(KeyEvent e) {
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) KeyListener(org.eclipse.swt.events.KeyListener)

Example 63 with KeyEvent

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

the class SQLEditorComposite method addListener.

/**
	 * Add listener for text
	 */
private void addListener() {
    text.addModifyListener(new ModifyListener() {

        IAction undoAction = ActionManager.getInstance().getAction(UndoAction.ID);

        IAction redoAction = ActionManager.getInstance().getAction(RedoAction.ID);

        public void modifyText(ModifyEvent event) {
            setDirty(true);
            if (!undoAction.isEnabled()) {
                FocusAction.changeActionStatus(undoAction, text);
            }
            if (!redoAction.isEnabled()) {
                FocusAction.changeActionStatus(redoAction, text);
            }
            ServerInfo serverInfo = queryEditor == null || queryEditor.getSelectedServer() == null ? null : queryEditor.getSelectedServer().getServerInfo();
            boolean isLowerCase = QueryOptions.getKeywordLowercase(serverInfo);
            boolean isNoAutoUpperCase = QueryOptions.getNoAutoUppercaseKeyword(serverInfo);
            if (!isLowerCase && !isNoAutoUpperCase) {
                autoReplaceKeyword();
            }
        }

        // FIXME extract method?
        // replace keyword to upper case automatically
        public void autoReplaceKeyword() {
            if (pendingCompletionsListener) {
                return;
            }
            int pos = text.getCaretOffset() - 1;
            if (pos <= 0) {
                return;
            }
            String currentKey = text.getText(pos, pos);
            if (currentKey == null || currentKey.length() <= 0) {
                return;
            }
            char cur = currentKey.charAt(0);
            if (cur != ' ' && cur != '(' && cur != '\t' && cur != '\n' && cur != '\r' && cur != ',') {
                return;
            }
            pos--;
            if (pos < 0) {
                return;
            }
            int spos = pos - 20;
            if (spos < 0) {
                spos = 0;
            }
            String txt = text.getText(spos, pos);
            spos = pos + 1;
            for (int i = txt.length() - 1; i >= 0; i--) {
                char c = txt.charAt(i);
                if (c == ' ' || c == '\t' || c == '\n' || c == '(') {
                    break;
                }
                spos--;
            }
            int epos = pos;
            if (spos < 0 || epos < 0 || spos > epos) {
                return;
            }
            String currentKeyword = text.getText(spos, epos);
            if (currentKeyword == null) {
                return;
            }
            int len = currentKeyword.length();
            for (int i = 0; i < QuerySyntax.KEYWORDS_AUTO_UPPER.length; i++) {
                String keyword = QuerySyntax.KEYWORDS_AUTO_UPPER[i];
                if (keyword.equalsIgnoreCase(currentKeyword)) {
                    pendingCompletionsListener = true;
                    text.replaceTextRange(spos, len, keyword.toUpperCase());
                    pendingCompletionsListener = false;
                    break;
                }
            }
        }
    });
    text.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent event) {
            if ((event.stateMask & SWT.SHIFT) != 0 && event.keyCode == SWT.TAB) {
                event.doit = false;
                return;
            }
            if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                event.doit = false;
                return;
            }
            if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.stateMask & SWT.ALT) != 0) {
                event.doit = false;
                return;
            }
            if (event.keyCode == SWT.TAB) {
                event.doit = false;
            } else {
                event.doit = true;
            }
        }
    });
    text.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.COMMAND) != 0) {
                //for Mac
                if ((event.stateMask & SWT.SHIFT) != 0) {
                    if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                        queryEditor.runQuery(false);
                        return;
                    }
                }
            }
            if (event.keyCode == SWT.F5 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'e') {
                queryEditor.runQuery(false);
            } else if (event.keyCode == SWT.F6 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'l') {
                queryEditor.runQuery(true);
            } else if (event.keyCode == SWT.F7) {
                queryEditor.getCombinedQueryComposite().showQueryHistory();
            } else if (event.keyCode == SWT.F8) {
                queryEditor.runMultiQuery();
            } else if (event.keyCode == SWT.F1) {
                ActionManager.getInstance().getAction(HelpDocumentAction.ID).run();
            } else if (event.keyCode == SWT.F3) {
                if ((event.stateMask & SWT.SHIFT) == 0) {
                    TextEditorFindReplaceMediator.findNext();
                } else {
                    TextEditorFindReplaceMediator.findPrevious();
                }
            } else if (event.keyCode == SWT.F9) {
                queryEditor.setTuningModeButton(!queryEditor.isTuningModeButton());
            } else if (event.keyCode == SWT.F11) {
                queryEditor.getCombinedQueryComposite().rotateQueryPlanDisplayMode();
            } else if ((event.stateMask & SWT.CTRL) == 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.stateMask & SWT.ALT) == 0 && event.keyCode == SWT.ESC) {
                int cursorOffset = text.getCaretOffset();
                text.setSelectionRange(cursorOffset, 0);
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.stateMask & SWT.ALT) == 0 && event.keyCode == ',') {
                new QuickBuilderDialog(getShell(), SWT.NONE).open();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == ' ') {
                contentAssistant.showPossibleCompletions();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'r') {
                recentlyUsedSQLcontentAssistant.showPossibleCompletions();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'd') {
                deleteRow();
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.ALT) != 0 && event.keyCode == SWT.ARROW_DOWN) {
                duplicateRow();
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0 && event.keyCode == 't') {
                //add sql tab
                queryEditor.addEditorTab();
            } else if (((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) && (event.keyCode == 'f' || event.keyCode == 'F')) {
                format();
            } else if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == '/') {
                contentAssist();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'o') {
                // Open a SQL file...
                ActionManager.getInstance().getAction(QueryOpenAction.ID).run();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 's') {
                // Save SQL to a file...
                try {
                    save();
                } catch (IOException e) {
                    MessageDialog.openError(getShell(), Messages.error, Messages.errCanNotSaveASQLFile);
                }
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0) {
                if (event.keyCode == '/') {
                    inputComment(false, false);
                } else if (event.keyCode == 'z') {
                    event.doit = false;
                    undo();
                } else if (event.keyCode == 'y') {
                    redo();
                } else if (event.keyCode == 'f' || event.keyCode == 'h') {
                    find();
                } else if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                    // NOPMD
                    queryEditor.runQueryPlanInCursorLine();
                } else if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                    queryEditor.runQueryInCursorLine();
                } else if (event.keyCode == 'g') {
                    gotoLine();
                }
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) {
                if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                    // NOPMD
                    queryEditor.runQuery(true);
                } else if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                    queryEditor.runQuery(false);
                } else if (event.keyCode == 'x') {
                    toUpperCase();
                } else if (event.keyCode == 'y') {
                    toLowerCase();
                }
            } else if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode == SWT.TAB) {
                indent();
            } else if ((event.stateMask & SWT.SHIFT) != 0 && event.keyCode == SWT.TAB) {
                unindent();
            }
            if (SQLContentAssistProcessor.isShowProposal(event.character)) {
                contentAssistant.showPossibleCompletions();
                useCompletions = true;
            } else if ((event.character >= 'A' && event.character <= 'Z') || (event.character >= 'a' && event.character <= 'z')) {
                if (useCompletions) {
                    contentAssistant.showPossibleCompletions();
                }
                useCompletions = false;
            } else if (event.character == ' ' || event.character == '\t' || event.keyCode == SWT.KEYPAD_CR || event.keyCode == SWT.CR || event.keyCode == SWT.BS || (text.getText().trim().length() < 1)) {
                useCompletions = true;
            }
            // ctrl + alt + 1 ~ 9 : change editor tab
            if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.ALT) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
                IWorkbenchPage page = LayoutUtil.getActivePage();
                if (page != null) {
                    int index = event.keyCode - '1';
                    IEditorReference[] refs = page.getEditorReferences();
                    for (int i = 0, selected = 0; i < refs.length; i++) {
                        IEditorReference ref = refs[i];
                        if (QueryEditorPart.ID.equals(ref.getId())) {
                            if (index == selected) {
                                IEditorPart part = ref.getEditor(true);
                                page.activate(part);
                            }
                            selected++;
                        }
                    }
                }
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
                // ctrl + 1 ~ 9 : change middle tab
                ITabSelection selector = queryEditor.getCombinedQueryComposite();
                selector.select(event.keyCode - '1', -1);
            } else if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
                // alt + 1 ~ 9 : change bottom tab
                ITabSelection selector = queryEditor.getCombinedQueryComposite();
                selector.select(-1, event.keyCode - '1');
            }
        }
    });
    text.addSelectionListener(new SelectionAdapter() {

        /**
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
			 * @param event an event containing information about the selection
			 */
        public void widgetSelected(SelectionEvent event) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            copyAction.setEnabled(false);
            IAction cutAction = ActionManager.getInstance().getAction(CutAction.ID);
            cutAction.setEnabled(false);
            IAction reformatColumnsAliasAction = ActionManager.getInstance().getAction(ReformatColumnsAliasAction.ID);
            reformatColumnsAliasAction.setEnabled(false);
            // show schema info view with a selected text
            IAction showSchemaAction = ActionManager.getInstance().getAction(ShowSchemaAction.ID);
            showSchemaAction.setEnabled(false);
            if (event.getSource() instanceof StyledText) {
                StyledText stext = (StyledText) event.getSource();
                if (stext != null && stext.getSelectionText() != null && stext.getSelectionText().length() > 0) {
                    copyAction.setEnabled(true);
                    cutAction.setEnabled(true);
                    reformatColumnsAliasAction.setEnabled(true);
                    CubridDatabase db = queryEditor.getSelectedDatabase();
                    if (DatabaseNavigatorMenu.SELF_DATABASE_ID.equals(db.getId()) && ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
                        showSchemaAction.setEnabled(false);
                    } else {
                        showSchemaAction.setEnabled(true);
                    }
                }
            }
        }
    });
    text.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    TextEditorFindReplaceMediator editorDialogMediator = new TextEditorFindReplaceMediator();
    text.addFocusListener(editorDialogMediator);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) StyledText(org.eclipse.swt.custom.StyledText) ModifyListener(org.eclipse.swt.events.ModifyListener) IAction(org.eclipse.jface.action.IAction) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IOException(java.io.IOException) IEditorPart(org.eclipse.ui.IEditorPart) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) QuickBuilderDialog(com.cubrid.common.ui.query.builder.quickbuilder.QuickBuilderDialog) IEditorReference(org.eclipse.ui.IEditorReference) TextEditorFindReplaceMediator(com.cubrid.tool.editor.TextEditorFindReplaceMediator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 64 with KeyEvent

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

the class SelectTreeObjContrItem method createControl.

/**
	 * Create the content
	 * 
	 * @param parent Composite
	 * @return Control
	 */
protected Control createControl(Composite parent) {
    //Fill in the vertical span for tool bar
    final ToolItem emptyToolItem = new ToolItem((ToolBar) parent, SWT.NONE);
    emptyToolItem.setEnabled(false);
    emptyToolItem.setImage(CommonUIPlugin.getImage("icons/empty.gif"));
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    composite.setLayout(gridLayout);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    composite.setLayoutData(gridData);
    combo = new CCombo(composite, SWT.BORDER | SWT.LEFT);
    combo.setToolTipText(Messages.tipFind);
    combo.setVisibleItemCount(10);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    gridData.widthHint = 95;
    combo.setLayoutData(gridData);
    combo.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            String str = combo.getText();
            if (str == null || str.trim().length() == 0) {
                NodeFilterManager.getInstance().setMatchFilter(null);
                tv.collapseAll();
            } else {
                NodeFilterManager.getInstance().setMatchFilter("*" + str + "*");
                tv.expandToLevel(2);
            }
            tv.refresh();
            super.keyReleased(e);
        }
    });
    return composite;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) CCombo(org.eclipse.swt.custom.CCombo) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) GridData(org.eclipse.swt.layout.GridData) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 65 with KeyEvent

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

the class ProductInfoDialog method addListeners.

/**
	 * Adds listeners to the given styled text
	 * 
	 * @param styledText the StyledText object
	 */
protected void addListeners(StyledText styledText) {
    styledText.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (event.button != 1) {
                return;
            }
            mouseDown = true;
        }

        public void mouseUp(MouseEvent event) {
            mouseDown = false;
            StyledText text = (StyledText) event.widget;
            int offset = text.getCaretOffset();
            if (dragEvent) {
                // don't activate a link during a drag/mouse up operation
                dragEvent = false;
                if (item != null && item.isLinkAt(offset)) {
                    text.setCursor(handCursor);
                }
            } else if (item != null && item.isLinkAt(offset)) {
                text.setCursor(busyCursor);
                String url = item.getLinkAt(offset);
                if (StringUtil.isEmpty(url)) {
                    LOGGER.warn("The url is a null or empty string : {}.", url);
                } else {
                    openLink(url);
                }
                StyleRange selectionRange = getCurrentRange(text);
                if (selectionRange == null) {
                    LOGGER.warn("The selectionRange is a null.");
                } else {
                    text.setSelectionRange(selectionRange.start, selectionRange.length);
                    text.setCursor(null);
                }
            }
        }
    });
    styledText.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent event) {
            if (mouseDown) {
                if (!dragEvent) {
                    StyledText text = (StyledText) event.widget;
                    text.setCursor(null);
                }
                dragEvent = true;
                return;
            }
            StyledText text = (StyledText) event.widget;
            int offset = -1;
            try {
                offset = text.getOffsetAtLocation(new Point(event.x, event.y));
            } catch (IllegalArgumentException ex) {
                offset = -1;
            }
            if (offset == -1) {
                text.setCursor(null);
            } else if (item != null && item.isLinkAt(offset)) {
                text.setCursor(handCursor);
            } else {
                text.setCursor(null);
            }
        }
    });
    styledText.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            StyledText text = (StyledText) event.widget;
            switch(event.detail) {
                case SWT.TRAVERSE_ESCAPE:
                    event.doit = true;
                    break;
                case SWT.TRAVERSE_TAB_NEXT:
                    // Previously traverse out in the backward direction?
                    Point nextSelection = text.getSelection();
                    int charCount = text.getCharCount();
                    if ((nextSelection.x == charCount) && (nextSelection.y == charCount)) {
                        text.setSelection(0);
                    }
                    StyleRange nextRange = findNextRange(text);
                    if (nextRange == null) {
                        // Next time in start at beginning, also used by
                        // TRAVERSE_TAB_PREVIOUS to indicate we traversed out
                        // in the forward direction
                        text.setSelection(0);
                        event.doit = true;
                    } else {
                        text.setSelectionRange(nextRange.start, nextRange.length);
                        event.doit = true;
                        event.detail = SWT.TRAVERSE_NONE;
                    }
                    break;
                case SWT.TRAVERSE_TAB_PREVIOUS:
                    // Previously traverse out in the forward direction?
                    Point previousSelection = text.getSelection();
                    if ((previousSelection.x == 0) && (previousSelection.y == 0)) {
                        text.setSelection(text.getCharCount());
                    }
                    StyleRange previousRange = findPreviousRange(text);
                    if (previousRange == null) {
                        // Next time in start at the end, also used by
                        // TRAVERSE_TAB_NEXT to indicate we traversed out
                        // in the backward direction
                        text.setSelection(text.getCharCount());
                        event.doit = true;
                    } else {
                        text.setSelectionRange(previousRange.start, previousRange.length);
                        event.doit = true;
                        event.detail = SWT.TRAVERSE_NONE;
                    }
                    break;
                default:
                    break;
            }
        }
    });
    // Listen for Tab and Space to allow keyboard navigation
    styledText.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            StyledText text = (StyledText) event.widget;
            if (event.character == ' ' || event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                if (item == null) {
                    LOGGER.warn("AboutItem is a null.");
                    return;
                }
                // Be sure we are in the selection
                int offset = text.getSelection().x + 1;
                if (item.isLinkAt(offset)) {
                    text.setCursor(busyCursor);
                    String url = item.getLinkAt(offset);
                    if (StringUtil.isEmpty(url)) {
                        LOGGER.warn("The url is a null or empty string : {}.", url);
                    } else {
                        openLink(url);
                    }
                    StyleRange selectionRange = getCurrentRange(text);
                    if (selectionRange == null) {
                        LOGGER.warn("The selectionRange is a null.");
                    } else {
                        text.setSelectionRange(selectionRange.start, selectionRange.length);
                        text.setCursor(null);
                    }
                }
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) StyledText(org.eclipse.swt.custom.StyledText) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) StyleRange(org.eclipse.swt.custom.StyleRange) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point)

Aggregations

KeyEvent (org.eclipse.swt.events.KeyEvent)98 KeyAdapter (org.eclipse.swt.events.KeyAdapter)63 GridData (org.eclipse.swt.layout.GridData)54 GridLayout (org.eclipse.swt.layout.GridLayout)42 Composite (org.eclipse.swt.widgets.Composite)42 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Text (org.eclipse.swt.widgets.Text)34 KeyListener (org.eclipse.swt.events.KeyListener)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 Label (org.eclipse.swt.widgets.Label)29 ModifyEvent (org.eclipse.swt.events.ModifyEvent)22 ModifyListener (org.eclipse.swt.events.ModifyListener)22 Point (org.eclipse.swt.graphics.Point)21 Button (org.eclipse.swt.widgets.Button)21 MouseEvent (org.eclipse.swt.events.MouseEvent)20 TableViewer (org.eclipse.jface.viewers.TableViewer)19 StyledText (org.eclipse.swt.custom.StyledText)13 FocusEvent (org.eclipse.swt.events.FocusEvent)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12