Search in sources :

Example 41 with MouseAdapter

use of org.eclipse.swt.events.MouseAdapter in project azure-tools-for-java by Microsoft.

the class ServiceExplorerView method hookMouseActions.

private void hookMouseActions() {
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            doubleClickAction.run();
        }
    });
    Tree tree = (Tree) viewer.getControl();
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (e.button == 1) {
                // left button
                TreeItem[] selection = ((Tree) e.widget).getSelection();
                if (selection.length > 0) {
                    TreeItem item = ((Tree) e.widget).getSelection()[0];
                    Node node = ((TreeNode) item.getData()).node;
                    // we do not propagate the click event to it
                    if (!node.isLoading()) {
                        node.getClickAction().fireNodeActionEvent();
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Tree(org.eclipse.swt.widgets.Tree) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent)

Example 42 with MouseAdapter

use of org.eclipse.swt.events.MouseAdapter in project KaiZen-OpenAPI-Editor by RepreZen.

the class QuickOutline method createTreeViewer.

protected TreeViewer createTreeViewer(Composite parent) {
    final Tree tree = new Tree(parent, SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = tree.getItemHeight();
    tree.setLayoutData(gd);
    final TreeViewer treeViewer = new TreeViewer(tree);
    treeViewer.setContentProvider(new OutlineContentProvider());
    treeViewer.setLabelProvider(new OutlineStyledLabelProvider());
    treeViewer.addFilter(new NamePatternFilter());
    // Using ALL_LEVELS will cause editor to hang on large specs
    treeViewer.setAutoExpandLevel(2);
    treeViewer.setUseHashlookup(true);
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (isInvocationEvent(e)) {
                e.doit = false;
                handleMultiView();
            } else if (e.keyCode == SWT.CR) {
                handleSelection();
                QuickOutline.this.close();
            }
        }
    });
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            super.mouseDown(e);
        }

        public void mouseUp(MouseEvent e) {
            if (tree.getSelectionCount() < 1) {
                return;
            }
            if (e.button != 1) {
                return;
            }
            if (tree.equals(e.getSource())) {
                Object o = tree.getItem(new Point(e.x, e.y));
                TreeItem selection = tree.getSelection()[0];
                if (selection.equals(o)) {
                    handleSelection();
                }
            }
        }
    });
    tree.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
        // do nothing
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            handleSelection();
        }
    });
    return treeViewer;
}
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) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) KeyListener(org.eclipse.swt.events.KeyListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 43 with MouseAdapter

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

the class SearchControl method initialize.

private void initialize(int style) {
    text = new Text(this, style);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    text.setMessage("search what you want");
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            text.selectAll();
        }
    });
    text.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            text.selectAll();
        }
    });
    clear = new ToolBar(this, SWT.FLAT);
    ToolItem item = new ToolItem(clear, SWT.PUSH);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            text.setText("");
        }
    });
    Point computeSize = clear.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int height = computeSize.y + 2;
    arcSize = height > arcSize ? height : arcSize;
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginBottom = 0;
    layout.marginHeight = 0;
    layout.marginLeft = marginHorizon;
    layout.marginRight = marginHorizon;
    layout.marginTop = 1;
    layout.marginWidth = 0;
    setLayout(layout);
    setBackground(backgroundColor);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 44 with MouseAdapter

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

the class VersionManagementPage method addItemElements.

@Override
protected void addItemElements(List<ItemVersionObject> elements) {
    if (elements == null || elements.isEmpty()) {
        return;
    }
    itemTable.setRedraw(false);
    final Color redColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
    for (final ItemVersionObject object : elements) {
        final TableItem tableItem = new TableItem(itemTable, SWT.NONE);
        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, object.getOldVersion());
        TableEditor versionEditor = null;
        if (isFixedVersion()) {
            String version = fixedVersionText.getText();
            tableItem.setText(2, version);
            if (VersionUtils.compareTo(version, object.getOldVersion()) > 0) {
                tableItem.setForeground(2, redColor);
            } else {
                tableItem.setForeground(2, Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
            }
        } else {
            // new version
            versionEditor = new TableEditor(itemTable);
            Composite versionComposit = new Composite(itemTable, SWT.NONE);
            GridLayout layout = new GridLayout(3, false);
            layout.horizontalSpacing = 1;
            layout.verticalSpacing = 0;
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            versionComposit.setLayout(layout);
            final Text text = new Text(versionComposit, SWT.BORDER | SWT.READ_ONLY);
            GridData data = new GridData(GridData.FILL_HORIZONTAL);
            text.setLayoutData(data);
            text.setEditable(false);
            text.setText(object.getNewVersion());
            if (VersionUtils.compareTo(object.getNewVersion(), object.getOldVersion()) > 0) {
                text.setForeground(redColor);
            } else {
                text.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
            }
            Button tableMajorBtn = new Button(versionComposit, SWT.NONE);
            //$NON-NLS-1$
            tableMajorBtn.setText("M");
            //$NON-NLS-1$
            tableMajorBtn.setToolTipText(Messages.getString("VersionManagementDialog.MajorVersionTip"));
            Button tableMinorBtn = new Button(versionComposit, SWT.NONE);
            //$NON-NLS-1$
            tableMinorBtn.setText("m");
            //$NON-NLS-1$
            tableMinorBtn.setToolTipText(Messages.getString("VersionManagementDialog.MinorVersionTip"));
            tableMajorBtn.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String version = object.getNewVersion();
                    version = VersionUtils.upMajor(version);
                    text.setText(version);
                    text.setForeground(redColor);
                    object.setNewVersion(version);
                }
            });
            tableMinorBtn.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String version = object.getNewVersion();
                    version = VersionUtils.upMinor(version);
                    text.setText(version);
                    text.setForeground(redColor);
                    object.setNewVersion(version);
                }
            });
            versionEditor.minimumWidth = itemTable.getColumn(2).getWidth();
            versionEditor.setEditor(versionComposit, 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 (isFixedVersion()) {
            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) NavigatorDecoratingLabelProvider(org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider) Color(org.eclipse.swt.graphics.Color) TableItem(org.eclipse.swt.widgets.TableItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) 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) Button(org.eclipse.swt.widgets.Button) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 45 with MouseAdapter

use of org.eclipse.swt.events.MouseAdapter in project bndtools by bndtools.

the class ResolutionChoiceSelectionDialog method createDialogArea.

@SuppressWarnings("unused")
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Multiple Provider Candidates");
    setMessage("Use the candidate list to specify your preferences. Candidates at the top of the list will be preferred by the resolver.");
    // Create controls
    Composite outer = (Composite) super.createDialogArea(parent);
    Composite contents = new Composite(outer, SWT.NONE);
    Label lblRequirement = new Label(contents, SWT.NONE);
    lblRequirement.setText("Requirement Info");
    lblRequirement.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    StyledText txtRequirement = new StyledText(contents, SWT.WRAP | SWT.BORDER);
    txtRequirement.setEditable(false);
    txtRequirement.setCaret(null);
    //        txtRequirement.setBackground(contents.getBackground());
    txtRequirement.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    new Label(contents, SWT.NONE);
    Label lblCandidates = new Label(contents, SWT.NONE);
    lblCandidates.setText("Candidates");
    lblCandidates.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    Composite lowerPanel = new Composite(contents, SWT.NONE);
    Table tbl = new Table(lowerPanel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    viewer = new CheckboxTableViewer(tbl);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new CapabilityLabelProvider());
    btnUp = new Button(lowerPanel, SWT.PUSH);
    btnUp.setText("Move Up");
    btnUp.setEnabled(false);
    btnDown = new Button(lowerPanel, SWT.PUSH);
    btnDown.setText("Move Down");
    btnDown.setEnabled(false);
    Composite cmpPreferences = new Composite(contents, SWT.NONE);
    btnSavePreference = new Button(cmpPreferences, SWT.CHECK | SWT.WRAP);
    txtSavePreference = new StyledText(cmpPreferences, SWT.WRAP);
    txtSavePreference.setEditable(false);
    txtSavePreference.setCaret(null);
    txtSavePreference.setBackground(contents.getBackground());
    txtSavePreference.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    // Events
    txtSavePreference.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            btnSavePreference.setSelection(!btnSavePreference.getSelection());
        }
    });
    // Load data
    StyledString label = createRequirementText();
    txtRequirement.setText(label.getString());
    txtRequirement.setStyleRanges(label.getStyleRanges());
    viewer.setInput(candidates);
    updateSavePreferenceText();
    // Layout
    GridLayout layout;
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    contents.setLayoutData(gd);
    layout = new GridLayout(1, false);
    contents.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    gd.horizontalIndent = 5;
    txtRequirement.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    lowerPanel.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    lowerPanel.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd.widthHint = 450;
    gd.heightHint = 250;
    tbl.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, false, false);
    btnUp.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, false, false);
    btnDown.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    cmpPreferences.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cmpPreferences.setLayout(layout);
    gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    btnSavePreference.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    txtSavePreference.setLayoutData(gd);
    return contents;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) CapabilityLabelProvider(bndtools.model.resolution.CapabilityLabelProvider) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledString(org.eclipse.jface.viewers.StyledString) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

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