Search in sources :

Example 21 with TextContentAdapter

use of org.eclipse.jface.fieldassist.TextContentAdapter in project webtools.servertools by eclipse.

the class HostnameComposite method createControl.

/**
 * Creates the UI of the page.
 */
protected void createControl() {
    GridLayout layout = new GridLayout();
    layout.horizontalSpacing = SWTUtil.convertHorizontalDLUsToPixels(this, 4);
    layout.verticalSpacing = SWTUtil.convertVerticalDLUsToPixels(this, 4);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 3;
    setLayout(layout);
    // WorkbenchHelp.setHelp(this, ContextIds.SELECT_CLIENT_WIZARD);
    Label label = new Label(this, SWT.WRAP);
    label.setText(Messages.hostname);
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    hostname = new Text(this, SWT.BORDER);
    hostname.setText(LOCALHOST);
    final ControlDecoration hostnameDecoration = new ControlDecoration(hostname, SWT.TOP | SWT.LEAD);
    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    data.horizontalSpan = 2;
    hostname.setLayoutData(data);
    hostname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            hostnameChanged(hostname.getText());
        }
    });
    FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
    FieldDecoration fd = registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    hostnameDecoration.setImage(fd.getImage());
    hostnameDecoration.setDescriptionText(fd.getDescription());
    hostname.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            hostnameDecoration.show();
        }

        public void focusLost(FocusEvent e) {
            hostnameDecoration.hide();
        }
    });
    List<String> hosts = ServerUIPlugin.getPreferences().getHostnames();
    String[] hosts2 = hosts.toArray(new String[hosts.size()]);
    new AutoCompleteField(hostname, new TextContentAdapter(), hosts2);
    Dialog.applyDialogFont(this);
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) FocusEvent(org.eclipse.swt.events.FocusEvent) AutoCompleteField(org.eclipse.jface.fieldassist.AutoCompleteField) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) FieldDecorationRegistry(org.eclipse.jface.fieldassist.FieldDecorationRegistry) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) FocusListener(org.eclipse.swt.events.FocusListener)

Example 22 with TextContentAdapter

use of org.eclipse.jface.fieldassist.TextContentAdapter in project n4js by eclipse.

the class WorkspaceWizardPage method setupContentProposal.

private void setupContentProposal(WorkspaceWizardPageForm wizardForm) {
    // Get the active binding's content assist key strokes
    KeyStroke keyInitiator = getActiveContentAssistBinding();
    // If unbound don't configure the content proposal
    if (null == keyInitiator) {
        return;
    }
    // Setup project content proposal
    ContentProposalAdapter projectAdapter = new ContentProposalAdapter(wizardForm.getProjectText(), new TextContentAdapter(), projectContentProposalProvider, keyInitiator, null);
    projectAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    ImageDescriptor projectSymbol = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT);
    projectAdapter.setLabelProvider(new SimpleImageContentProposalLabelProvider(projectSymbol));
    createContentProposalDecoration(wizardForm.getProjectText());
    sourceFolderContentProposalAdapter = new ContentProposalAdapter(wizardForm.getSourceFolderText(), new TextContentAdapter(), null, keyInitiator, null);
    sourceFolderContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    sourceFolderContentProposalAdapter.setLabelProvider(new SimpleImageContentProposalLabelProvider(ImageDescriptorCache.ImageRef.SRC_FOLDER.asImageDescriptor().orNull()));
    createContentProposalDecoration(wizardForm.getSourceFolderText());
    moduleSpecifierContentProposalAdapter = new ContentProposalAdapter(wizardForm.getModuleSpecifierText().getInternalText(), new TextContentAdapter(), null, keyInitiator, null);
    wizardForm.getModuleSpecifierText().createDecoration(contentProposalDecorationImage);
    // Update proposal context whenever the model changes
    model.addPropertyChangeListener(evt -> {
        if (evt.getPropertyName() == WorkspaceWizardModel.PROJECT_PROPERTY || evt.getPropertyName() == WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY) {
            updateProposalContext();
        }
    });
    updateProposalContext();
    moduleSpecifierContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    moduleSpecifierContentProposalAdapter.setLabelProvider(new ModuleSpecifierProposalLabelProvider());
}
Also used : ModuleSpecifierProposalLabelProvider(org.eclipse.n4js.ui.wizard.contentproposal.ModuleSpecifierContentProposalProviderFactory.ModuleSpecifierProposalLabelProvider) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) SimpleImageContentProposalLabelProvider(org.eclipse.n4js.ui.wizard.contentproposal.SimpleImageContentProposalLabelProvider) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 23 with TextContentAdapter

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

the class UIUtils method addContentProposalToText.

/**
 * Adds a content proposal for arbitrary elements to a text field.
 *
 * @param <T>
 *            type of the proposal candidate objects
 *
 * @param textField
 *            the text field
 * @param candidateProvider
 *            {@link IContentProposalCandidateProvider} providing the
 *            candidates eligible for creating {@link IContentProposal}s
 * @param factory
 *            {@link IContentProposalFactory} to use to create proposals
 *            from candidates
 * @param patternProvider
 *            to convert the current text of the field into a pattern
 *            suitable for filtering the candidates. If {@code null}, a
 *            default pattern is constructed using
 *            {@link #createProposalPattern(String)}.
 * @param startTypingMessage
 *            hover message if no content assist key binding is active
 * @param shortcutMessage
 *            hover message if a content assist key binding is active,
 *            should have a "{0}" placeholder that will be filled by the
 *            appropriate keystroke
 * @return the content proposal adapter set on the {@code textField}
 */
public static final <T> ExplicitContentProposalAdapter addContentProposalToText(Text textField, IContentProposalCandidateProvider<T> candidateProvider, IContentProposalFactory<T> factory, Function<String, Pattern> patternProvider, String startTypingMessage, String shortcutMessage) {
    KeyStroke stroke = UIUtils.getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
    if (stroke == null) {
        if (startTypingMessage == null) {
            return null;
        }
        addBulbDecorator(textField, startTypingMessage);
    } else {
        addBulbDecorator(textField, NLS.bind(shortcutMessage, stroke.format()));
    }
    IContentProposalProvider cp = new IContentProposalProvider() {

        @Override
        public IContentProposal[] getProposals(String contents, int position) {
            List<IContentProposal> resultList = new ArrayList<>();
            Collection<? extends T> candidates = candidateProvider.getCandidates();
            if (candidates == null) {
                return null;
            }
            Pattern pattern = patternProvider != null ? patternProvider.apply(contents) : createProposalPattern(contents);
            for (final T candidate : candidates) {
                IContentProposal proposal = factory.getProposal(pattern, candidate);
                if (proposal != null) {
                    resultList.add(proposal);
                }
            }
            return resultList.toArray(new IContentProposal[resultList.size()]);
        }
    };
    ExplicitContentProposalAdapter adapter = new ExplicitContentProposalAdapter(textField, new TextContentAdapter(), cp, stroke, UIUtils.VALUE_HELP_ACTIVATIONCHARS);
    // set the acceptance style to always replace the complete content
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    return adapter;
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) Pattern(java.util.regex.Pattern) SWT(org.eclipse.swt.SWT) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) ArrayList(java.util.ArrayList) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter)

Example 24 with TextContentAdapter

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

the class RefSpecPanel method createRefCellEditor.

private CellEditor createRefCellEditor(final Table table, final IContentProposalProvider proposalProvider) {
    final CellEditor cellEditor = new TextCellEditor(table);
    final Text text = (Text) cellEditor.getControl();
    final ContentAssistCommandAdapter assist = new ContentAssistCommandAdapter(text, new TextContentAdapter(), proposalProvider, null, null, true);
    assist.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    return cellEditor;
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ContentAssistCommandAdapter(org.eclipse.ui.fieldassist.ContentAssistCommandAdapter) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter)

Example 25 with TextContentAdapter

use of org.eclipse.jface.fieldassist.TextContentAdapter in project mechanoid by robotoworks.

the class PackageBrowserField method attachProposalProvider.

private void attachProposalProvider() {
    try {
        mProposalProvider = new PackageProposalProvider();
        mPackageProposalAdapter = new ContentProposalAdapter(getTextField(), new TextContentAdapter(), mProposalProvider, KeyStroke.getInstance("Ctrl+Space"), new char[] { '.' });
        mPackageProposalAdapter.setLabelProvider(new LabelProvider() {

            @Override
            public Image getImage(Object element) {
                return mPackageImage;
            }

            @Override
            public String getText(Object element) {
                PackageProposal p = (PackageProposal) element;
                return p.getContent();
            }
        });
        mPackageProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
Also used : ParseException(org.eclipse.jface.bindings.keys.ParseException) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) Image(org.eclipse.swt.graphics.Image) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Aggregations

TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)25 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)12 Text (org.eclipse.swt.widgets.Text)11 SimpleContentProposalProvider (org.eclipse.jface.fieldassist.SimpleContentProposalProvider)10 GridData (org.eclipse.swt.layout.GridData)10 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)7 Label (org.eclipse.swt.widgets.Label)7 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 ModifyListener (org.eclipse.swt.events.ModifyListener)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)5 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)4 Button (org.eclipse.swt.widgets.Button)4 Composite (org.eclipse.swt.widgets.Composite)4 SWT (org.eclipse.swt.SWT)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Pattern (java.util.regex.Pattern)2