Search in sources :

Example 1 with IContentProposalListener

use of org.eclipse.jface.fieldassist.IContentProposalListener in project tdi-studio-se by Talend.

the class TalendEditorComponentCreationAssist method initListeners.

private void initListeners() {
    assistText.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.stateMask == SWT.NONE) {
                if (e.keyCode == SWT.ESC) {
                    disposeAssistText();
                } else if (e.keyCode == SWT.CR) {
                    acceptProposal();
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }
    });
    assistText.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!(contentProposalAdapter.isProposalPopupOpen())) {
                disposeAssistText();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {

        @Override
        public void proposalPopupOpened(ContentProposalAdapter adapter) {
        }

        @Override
        public void proposalPopupClosed(ContentProposalAdapter adapter) {
            if (assistText != null && !assistText.isFocusControl()) {
                disposeAssistText();
            }
        }
    });
    contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            acceptProposal();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) KeyListener(org.eclipse.swt.events.KeyListener) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) IContentProposalListener2(org.eclipse.jface.fieldassist.IContentProposalListener2) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 2 with IContentProposalListener

use of org.eclipse.jface.fieldassist.IContentProposalListener in project bndtools by bndtools.

the class GeneralInfoPart method createSection.

private void createSection(Section section, FormToolkit toolkit) {
    section.setText("Basic Information");
    KeyStroke assistKeyStroke = null;
    try {
        assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException x) {
    // Ignore
    }
    FieldDecoration contentAssistDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    toolkit.createLabel(composite, "Version:");
    txtVersion = toolkit.createText(composite, "", SWT.BORDER);
    ToolTips.setupMessageAndToolTipFromSyntax(txtVersion, Constants.BUNDLE_VERSION);
    Hyperlink linkActivator = toolkit.createHyperlink(composite, "Activator:", SWT.NONE);
    txtActivator = toolkit.createText(composite, "", SWT.BORDER);
    ToolTips.setupMessageAndToolTipFromSyntax(txtActivator, Constants.BUNDLE_ACTIVATOR);
    // Content Proposal for the Activator field
    ContentProposalAdapter activatorProposalAdapter = null;
    ActivatorClassProposalProvider proposalProvider = new ActivatorClassProposalProvider();
    activatorProposalAdapter = new ContentProposalAdapter(txtActivator, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
    activatorProposalAdapter.addContentProposalListener(proposalProvider);
    activatorProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    activatorProposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());
    activatorProposalAdapter.setAutoActivationDelay(1000);
    // Decorator for the Activator field
    ControlDecoration decorActivator = new ControlDecoration(txtActivator, SWT.LEFT | SWT.CENTER, composite);
    decorActivator.setImage(contentAssistDecoration.getImage());
    decorActivator.setMarginWidth(3);
    if (assistKeyStroke == null) {
        decorActivator.setDescriptionText("Content Assist is available. Start typing to activate");
    } else {
        decorActivator.setDescriptionText(MessageFormat.format("Content Assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
    }
    decorActivator.setShowOnlyOnFocus(true);
    decorActivator.setShowHover(true);
    // Listeners
    txtVersion.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    addDirtyProperty(Constants.BUNDLE_VERSION);
                }
            });
        }
    });
    txtActivator.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    addDirtyProperty(Constants.BUNDLE_ACTIVATOR);
                }
            });
        }
    });
    linkActivator.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent ev) {
            String activatorClassName = txtActivator.getText();
            if (activatorClassName != null && activatorClassName.length() > 0) {
                try {
                    IJavaProject javaProject = getJavaProject();
                    if (javaProject == null)
                        return;
                    IType activatorType = javaProject.findType(activatorClassName);
                    if (activatorType != null) {
                        JavaUI.openInEditor(activatorType, true, true);
                    }
                } catch (PartInitException e) {
                    ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening an editor for activator class '{0}'.", activatorClassName), e));
                } catch (JavaModelException e) {
                    ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error searching for activator class '{0}'.", activatorClassName), e));
                }
            }
        }
    });
    activatorProposalAdapter.addContentProposalListener(new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            if (proposal instanceof JavaContentProposal) {
                String selectedPackageName = ((JavaContentProposal) proposal).getPackageName();
                if (!model.isIncludedPackage(selectedPackageName)) {
                    model.addPrivatePackage(selectedPackageName);
                }
            }
        }
    });
    // Layout
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 15;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
    txtVersion.setLayoutData(gd);
    txtActivator.setLayoutData(gd);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) IType(org.eclipse.jdt.core.IType) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) JavaContentProposal(bndtools.utils.JavaContentProposal) PartInitException(org.eclipse.ui.PartInitException) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Composite(org.eclipse.swt.widgets.Composite) JavaContentProposalLabelProvider(bndtools.utils.JavaContentProposalLabelProvider) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IJavaProject(org.eclipse.jdt.core.IJavaProject) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) GridData(org.eclipse.swt.layout.GridData) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener) ParseException(org.eclipse.jface.bindings.keys.ParseException) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 3 with IContentProposalListener

use of org.eclipse.jface.fieldassist.IContentProposalListener in project nebula.widgets.nattable by eclipse.

the class TextCellEditor method configureContentProposalAdapter.

/**
 * Adds the listeners necessary for interaction between the control of this
 * TextCellEditor and the ContentProposalAdapter.
 *
 * @param contentProposalAdapter
 *            The {@link ContentProposalAdapter} that should be used to add
 *            content proposal abilities to this {@link TextCellEditor}.
 * @since 1.4
 */
protected void configureContentProposalAdapter(final ContentProposalAdapter contentProposalAdapter) {
    // add the necessary listeners to support the interaction between the
    // content proposal and this text editor
    contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            commit(MoveDirectionEnum.NONE);
        }
    });
    contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {

        @Override
        public void proposalPopupClosed(ContentProposalAdapter adapter) {
            if (TextCellEditor.this.focusListener instanceof InlineFocusListener) {
                ((InlineFocusListener) TextCellEditor.this.focusListener).handleFocusChanges = true;
            }
        }

        @Override
        public void proposalPopupOpened(ContentProposalAdapter adapter) {
            if (TextCellEditor.this.focusListener instanceof InlineFocusListener) {
                ((InlineFocusListener) TextCellEditor.this.focusListener).handleFocusChanges = false;
            }
            // set the focus to the popup so on enabling via keystroke the
            // selection via keyboard is immediately possible
            contentProposalAdapter.setProposalPopupFocus();
        }
    });
}
Also used : IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener) IContentProposalListener2(org.eclipse.jface.fieldassist.IContentProposalListener2) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 4 with IContentProposalListener

use of org.eclipse.jface.fieldassist.IContentProposalListener in project egit by eclipse.

the class RefSpecPanel method createCreationPanel.

private void createCreationPanel() {
    final Group creationPanel = new Group(panel, SWT.NONE);
    creationPanel.setText(UIText.RefSpecPanel_creationGroup);
    creationPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    final GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.horizontalSpacing = 10;
    layout.verticalSpacing = 2;
    creationPanel.setLayout(layout);
    new Label(creationPanel, SWT.NONE).setText(UIText.RefSpecPanel_creationSrc);
    new Label(creationPanel, SWT.NONE).setText(UIText.RefSpecPanel_creationDst);
    creationButton = new Button(creationPanel, SWT.PUSH);
    creationButton.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false, 1, 2));
    creationButton.setImage(imageRegistry.get(IMAGE_ADD));
    creationButton.setText(UIText.RefSpecPanel_creationButton);
    creationButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final String src = creationSrcComboSupport.getContent();
            final String dst = creationDstComboSupport.getContent();
            RefSpec spec = new RefSpec(src + ':' + dst);
            addRefSpec(spec);
            // $NON-NLS-1$
            creationSrcCombo.setText("");
            // $NON-NLS-1$
            creationDstCombo.setText("");
        }
    });
    creationButton.setToolTipText(NLS.bind(UIText.RefSpecPanel_creationButtonDescription, typeString()));
    creationSrcDecoration = createAssistedDecoratedCombo(creationPanel, getRefsProposalProvider(pushSpecs), new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            tryAutoCompleteSrcToDst();
        }
    });
    creationSrcCombo = (Combo) creationSrcDecoration.getControl();
    creationSrcCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    creationSrcCombo.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            // it can be confused with RETURN for content proposal
            if (e.detail == SWT.TRAVERSE_TAB_NEXT)
                tryAutoCompleteSrcToDst();
        }
    });
    if (pushSpecs)
        creationSrcCombo.setToolTipText(UIText.RefSpecPanel_srcPushDescription);
    else
        creationSrcCombo.setToolTipText(UIText.RefSpecPanel_srcFetchDescription);
    creationSrcComboSupport = new ComboLabelingSupport(creationSrcCombo, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tryAutoCompleteSrcToDst();
        }
    });
    creationDstDecoration = createAssistedDecoratedCombo(creationPanel, getRefsProposalProvider(!pushSpecs), new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            tryAutoCompleteDstToSrc();
        }
    });
    creationDstCombo = (Combo) creationDstDecoration.getControl();
    creationDstCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    creationDstCombo.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            // it can be confused with RETURN for content proposal
            if (e.detail == SWT.TRAVERSE_TAB_NEXT)
                tryAutoCompleteDstToSrc();
        }
    });
    if (pushSpecs)
        creationDstCombo.setToolTipText(UIText.RefSpecPanel_dstPushDescription);
    else
        creationDstCombo.setToolTipText(UIText.RefSpecPanel_dstFetchDescription);
    creationDstComboSupport = new ComboLabelingSupport(creationDstCombo, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tryAutoCompleteDstToSrc();
        }
    });
    validateCreationPanel();
    final ModifyListener validator = new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            validateCreationPanel();
        }
    };
    creationSrcCombo.addModifyListener(validator);
    creationDstCombo.addModifyListener(validator);
    Control[] tabList = new Control[] { creationSrcCombo, creationDstCombo, creationButton };
    creationPanel.setTabList(tabList);
}
Also used : Group(org.eclipse.swt.widgets.Group) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) RefSpec(org.eclipse.jgit.transport.RefSpec) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener)

Aggregations

IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)4 IContentProposalListener (org.eclipse.jface.fieldassist.IContentProposalListener)4 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)3 IContentProposalListener2 (org.eclipse.jface.fieldassist.IContentProposalListener2)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 JavaContentProposal (bndtools.utils.JavaContentProposal)1 JavaContentProposalLabelProvider (bndtools.utils.JavaContentProposalLabelProvider)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)1 ParseException (org.eclipse.jface.bindings.keys.ParseException)1 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)1 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)1