Search in sources :

Example 61 with FocusAdapter

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

the class OverviewSection method createControls.

/*
     * @see AbstractJvmPropertySection#createControls(Composite)
     */
@Override
protected void createControls(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    viewer = new PropertiesFilteredTree(composite, getActionBars()) {

        private ShowInTimelineAction showInTimelineAction;

        @Override
        protected List<Action> createActions(IActionBars actionBars) {
            List<Action> actions = new ArrayList<Action>();
            CopyAction copyAction = CopyAction.createCopyAction(actionBars);
            actions.add(copyAction);
            showInTimelineAction = new MyShowInTimelineAction(OverviewSection.this);
            actions.add(showInTimelineAction);
            return actions;
        }

        @Override
        public void menuAboutToshow() {
        // do nothing
        }
    }.getViewer();
    viewer.setContentProvider(new OverviewContentProvider(overviewProperties));
    viewer.setLabelProvider(new OverviewLabelProvider());
    ((Tree) viewer.getControl()).addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            storeTreeExpansionState();
        }
    });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.OVERVIEW_PAGE);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) CopyAction(org.talend.designer.runtime.visualization.internal.actions.CopyAction) Action(org.eclipse.jface.action.Action) RefreshAction(org.talend.designer.runtime.visualization.internal.actions.RefreshAction) ShowInTimelineAction(org.talend.designer.runtime.visualization.internal.actions.ShowInTimelineAction) Composite(org.eclipse.swt.widgets.Composite) CopyAction(org.talend.designer.runtime.visualization.internal.actions.CopyAction) ArrayList(java.util.ArrayList) PropertiesFilteredTree(org.talend.designer.runtime.visualization.internal.ui.properties.PropertiesFilteredTree) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ShowInTimelineAction(org.talend.designer.runtime.visualization.internal.actions.ShowInTimelineAction) PropertiesFilteredTree(org.talend.designer.runtime.visualization.internal.ui.properties.PropertiesFilteredTree) Tree(org.eclipse.swt.widgets.Tree) IActionBars(org.eclipse.ui.IActionBars)

Example 62 with FocusAdapter

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

the class PkgPatternsListPart method createSection.

protected void createSection(Section section, FormToolkit toolkit) {
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
    addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    addItem.setToolTipText("Add");
    final ToolItem insertItem = new ToolItem(toolbar, SWT.PUSH);
    insertItem.setImage(imgInsert);
    insertItem.setToolTipText("Insert");
    insertItem.setEnabled(false);
    final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
    removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    removeItem.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    removeItem.setToolTipText("Remove");
    removeItem.setEnabled(false);
    Table table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setUseHashlookup(false);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(labelProvider);
    toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
    final ToolItem btnMoveUp = new ToolItem(toolbar, SWT.PUSH);
    btnMoveUp.setText("Up");
    btnMoveUp.setImage(imgUp);
    btnMoveUp.setEnabled(false);
    final ToolItem btnMoveDown = new ToolItem(toolbar, SWT.PUSH);
    btnMoveDown.setText("Down");
    btnMoveDown.setImage(imgDown);
    btnMoveDown.setEnabled(false);
    // Listeners
    table.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            ISelection selection = viewer.getSelection();
            if (!selection.isEmpty())
                managedForm.fireSelectionChanged(PkgPatternsListPart.this, selection);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            List<C> oldSelection = selection;
            IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("unchecked") List<C> newSelection = structSel.toList();
            selection = newSelection;
            propChangeSupport.firePropertyChange(PROP_SELECTION, oldSelection, selection);
            managedForm.fireSelectionChanged(PkgPatternsListPart.this, event.getSelection());
            boolean enabled = !viewer.getSelection().isEmpty();
            insertItem.setEnabled(enabled);
            removeItem.setEnabled(enabled);
            btnMoveUp.setEnabled(enabled);
            btnMoveDown.setEnabled(enabled);
        }
    });
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), ResourceTransfer.getInstance(), TextTransfer.getInstance() }, new PackageDropAdapter<C>(viewer) {

        @Override
        protected C createNewEntry(String packageName) {
            return newHeaderClause(packageName);
        }

        @Override
        protected void addRows(int index, Collection<C> rows) {
            doAddClauses(rows, index, true);
        }

        @Override
        protected int indexOf(Object object) {
            return clauses.indexOf(object);
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemoveSelectedClauses();
            } else if (e.character == '+') {
                doAddClausesAfterSelection(generateClauses());
            }
        }
    });
    addItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddClausesAfterSelection(generateClauses());
        }
    });
    insertItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doInsertClausesAtSelection(generateClauses());
        }
    });
    removeItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemoveSelectedClauses();
        }
    });
    btnMoveUp.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doMoveUp();
        }
    });
    btnMoveDown.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doMoveDown();
        }
    });
    // Layout
    GridLayout layout;
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 75;
    gd.heightHint = 75;
    table.setLayoutData(gd);
    toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) ToolItem(org.eclipse.swt.widgets.ToolItem) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 63 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project knime-core by knime.

the class SearchQueryContributionItem method createControl.

/**
 * {@inheritDoc}
 */
@Override
protected Control createControl(final Composite parent) {
    m_text = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.BORDER_SOLID);
    m_text.addKeyListener(this);
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
        m_text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(final FocusEvent fe) {
                try {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(DefaultRepositoryView.ID);
                    // You would think that this would be ripe for an infinite loop, but luckily SWT is doing the
                    // correct thing and not notifying focusGained for an already focused item (and similarly
                    // the workbench is not re-focusing and already focus'd view, which temporarily robs
                    // the SWT focus of its subcomponent...)
                    Display.getDefault().asyncExec(() -> {
                        m_text.setFocus();
                    });
                } catch (PartInitException e) {
                    LOGGER.warn("Exception encountered attempting to give focus to node repository view.", e);
                }
            }
        });
    }
    m_text.setToolTipText("Filter contents");
    return m_text;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Text(org.eclipse.swt.widgets.Text) PartInitException(org.eclipse.ui.PartInitException) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 64 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.

private Composite createJSONEditorComposite(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    if (isWindows()) {
        Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        final GridLayout gridLayout = new GridLayout();
        gridLayout.verticalSpacing = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
        gridLayout.horizontalSpacing = 0;
        embedComposite.setLayout(gridLayout);
        embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        Frame frame = SWT_AWT.new_Frame(embedComposite);
        Panel heavyWeightPanel = new Panel();
        heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
        frame.add(heavyWeightPanel);
        frame.setFocusTraversalKeysEnabled(false);
        // Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
        // This reduces flicker on resize in RSyntaxTextArea
        JApplet applet = new JApplet();
        JRootPane root = applet.getRootPane();
        Container contentPane = root.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        heavyWeightPanel.add(applet);
        m_textArea = new RSyntaxTextArea(10, 60);
        m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
        m_textArea.setCodeFoldingEnabled(true);
        m_textArea.setAntiAliasingEnabled(true);
        RTextScrollPane sp = new RTextScrollPane(m_textArea);
        sp.setDoubleBuffered(true);
        m_textArea.setText(m_jsonDocument);
        m_textArea.setEditable(true);
        m_textArea.setEnabled(true);
        contentPane.add(sp);
        Dimension size = sp.getPreferredSize();
        embedComposite.setSize(size.width, size.height);
        // forward focus to RSyntaxTextArea
        embedComposite.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(final FocusEvent e) {
                ViewUtils.runOrInvokeLaterInEDT(new Runnable() {

                    @Override
                    public void run() {
                        m_textArea.requestFocus();
                        m_textArea.setCaretPosition(m_caretPosition);
                    }
                });
            }

            @Override
            public void focusLost(final FocusEvent e) {
            // do nothing
            }
        });
        // delete content of status line, when something is inserted or deleted
        m_textArea.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(final DocumentEvent arg0) {
                if (!composite.isDisposed()) {
                    composite.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (m_statusLine != null && !m_statusLine.isDisposed()) {
                                m_statusLine.setText("");
                                updateModelFromJson();
                            }
                        }
                    });
                }
            }

            @Override
            public void insertUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }

            @Override
            public void removeUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }
        });
        // remember caret position
        m_textArea.addCaretListener(new CaretListener() {

            @Override
            public void caretUpdate(final CaretEvent arg0) {
                m_caretPosition = arg0.getDot();
            }
        });
    } else {
        m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        GridData layoutData = new GridData(GridData.FILL_BOTH);
        layoutData.widthHint = 600;
        layoutData.heightHint = 400;
        m_text.setLayoutData(layoutData);
        m_text.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                m_jsonDocument = m_text.getText();
                if (m_statusLine != null && !m_statusLine.isDisposed()) {
                    m_statusLine.setText("");
                    updateModelFromJson();
                }
            }
        });
        m_text.setText(m_jsonDocument);
    }
    // add status line
    m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
    GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
    int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
    statusGridData.heightHint = maxHeight + 5;
    // seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
    statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
    m_statusLine.setLayoutData(statusGridData);
    compareNodeIDs();
    return composite;
}
Also used : CaretEvent(javax.swing.event.CaretEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) DocumentListener(javax.swing.event.DocumentListener) Frame(java.awt.Frame) ModifyListener(org.eclipse.swt.events.ModifyListener) BoxLayout(javax.swing.BoxLayout) Label(org.eclipse.swt.widgets.Label) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) JApplet(javax.swing.JApplet) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Container(java.awt.Container) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Text(org.eclipse.swt.widgets.Text) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) Point(org.eclipse.swt.graphics.Point) Panel(java.awt.Panel) CaretListener(javax.swing.event.CaretListener) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) JRootPane(javax.swing.JRootPane) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Example 65 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project knime-core by knime.

the class StyledTextEditor method createStyledText.

private Control createStyledText(final Composite parent) {
    m_styledText = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.FULL_SELECTION);
    // by default we are a workflow annotation editor
    // can be changed by changing the default font (setDefaultFont(Font))
    m_styledText.setFont(AnnotationEditPart.getWorkflowAnnotationDefaultFont());
    m_styledText.setAlignment(SWT.LEFT);
    m_styledText.setText("");
    m_styledText.setTabs(TAB_SIZE);
    m_styledText.addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(final VerifyEvent event) {
            if (event.character == SWT.CR && (event.stateMask & SWT.MOD1) != 0) {
                event.doit = false;
            }
        }
    });
    // forward some events to the cell editor
    m_styledText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(final KeyEvent e) {
            keyReleaseOccured(e);
        }
    });
    m_styledText.addFocusListener(new FocusAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void focusLost(final org.eclipse.swt.events.FocusEvent e) {
            // effect of an opening font editor, for instance)
            if (m_allowFocusLost.get()) {
                lostFocus();
            }
        }
    });
    m_styledText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            // super marks it dirty (otherwise no commit at the end)
            fireEditorValueChanged(true, true);
        }
    });
    m_styledText.addExtendedModifyListener(new ExtendedModifyListener() {

        @Override
        public void modifyText(final ExtendedModifyEvent event) {
            if (event.length > 0) {
                textInserted(event.start, event.length);
            }
        }
    });
    m_styledText.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectionChanged();
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            selectionChanged();
        }
    });
    m_styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    addMenu(m_styledText);
    // toolbar gets created first - enable its style buttons!
    selectionChanged();
    return m_styledText;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) StyledText(org.eclipse.swt.custom.StyledText) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

FocusAdapter (org.eclipse.swt.events.FocusAdapter)68 FocusEvent (org.eclipse.swt.events.FocusEvent)64 SelectionEvent (org.eclipse.swt.events.SelectionEvent)42 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)36 Composite (org.eclipse.swt.widgets.Composite)29 GridData (org.eclipse.swt.layout.GridData)28 Text (org.eclipse.swt.widgets.Text)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Label (org.eclipse.swt.widgets.Label)20 Button (org.eclipse.swt.widgets.Button)17 Menu (org.eclipse.swt.widgets.Menu)17 Point (org.eclipse.swt.graphics.Point)16 MenuManager (org.eclipse.jface.action.MenuManager)15 MenuItem (org.eclipse.swt.widgets.MenuItem)15 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14 KeyEvent (org.eclipse.swt.events.KeyEvent)12 Combo (org.eclipse.swt.widgets.Combo)12 KeyAdapter (org.eclipse.swt.events.KeyAdapter)11 Group (org.eclipse.swt.widgets.Group)11