Search in sources :

Example 6 with IContentProposalProvider

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

the class ExpressionProposalProvider method getProposals.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
     */
public IContentProposal[] getProposals(String contents, int position) {
    List<IContentProposal> proposals = new ArrayList<IContentProposal>();
    TableEntryLocation sourceEntryLocation = new TableEntryLocation();
    // Proposals based on process context
    for (IDataMapTable table : this.tables) {
        // proposals.add(new TableContentProposal(table, this.currentLanguage));
        List<IColumnEntry> dataMapTableEntries = table.getColumnEntries();
        for (IColumnEntry entrySource : dataMapTableEntries) {
            sourceEntryLocation.tableName = entrySource.getParentName();
            sourceEntryLocation.columnName = entrySource.getName();
            if (mapperManager.getUiManager().checkSourceLocationIsValid(entrySource, currentModifiedEntry)) {
                proposals.add(new EntryContentProposal(entrySource, this.currentLanguage));
            }
        }
    }
    for (IContentProposalProvider contentProposalProvider : otherContentProposalProviders) {
        proposals.addAll(Arrays.asList(contentProposalProvider.getProposals(contents, position)));
    }
    IContentProposal[] res = new IContentProposal[proposals.size()];
    res = proposals.toArray(res);
    return res;
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) ArrayList(java.util.ArrayList) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry)

Example 7 with IContentProposalProvider

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

the class UIUtils method addPreviousValuesContentProposalToText.

/**
 * Adds a "previously used values" content proposal handler to a text field.
 * <p>
 * The list will be limited to 10 values.
 *
 * @param textField
 *            the text field
 * @param preferenceKey
 *            the key under which to store the "previously used values" in
 *            the dialog settings
 * @return the handler the proposal handler
 */
public static IPreviousValueProposalHandler addPreviousValuesContentProposalToText(final Text textField, final String preferenceKey) {
    KeyStroke stroke = UIUtils.getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
    if (stroke == null)
        addBulbDecorator(textField, UIText.UIUtils_StartTypingForPreviousValuesMessage);
    else
        addBulbDecorator(textField, NLS.bind(UIText.UIUtils_PressShortcutMessage, stroke.format()));
    IContentProposalProvider cp = new IContentProposalProvider() {

        @Override
        public IContentProposal[] getProposals(String contents, int position) {
            List<IContentProposal> resultList = new ArrayList<>();
            Pattern pattern = createProposalPattern(contents);
            String[] proposals = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings().getArray(preferenceKey);
            if (proposals != null) {
                for (final String uriString : proposals) {
                    if (pattern != null && !pattern.matcher(uriString).matches()) {
                        continue;
                    }
                    IContentProposal propsal = new IContentProposal() {

                        @Override
                        public String getLabel() {
                            return null;
                        }

                        @Override
                        public String getDescription() {
                            return null;
                        }

                        @Override
                        public int getCursorPosition() {
                            return 0;
                        }

                        @Override
                        public String getContent() {
                            return uriString;
                        }
                    };
                    resultList.add(propsal);
                }
            }
            return resultList.toArray(new IContentProposal[resultList.size()]);
        }
    };
    ContentProposalAdapter adapter = new ContentProposalAdapter(textField, new TextContentAdapter(), cp, stroke, VALUE_HELP_ACTIVATIONCHARS);
    // set the acceptance style to always replace the complete content
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    return new IPreviousValueProposalHandler() {

        @Override
        public void updateProposals() {
            String value = textField.getText();
            // don't store empty values
            if (value.length() > 0) {
                // we don't want to save too much in the preferences
                if (value.length() > 2000) {
                    value = value.substring(0, 1999);
                }
                // now we need to mix the value into the list
                IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
                String[] existingValues = settings.getArray(preferenceKey);
                if (existingValues == null) {
                    existingValues = new String[] { value };
                    settings.put(preferenceKey, existingValues);
                } else {
                    List<String> values = new ArrayList<>(existingValues.length + 1);
                    for (String existingValue : existingValues) values.add(existingValue);
                    // anything
                    if (values.indexOf(value) == 0)
                        return;
                    values.remove(value);
                    // we insert at the top
                    values.add(0, value);
                    // of values
                    while (values.size() > 10) values.remove(values.size() - 1);
                    settings.put(preferenceKey, values.toArray(new String[values.size()]));
                }
            }
        }
    };
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke)

Example 8 with IContentProposalProvider

use of org.eclipse.jface.fieldassist.IContentProposalProvider in project tdq-studio-se by Talend.

the class AbstractMetadataFormPage method installProposals.

/**
 * install proposal on the control.
 *
 * @param control
 */
public void installProposals(Control control) {
    IContentProposalProvider cpp = new TdqProposalProvider((SupportContextEditor) currentEditor);
    ProposalUtils.getCommonProposal(control, cpp);
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) TdqProposalProvider(org.talend.dataprofiler.core.ui.views.proposal.TdqProposalProvider)

Example 9 with IContentProposalProvider

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

the class StyledTextHandler method setSelectedNodePart.

public void setSelectedNodePart(TableEntityPart selectedNode) {
    this.selectedNodePart = selectedNode;
    this.selectedNode = (AbstractNode) selectedNodePart.getModel();
    IContentProposalProvider[] contentProposalProviders = new IContentProposalProvider[0];
    contentProposalProviders = new IContentProposalProvider[] { new TalendProposalProvider(mapperManager.getMapperComponent().getProcess()) };
    ExpressionProposalProvider provider = new ExpressionProposalProvider(mapperManager, contentProposalProviders);
    provider.init(selectedNode);
    getContentProposalAdapter().setContentProposalProvider(provider);
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) TalendProposalProvider(org.talend.core.ui.proposal.TalendProposalProvider) ExpressionProposalProvider(org.talend.designer.xmlmap.parts.directedit.proposal.ExpressionProposalProvider)

Example 10 with IContentProposalProvider

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

the class SQLBuilderEditorComposite method createEditorProposal.

/**
     * Creates proposal for editor.
     */
private void createEditorProposal() {
    try {
        // create KeyStroke use Ctrl+Space as default
        KeyStroke keyStroke = HotKeyUtil.getHotKey(HotKeyUtil.contentAssist);
        IControlContentAdapter controlContentAdapter = new StyledTextContentAdapter();
        IContentProposalProvider contentProposalProvider = new SQLEditorProposalProvider(repositoryNode, language);
        SQLEditorProposalAdapter contentProposalAdapter = new SQLEditorProposalAdapter(colorText, controlContentAdapter, contentProposalProvider, keyStroke, new char[] { ' ', '.' });
        contentProposalAdapter.setPropagateKeys(true);
        contentProposalAdapter.setFilterStyle(ContentProposalAdapter.FILTER_CUMULATIVE);
        contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        contentProposalAdapter.setLabelProvider(new SQLEditorLabelProvider());
        contentProposalAdapter.setAutoActivationDelay(10);
        contentProposalAdapter.setPopupSize(new Point(300, 200));
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("SQLBuilderEditorComposite.logMessage"), e);
    }
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) SQLEditorLabelProvider(org.talend.sqlbuilder.ui.proposal.SQLEditorLabelProvider) SQLEditorProposalAdapter(org.talend.sqlbuilder.ui.proposal.SQLEditorProposalAdapter) IControlContentAdapter(org.eclipse.jface.fieldassist.IControlContentAdapter) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) StyledTextContentAdapter(org.talend.commons.ui.swt.proposal.StyledTextContentAdapter) Point(org.eclipse.swt.graphics.Point) SQLEditorProposalProvider(org.talend.sqlbuilder.ui.proposal.SQLEditorProposalProvider)

Aggregations

IContentProposalProvider (org.eclipse.jface.fieldassist.IContentProposalProvider)11 ArrayList (java.util.ArrayList)5 IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)5 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)4 Pattern (java.util.regex.Pattern)2 IControlContentAdapter (org.eclipse.jface.fieldassist.IControlContentAdapter)2 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)2 Point (org.eclipse.swt.graphics.Point)2 StyledTextContentAdapter (org.talend.commons.ui.swt.proposal.StyledTextContentAdapter)2 TalendProposalProvider (org.talend.core.ui.proposal.TalendProposalProvider)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)2 ExpressionProposalProvider (org.talend.designer.xmlmap.parts.directedit.proposal.ExpressionProposalProvider)2 SQLEditorLabelProvider (org.talend.sqlbuilder.ui.proposal.SQLEditorLabelProvider)2 SQLEditorProposalAdapter (org.talend.sqlbuilder.ui.proposal.SQLEditorProposalAdapter)2 SQLEditorProposalProvider (org.talend.sqlbuilder.ui.proposal.SQLEditorProposalProvider)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)1 SWT (org.eclipse.swt.SWT)1 ContentProposalAdapterExtended (org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended)1