Java Code Examples for org.eclipse.core.databinding.observable.value.IObservableValue#setValue()

The following examples show how to use org.eclipse.core.databinding.observable.value.IObservableValue#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void validateExternalDatabindingContextTargets(final DataBindingContext dbc) {
    if (dbc != null) {
        final IObservableList validationStatusProviders = dbc.getValidationStatusProviders();
        final Iterator iterator = validationStatusProviders.iterator();
        while (iterator.hasNext()) {
            final ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) iterator.next();
            final IObservableValue validationStatus = validationStatusProvider.getValidationStatus();
            if (!(validationStatus instanceof UnmodifiableObservableValue)) {
                final IStatus status = (IStatus) validationStatus.getValue();
                if (status != null) {
                    if (status.getSeverity() == IStatus.OK) {
                        validationStatus.setValue(ValidationStatus.ok());
                    } else if (status.getSeverity() == IStatus.WARNING) {
                        validationStatus.setValue(ValidationStatus.warning(status.getMessage()));
                    } else if (status.getSeverity() == IStatus.INFO) {
                        validationStatus.setValue(ValidationStatus.info(status.getMessage()));
                    } else if (status.getSeverity() == IStatus.ERROR) {
                        validationStatus.setValue(ValidationStatus.error(status.getMessage()));
                    } else if (status.getSeverity() == IStatus.CANCEL) {
                        validationStatus.setValue(ValidationStatus.cancel(status.getMessage()));
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: SelectDatabaseOutputTypeWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void parseQuery() {
    if (graphicalModeSelectionValue != null) {
        final IObservableValue enableGraphicalMode = SWTObservables.observeEnabled(gModeRadio);
        if (SQLQueryUtil.isGraphicalModeSupportedFor(scriptExpression)) {
            enableGraphicalMode.setValue(true);
            if (!editing) {
                graphicalModeSelectionValue.setValue(true);
                if (outputTypeExpression.getContent() != null) {
                    radioGroupObservable.setValue(outputTypeExpression.getContent());
                } else {
                    radioGroupObservable.setValue(TABLE);
                }
            } else if (outputTypeExpression.getContent() == null) {
                graphicalModeSelectionValue.setValue(false);
            }
            updateEnabledChoices();
        } else {
            enableGraphicalMode.setValue(false);
            graphicalModeSelectionValue.setValue(false);
            scriptValue.setValue(true);
            radioGroupObservable.setValue(null);
        }
    }
}
 
Example 3
Source File: ConverterBuilderTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_create_and_use_string_to_int_converter() {

    IConverter stringToInt = ConverterBuilder.<String, Integer> newConverter()
            .fromType(String.class)
            .toType(Integer.class)
            .withConvertFunction(Integer::parseInt)
            .create();

    IConverter intToString = ConverterBuilder.<Integer, String> newConverter()
            .fromType(Integer.class)
            .toType(String.class)
            .withConvertFunction(String::valueOf)
            .create();

    A a = new A();
    B b = new B();

    DataBindingContext ctx = new DataBindingContext();
    IObservableValue<String> observeA = PojoProperties.value("a").observe(a);
    IObservableValue<Integer> observeB = PojoProperties.value("b").observe(b);
    ctx.bindValue(observeA, observeB, UpdateStrategyFactory.updateValueStrategy().withConverter(stringToInt).create(),
            UpdateStrategyFactory.updateValueStrategy().withConverter(intToString).create());

    observeA.setValue("123");
    assertThat(b.getB()).isEqualTo(123);

    observeB.setValue(321);
    assertThat(a.getA()).isEqualTo("321");
}
 
Example 4
Source File: SelectDatabaseOutputTypeWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void updateQuery() {
    if (graphicalModeSelectionValue != null) {
        final IObservableValue enableGraphicalMode = SWTObservables.observeEnabled(gModeRadio);
        if (SQLQueryUtil.isGraphicalModeSupportedFor(scriptExpression)) {
            enableGraphicalMode.setValue(true);
            updateEnabledChoices();
        } else {
            enableGraphicalMode.setValue(false);
            graphicalModeSelectionValue.setValue(false);
            scriptValue.setValue(true);
            radioGroupObservable.setValue(null);
        }
    }
}
 
Example 5
Source File: ImportBosArchiveControlSupplier.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void updateFilePath(String filePath) {
    textWidget.setText(filePath);
    if (archiveModel != null) {
        IObservableValue validationStatus = textWidget.getValueBinding().getValidationStatus();
        validationStatus.setValue(archiveModel.getValidationStatus());
    }
    textWidget.getParent().getParent().layout();
    if (new File(filePath).exists()) {
        savePath(filePath);
    }
}
 
Example 6
Source File: ImportFileWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected Composite doCreateControls(Composite parent, DataBindingContext dbc) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(0, 0).extendedMargins(10, 10, 10, 0).create());

    final Group transfoGroup = new Group(mainComposite, SWT.NONE);
    transfoGroup.setText(Messages.fileFormat);
    transfoGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(3, 1).create());
    transfoGroup.setLayout(new GridLayout(2, true));

    final TableViewer importList = new TableViewer(transfoGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    importList.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    importList.setContentProvider(ArrayContentProvider.getInstance());
    importList.setComparator(new ImporterPriorityDisplayComparator());
    importList.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object item) {
            return ((ImporterFactory) item).getName();
        }
    });

    final List<ImporterFactory> allAvailableImports = ImporterRegistry.getInstance().getAllAvailableImports();
    importList.setInput(allAvailableImports);

    final IObservableValue importerFactoryObservable = PojoObservables.observeValue(importFileData, "importerFactory");
    importerFactoryObservable.setValue(importList.getElementAt(0));

    dbc.bindValue(ViewersObservables.observeSingleSelection(importList), importerFactoryObservable,
            updateValueStrategy().withValidator(mandatoryValidator(Messages.fileFormat)).create(),
            updateValueStrategy().create());

    final Composite descComposite = new Composite(transfoGroup, SWT.NONE);
    descComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).spacing(5, 3).create());
    descComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());

    final Label importDescriptionLabel = new Label(descComposite, SWT.NONE);
    importDescriptionLabel.setText(Messages.importDescriptionLabel);

    final Label descriptionImage = new Label(descComposite, SWT.NONE);
    descriptionImage.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).create());

    final Label separator = new Label(descComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final Label descriptionLabel = new Label(descComposite, SWT.WRAP);
    descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().hint(230, SWT.DEFAULT).grab(false, true).create());

    updatePanel(importFileData.getImporterFactory(), descriptionImage, descriptionLabel);

    doCreateAdditionalControls(mainComposite, dbc);

    final Label fileLabel = new Label(mainComposite, SWT.NONE);
    fileLabel.setText(Messages.selectFileToImport);

    final Text text = new Text(mainComposite, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final IObservableValue filePathObservable = PojoObservables.observeValue(importFileData, "filePath");
    dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), filePathObservable,
            updateValueStrategy().withValidator(pathValidator(Messages.selectFileToImport).overrideMessage(Messages.invalidFilePath)).create(),
            updateValueStrategy().create());

    final Button browseButton = new Button(mainComposite, SWT.PUSH);
    browseButton.setText(Messages.browseButton_label);
    browseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final String file = openFileDialog();
            if (file != null) {
                text.setText(file);
                if (new File(file).exists()) {
                    savePath(new File(file).getParentFile().getAbsolutePath());
                }
            }
        }
    });

    importList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updatePanel((ImporterFactory) importerFactoryObservable.getValue(), descriptionImage, descriptionLabel);
        }

    });
    importList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent arg0) {
            updatePanel((ImporterFactory) importerFactoryObservable.getValue(), descriptionImage, descriptionLabel);
            browseButton.notifyListeners(SWT.Selection, null);
        }
    });

    return mainComposite;
}