Search in sources :

Example 1 with AutoCompleteField

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);
}
Also used : Binding(org.eclipse.core.databinding.Binding) IStatus(org.eclipse.core.runtime.IStatus) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) AutoCompleteField(org.eclipse.jface.fieldassist.AutoCompleteField) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) Converter(org.eclipse.core.databinding.conversion.Converter)

Example 2 with AutoCompleteField

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

Aggregations

AutoCompleteField (org.eclipse.jface.fieldassist.AutoCompleteField)2 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)2 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)2 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 Binding (org.eclipse.core.databinding.Binding)1 Converter (org.eclipse.core.databinding.conversion.Converter)1 IValidator (org.eclipse.core.databinding.validation.IValidator)1 IStatus (org.eclipse.core.runtime.IStatus)1 FieldDecorationRegistry (org.eclipse.jface.fieldassist.FieldDecorationRegistry)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1