Search in sources :

Example 11 with KeyEvent

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

Example 12 with KeyEvent

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

the class JSONFileOutputStep3Form method addFieldsListeners.

@Override
protected void addFieldsListeners() {
    metadataNameText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            MetadataToolHelper.validateSchema(metadataNameText.getText());
            metadataTable.setLabel(metadataNameText.getText());
            checkFieldsValue();
        }
    });
    metadataNameText.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            MetadataToolHelper.checkSchema(getShell(), e);
        }
    });
    metadataCommentText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            metadataTable.setComment(metadataCommentText.getText());
        }
    });
    tableEditorView.getMetadataEditor().addAfterOperationListListener(new IListenableListListener() {

        public void handleEvent(ListenableListEvent event) {
            checkFieldsValue();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener)

Example 13 with KeyEvent

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

the class SchemaDetailsCheckBoxCellEditor method createControl.

@Override
protected Control createControl(Composite parent) {
    checkBtn = new Button(parent, SWT.CHECK);
    checkBtn.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            if (e.character == '') {
                // Escape
                fireCancelEditor();
            }
        }
    });
    checkBtn.addFocusListener(getButtonFocusListener());
    checkBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            markDirty();
            doSetValue(checkBtn.getSelection());
        // fireApplyEditorValue();
        }
    });
    setValueValid(true);
    return checkBtn;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Button(org.eclipse.swt.widgets.Button) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 14 with KeyEvent

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

the class RowGenMain method addAllControlForKeyListener.

/**
     * qzhang Comment method "addAllControlForKeyListener".
     * 
     * @param parent
     * @param keyAdapter
     * @return
     */
private void addAllControlForKeyListener(Control parent) {
    KeyAdapter keyAdapter = new KeyAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
             */
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.F5) {
                MetadataTableEditorViewExt viewExt = generatorUI.getDataTableView();
                viewExt.refreshPreviewColumn();
            }
        }
    };
    parent.addKeyListener(keyAdapter);
    if (parent instanceof Composite) {
        Control[] children = ((Composite) parent).getChildren();
        for (Control control : children) {
            if (control != null && !control.isDisposed()) {
                addAllControlForKeyListener(control);
            }
        }
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MetadataTableEditorViewExt(org.talend.designer.rowgenerator.ui.editor.MetadataTableEditorViewExt)

Example 15 with KeyEvent

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

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