use of org.eclipse.jface.fieldassist.AutoCompleteField in project jbosstools-openshift by jbosstools.
the class SelectProjectComponentBuilder method build.
public void build(Composite container, DataBindingContext dbc) {
Label existingProjectLabel = new Label(container, SWT.NONE);
existingProjectLabel.setText("Eclipse Project: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(existingProjectLabel);
final Text existingProjectNameText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(hSpan, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(existingProjectNameText);
projectNameTextObservable = WidgetProperties.text(SWT.Modify).observe(existingProjectNameText);
Binding eclipseProjectBinding = ValueBindingBuilder.bind(projectNameTextObservable).validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
if (value instanceof String) {
return ValidationStatus.ok();
} else if (value == null) {
if (required) {
return ValidationStatus.error("Select an existing project");
} else if (!StringUtils.isEmpty(existingProjectNameText.getText())) {
return ValidationStatus.error(NLS.bind("Project {0} does not exist", existingProjectNameText.getText()));
}
}
return ValidationStatus.ok();
}
}).converting(new Converter(String.class, IProject.class) {
@Override
public Object convert(Object fromObject) {
String name = (String) fromObject;
return ProjectUtils.getProject(name);
}
}).to(eclipseProjectObservable).converting(new Converter(IProject.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject == null ? "" : ((IProject) fromObject).getName();
}
}).in(dbc);
ControlDecorationSupport.create(eclipseProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
// project name content assist
ControlDecoration dec = new ControlDecoration(existingProjectNameText, SWT.TOP | SWT.RIGHT);
FieldDecoration contentProposalFieldIndicator = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
dec.setImage(contentProposalFieldIndicator.getImage());
dec.setDescriptionText("Auto-completion is enabled when you start typing a project name.");
dec.setShowOnlyOnFocus(true);
new AutoCompleteField(existingProjectNameText, new TextContentAdapter(), ProjectUtils.getAllAccessibleProjectNames());
// browse projects
Button browseProjectsButton = new Button(container, SWT.NONE);
browseProjectsButton.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).indent(buttonIndent, 0).applyTo(browseProjectsButton);
UIUtils.setDefaultButtonWidth(browseProjectsButton);
browseProjectsButton.addSelectionListener(selectionListener);
}
use of org.eclipse.jface.fieldassist.AutoCompleteField 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);
}
Aggregations