Search in sources :

Example 11 with MouseAdapter

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

Example 12 with MouseAdapter

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

the class MavenVersionManagementProjectSettingPage method addItemElements.

@Override
protected void addItemElements(List<ItemVersionObject> elements) {
    if (elements == null || elements.isEmpty()) {
        return;
    }
    itemTable.setRedraw(false);
    for (final ItemVersionObject object : elements) {
        final TableItem tableItem = new TableItem(itemTable, SWT.CENTER);
        tableItem.setData(object);
        Item item = object.getItem();
        IBaseLabelProvider labelProvider = treeViewer.getLabelProvider();
        Image itemsImage = null;
        if (labelProvider instanceof NavigatorDecoratingLabelProvider) {
            NavigatorDecoratingLabelProvider navigatorProvider = (NavigatorDecoratingLabelProvider) labelProvider;
            itemsImage = navigatorProvider.getImage(object.getRepositoryNode());
        } else {
            ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
            itemsImage = getItemsImage(CoreImageProvider.getIcon(itemType));
        }
        tableItem.setImage(itemsImage);
        tableItem.setText(item.getProperty().getLabel());
        // old version
        tableItem.setText(1, MavenVersionUtils.getItemMavenVersion(item.getProperty()));
        TableEditor versionEditor = null;
        if (fixedVersionButton.getSelection()) {
            tableItem.setText(2, appliedFixedVersion);
        } else if (useJobVersionButton.getSelection()) {
            String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(item.getProperty().getVersion());
            tableItem.setText(2, jobDefaultVersion);
            object.setNewVersion(jobDefaultVersion);
        } else {
            // new version
            versionEditor = new TableEditor(itemTable);
            Composite versionComposite = new Composite(itemTable, SWT.NONE);
            GridLayout layout = new GridLayout(1, false);
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            layout.marginLeft = 0;
            layout.marginRight = 1;
            versionComposite.setLayout(layout);
            final Text text = new Text(versionComposite, SWT.CENTER | SWT.BORDER);
            GridData data = new GridData(GridData.FILL_BOTH);
            text.setLayoutData(data);
            String newVersion = object.getNewVersion();
            if (newVersion == null || "".equals(newVersion.trim())) {
                //$NON-NLS-1$
                newVersion = appliedFixedVersion;
                object.setNewVersion(newVersion);
            }
            text.setText(newVersion);
            checkVersionPattern(text, newVersion);
            text.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    String version = text.getText();
                    checkVersionPattern(text, version);
                    object.setNewVersion(version);
                    checkValid();
                }
            });
            versionEditor.minimumWidth = itemTable.getColumn(2).getWidth();
            versionEditor.setEditor(versionComposite, tableItem, 2);
        }
        TableEditor delEditor = new TableEditor(itemTable);
        Label delLabel = new Label(itemTable, SWT.CENTER);
        delLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
        delLabel.setImage(ImageProvider.getImage(EImage.DELETE_ICON));
        //$NON-NLS-1$
        delLabel.setToolTipText(Messages.getString("VersionManagementDialog.DeletedTip"));
        delLabel.pack();
        delLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                checkedObjects.remove(object);
                removeTableItem(tableItem);
                refreshCheckedTreeView();
                checkButtonsState();
                checkButtonsState(false);
            }
        });
        delEditor.minimumWidth = 25;
        delEditor.horizontalAlignment = SWT.CENTER;
        delEditor.setEditor(delLabel, tableItem, 3);
        if (fixedVersionButton.getSelection() || useJobVersionButton.getSelection()) {
            tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { delEditor });
        } else if (versionEditor != null) {
            tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { versionEditor, delEditor });
        }
        itemTable.setRedraw(true);
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) NavigatorDecoratingLabelProvider(org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage) TableEditor(org.eclipse.swt.custom.TableEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) GridData(org.eclipse.swt.layout.GridData) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 13 with MouseAdapter

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

the class TestComposite method installListener.

private void installListener() {
    buttonAddVar.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            List<Variable> input = (List<Variable>) variableTableViewer.getInput();
            input.add(new Variable(input.size()));
            variableTableViewer.refresh();
        }
    });
    buttonRemoveVar.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            ISelection selection = variableTableViewer.getSelection();
            List<Variable> list = ((List<Variable>) variableTableViewer.getInput());
            if (!selection.isEmpty() && selection instanceof StructuredSelection) {
                Object[] vars = ((StructuredSelection) selection).toArray();
                for (Object var : vars) {
                    list.remove(var);
                    variableTableViewer.refresh();
                }
            } else if (!list.isEmpty()) {
                list.remove(list.size() - 1);
                variableTableViewer.refresh();
            }
        }
    });
    testButton.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            new ExpressionTestMain(CategoryComposite.getSelectedFunction(), testResultText);
        }
    });
    clearButton.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            //$NON-NLS-1$
            testResultText.setText("");
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExpressionTestMain(org.talend.expressionbuilder.test.shadow.ExpressionTestMain) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 14 with MouseAdapter

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

the class SQLBuilderEditorComposite method createStatusArea.

/**
     * Creates UI for status bar.
     * 
     * @param parent
     */
private void createStatusArea(Composite parent) {
    // create bottom status bar
    Composite statusBar = new Composite(parent, SWT.NULL);
    GridLayout statusBarLayout = new GridLayout();
    statusBarLayout.numColumns = 3;
    statusBarLayout.verticalSpacing = 0;
    statusBarLayout.marginHeight = 0;
    statusBarLayout.marginWidth = 0;
    statusBarLayout.marginTop = 0;
    statusBarLayout.marginBottom = 0;
    statusBarLayout.marginRight = 5;
    statusBarLayout.horizontalSpacing = 5;
    statusBarLayout.verticalSpacing = 0;
    statusBar.setLayout(statusBarLayout);
    GridData statusBarGridData = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
    statusBarGridData.verticalIndent = 0;
    statusBarGridData.horizontalIndent = 0;
    statusBar.setLayoutData(statusBarGridData);
    // add status line manager
    StatusLineManager statusMgr = new StatusLineManager();
    statusMgr.createControl(statusBar);
    GridData c1Grid = new GridData();
    c1Grid.horizontalAlignment = SWT.FILL;
    c1Grid.verticalAlignment = SWT.BOTTOM;
    c1Grid.grabExcessHorizontalSpace = true;
    c1Grid.grabExcessVerticalSpace = false;
    statusMgr.getControl().setLayoutData(c1Grid);
    // add checkbox for limiting results
    GridData c2Grid = new GridData();
    c2Grid.horizontalAlignment = SWT.RIGHT;
    c2Grid.verticalAlignment = SWT.CENTER;
    c2Grid.grabExcessHorizontalSpace = false;
    c2Grid.grabExcessVerticalSpace = false;
    final Button limitResults = new Button(statusBar, SWT.CHECK);
    //$NON-NLS-1$
    limitResults.setText(Messages.getString("SQL_Limit_Rows_2"));
    limitResults.setSelection(true);
    limitResults.setLayoutData(c2Grid);
    // add input field for result limit
    GridData c3Grid = new GridData();
    c3Grid.horizontalAlignment = SWT.RIGHT;
    c3Grid.verticalAlignment = SWT.CENTER;
    c3Grid.grabExcessHorizontalSpace = false;
    c3Grid.grabExcessVerticalSpace = false;
    c3Grid.widthHint = 30;
    maxResultText = new Text(statusBar, SWT.BORDER | SWT.SINGLE);
    maxResultText.setText(IConstants.MAX_SQL_ROWS);
    maxResultText.setLayoutData(c3Grid);
    limitResults.addMouseListener(new MouseAdapter() {

        // enable/disable input field when checkbox is clicked
        @Override
        public void mouseUp(MouseEvent e) {
            maxResultText.setEnabled(limitResults.getSelection());
            ifLimit = limitResults.getSelection();
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) StatusLineManager(org.eclipse.jface.action.StatusLineManager) GridData(org.eclipse.swt.layout.GridData) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledText(org.eclipse.swt.custom.StyledText) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) Text(org.eclipse.swt.widgets.Text)

Example 15 with MouseAdapter

use of org.eclipse.swt.events.MouseAdapter in project cubrid-manager by CUBRID.

the class CubridNavigatorView method addListener.

/**
	 *
	 * Add listener
	 *
	 */
protected void addListener() {
    tv.getTree().addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
        }

        public void mouseUp(MouseEvent event) {
            if (event.button == 1 && LayoutManager.getInstance().isUseClickOnce()) {
                ISelection selection = tv.getSelection();
                if (selection == null || selection.isEmpty()) {
                    return;
                }
                Object obj = ((IStructuredSelection) selection).getFirstElement();
                if (!(obj instanceof ICubridNode)) {
                    return;
                }
                ICubridNode cubridNode = (ICubridNode) obj;
                LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(cubridNode);
            }
        }
    });
    tv.getTree().addMouseTrackListener(new MouseTrackAdapter() {

        public void mouseHover(MouseEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
            int x = event.x;
            int y = event.y;
            TreeItem item = tv.getTree().getItem(new Point(x, y));
            if (item == null) {
                return;
            }
            showToolTip(item);
        }
    });
    tv.getTree().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
            TreeItem[] items = tv.getTree().getSelection();
            if (items == null || items.length == 0) {
                return;
            }
            showToolTip(items[0]);
            if (items.length == 1) {
                showSchemaInfo(items[0]);
            } else {
                showSchemaInfo(null);
            }
        }
    });
    addDragDropSupport(tv.getTree());
    tv.getTree().addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            // prevent to make events by key press for a long time
            if (e.character == ' ') {
                TreeItem[] items = tv.getTree().getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                if (items.length == 1) {
                    showSchemaInfo(items[0]);
                } else {
                    showSchemaInfo(null);
                }
            }
            lastKeyInputTimestamp = System.currentTimeMillis();
            // by showing object information tab on the query editor.
            if (e.keyCode == SWT.F2) {
                TreeItem[] items = tv.getTree().getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                for (TreeItem item : items) {
                    Object obj = item.getData();
                    if (obj instanceof ICubridNode) {
                        ICubridNode node = (ICubridNode) obj;
                        if (NodeType.USER_TABLE.equals(node.getType()) || NodeType.SYSTEM_TABLE.equals(node.getType()) || NodeType.USER_VIEW.equals(node.getType()) || NodeType.SYSTEM_VIEW.equals(node.getType())) {
                            DefaultSchemaNode table = (DefaultSchemaNode) obj;
                            OpenTargetAction action = new OpenTargetAction();
                            action.showObjectInfo(table);
                        } else if (NodeType.TABLE_FOLDER.equals(node.getType())) {
                            CubridNavigatorView view = CubridNavigatorView.getNavigatorView(ID_CQB);
                            if (view == null) {
                                view = CubridNavigatorView.getNavigatorView(ID_CM);
                            }
                            if (view == null) {
                                return;
                            }
                            TreeViewer treeViewer = view.getViewer();
                            //if not expand ,expand the node and wait until all children be added
                            if (!treeViewer.getExpandedState(node)) {
                                treeViewer.expandToLevel(node, 1);
                                while (node.getChildren().size() == 0) {
                                    try {
                                        Thread.sleep(500);
                                    } catch (Exception ignored) {
                                    }
                                }
                            }
                            CubridDatabase database = (CubridDatabase) node.getParent();
                            OpenTargetAction action = new OpenTargetAction();
                            action.showTableDashboard(database);
                        }
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) OpenTargetAction(com.cubrid.common.ui.common.action.OpenTargetAction) KeyEvent(org.eclipse.swt.events.KeyEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

MouseAdapter (org.eclipse.swt.events.MouseAdapter)39 MouseEvent (org.eclipse.swt.events.MouseEvent)39 GridData (org.eclipse.swt.layout.GridData)20 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 Composite (org.eclipse.swt.widgets.Composite)15 GridLayout (org.eclipse.swt.layout.GridLayout)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 KeyEvent (org.eclipse.swt.events.KeyEvent)11 Button (org.eclipse.swt.widgets.Button)11 Point (org.eclipse.swt.graphics.Point)10 Text (org.eclipse.swt.widgets.Text)9 KeyAdapter (org.eclipse.swt.events.KeyAdapter)8 StyledText (org.eclipse.swt.custom.StyledText)6 SelectionListener (org.eclipse.swt.events.SelectionListener)6 Label (org.eclipse.swt.widgets.Label)6 TraverseEvent (org.eclipse.swt.events.TraverseEvent)5 TraverseListener (org.eclipse.swt.events.TraverseListener)5 ArrayList (java.util.ArrayList)4 Table (org.eclipse.swt.widgets.Table)4 Tree (org.eclipse.swt.widgets.Tree)4