Search in sources :

Example 1 with KeyListener

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

the class StyledTextHandler method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    styledText.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            refreshProposalSize();
        }

        public void focusLost(FocusEvent e) {
        }
    });
    styledText.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            refreshProposalSize();
        }
    });
    styledText.addExtendedModifyListener(new ExtendedModifyListener() {

        public void modifyText(ExtendedModifyEvent event) {
            // System.out.println("ExtendedModifyListener modify text");
            updateCellExpression();
        }
    });
    styledText.getContent().addTextChangeListener(new TextChangeListener() {

        public void textChanged(TextChangedEvent event) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void textChanging(TextChangingEvent event) {
        // System.out.println("textChanging");
        }

        public void textSet(TextChangedEvent event) {
        // System.out.println("textSet");
        }
    });
    styledText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }
    });
    styledText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub
        }
    });
    styledText.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent verifyEvent) {
            if (verifyEvent.character == '\r' && contentProposalAdapter != null && contentProposalAdapter.isProposalOpened()) {
                verifyEvent.doit = false;
            } else {
                verifyEvent.doit = true;
            }
        }
    });
    styledText.addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void mouseDown(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void mouseUp(MouseEvent e) {
        }
    });
}
Also used : ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) ControlListener(org.eclipse.swt.events.ControlListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) KeyListener(org.eclipse.swt.events.KeyListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) FocusListener(org.eclipse.swt.events.FocusListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 2 with KeyListener

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

the class BasicNotePropertyComposite method createTextControl.

/**
     * DOC qwei Comment method "createTextcontrol".
     */
private void createTextControl(Composite parent) {
    //$NON-NLS-1$
    CLabel textLabel = getWidgetFactory().createCLabel(composite, Messages.getString("TextNoteSection.Label"));
    //$NON-NLS-1$
    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = new FormAttachment(colorsAndFontsGroup, 30);
    textLabel.setLayoutData(data);
    //$NON-NLS-1$
    text = getWidgetFactory().createText(composite, "", SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    //$NON-NLS-1$
    data = new FormData();
    data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
    data.right = new FormAttachment(textLabel, 560);
    data.top = new FormAttachment(textLabel, 0, SWT.TOP);
    // 5 lines
    data.height = 5 * text.getLineHeight();
    text.setLayoutData(data);
    text.setForeground(new Color(null, ColorUtils.stringToRGB((String) note.getPropertyValue(EParameterName.NOTETXT_COLOR.getName()))));
    text.setText(note.getText());
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!text.getText().equals(note.getText())) {
                ChangeNoteTextCommand command = new ChangeNoteTextCommand(note, text.getText());
                getCommandStack().execute(command);
            }
        }
    });
    text.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            // TODO Auto-generated method stub
            if (!text.getText().equals(note.getText())) {
                ChangeNoteTextCommand command = new ChangeNoteTextCommand(note, text.getText());
                getCommandStack().execute(command);
            }
        }
    });
    textChanged();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Color(org.eclipse.swt.graphics.Color) KeyListener(org.eclipse.swt.events.KeyListener) FocusEvent(org.eclipse.swt.events.FocusEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) ChangeNoteTextCommand(org.talend.designer.core.ui.editor.cmd.ChangeNoteTextCommand)

Example 3 with KeyListener

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

the class TalendEditorComponentCreationAssist method initListeners.

private void initListeners() {
    assistText.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.stateMask == SWT.NONE) {
                if (e.keyCode == SWT.ESC) {
                    disposeAssistText();
                } else if (e.keyCode == SWT.CR) {
                    acceptProposal();
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }
    });
    assistText.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!(contentProposalAdapter.isProposalPopupOpen())) {
                disposeAssistText();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {

        @Override
        public void proposalPopupOpened(ContentProposalAdapter adapter) {
        }

        @Override
        public void proposalPopupClosed(ContentProposalAdapter adapter) {
            if (assistText != null && !assistText.isFocusControl()) {
                disposeAssistText();
            }
        }
    });
    contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            acceptProposal();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) KeyListener(org.eclipse.swt.events.KeyListener) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) IContentProposalListener2(org.eclipse.jface.fieldassist.IContentProposalListener2) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 4 with KeyListener

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

the class TalendEditorComponentCreationUtil method removeComponentCreationAssist.

public static void removeComponentCreationAssist(AbstractTalendEditor talendEditor) {
    GraphicalViewer graphicalViewer = (GraphicalViewer) talendEditor.getAdapter(GraphicalViewer.class);
    Object data = graphicalViewer.getControl().getData(COMPONENT_CREATION_ASSIST_LISTENER);
    if (data != null && data instanceof KeyListener) {
        graphicalViewer.getControl().removeKeyListener((KeyListener) data);
        graphicalViewer.getControl().update();
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) KeyListener(org.eclipse.swt.events.KeyListener)

Example 5 with KeyListener

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

the class DataMapTableView method attachCellExpressionToStyledTextEditor.

/**
     * DOC amaumont Comment method "attachCellExpressionToStyledTextEditor".
     * 
     * @param tableViewerCreator TODO
     * @param styledTextHandler
     * @param expressionEditorText2
     */
protected void attachCellExpressionToStyledTextEditor(final TableViewerCreator tableViewerCreator, final Text expressionTextEditor, final StyledTextHandler styledTextHandler) {
    expressionTextEditor.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            ITableEntry currentModifiedEntry = (ITableEntry) tableViewerCreator.getModifiedObjectInfo().getCurrentModifiedBean();
            styledTextHandler.setCurrentEntry(currentModifiedEntry);
            Text text = (Text) e.widget;
            if (Math.abs(text.getText().length() - styledTextHandler.getStyledText().getText().length()) > 1) {
                styledTextHandler.setTextWithoutNotifyListeners(text.getText());
            // highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
            }
        }
    });
    expressionTextEditor.addKeyListener(new KeyListener() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
             */
        @Override
        public void keyPressed(KeyEvent e) {
            // System.out.println("e.character=" + e.character);
            // System.out.println("keyCode=" + e.keyCode);
            boolean ctrl = (e.stateMask & SWT.CTRL) != 0;
            boolean altgr = (e.stateMask & SWT.ALT) != 0;
            if (e.character == '\0' || ctrl && !altgr) {
                highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
            } else {
                UnnotifiableColorStyledText mapperColorStyledText = (UnnotifiableColorStyledText) styledTextHandler.getStyledText();
                Point selection = expressionTextEditor.getSelection();
                if (e.character == '\r' || e.character == '') {
                    e.doit = false;
                    styledTextHandler.setTextWithoutNotifyListeners(expressionTextEditor.getText());
                    highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
                } else {
                    if (e.character == SWT.BS || e.character == SWT.DEL) {
                        if (selection.x == selection.y) {
                            if (e.character == SWT.BS) {
                                if (selection.x - 1 > 0 && mapperColorStyledText.getText().length() > selection.x - 1) {
                                    char previousChar = mapperColorStyledText.getText().charAt(selection.x - 1);
                                    if (previousChar == '\n') {
                                        //$NON-NLS-1$
                                        mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x - 2, 2, "");
                                    } else {
                                        //$NON-NLS-1$
                                        mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x - 1, 1, "");
                                    }
                                }
                            } else {
                                if (selection.x < mapperColorStyledText.getText().length()) {
                                    char nextChar = mapperColorStyledText.getText().charAt(selection.x);
                                    if (nextChar == '\r') {
                                        //$NON-NLS-1$
                                        mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, 2, "");
                                    } else {
                                        //$NON-NLS-1$
                                        mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, 1, "");
                                    }
                                }
                            }
                        } else {
                            if (selection.y <= mapperColorStyledText.getCharCount()) {
                                mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, selection.y - selection.x, //$NON-NLS-1$
                                "");
                            }
                            highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
                        }
                    } else {
                        // System.out.println("mapperColorStyledText.getText()="+mapperColorStyledText.getText().length());
                        if (selection.y <= mapperColorStyledText.getCharCount()) {
                            mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, selection.y - selection.x, String.valueOf(e.character));
                        }
                        highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
                    }
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        // highlightLineOfCursorPosition();
        }
    });
    expressionTextEditor.addMouseListener(new MouseListener() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
        }

        @Override
        public void mouseDown(MouseEvent e) {
            highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
        }

        @Override
        public void mouseUp(MouseEvent e) {
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) KeyListener(org.eclipse.swt.events.KeyListener) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) 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)31 Button (org.eclipse.swt.widgets.Button)29 Label (org.eclipse.swt.widgets.Label)29 MouseEvent (org.eclipse.swt.events.MouseEvent)24 SelectionListener (org.eclipse.swt.events.SelectionListener)22 Point (org.eclipse.swt.graphics.Point)22 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)19 ModifyEvent (org.eclipse.swt.events.ModifyEvent)16 ModifyListener (org.eclipse.swt.events.ModifyListener)16 MouseListener (org.eclipse.swt.events.MouseListener)14 Combo (org.eclipse.swt.widgets.Combo)14 Event (org.eclipse.swt.widgets.Event)14 ArrayList (java.util.ArrayList)12 StyledText (org.eclipse.swt.custom.StyledText)9