Example usage for org.eclipse.jface.databinding.swt SWTObservables observeText

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeText

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables observeText.

Prototype

@Deprecated
public static ISWTObservableValue observeText(Control control, int event) 

Source Link

Document

Returns an observable observing the text attribute of the provided control.

Usage

From source file:org.eclipse.jubula.client.ui.rcp.wizards.pages.ExportTestResultDetailsDestinationWizardPage.java

License:Open Source License

/**
 * {@inheritDoc}//from w w  w . j  av a  2 s  .c  om
 */
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    DataBindingContext dbc = new DataBindingContext();

    // destination specification group
    Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    destinationSelectionGroup.setLayout(layout);
    destinationSelectionGroup
            .setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
    destinationLabel.setText(Messages.ExportTestResultDetailsWizardDestinationPageDestinationLabelText);
    // destination name entry field
    final Text destinationNameField = new Text(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    destinationNameField.setLayoutData(data);
    UpdateValueStrategy targetToModelUpdateStrategy = new UpdateValueStrategy(
            UpdateValueStrategy.POLICY_UPDATE);
    targetToModelUpdateStrategy.setAfterGetValidator(new IValidator() {
        public IStatus validate(Object value) {
            String stringValue = String.valueOf(value);
            if (!FileUtils.isValidPath(stringValue)) {
                return ValidationStatus.error(Messages.ExportTestResultDetailsWizardDestinationPageInvDest);
            }
            return ValidationStatus.ok();
        }
    });

    dbc.bindValue(SWTObservables.observeText(destinationNameField, SWT.Modify),
            PojoObservables.observeValue(this, PROP_NAME_DESTINATION), targetToModelUpdateStrategy,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));

    try {
        destinationNameField.setText(new File(Utils.getLastDirPath()).getCanonicalPath());
    } catch (IOException ioe) {
        LOG.error(Messages.AnErrorOccurredWhileInitializingTheDestinationPath + StringConstants.DOT, ioe);
    }

    // destination browse button
    Button destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
    destinationBrowseButton.setText(Messages.ExportTestResultDetailsWizardDestinationPageBrowseBtnText);
    destinationBrowseButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            final DirectoryDialog fileDialog = new DirectoryDialog(getWizard().getContainer().getShell(),
                    SWT.SAVE | SWT.APPLICATION_MODAL);
            fileDialog.setText(Messages.ExportTestResultDetailsWizardDestinationPageDialogTitle);
            fileDialog.setFilterPath(Utils.getLastDirPath());
            String newFileName = fileDialog.open();
            if (newFileName != null) {
                Utils.storeLastDirPath(newFileName);
                destinationNameField.setText(newFileName);
            }
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }
    });
    setButtonLayoutData(destinationBrowseButton);
    setControl(parent);
    WizardPageSupport.create(this, dbc);
}

From source file:org.eclipse.jubula.client.ui.wizards.pages.DatabaseConnectionWizardPage.java

License:Open Source License

/**
 * //from   w ww .  j  av a  2s  . c o  m
 * {@inheritDoc}
 */
public void createControl(Composite parent) {
    setTitle(I18n.getString("DatabaseConnectionWizardPage.title")); //$NON-NLS-1$
    setDescription(I18n.getString("DatabaseConnectionWizardPage.description")); //$NON-NLS-1$
    final DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);
    GridDataFactory textGridDataFactory = GridDataFactory.fillDefaults().grab(true, false);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
    setControl(composite);

    UIComponentHelper.createLabel(composite, I18n.getString("DatabaseConnection.Name"), SWT.NONE); //$NON-NLS-1$
    Text nameText = new Text(composite, SWT.BORDER);
    DialogUtils.setWidgetName(nameText, "DatabaseConnection.Name"); //$NON-NLS-1$
    nameText.setLayoutData(textGridDataFactory.create());
    dbc.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
            BeansObservables.observeValue(m_connectionToEdit, DatabaseConnection.PROP_NAME_NAME),
            new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
                public IStatus validate(Object value) {
                    if (StringUtils.isEmpty((String) value)) {
                        return ValidationStatus
                                .error(I18n.getString("DatabaseConnectionWizardPage.Error.emptyName")); //$NON-NLS-1$
                    }
                    return ValidationStatus.ok();
                }
            }), new UpdateValueStrategy());
    nameText.setFocus();
    nameText.selectAll();

    UIComponentHelper.createLabel(composite, I18n.getString("DatabaseConnection.Type"), SWT.NONE); //$NON-NLS-1$
    ComboViewer typeComboViewer = new ComboViewer(composite);
    DialogUtils.setWidgetName(typeComboViewer.getControl(), "DatabaseConnection.Type"); //$NON-NLS-1$
    typeComboViewer.setContentProvider(new ArrayContentProvider());
    typeComboViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((IDetailAreaBuilder) element).getTypeName();
        }
    });
    typeComboViewer.setInput(m_detailAreaBuilders);
    typeComboViewer.getControl().setLayoutData(textGridDataFactory.create());

    final Composite detailArea = createDetailArea(composite, nameText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    DialogUtils.setWidgetName(detailArea, "DatabaseConnection.DetailArea"); //$NON-NLS-1$

    IObservableValue connectionInfoObservable = BeansObservables.observeValue(m_connectionToEdit,
            DatabaseConnection.PROP_NAME_CONN_INFO);

    bindComboViewer(dbc, typeComboViewer, detailArea, connectionInfoObservable);

    Text url = new Text(composite, SWT.BORDER);
    DialogUtils.setWidgetName(url, "DatabaseConnection.URL"); //$NON-NLS-1$
    url.setEditable(false);
    url.setBackground(composite.getBackground());
    url.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    dbc.bindValue(SWTObservables.observeText(url), BeansObservables.observeDetailValue(connectionInfoObservable,
            DatabaseConnectionInfo.PROP_NAME_CONN_URL, null));

    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
            ContextHelpIds.DATABASE_CONNECTION_CONFIGURATION_DIALOG);
}

From source file:org.eclipse.libra.facet.ui.wizards.OSGiBundleFacetInstallPage.java

License:Open Source License

public void createControl(Composite parent) {
    DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);

    Composite container = new Composite(parent, SWT.NONE);

    Label symbolicNameLabel = new Label(container, SWT.NONE);
    symbolicNameLabel.setText(Messages.OSGiBundleFacetInstallPage_SymbolicName);
    Text symbolicNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    dbc.bindValue(SWTObservables.observeText(symbolicNameText, SWT.Modify), config.getSymbolicNameValue(),
            new UpdateValueStrategy()
                    .setAfterConvertValidator(new OSGiBundleFacetInstallConfig.SymbolicNameValidator()),
            null);/*  w w w .  j ava2 s.co  m*/

    Label versionLabel = new Label(container, SWT.NONE);
    versionLabel.setText(Messages.OSGiBundleFacetInstallPage_Version);
    Text versionText = new Text(container, SWT.BORDER | SWT.SINGLE);
    dbc.bindValue(SWTObservables.observeText(versionText, SWT.Modify), config.getVersionValue(),
            new UpdateValueStrategy()
                    .setAfterConvertValidator(new OSGiBundleFacetInstallConfig.VersionValidator()),
            null);

    Label nameLabel = new Label(container, SWT.NONE);
    nameLabel.setText(Messages.OSGiBundleFacetInstallPage_Name);
    Text nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    dbc.bindValue(SWTObservables.observeText(nameText, SWT.Modify), config.getNameValue(), null, null);

    Label vendorLabel = new Label(container, SWT.NONE);
    vendorLabel.setText(Messages.OSGiBundleFacetInstallPage_Vendor);
    Text vendorText = new Text(container, SWT.BORDER | SWT.SINGLE);
    dbc.bindValue(SWTObservables.observeText(vendorText, SWT.Modify), config.getVendorValue(), null, null);

    GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(container);
    setControl(container);
    Dialog.applyDialogFont(container);
}

From source file:org.eclipse.mylyn.commons.repositories.ui.RepositoryLocationPart.java

License:Open Source License

protected void bind(Text text, String property, UpdateValueStrategy targetObservableValue,
        UpdateValueStrategy modelObservableValue) {
    ISWTObservableValue uiElement = SWTObservables.observeText(text, SWT.Modify);
    IObservableValue modelElement = new RepositoryLocationValueProperty(property, null).observe(workingCopy);
    bindingContext.bindValue(uiElement, modelElement, targetObservableValue, modelObservableValue);
}

From source file:org.eclipse.mylyn.internal.docs.epub.ui.MainPage.java

License:Open Source License

protected DataBindingContext initDataBindings() {

    DataBindingContext bindingContext = new DataBindingContext();
    ////from   w w  w .j  a  v a 2  s. c  o  m
    IObservableValue textObserveTextObserveWidget = SWTObservables.observeText(titleText, SWT.Modify);
    final IObservableValue beanTitleObserveValue = PojoObservables.observeValue(bean, "title"); //$NON-NLS-1$
    UpdateValueStrategy titleStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    titleStrategy.setBeforeSetValidator(new StringValidator("A title must be specified", titleText)); //$NON-NLS-1$
    bindingContext.bindValue(textObserveTextObserveWidget, beanTitleObserveValue, titleStrategy, null);
    //
    IObservableValue text_3ObserveTextObserveWidget = SWTObservables.observeText(authorText, SWT.Modify);
    final IObservableValue beanCreatorObserveValue = PojoObservables.observeValue(bean, "creator"); //$NON-NLS-1$
    UpdateValueStrategy authorStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    authorStrategy.setBeforeSetValidator(new StringValidator("An author must be specified", authorText)); //$NON-NLS-1$
    bindingContext.bindValue(text_3ObserveTextObserveWidget, beanCreatorObserveValue, authorStrategy, null);
    //
    IObservableValue dateTimeObserveSelectionObserveWidget = SWTObservables.observeSelection(dateTime);
    final IObservableValue beanPublicationDateObserveValue = PojoObservables.observeValue(bean,
            "publicationDate"); //$NON-NLS-1$
    bindingContext.bindValue(dateTimeObserveSelectionObserveWidget, beanPublicationDateObserveValue, null,
            null);
    //
    IObservableValue text_4ObserveTextObserveWidget = SWTObservables.observeText(identifierText, SWT.Modify);
    final IObservableValue beanIdentifierObserveValue = PojoObservables.observeValue(bean, "identifier"); //$NON-NLS-1$
    UpdateValueStrategy identifierStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    identifierStrategy
            .setBeforeSetValidator(new StringValidator("An identifier must be specified", identifierText)); //$NON-NLS-1$
    bindingContext.bindValue(text_4ObserveTextObserveWidget, beanIdentifierObserveValue, identifierStrategy,
            null);
    //
    IObservableValue schemeTextObserveTextObserveWidget = SWTObservables.observeText(schemeText);
    final IObservableValue beanIdSchemeObserveValue = PojoObservables.observeValue(bean, "scheme"); //$NON-NLS-1$
    UpdateValueStrategy schemeStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    schemeStrategy
            .setBeforeSetValidator(new StringValidator("An identifier scheme must be specified", schemeText)); //$NON-NLS-1$
    bindingContext.bindValue(schemeTextObserveTextObserveWidget, beanIdSchemeObserveValue, schemeStrategy,
            null);
    //
    IObservableValue text_1ObserveTextObserveWidget = SWTObservables.observeText(copyrightText, SWT.Modify);
    final IObservableValue beanRightsObserveValue = PojoObservables.observeValue(bean, "rights"); //$NON-NLS-1$
    UpdateValueStrategy rightsStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    rightsStrategy.setBeforeSetValidator(new StringValidator("Rights must be specified", copyrightText)); //$NON-NLS-1$
    bindingContext.bindValue(text_1ObserveTextObserveWidget, beanRightsObserveValue, rightsStrategy, null);
    //
    IObservableValue comboObserveTextObserveWidget = SWTObservables.observeText(combo);
    final IObservableValue beanLanguageObserveValue = PojoObservables.observeValue(bean, "language"); //$NON-NLS-1$
    UpdateValueStrategy languageStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    languageStrategy.setBeforeSetValidator(new StringValidator("A language must be specified", combo)); //$NON-NLS-1$
    bindingContext.bindValue(comboObserveTextObserveWidget, beanLanguageObserveValue, languageStrategy, null);
    //
    IObservableValue subjectTextObserveTextObserveWidget = SWTObservables.observeText(subjectText, SWT.Modify);
    final IObservableValue beanSubjectObserveValue = PojoObservables.observeValue(bean, "subject"); //$NON-NLS-1$
    UpdateValueStrategy subjectStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    subjectStrategy.setBeforeSetValidator(new StringValidator("A subject must be specified", subjectText)); //$NON-NLS-1$
    bindingContext.bindValue(subjectTextObserveTextObserveWidget, beanSubjectObserveValue, subjectStrategy,
            null);
    //
    IObservableValue coverObserveTextObserveWidget = SWTObservables.observeText(coverText, SWT.Modify);
    IObservableValue beanCoverObserveValue = PojoObservables.observeValue(bean, "cover"); //$NON-NLS-1$
    UpdateValueStrategy coverStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    coverStrategy.setBeforeSetValidator(new FileValidator(
            "The cover image must be a valid image file of type PNG, SVG or JPEG.", coverText, new String[] { //$NON-NLS-1$
                    ".png", ".svg", ".jpeg", ".jpg" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    bindingContext.bindValue(coverObserveTextObserveWidget, beanCoverObserveValue, coverStrategy, null);
    //
    IObservableValue styleSheetTextObserveTextObserveWidget = SWTObservables.observeText(styleSheetText,
            SWT.Modify);
    IObservableValue beanStyleSheetObserveValue = PojoObservables.observeValue(bean, "styleSheet"); //$NON-NLS-1$
    UpdateValueStrategy styleSheetStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    styleSheetStrategy.setBeforeSetValidator(new FileValidator("The style sheet must be a valid CSS file.", //$NON-NLS-1$
            styleSheetText, new String[] { ".css" })); //$NON-NLS-1$
    bindingContext.bindValue(styleSheetTextObserveTextObserveWidget, beanStyleSheetObserveValue,
            styleSheetStrategy, null);
    //
    return bindingContext;
}

From source file:org.eclipse.pde.ds.ui.internal.editor.wizard.NewPropertyPage.java

License:Open Source License

public void createControl(Composite parent) {

    propertyComposite = new PropertyComposite(parent, SWT.NULL);

    EditingDomain ed = ((AddPropertiesWizard) getWizard()).getEditingDomain();

    p = ScrFactory.eINSTANCE.createProperty();
    setControl(propertyComposite);//from   ww  w. j a va2s.co m

    //binding
    DataBindingContext bindingContext = new DataBindingContext();
    WizardPageSupport.create(this, bindingContext);

    IObservableValue iov = new WritableValue();
    iov.setValue(p);
    //Name
    bindingContext.bindValue(SWTObservables.observeText(propertyComposite.getTextName(), SWT.Modify),
            EMFEditProperties.value(ed, ScrPackage.eINSTANCE.getProperty_Name()).observeDetail(iov),
            new EMFUpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    if (value != null && !"".equals((String) value)) //$NON-NLS-1$
                        setPageComplete(true);
                    return super.convert(value);
                }
            }, null);

    //Value
    bindingContext.bindValue(SWTObservables.observeText(propertyComposite.getTextValue(), SWT.FocusOut),
            EMFEditProperties.value(ed, ScrPackage.eINSTANCE.getProperty_Value()).observeDetail(iov), null,
            null);
}

From source file:org.eclipse.rap.demo.databinding.nestedselection.TestMasterDetailView.java

License:Open Source License

private void bind(final Control parent) {
    Realm realm = SWTObservables.getRealm(parent.getDisplay());
    TableViewer peopleViewer = new TableViewer(personsTable);
    ObservableListContentProvider peopleViewerContent = new ObservableListContentProvider();
    peopleViewer.setContentProvider(peopleViewerContent);

    String[] attrSimplePerson = new String[] { "name", "state" };
    IObservableMap[] attributeMaps = BeansObservables.observeMaps(peopleViewerContent.getKnownElements(),
            SimplePerson.class, attrSimplePerson);
    ObservableMapLabelProvider omlProvider = new ObservableMapLabelProvider(attributeMaps);
    peopleViewer.setLabelProvider(omlProvider);
    peopleViewer.setInput(new WritableList(realm, model.getPersonList(), SimpleModel.class));
    IObservableValue selectedPerson = ViewersObservables.observeSingleSelection(peopleViewer);
    DataBindingContext dbc = new DataBindingContext(realm) {
        protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(IObservableValue fromValue,
                IObservableValue toValue) {
            return new CustomUpdateValueStrategy();
        }/*  w w w.  j  a  v a 2 s.  co m*/
    };
    IConverter upperCaseConverter = new IConverter() {
        public Object convert(Object fromObject) {
            return ((String) fromObject).toUpperCase();
        }

        public Object getFromType() {
            return String.class;
        }

        public Object getToType() {
            return String.class;
        }
    };
    IValidator vowelValidator = new IValidator() {
        public IStatus validate(Object value) {
            String s = (String) value;
            if (!s.matches("[aeiouAEIOU]*")) {
                return ValidationStatus.error("only vowels allowed");
            }
            return Status.OK_STATUS;
        }
    };

    IObservableValue modelObservableValue = BeansObservables.observeDetailValue(realm, selectedPerson, "name",
            String.class);
    ISWTObservableValue targetObservableValue = SWTObservables.observeText(name, SWT.Modify);
    CustomUpdateValueStrategy customUpdateValueStrategy = new CustomUpdateValueStrategy();
    customUpdateValueStrategy.setConverter(upperCaseConverter);
    UpdateValueStrategy targetToModel = customUpdateValueStrategy.setAfterGetValidator(vowelValidator);
    Binding binding = dbc.bindValue(targetObservableValue, modelObservableValue, targetToModel, null);

    UpdateValueStrategy updateValueStrategy = new UpdateValueStrategy();
    updateValueStrategy.setConverter(new ObjectToStringConverter());
    dbc.bindValue(SWTObservables.observeText(validationStatus, SWT.NONE), binding.getValidationStatus(), null,
            updateValueStrategy);
    dbc.bindValue(SWTObservables.observeText(address, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "address", String.class), null, null);
    dbc.bindValue(SWTObservables.observeText(city, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "city", String.class), null, null);
    dbc.bindValue(SWTObservables.observeText(state, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "state", String.class), null, null);
    TableViewer ordersViewer = new TableViewer(ordersTable);
    ObservableListContentProvider ordersViewerContent = new ObservableListContentProvider();
    ordersViewer.setContentProvider(ordersViewerContent);
    String[] propertyNames = new String[] { "orderNumber", "date" };
    IObservableMap[] observeMaps = BeansObservables.observeMaps(ordersViewerContent.getKnownElements(),
            SimpleOrder.class, propertyNames);
    ObservableMapLabelProvider observableMapLabelProvider = new ObservableMapLabelProvider(observeMaps);
    ordersViewer.setLabelProvider(observableMapLabelProvider);
    IObservableList orders = BeansObservables.observeDetailList(realm, selectedPerson, "orders",
            SimpleOrder.class);
    ordersViewer.setInput(orders);
}

From source file:org.eclipse.rap.demo.databinding.Snippet000HelloWorld.java

License:Open Source License

public void createPartControl() {
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = DatabindingSnippetsView.GROUP_MARGIN_HEIGHT;
    formLayout.marginWidth = DatabindingSnippetsView.GROUP_MARGIN_WIDTH;
    setLayout(formLayout);/*from  w ww .java 2 s.c  o  m*/
    setText("Hello World Snippet 0001 - Binding Example");
    // Info Label
    Label info1 = new Label(this, SWT.NONE);
    info1.setText("This Textbox is linked to the Model (Person/Name). "
            + "If you type in a text, it automatically updates " + "the name property of the model");
    FormData data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info1.setLayoutData(data);
    name = new Text(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(info1, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    name.setLayoutData(data);
    Label info2 = new Label(this, SWT.NONE);
    info2.setText("This Label is also linked (readonly) to the Model." + " It gets updated on all changes");
    data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(name, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info2.setLayoutData(data);
    labelName = new Label(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(info2, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    labelName.setLayoutData(data);
    labelName.setText("not changed yet...");

    Realm realm = SWTObservables.getRealm(Display.getCurrent());
    DataBindingContext bindingContext = new DataBindingContext(realm);
    Person person = viewModel.getPerson();
    bindingContext.bindValue(SWTObservables.observeText(name, SWT.Modify),
            BeansObservables.observeValue(realm, person, "name"), null, null);
    bindingContext.bindValue(SWTObservables.observeText(labelName),
            BeansObservables.observeValue(realm, person, "name"), null, null);
}

From source file:org.eclipse.rap.demo.databinding.Snippet001NestedSelectionWithCombo.java

License:Open Source License

public void createPartControl() {
    // Initiating the realm
    Realm realm = SWTObservables.getRealm(Display.getCurrent());

    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = DatabindingSnippetsView.GROUP_MARGIN_HEIGHT;
    formLayout.marginWidth = DatabindingSnippetsView.GROUP_MARGIN_WIDTH;
    setLayout(formLayout);// w  ww.j a va 2s .  co  m
    setText("Nested Selection Snippet 001 - Binding Example");
    // Info Label
    Label info1 = new Label(this, SWT.NONE);
    info1.setText("This snippet demonstrates the databinding" + " using a Lists and Combos");
    FormData data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info1.setLayoutData(data);
    Label info2 = new Label(this, SWT.NONE);
    info2.setText("Modifications in the TextBox and the" + " Combobox will update the model "
            + "(for the selection in the list).");
    data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(info1, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info2.setLayoutData(data);
    List peopleList = new List(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH, SWT.DEFAULT);
    data.top = new FormAttachment(info2, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    peopleList.setLayoutData(data);
    ListViewer peopleListViewer = new ListViewer(peopleList);
    IObservableSet staticObservableSet = Observables.staticObservableSet(realm,
            new HashSet(viewModel.getPeople()));
    IObservableMap attributeMap = BeansObservables.observeMap(staticObservableSet, Person.class, "name");
    ObservableMapLabelProvider omlProvider = new ObservableMapLabelProvider(attributeMap);
    peopleListViewer.setLabelProvider(omlProvider);
    peopleListViewer.setContentProvider(new ArrayContentProvider());
    peopleListViewer.setInput(viewModel.getPeople());
    Text name = new Text(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH, SWT.DEFAULT);
    data.top = new FormAttachment(peopleList, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    name.setLayoutData(data);
    Combo city = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH, SWT.DEFAULT);
    data.top = new FormAttachment(name, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    city.setLayoutData(data);

    DataBindingContext dbc = new DataBindingContext(realm);
    IObservableValue selectedPerson = ViewersObservables.observeSingleSelection(peopleListViewer);
    dbc.bindValue(SWTObservables.observeText(name, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "name", String.class), null, null);
    ComboViewer cityViewer = new ComboViewer(city);
    cityViewer.setContentProvider(new ArrayContentProvider());
    cityViewer.setInput(viewModel.getCities());
    IObservableValue citySelection = ViewersObservables.observeSingleSelection(cityViewer);
    dbc.bindValue(citySelection,
            BeansObservables.observeDetailValue(realm, selectedPerson, "city", String.class), null, null);
}

From source file:org.eclipse.rap.demo.databinding.Snippet004DataBindingContextErrorLabel.java

License:Open Source License

public void createPartControl() {
    // Initiating the realm
    Realm realm = SWTObservables.getRealm(Display.getCurrent());
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = DatabindingSnippetsView.GROUP_MARGIN_HEIGHT;
    formLayout.marginWidth = DatabindingSnippetsView.GROUP_MARGIN_WIDTH;
    setLayout(formLayout);/*from   w  w w .j  a  va  2 s  .c  o m*/
    setText("Context Error Label Snippet 004 - Binding Example");
    Label info1 = new Label(this, SWT.NONE);
    info1.setText("Enter '5' to be valid:");
    FormData data = new FormData(DatabindingSnippetsView.STD_LABEL_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info1.setLayoutData(data);
    Text text = new Text(this, SWT.BORDER);
    WritableValue value = new WritableValue(realm, null, String.class);
    data = new FormData(DatabindingSnippetsView.STD_LABEL_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(info1, 0);
    text.setLayoutData(data);
    Label info2 = new Label(this, SWT.NONE);
    info2.setText("Error/Validation:");
    data = new FormData(DatabindingSnippetsView.STD_LABEL_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(info1, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info2.setLayoutData(data);
    Label errorLabel = new Label(this, SWT.BORDER);
    Color color = Graphics.getColor(255, 0, 0);
    errorLabel.setForeground(color);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(text, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(info2, 0);
    errorLabel.setLayoutData(data);
    errorLabel.setText("hallo");
    DataBindingContext dbc = new DataBindingContext(realm);
    // Bind the text to the value.
    UpdateValueStrategy updateValueStrategy = new UpdateValueStrategy();
    updateValueStrategy.setAfterConvertValidator(new FiveValidator());
    dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), value, updateValueStrategy, null);
    // Bind the error label to the validation error on the dbc.
    int severity = AggregateValidationStatus.MAX_SEVERITY;
    AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(realm,
            dbc.getBindings(), severity);
    dbc.bindValue(SWTObservables.observeText(errorLabel), aggregateValidationStatus, null, null);
}