Search in sources :

Example 66 with KeyListener

use of org.eclipse.swt.events.KeyListener in project tdi-studio-se by Talend.

the class SqlMemoController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(Composite subComposite, IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    final DecoratedField dField1 = new DecoratedField(subComposite, SWT.PUSH, new IControlCreator() {

        @Override
        public Control createControl(Composite parent, int style) {
            return new Button(parent, style);
        }
    });
    Control buttonControl = dField1.getLayoutControl();
    openSQLEditorButton = (Button) dField1.getControl();
    openSQLEditorButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    openSQLEditorButton.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    buttonControl.setBackground(subComposite.getBackground());
    openSQLEditorButton.setEnabled(true);
    openSQLEditorButton.setData(NAME, SQLEDITOR);
    openSQLEditorButton.setData(PARAMETER_NAME, param.getName());
    openSQLEditorButton.setEnabled(!param.isReadOnly());
    openSQLEditorButton.addSelectionListener(listenerSelection);
    if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
        openSQLEditorButton.setEnabled(ExtractMetaDataUtils.getInstance().haveLoadMetadataNode());
    }
    // Added by Marvin Wang on Dec.13, 2012 for bug TDI-7559.
    //$NON-NLS-1$
    IElementParameter typePara = elem.getElementParameter("TYPE");
    if (typePara != null && "Hive".equalsIgnoreCase((String) typePara.getValue())) {
        //$NON-NLS-1$
        openSQLEditorButton.setVisible(false);
    }
    if (typePara != null && "Impala".equalsIgnoreCase((String) typePara.getValue())) {
        //$NON-NLS-1$
        openSQLEditorButton.setVisible(false);
    }
    FormData data1 = new FormData();
    data1.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
    data1.left = new FormAttachment(100, -(ITabbedPropertyConstants.HSPACE + STANDARD_BUTTON_WIDTH));
    data1.top = new FormAttachment(0, top);
    buttonControl.setLayoutData(data1);
    int nbLines = param.getNbLines();
    IControlCreator txtCtrl = new IControlCreator() {

        @Override
        public Control createControl(final Composite parent, final int style) {
            return createColorStyledText(parent, style);
        }
    };
    DecoratedField dField = null;
    if (param.getNbLines() != 1) {
        dField = new DecoratedField(subComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, txtCtrl);
    } else {
        dField = new DecoratedField(subComposite, SWT.BORDER, txtCtrl);
    }
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();
    queryText = (ColorStyledText) dField.getControl();
    queryText.setData(PARAMETER_NAME, param.getName());
    editionControlHelper.register(param.getName(), queryText);
    FormData d = (FormData) queryText.getLayoutData();
    if (getAdditionalHeightSize() != 0) {
        nbLines += this.getAdditionalHeightSize() / queryText.getLineHeight();
    }
    d.height = queryText.getLineHeight() * nbLines;
    FormData data;
    queryText.getParent().setSize(subComposite.getSize().x, queryText.getLineHeight() * nbLines);
    cLayout.setBackground(subComposite.getBackground());
    // for bug 7580
    if (!(queryText instanceof ColorStyledText)) {
        queryText.setEnabled(!param.isReadOnly());
    } else {
        queryText.setEditable(!param.isReadOnly());
    }
    if (elem instanceof Node) {
        queryText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    queryText.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (switchParam != null) {
                switchParam.setValue(Boolean.FALSE);
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    if (param.isReadOnly() && param.isRepositoryValueUsed()) {
        cLayout.addMouseListener(listenerClick);
    }
    addDragAndDropTarget(queryText);
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // *********************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.right = new FormAttachment(buttonControl, -5, SWT.LEFT);
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************
    hashCurControls.put(param.getName(), queryText);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    // curRowSize = initialSize.y + ITabbedPropertyConstants.VSPACE;
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return null;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) IControlCreator(org.eclipse.jface.fieldassist.IControlCreator) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IElementParameter(org.talend.core.model.process.IElementParameter) KeyListener(org.eclipse.swt.events.KeyListener) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 67 with KeyListener

use of org.eclipse.swt.events.KeyListener in project tdi-studio-se by Talend.

the class ToolbarSearchZone method addCommonsComponentListeners.

private void addCommonsComponentListeners() {
    final SearchZoneMapper searchZoneMapper = new SearchZoneMapper(mapperManager);
    searchText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // if change the search text ,need clear the data .
            hightLightAllButton.setSelection(false);
            searchZoneMapper.setHightlightAll(hightLightAllButton.getSelection());
            if (searchMaps.size() > 0) {
                searchZoneMapper.hightlightAll(searchMaps, false);
                searchMaps.clear();
            }
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                e.doit = false;
                searchZoneMapper.search(searchMaps, searchText.getText());
                selectKey = searchZoneMapper.selectHightlight(searchMaps, 0, "first");
            }
        }

        public void keyReleased(KeyEvent e) {
        }
    });
    downTableButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (searchMaps.isEmpty()) {
                searchZoneMapper.search(searchMaps, searchText.getText());
            }
            if (selectKey + 1 < searchMaps.size()) {
                if (!searchZoneMapper.isHightlightAll()) {
                    searchZoneMapper.hightlightAll(searchMaps, false);
                } else {
                    searchZoneMapper.hightlightAll(searchMaps, true);
                }
            }
            Integer selectKeyAtTableItem = searchZoneMapper.getSelectedKeyAtSelectedTableItem(searchMaps);
            if (selectKeyAtTableItem > 0) {
                selectKey = searchZoneMapper.selectHightlight(searchMaps, selectKeyAtTableItem, "next");
            } else if (selectKeyAtTableItem == 0 && selectKey == -1) {
                selectKey = searchZoneMapper.selectHightlight(searchMaps, 0, "first");
            } else {
                selectKey = searchZoneMapper.selectHightlight(searchMaps, selectKey, "next");
            }
        }
    });
    upTableButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (searchMaps.isEmpty()) {
                searchZoneMapper.search(searchMaps, searchText.getText());
            }
            if (selectKey > 0) {
                if (!searchZoneMapper.isHightlightAll()) {
                    searchZoneMapper.hightlightAll(searchMaps, false);
                } else {
                    searchZoneMapper.hightlightAll(searchMaps, true);
                }
            }
            Integer selectKeyAtTableItem = searchZoneMapper.getSelectedKeyAtSelectedTableItem(searchMaps);
            if (selectKeyAtTableItem > 0) {
                selectKey = searchZoneMapper.selectHightlight(searchMaps, selectKeyAtTableItem, "previous");
            } else if (selectKeyAtTableItem == 0 && selectKey == -1) {
                selectKey = searchZoneMapper.selectHightlight(searchMaps, 0, "first");
            } else {
                selectKey = searchZoneMapper.selectHightlight(searchMaps, selectKey, "previous");
            }
        }
    });
    hightLightAllButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (hightLightAllButton.getSelection()) {
                searchMaps.clear();
                searchZoneMapper.search(searchMaps, searchText.getText());
            }
            searchZoneMapper.setHightlightAll(hightLightAllButton.getSelection());
            searchZoneMapper.hightlightAll(searchMaps, hightLightAllButton.getSelection());
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Listener(org.eclipse.swt.widgets.Listener) KeyListener(org.eclipse.swt.events.KeyListener) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyListener(org.eclipse.swt.events.KeyListener)

Example 68 with KeyListener

use of org.eclipse.swt.events.KeyListener in project eclipse.platform.text by eclipse.

the class HyperlinkDetectorsConfigurationBlock method createControl.

@Override
public Control createControl(Composite parent) {
    PixelConverter pixelConverter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    addFiller(composite, 2);
    String label = TextEditorMessages.HyperlinksEnabled_label;
    fHyperlinksEnabledCheckBox = addCheckBox(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED, 0);
    fHyperlinksEnabledCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean state = fHyperlinksEnabledCheckBox.getSelection();
            fHyperlinkDefaultKeyModifierText.setEnabled(state);
            fHyperlinkKeyModifierText.setEnabled(state && getSelectedItem() != null);
            fHyperlinkDetectorsViewer.getTable().setEnabled(state);
            handleHyperlinkKeyModifierModified();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    // Text field for default modifier string
    label = TextEditorMessages.HyperlinkDefaultKeyModifier_label;
    fHyperlinkDefaultKeyModifierText = (Text) addTextField(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER, 15, 20, pixelConverter)[1];
    fHyperlinkDefaultKeyModifierText.addKeyListener(new KeyListener() {

        private boolean isModifierCandidate;

        @Override
        public void keyPressed(KeyEvent e) {
            isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
                // && e.time -time < 1000) {
                String modifierString = fHyperlinkDefaultKeyModifierText.getText();
                Point selection = fHyperlinkDefaultKeyModifierText.getSelection();
                int i = selection.x - 1;
                while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
                    i--;
                }
                boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                i = selection.y;
                while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
                    i++;
                }
                boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                String insertString;
                if (needsPrefixDelimiter && needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else if (needsPrefixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
                else if (needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else
                    insertString = Action.findModifierString(e.stateMask);
                fHyperlinkDefaultKeyModifierText.insert(insertString);
            }
        }
    });
    fHyperlinkDefaultKeyModifierText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            handleHyperlinkDefaultKeyModifierModified();
        }
    });
    addFiller(composite, 2);
    Composite editorComposite = new Composite(composite, SWT.NONE);
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.TOP, true, false);
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 20;
    editorComposite.setLayoutData(gd);
    TableColumnLayout tableColumnlayout = new TableColumnLayout();
    editorComposite.setLayout(tableColumnlayout);
    // Hyperlink detector table
    Table hyperlinkDetectorTable = new Table(editorComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK);
    hyperlinkDetectorTable.setHeaderVisible(true);
    hyperlinkDetectorTable.setLinesVisible(true);
    hyperlinkDetectorTable.setFont(parent.getFont());
    hyperlinkDetectorTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleListSelection();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    ColumnLayoutData columnLayoutData = new ColumnWeightData(1);
    TableColumn nameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 0);
    nameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_nameColumn);
    tableColumnlayout.setColumnData(nameColumn, columnLayoutData);
    TableColumn modifierKeysColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 1);
    modifierKeysColumn.setText(TextEditorMessages.HyperlinkDetectorTable_modifierKeysColumn);
    tableColumnlayout.setColumnData(modifierKeysColumn, columnLayoutData);
    TableColumn targetNameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 2);
    targetNameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_targetNameColumn);
    tableColumnlayout.setColumnData(targetNameColumn, columnLayoutData);
    fHyperlinkDetectorsViewer = new CheckboxTableViewer(hyperlinkDetectorTable);
    fHyperlinkDetectorsViewer.setUseHashlookup(true);
    fHyperlinkDetectorsViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            String id = ((ListItem) event.getElement()).id;
            if (id == null)
                return;
            fStore.setValue(id, !event.getChecked());
        }
    });
    fHyperlinkDetectorsViewer.setLabelProvider(new ItemLabelProvider());
    fHyperlinkDetectorsViewer.setContentProvider(new ItemContentProvider());
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = pixelConverter.convertHeightInCharsToPixels(10);
    fHyperlinkDetectorsViewer.getControl().setLayoutData(gd);
    // addFiller(composite, 2);
    // Text field for modifier string
    label = TextEditorMessages.HyperlinkKeyModifier_label;
    fHyperlinkKeyModifierText = (Text) addTextField(composite, label, null, 15, 20, pixelConverter)[1];
    fHyperlinkKeyModifierText.addKeyListener(new KeyListener() {

        private boolean isModifierCandidate;

        @Override
        public void keyPressed(KeyEvent e) {
            isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
                // && e.time -time < 1000) {
                String modifierString = fHyperlinkKeyModifierText.getText();
                Point selection = fHyperlinkKeyModifierText.getSelection();
                int i = selection.x - 1;
                while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
                    i--;
                }
                boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                i = selection.y;
                while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
                    i++;
                }
                boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                String insertString;
                if (needsPrefixDelimiter && needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else if (needsPrefixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
                else if (needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else
                    insertString = Action.findModifierString(e.stateMask);
                fHyperlinkKeyModifierText.insert(insertString);
            }
        }
    });
    fHyperlinkKeyModifierText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            handleHyperlinkKeyModifierModified();
        }
    });
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) PixelConverter(org.eclipse.jface.layout.PixelConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) KeyListener(org.eclipse.swt.events.KeyListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 69 with KeyListener

use of org.eclipse.swt.events.KeyListener in project eclipse.platform.text by eclipse.

the class AbstractControlContentAssistSubjectAdapter method installControlListener.

/**
 * Installs <code>fControlListener</code>, which handles VerifyEvents and KeyEvents by
 * passing them to {@link #fVerifyKeyListeners} and {@link #fKeyListeners}.
 */
private void installControlListener() {
    if (DEBUG)
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size());
    if (fControlListener != null)
        return;
    fControlListener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (!getControl().isFocusControl())
                // SWT.TRAVERSE_MNEMONIC events can also come in to inactive widgets
                return;
            VerifyEvent verifyEvent = new VerifyEvent(e);
            KeyEvent keyEvent = new KeyEvent(e);
            switch(e.type) {
                case SWT.Traverse:
                    if (DEBUG)
                        // $NON-NLS-1$
                        dump("before traverse", e, verifyEvent);
                    verifyEvent.doit = true;
                    for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) {
                        verifyKeyListener.verifyKey(verifyEvent);
                        if (!verifyEvent.doit) {
                            e.detail = SWT.TRAVERSE_NONE;
                            e.doit = true;
                            if (DEBUG)
                                // $NON-NLS-1$
                                dump("traverse eaten by verify", e, verifyEvent);
                            return;
                        }
                        if (DEBUG)
                            // $NON-NLS-1$
                            dump("traverse OK", e, verifyEvent);
                    }
                    break;
                case SWT.KeyDown:
                    for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) {
                        verifyKeyListener.verifyKey(verifyEvent);
                        if (!verifyEvent.doit) {
                            e.doit = verifyEvent.doit;
                            if (DEBUG)
                                // $NON-NLS-1$
                                dump("keyDown eaten by verify", e, verifyEvent);
                            return;
                        }
                    }
                    if (DEBUG)
                        // $NON-NLS-1$
                        dump("keyDown OK", e, verifyEvent);
                    for (KeyListener keyListener : fKeyListeners) {
                        keyListener.keyPressed(keyEvent);
                    }
                    break;
                default:
                    Assert.isTrue(false);
            }
        }

        /**
         * Dump the given events to "standard" output.
         *
         * @param who who dump's
         * @param e the event
         * @param ve the verify event
         */
        private void dump(String who, Event e, VerifyEvent ve) {
            // $NON-NLS-1$
            StringBuilder sb = new StringBuilder("--- [AbstractControlContentAssistSubjectAdapter]\n");
            sb.append(who);
            // $NON-NLS-1$
            sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode));
            // $NON-NLS-1$
            sb.append("; character=" + e.character + hex(e.character));
            // $NON-NLS-1$
            sb.append("; stateMask=" + e.stateMask + hex(e.stateMask));
            // $NON-NLS-1$
            sb.append("; doit=" + e.doit);
            // $NON-NLS-1$
            sb.append("; detail=" + e.detail + hex(e.detail));
            // $NON-NLS-1$
            sb.append("; widget=" + e.widget);
            // $NON-NLS-1$
            sb.append("\n");
            // $NON-NLS-1$
            sb.append("  verifyEvent keyCode=" + e.keyCode + hex(e.keyCode));
            // $NON-NLS-1$
            sb.append("; character=" + e.character + hex(e.character));
            // $NON-NLS-1$
            sb.append("; stateMask=" + e.stateMask + hex(e.stateMask));
            // $NON-NLS-1$
            sb.append("; doit=" + ve.doit);
            // $NON-NLS-1$
            sb.append("; widget=" + e.widget);
            System.out.println(sb);
        }

        private String hex(int i) {
            // $NON-NLS-1$
            return "[0x" + Integer.toHexString(i) + ']';
        }
    };
    getControl().addListener(SWT.Traverse, fControlListener);
    getControl().addListener(SWT.KeyDown, fControlListener);
    if (DEBUG)
        // $NON-NLS-1$
        System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() - installed");
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Listener(org.eclipse.swt.widgets.Listener) KeyListener(org.eclipse.swt.events.KeyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) LabelProviderChangedEvent(org.eclipse.jface.viewers.LabelProviderChangedEvent) Event(org.eclipse.swt.widgets.Event) VerifyEvent(org.eclipse.swt.events.VerifyEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) KeyListener(org.eclipse.swt.events.KeyListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 70 with KeyListener

use of org.eclipse.swt.events.KeyListener in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup2 method showProposals.

/**
 * Computes and presents completion proposals. The flag indicates whether this call has
 * be made out of an auto activation context.
 *
 * @param autoActivated <code>true</code> if auto activation context
 * @return an error message or <code>null</code> in case of no error
 */
public String showProposals(final boolean autoActivated) {
    if (fKeyListener == null) {
        fKeyListener = new KeyListener() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (!Helper2.okToUse(fProposalShell))
                    return;
                if (e.character == 0 && e.keyCode == SWT.CTRL) {
                    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
                    int index = fProposalTable.getSelectionIndex();
                    if (index >= 0)
                        selectProposal(index, true);
                }
            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (!Helper2.okToUse(fProposalShell))
                    return;
                if (e.character == 0 && e.keyCode == SWT.CTRL) {
                    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
                    int index = fProposalTable.getSelectionIndex();
                    if (index >= 0)
                        selectProposal(index, false);
                }
            }
        };
    }
    final StyledText styledText = fViewer.getTextWidget();
    if (styledText != null && !styledText.isDisposed())
        styledText.addKeyListener(fKeyListener);
    // BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() {
    // public void run() {
    fInvocationOffset = fViewer.getSelectedRange().x;
    // lazily compute proposals
    // if (fComputedProposals == null)	fComputedProposals= computeProposals(fContentAssistant.getCompletionPosition());
    fComputedProposals = computeProposals(fInvocationOffset);
    int count = (fComputedProposals == null ? 0 : fComputedProposals.length);
    if (count == 0) {
        if (!autoActivated)
            styledText.getDisplay().beep();
    } else {
        if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting())
            insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);
        else {
            if (fLineDelimiter == null)
                fLineDelimiter = styledText.getLineDelimiter();
            createProposalSelector();
            setProposals(fComputedProposals);
            resizeProposalSelector(true);
            displayProposals();
        }
    }
    return getErrorMessage();
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) StyledText(org.eclipse.swt.custom.StyledText) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point)

Aggregations

KeyListener (org.eclipse.swt.events.KeyListener)99 KeyEvent (org.eclipse.swt.events.KeyEvent)91 GridData (org.eclipse.swt.layout.GridData)39 Composite (org.eclipse.swt.widgets.Composite)37 SelectionEvent (org.eclipse.swt.events.SelectionEvent)36 GridLayout (org.eclipse.swt.layout.GridLayout)33 Text (org.eclipse.swt.widgets.Text)32 Button (org.eclipse.swt.widgets.Button)29 Label (org.eclipse.swt.widgets.Label)29 MouseEvent (org.eclipse.swt.events.MouseEvent)24 Point (org.eclipse.swt.graphics.Point)23 SelectionListener (org.eclipse.swt.events.SelectionListener)22 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)19 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14 MouseListener (org.eclipse.swt.events.MouseListener)14 Combo (org.eclipse.swt.widgets.Combo)14 Event (org.eclipse.swt.widgets.Event)13 ArrayList (java.util.ArrayList)12 StyledText (org.eclipse.swt.custom.StyledText)9