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