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;
}
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()]));
}
}
}
};
}
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);
}
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);
}
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);
}
}
Aggregations