Search in sources :

Example 21 with MouseEvent

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

the class TalendEditPartTipHelper method hookShellListeners.

@Override
protected void hookShellListeners() {
    /*
         * If the cursor leaves the tip window, hide the tooltip and dispose of its shell
         */
    getShell().addMouseTrackListener(new MouseTrackAdapter() {

        @Override
        public void mouseExit(MouseEvent e) {
            getShell().setCapture(false);
            dispose();
        }
    });
    /*
         * If the mouseExit listener does not get called, dispose of the shell if the cursor is no longer in the
         * tooltip. This occurs in the rare case that a mouseEnter is not received on the tooltip when it appears.
         */
    getShell().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
            if (!getShell().getBounds().contains(eventPoint)) {
                if (isShowing()) {
                    getShell().setCapture(false);
                }
                dispose();
            }
        }
    });
    // window.
    if (shellListener == null) {
        shellListener = new ShellAdapter() {

            @Override
            public void shellDeactivated(ShellEvent event) {
                Display.getCurrent().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell active = Display.getCurrent().getActiveShell();
                        if (getShell() == active || control.getShell() == active || getShell().isDisposed()) {
                            return;
                        }
                        if (isShowing()) {
                            getShell().setCapture(false);
                        }
                        dispose();
                    }
                });
            }
        };
        control.getShell().addShellListener(shellListener);
        getShell().addShellListener(shellListener);
    }
    /*
         * Workaround for GTK Bug - Control.setCapture(boolean) not implemented: If the cursor is not over the shell
         * when it is first painted, hide the tooltip and dispose of the shell.
         */
    if (SWT.getPlatform().equals("gtk")) {
        //$NON-NLS-1$
        getShell().addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent event) {
                Point cursorLoc = Display.getCurrent().getCursorLocation();
                if (!getShell().getBounds().contains(cursorLoc)) {
                    // This must be run asynchronously. If not, other paint
                    // listeners may attempt to paint on a disposed control.
                    Display.getCurrent().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (isShowing()) {
                                getShell().setCapture(false);
                            }
                            dispose();
                        }
                    });
                }
            }
        });
    }
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Shell(org.eclipse.swt.widgets.Shell) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ShellEvent(org.eclipse.swt.events.ShellEvent) Point(org.eclipse.swt.graphics.Point)

Example 22 with MouseEvent

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

the class SQLPatternComposite method createCodeControl.

/**
     * DOC bqian Comment method "createCodeControl".
     * 
     * @param panel
     * @param
     */
private void createCodeControl(Composite panel, Control reference) {
    codeText = new Text(panel, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    codeText.setEditable(false);
    FormData fd = new FormData();
    fd.left = new FormAttachment(10, 0);
    fd.right = new FormAttachment(90, 0);
    fd.top = new FormAttachment(reference, 2);
    fd.bottom = new FormAttachment(95, 0);
    codeText.setLayoutData(fd);
    codeText.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (tableViewer.getTable().getSelection().length == 0) {
                return;
            }
            TableItem item = tableViewer.getTable().getSelection()[0];
            if (item == null || item.getText() == null) {
                return;
            }
            String sqlpatternName = item.getText();
            SQLPatternItem patternItem = SQLPatternUtils.getSQLPatternItem(SQLPatternComposite.this.element, sqlpatternName);
            if (patternItem.isSystem()) {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.forbidModification"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IElementParameter parameter = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
                String dbName = (String) parameter.getValue();
                //$NON-NLS-1$
                String path = dbName + "/" + RepositoryConstants.USER_DEFINED;
                repositoryService.createSqlpattern(path, true);
            } else if (sqlPatternAndProject.get(patternItem) != null) {
                MessageDialog.openInformation(getShell(), "Information", "Forbid modification on sql template from reference project");
            } else {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.modifySQLPattern"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                repositoryService.openSQLPatternEditor(patternItem, false);
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
        // do nothing
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            mouseUp(e);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) TableItem(org.eclipse.swt.widgets.TableItem) IElementParameter(org.talend.core.model.process.IElementParameter) Text(org.eclipse.swt.widgets.Text) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) FormAttachment(org.eclipse.swt.layout.FormAttachment) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 23 with MouseEvent

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

the class WidgetFactory method adapt.

@Override
public void adapt(Composite composite) {
    composite.setBackground(getColors().getBackground());
    MouseAdapter listener = new MouseAdapter() {

        public void mouseDown(MouseEvent e) {
            Control control = (Control) e.widget;
            if (control instanceof Composite) {
                Composite parent = (Composite) control;
                setChildFocus(parent);
            } else {
                control.setFocus();
            }
        }
    };
    composite.addMouseListener(listener);
    composite.getParent().addMouseListener(listener);
    composite.setMenu(composite.getParent().getMenu());
}
Also used : Control(org.eclipse.swt.widgets.Control) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Example 24 with MouseEvent

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

the class ExpressionBuilderDialog method createButtonsForButtonBar.

/**
     * Create contents of the button bar
     * 
     * @param parent
     */
@Override
protected void createButtonsForButtonBar(Composite parent) {
    ((GridLayout) parent.getLayout()).numColumns++;
    Composite buttons = new Composite(parent, SWT.NONE);
    buttons.setLayout(new GridLayout(2, false));
    final Button importButton = new Button(buttons, SWT.PUSH);
    //$NON-NLS-1$
    importButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.import"));
    importButton.setImage(ImageProvider.getImage(EImage.IMPORT_ICON));
    final Button exportButton = new Button(buttons, SWT.PUSH);
    //$NON-NLS-1$
    exportButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.export"));
    exportButton.setImage(ImageProvider.getImage(EImage.EXPORT_ICON));
    //$NON-NLS-1$
    createButton(parent, IDialogConstants.OK_ID, Messages.getString("ExpressionBuilderDialog.ok.button"), true);
    //$NON-NLS-1$
    createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("ExpressionBuilderDialog.cancel.button"), false);
    exportButton.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
            //$NON-NLS-1$
            dialog.setFilterExtensions(new String[] { "*.xml" });
            String filePath = dialog.open();
            if (filePath != null) {
                String expresionContent = expressionComposite.getExpression();
                List<Variable> variables = new ArrayList<Variable>();
                variables = testComposite.getVariableList();
                File file = new File(filePath);
                ExpressionFileOperation operation = new ExpressionFileOperation();
                try {
                    if (file != null) {
                        file.createNewFile();
                    }
                    operation.saveExpressionToFile(file, variables, expresionContent);
                } catch (IOException e1) {
                    RuntimeExceptionHandler.process(e1);
                } catch (ParserConfigurationException e1) {
                    RuntimeExceptionHandler.process(e1);
                }
            }
        }
    });
    importButton.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            //$NON-NLS-1$
            dialog.setFilterExtensions(new String[] { "*.xml" });
            String filePath = dialog.open();
            if (filePath != null) {
                File file = new File(filePath);
                ExpressionFileOperation operation = new ExpressionFileOperation();
                try {
                    List list = operation.importExpressionFromFile(file, getShell());
                    if (list != null && list.size() != 0) {
                        expressionComposite.setExpression((String) list.get(0), false);
                        list.remove(0);
                        if (list.size() > 0) {
                            testComposite.addVariables(list);
                        }
                    }
                } catch (IOException e1) {
                    RuntimeExceptionHandler.process(e1);
                } catch (ParserConfigurationException e1) {
                    RuntimeExceptionHandler.process(e1);
                } catch (SAXException e1) {
                    RuntimeExceptionHandler.process(e1);
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) ExpressionFileOperation(org.talend.expressionbuilder.ExpressionFileOperation) Composite(org.eclipse.swt.widgets.Composite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 25 with MouseEvent

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

the class ExpressionCellEditor method createText.

public Text createText(Composite parent) {
    text = new Text(parent, SWT.NONE);
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            handleDefaultSelection(e);
        }
    });
    text.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
            }
        }
    });
    // We really want a selection listener but it is not supported so we
    // use a key listener and a mouse listener to know when selection
    // changes
    // may have occured
    text.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent e) {
            highlightLineAndSetSelectionOfStyledTextFromTextControl(text);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            checkSelection();
            checkDeleteable();
            checkSelectable();
        }
    });
    text.setFont(parent.getFont());
    text.setBackground(parent.getBackground());
    //$NON-NLS-1$
    text.setText("");
    text.addModifyListener(getModifyListener());
    return text;
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) Text(org.eclipse.swt.widgets.Text)

Aggregations

MouseEvent (org.eclipse.swt.events.MouseEvent)75 MouseAdapter (org.eclipse.swt.events.MouseAdapter)39 GridData (org.eclipse.swt.layout.GridData)30 SelectionEvent (org.eclipse.swt.events.SelectionEvent)29 MouseListener (org.eclipse.swt.events.MouseListener)25 Point (org.eclipse.swt.graphics.Point)25 KeyEvent (org.eclipse.swt.events.KeyEvent)22 Composite (org.eclipse.swt.widgets.Composite)22 GridLayout (org.eclipse.swt.layout.GridLayout)21 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)18 Button (org.eclipse.swt.widgets.Button)15 FocusEvent (org.eclipse.swt.events.FocusEvent)14 PaintEvent (org.eclipse.swt.events.PaintEvent)12 Text (org.eclipse.swt.widgets.Text)12 KeyListener (org.eclipse.swt.events.KeyListener)11 ModifyEvent (org.eclipse.swt.events.ModifyEvent)11 ModifyListener (org.eclipse.swt.events.ModifyListener)11 TraverseEvent (org.eclipse.swt.events.TraverseEvent)11 Event (org.eclipse.swt.widgets.Event)11 Label (org.eclipse.swt.widgets.Label)11