Search in sources :

Example 6 with MouseAdapter

use of org.eclipse.swt.events.MouseAdapter in project translationstudio8 by heartsome.

the class NatCombo method createTextControl.

private void createTextControl() {
    text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
    text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(gridData);
    text.forceFocus();
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
                showDropdownControl();
                int selectionIndex = dropdownList.getSelectionIndex();
                selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
                if (selectionIndex < 0) {
                    selectionIndex = 0;
                }
                dropdownList.select(selectionIndex);
                text.setText(dropdownList.getSelection()[0]);
            }
        }
    });
    iconImage = GUIHelper.getImage("down_2");
    final Canvas iconCanvas = new Canvas(this, SWT.NONE) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle iconImageBounds = iconImage.getBounds();
            return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
        }
    };
    gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
    iconCanvas.setLayoutData(gridData);
    iconCanvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent event) {
            GC gc = event.gc;
            Rectangle iconCanvasBounds = iconCanvas.getBounds();
            Rectangle iconImageBounds = iconImage.getBounds();
            int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
            int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
            gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
            Color originalFg = gc.getForeground();
            gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
            gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
            gc.setForeground(originalFg);
        }
    });
    iconCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            showDropdownControl();
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) GC(org.eclipse.swt.graphics.GC)

Example 7 with MouseAdapter

use of org.eclipse.swt.events.MouseAdapter in project otertool by wuntee.

the class LoadApkFromDeviceDialog method createContents.

/**
	 * Create contents of the dialog.
	 */
private void createContents() {
    shlSelectApk = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
    shlSelectApk.setSize(592, 486);
    shlSelectApk.setText("Select APK");
    shlSelectApk.setLayout(new GridLayout(1, false));
    table = new Table(shlSelectApk, SWT.BORDER | SWT.FULL_SELECTION);
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            result = (PackageBean) table.getSelection()[0].getData(PACKAGE_BEAN);
            shlSelectApk.close();
        }
    });
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setBounds(0, 0, 3, 19);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final TableColumn tblclmnApk = new TableColumn(table, SWT.NONE);
    tblclmnApk.setWidth(240);
    tblclmnApk.setText("APK");
    final TableColumn tblclmnPackage = new TableColumn(table, SWT.NONE);
    tblclmnPackage.setWidth(338);
    tblclmnPackage.setText("Package");
    final String[] keys = { PACKAGE_BEAN };
    GuiWorkshop.addColumnSorter(table, tblclmnApk, 0, keys);
    GuiWorkshop.addColumnSorter(table, tblclmnPackage, 1, keys);
    Composite composite = new Composite(shlSelectApk, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite.setBounds(0, 0, 64, 64);
    GridLayout gl_composite = new GridLayout(2, false);
    gl_composite.verticalSpacing = 0;
    gl_composite.marginWidth = 0;
    gl_composite.marginHeight = 0;
    gl_composite.horizontalSpacing = 0;
    composite.setLayout(gl_composite);
    Button btnLoad = new Button(composite, SWT.NONE);
    btnLoad.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (table.getSelection().length == 0) {
                GuiWorkshop.messageError(shlSelectApk, "Please Select an APK to load.");
            } else {
                result = (PackageBean) table.getSelection()[0].getData(PACKAGE_BEAN);
                shlSelectApk.close();
            }
        }
    });
    btnLoad.setText("Load");
    Button btnCancel = new Button(composite, SWT.NONE);
    btnCancel.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            result = null;
            shlSelectApk.close();
        }
    });
    btnCancel.setText("Cancel");
}
Also used : Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) PackageBean(com.wuntee.oter.packagemanager.PackageBean) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 8 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 9 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 10 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)

Aggregations

MouseAdapter (org.eclipse.swt.events.MouseAdapter)50 MouseEvent (org.eclipse.swt.events.MouseEvent)50 GridData (org.eclipse.swt.layout.GridData)25 SelectionEvent (org.eclipse.swt.events.SelectionEvent)19 Composite (org.eclipse.swt.widgets.Composite)18 GridLayout (org.eclipse.swt.layout.GridLayout)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)14 Point (org.eclipse.swt.graphics.Point)14 Button (org.eclipse.swt.widgets.Button)14 KeyEvent (org.eclipse.swt.events.KeyEvent)11 Text (org.eclipse.swt.widgets.Text)10 KeyAdapter (org.eclipse.swt.events.KeyAdapter)8 StyledText (org.eclipse.swt.custom.StyledText)7 Label (org.eclipse.swt.widgets.Label)7 PaintEvent (org.eclipse.swt.events.PaintEvent)6 PaintListener (org.eclipse.swt.events.PaintListener)6 SelectionListener (org.eclipse.swt.events.SelectionListener)6 FillLayout (org.eclipse.swt.layout.FillLayout)6 Table (org.eclipse.swt.widgets.Table)6 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)5