Search in sources :

Example 41 with KeyListener

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

the class TalendEditorComponentCreationUtil method addComponentCreationAssist.

public static void addComponentCreationAssist(AbstractTalendEditor talendEditor) {
    final GraphicalViewer graphicalViewer = (GraphicalViewer) talendEditor.getAdapter(GraphicalViewer.class);
    final CommandStack commandStack = (CommandStack) talendEditor.getAdapter(CommandStack.class);
    final String categoryName = talendEditor.getComponenentsHandler().extractComponentsCategory().getName();
    final IProcess2 process = talendEditor.getProcess();
    KeyListener listener = new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (Character.isISOControl(e.character) || Character.isSpaceChar(e.character)) {
                return;
            }
            TalendEditorComponentCreationAssist assist = new TalendEditorComponentCreationAssist(categoryName, graphicalViewer, commandStack, process);
            assist.showComponentCreationAssist(e.character);
        }
    };
    graphicalViewer.getControl().addKeyListener(listener);
    graphicalViewer.getControl().setData(COMPONENT_CREATION_ASSIST_LISTENER, listener);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IProcess2(org.talend.core.model.process.IProcess2) KeyListener(org.eclipse.swt.events.KeyListener)

Example 42 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 43 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 44 with KeyListener

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

the class Bug528549_browser_MouseFocusEventListeners method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setSize(500, 200);
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            System.out.println("Browser Focus lost " + e.toString());
        }

        @Override
        public void focusGained(FocusEvent e) {
            System.out.println("Browser Focus gained " + e.toString());
        }
    });
    browser.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            System.out.println("Browser Mouse Up " + e.toString());
        }

        @Override
        public void mouseDown(MouseEvent e) {
            System.out.println("Browser Mouse Down " + e.toString());
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            System.out.println("Browse Mouse Double click " + e.toString());
        }
    });
    // Below listeners already worked before bug. But good to have around.
    browser.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            System.out.println("Browser key released " + e.toString());
        }

        @Override
        public void keyPressed(KeyEvent e) {
            System.out.println("Browser key pressed " + e.toString());
        }
    });
    browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString()));
    // Generates a lot of events...
    browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString()));
    Button jsOnButton = new Button(shell, SWT.PUSH);
    jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    jsOnButton.setText("JS Off");
    jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false)));
    Button jsOffButton = new Button(shell, SWT.PUSH);
    jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    jsOffButton.setText("JS On");
    jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true)));
    Button loadNextPage = new Button(shell, SWT.PUSH);
    loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    loadNextPage.setText("Load next page");
    loadNextPage.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText())));
    browser.setText(getNewText());
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FocusEvent(org.eclipse.swt.events.FocusEvent) Display(org.eclipse.swt.widgets.Display) FocusListener(org.eclipse.swt.events.FocusListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) SWT(org.eclipse.swt.SWT) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyListener(org.eclipse.swt.events.KeyListener) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) SelectionListener(org.eclipse.swt.events.SelectionListener) MouseEvent(org.eclipse.swt.events.MouseEvent) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 45 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)

Aggregations

KeyListener (org.eclipse.swt.events.KeyListener)47 KeyEvent (org.eclipse.swt.events.KeyEvent)44 MouseEvent (org.eclipse.swt.events.MouseEvent)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 Point (org.eclipse.swt.graphics.Point)14 GridData (org.eclipse.swt.layout.GridData)13 Button (org.eclipse.swt.widgets.Button)11 FocusEvent (org.eclipse.swt.events.FocusEvent)10 MouseListener (org.eclipse.swt.events.MouseListener)9 Composite (org.eclipse.swt.widgets.Composite)9 ModifyEvent (org.eclipse.swt.events.ModifyEvent)8 ModifyListener (org.eclipse.swt.events.ModifyListener)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 Event (org.eclipse.swt.widgets.Event)8 Text (org.eclipse.swt.widgets.Text)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 StyledText (org.eclipse.swt.custom.StyledText)6 ControlEvent (org.eclipse.swt.events.ControlEvent)6 Label (org.eclipse.swt.widgets.Label)6