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:de.walware.statet.nico.internal.ui.preferences.ConsolePreferencePage.java

License:Open Source License

@Override
protected void addBindings(final DataBindingSupport db) {
    db.getContext().bindValue(fSubmitTypeControl.getObservable(),
            createObservable(ConsolePreferences.PREF_HISTORYNAVIGATION_SUBMIT_TYPES));

    db.getContext().bindValue(SWTObservables.observeText(fCharLimitControl, SWT.Modify),
            createObservable(ConsolePreferences.PREF_CHARLIMIT),
            new UpdateValueStrategy().setAfterGetValidator(new IntegerValidator(10000, 1000000000,
                    "Invalid char limit specified (10000-1000000000).")),
            null);// w ww  .  j  a  v a  2 s .com
}

From source file:de.walware.statet.nico.internal.ui.preferences.ResourceMappingPreferencePage.java

License:Open Source License

@Override
protected void addBindings(final DataBindingSupport db) {
    db.getContext().bindValue(fLocalControl.getObservable(), fLocalValue,
            new UpdateValueStrategy().setAfterGetValidator(fLocalControl.getValidator()), null);
    db.getContext().bindValue(SWTObservables.observeText(fHostControl, SWT.Modify), fHostValue,
            new UpdateValueStrategy().setAfterGetValidator(
                    new NotEmptyValidator("Missing host; it must be specified by its hostname or IP number.")),
            null);/*  ww  w .j  a  v a 2s .c  o m*/
    db.getContext().bindValue(SWTObservables.observeText(fRemoteControl, SWT.Modify), fRemoteValue,
            new UpdateValueStrategy().setAfterGetValidator(new NotEmptyValidator("Missing remote path.")),
            null);
}

From source file:de.walware.statet.nico.ui.util.TrackingConfigurationComposite.java

License:Open Source License

protected void addBindings(final DataBindingSupport db) {
    if (fNameControl != null) {
        db.getContext().bindValue(SWTObservables.observeText(fNameControl, SWT.Modify),
                BeansObservables.observeValue(fInput, "name"), //$NON-NLS-1$
                new UpdateValueStrategy().setAfterGetValidator(
                        new NotEmptyValidator(Messages.Tracking_Name_error_Missing_message)),
                null);//from www.ja  va  2s .  c om
    }

    final IObservableValue infoUIObs = SWTObservables.observeSelection(fStreamInfoControl);
    db.getContext().bindValue(infoUIObs, BeansObservables.observeValue(fInput, "trackStreamInfo")); //$NON-NLS-1$

    final IObservableValue inputUIObs = SWTObservables.observeSelection(fStreamInputControl);
    db.getContext().bindValue(inputUIObs, BeansObservables.observeValue(fInput, "trackStreamInput")); //$NON-NLS-1$
    if (fStreamInputHistoryOnlyControl != null) {
        db.getContext().bindValue(SWTObservables.observeEnabled(fStreamInputHistoryOnlyControl), inputUIObs);
        db.getContext().bindValue(SWTObservables.observeSelection(fStreamInputHistoryOnlyControl),
                BeansObservables.observeValue(fInput, "trackStreamInputHistoryOnly")); //$NON-NLS-1$
    }

    final IObservableValue outputUIObs = SWTObservables.observeSelection(fStreamOutputErrorControl);
    final IObservableValue outputModelObs = BeansObservables.observeValue(fInput, "trackStreamOutput"); //$NON-NLS-1$
    db.getContext().bindValue(outputUIObs, outputModelObs);
    if (fStreamOutputErrorTruncateControl != null) {
        final IObservableValue outputTruncateUIObs = SWTObservables
                .observeSelection(fStreamOutputErrorTruncateControl);
        final IObservableValue outputTruncateModelObs = BeansObservables.observeValue(fInput,
                "trackStreamOutputTruncate"); //$NON-NLS-1$
        db.getContext().bindValue(SWTObservables.observeEnabled(fStreamOutputErrorTruncateControl),
                outputUIObs);
        db.getContext().bindValue(outputTruncateUIObs, outputTruncateModelObs);
        db.getContext().bindValue(SWTObservables.observeEnabled(fStreamOutputErrorTruncateLinesControl),
                new ComputedOnChangeValue(Boolean.class, outputModelObs, outputTruncateModelObs) {
                    @Override
                    protected Object calculate() {
                        final Boolean one = (Boolean) outputModelObs.getValue();
                        final Boolean two = (Boolean) outputTruncateModelObs.getValue();
                        return Boolean.valueOf(one.booleanValue() && two.booleanValue());
                    }
                });
        db.getContext().bindValue(
                SWTObservables.observeText(fStreamOutputErrorTruncateLinesControl, SWT.Modify),
                BeansObservables.observeValue(fInput, "trackStreamOutputTruncateLines"), //$NON-NLS-1$
                new UpdateValueStrategy().setAfterGetValidator(new IntegerValidator(2, 1000000,
                        Messages.Tracking_OutputStream_TruncateLines_error_Invalid_message)),
                null);
    }

    if (fSubmitTypeControl != null) {
        db.getContext().bindValue(fSubmitTypeControl.getObservable(),
                BeansObservables.observeValue(fInput, "submitTypes")); //$NON-NLS-1$
    }

    db.getContext().bindValue(fFilePathControl.getObservable(),
            BeansObservables.observeValue(fInput, "filePath"), //$NON-NLS-1$
            new UpdateValueStrategy().setAfterGetValidator(fFilePathControl.getValidator()), null);
    final IObservableValue fileModeModelObs = BeansObservables.observeValue(fInput, "fileMode"); //$NON-NLS-1$
    db.getContext().bindValue(SWTObservables.observeSelection(fFileAppendControl),
            new ComputedOnChangeValue(Boolean.class, fileModeModelObs) {
                @Override
                protected Object calculate() {
                    final Integer mode = (Integer) fileModeModelObs.getValue();
                    return Boolean.valueOf((mode.intValue() & EFS.APPEND) == EFS.APPEND);
                }

                @Override
                protected void extractAndSet(final Object value) {
                    final Boolean selected = (Boolean) value;
                    fileModeModelObs.setValue(selected.booleanValue() ? EFS.APPEND : EFS.NONE);
                }
            });
    db.getContext().bindValue(SWTObservables.observeSelection(fFileOverwriteControl),
            new ComputedOnChangeValue(Boolean.class, fileModeModelObs) {
                @Override
                protected Object calculate() {
                    final Integer mode = (Integer) fileModeModelObs.getValue();
                    return Boolean.valueOf((mode.intValue() & EFS.OVERWRITE) == EFS.OVERWRITE);
                }

                @Override
                protected void extractAndSet(final Object value) {
                    final Boolean selected = (Boolean) value;
                    fileModeModelObs.setValue(selected.booleanValue() ? EFS.OVERWRITE : EFS.NONE);
                }
            });

    if (fPrependTimestampControl != null) {
        db.getContext().bindValue(SWTObservables.observeSelection(fPrependTimestampControl),
                BeansObservables.observeValue(fInput, "prependTimestamp")); //$NON-NLS-1$
    }
}

From source file:de.walware.statet.r.internal.cmd.ui.launching.RCmdMainTab.java

License:Open Source License

@Override
protected void addBindings(final DataBindingContext dbc, final Realm realm) {
    fCmdValue = new WritableValue(realm, Cmd.class);
    fArgumentsValue = new WritableValue(realm, String.class);
    fResourceValue = new WritableValue(realm, String.class);

    final IObservableValue cmdSelection = ViewersObservables.observeSingleSelection(fCmdCombo);
    dbc.bindValue(cmdSelection, fCmdValue, null, null);
    final IValidator cmdValidator = new IValidator() {
        @Override//w  w w .j  av  a 2  s  . c  o  m
        public IStatus validate(final Object value) {
            final String s = (String) value;
            if (s == null || s.trim().isEmpty()) {
                return ValidationStatus.warning(RCmdMessages.RCmd_MainTab_error_MissingCMD_message);
            }
            return ValidationStatus.ok();
        }
    };
    dbc.bindValue(SWTObservables.observeText(fCmdText, SWT.Modify),
            BeansObservables.observeDetailValue(cmdSelection, "command", String.class), //$NON-NLS-1$
            new UpdateValueStrategy().setAfterGetValidator(cmdValidator),
            new UpdateValueStrategy().setBeforeSetValidator(cmdValidator));
    dbc.bindValue(SWTObservables.observeText(fArgumentsControl.getTextControl(), SWT.Modify), fArgumentsValue,
            null, null);

    fResourceControl.getValidator().setOnLateResolve(IStatus.WARNING);
    fResourceControl.getValidator().setOnEmpty(IStatus.OK);
    fResourceControl.getValidator().setIgnoreRelative(true);
    final Binding resourceBinding = dbc
            .bindValue(
                    fResourceControl.getObservable(), fResourceValue, new UpdateValueStrategy()
                            .setAfterGetValidator(new SavableErrorValidator(fResourceControl.getValidator())),
                    null);
    cmdSelection.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            final Cmd cmd = (Cmd) event.diff.getNewValue();
            if (cmd != null) {
                fCmdText.setEditable(cmd.getType() == Cmd.CUSTOM);
                String label;
                int mode = 0;
                switch (cmd.getType()) {
                case Cmd.PACKAGE_DIR:
                    label = RCmdMessages.RCmd_Resource_PackageDir_label;
                    mode = ResourceInputComposite.MODE_DIRECTORY;
                    break;
                case Cmd.PACKAGE_DIR_OR_ARCHIVE:
                    label = RCmdMessages.RCmd_Resource_PackageDirOrArchive_label;
                    mode = ResourceInputComposite.MODE_FILE | ResourceInputComposite.MODE_DIRECTORY;
                    break;
                case Cmd.DOC:
                    label = RCmdMessages.RCmd_Resource_Doc_label;
                    mode = ResourceInputComposite.MODE_FILE;
                    break;
                case Cmd.DOC_OR_DIR:
                    label = RCmdMessages.RCmd_Resource_DocOrDir_label;
                    mode = ResourceInputComposite.MODE_FILE | ResourceInputComposite.MODE_DIRECTORY;
                    break;
                default: // Cmd.CUSTOM:
                    label = RCmdMessages.RCmd_Resource_Other_label;
                    mode = ResourceInputComposite.MODE_FILE | ResourceInputComposite.MODE_DIRECTORY;
                    break;
                }
                fResourceControl.setResourceLabel(label);
                fResourceControl.setMode(mode | ResourceInputComposite.MODE_OPEN);
                resourceBinding.validateTargetToModel();
            }
        }
    });
}

From source file:de.walware.statet.r.internal.console.ui.launching.RConsoleMainTab.java

License:Open Source License

@Override
protected void addBindings(final DataBindingContext dbc, final Realm realm) {
    fTypeValue = new WritableValue(realm, RConsoleType.class);
    fWorkingDirectoryValue = new WritableValue(realm, null, String.class);
    fArgumentsValue = new WritableValue(realm, String.class);

    final IObservableValue typeSelection = ViewersObservables.observeSingleSelection(fTypesCombo);
    dbc.bindValue(typeSelection, fTypeValue, null, null);

    dbc.bindValue(SWTObservables.observeText(fArgumentsControl.getTextControl(), SWT.Modify), fArgumentsValue,
            null, null);/*from   ww w.ja  va  2 s.c om*/

    fWorkingDirectoryControl.getValidator().setOnEmpty(IStatus.OK);
    dbc.bindValue(
            fWorkingDirectoryControl.getObservable(), fWorkingDirectoryValue, new UpdateValueStrategy()
                    .setAfterGetValidator(new SavableErrorValidator(fWorkingDirectoryControl.getValidator())),
            null);

    fTypeValue.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            final Object newValue = event.diff.getNewValue();
            updateType((RConsoleType) newValue);
        }
    });
}

From source file:de.walware.statet.r.internal.console.ui.launching.RConsoleOptionsTab.java

License:Open Source License

@Override
protected void addBindings(final DataBindingContext dbc, final Realm realm) {
    fPinValue = new WritableValue(realm, Boolean.class);
    dbc.bindValue(SWTObservables.observeSelection(fPinControl), fPinValue, null, null);

    fTrackingList = new WritableList(realm, new ArrayList<Object>(), TrackingConfiguration.class);
    fTrackingTable.setContentProvider(new ObservableListContentProvider());
    fTrackingTable.setInput(fTrackingList);

    fStartupSnippetValue = new WritableValue(realm, String.class);
    dbc.bindValue(new SnippetEditorObservable(realm, fStartupSnippetEditor, SWT.Modify), fStartupSnippetValue,
            null, null);//from  w ww . j  a  va  2  s  . co m

    fRHelpByStatetValue = new WritableValue(realm, Boolean.class);
    fRGraphicsByStatetValue = new WritableValue(realm, Boolean.class);
    fRDbgExtValue = new WritableValue(realm, Boolean.class);
    dbc.bindValue(SWTObservables.observeSelection(fRHelpByStatetControl), fRHelpByStatetValue, null, null);
    dbc.bindValue(SWTObservables.observeSelection(fRGraphicsByStatetControl), fRGraphicsByStatetValue, null,
            null);
    dbc.bindValue(SWTObservables.observeSelection(fRDbgExtControl), fRDbgExtValue, null, null);

    fObjectDBEnabledValue = new WritableValue(realm, Boolean.class);
    fObjectDBAutoEnabledValue = new WritableValue(realm, Boolean.class);
    fObjectDBListsChildrenValue = new WritableValue(realm, Integer.class);
    fObjectDBEnvsChildrenValue = new WritableValue(realm, Integer.class);
    final ISWTObservableValue dbObs = SWTObservables.observeSelection(fObjectDBEnabledControl);
    dbc.bindValue(dbObs, fObjectDBEnabledValue, null, null);
    dbc.bindValue(SWTObservables.observeSelection(fObjectDBAutoEnabledControl), fObjectDBAutoEnabledValue, null,
            null);
    dbc.bindValue(SWTObservables.observeText(fObjectDBListsChildrenControl, SWT.Modify),
            fObjectDBListsChildrenValue,
            new UpdateValueStrategy().setAfterGetValidator(new IntegerValidator(100, Integer.MAX_VALUE,
                    "Invalid max value for length of R lists to fetch (100-).")),
            null);
    dbc.bindValue(SWTObservables.observeText(fObjectDBEnvsChildrenControl, SWT.Modify),
            fObjectDBEnvsChildrenValue, new UpdateValueStrategy().setAfterGetValidator(new IntegerValidator(100,
                    Integer.MAX_VALUE, "Invalid max value for length of R environments to fetch (100-).")),
            null);

    dbc.bindValue(new SWTMultiEnabledObservable(realm, new Control[] { fObjectDBAutoEnabledControl,
            fObjectDBEnvsChildrenControl, fObjectDBListsChildrenControl, }, null), dbObs, null, null);

    fTrackingButtons.connectTo(fTrackingTable,
            new DataAdapter.ListAdapter<TrackingConfiguration>(fTrackingList, null) {
                @Override
                public boolean isDeleteAllowed(final Object element) {
                    return (super.isDeleteAllowed(element)
                            && ((TrackingConfiguration) element).getId().startsWith(CUSTOM_TRACKING_ID_PREFIX));
                }
            });

    fTrackingEnabledSet = new WritableSet(realm, new HashSet<Object>(), TrackingConfiguration.class);
    fTrackingButtons.setCheckedModel(fTrackingEnabledSet);
    dbc.bindSet(ViewersObservables.observeCheckedElements(fTrackingTable, TrackingConfiguration.class),
            fTrackingEnabledSet);
}

From source file:de.walware.statet.r.internal.console.ui.launching.RRemoteConsoleMainTab.java

License:Open Source License

@Override
protected void addBindings(final DataBindingContext dbc, final Realm realm) {
    super.addBindings(dbc, realm);

    final MultiValidator validator = new MultiValidator() {
        @Override//from   w  ww.jav a 2 s.c  om
        protected IStatus validate() {
            // Calculate the validation status
            if (!getType().getId().equals(REMOTE_RJS_RECONNECT)) {
                final String text = (String) fAddressValue.getValue();
                if (text == null || text.isEmpty()) {
                    return ValidationStatus
                            .error("Missing address for R remote engine ('//host[:port]/rsessionname').");
                }
                try {
                    RMIAddress.validate(text);
                } catch (final MalformedURLException e) {
                    return ValidationStatus
                            .error("Invalid address for R remote engine: " + e.getLocalizedMessage());
                }
            }
            return ValidationStatus.ok();
        }
    };

    final WritableValue addressValue1 = new WritableValue("", String.class); //$NON-NLS-1$
    dbc.bindValue(SWTObservables.observeText(fAddressControl, SWT.Modify), addressValue1, null, null);
    validator.observeValidatedValue(addressValue1);
    fAddressValue = new WritableValue("", String.class);
    dbc.bindValue(addressValue1, fAddressValue, null, null);

    fUserValue = new WritableValue("", String.class);
    dbc.bindValue(SWTObservables.observeText(fUsernameControl, SWT.Modify), fUserValue, null, null);

    fSshPortValue = new WritableValue(null, Integer.class);
    dbc.bindValue(SWTObservables.observeText(fSshPortControl, SWT.Modify), fSshPortValue,
            new UpdateValueStrategy().setAfterGetValidator(
                    new IntegerValidator(0, 65535, true, "Invalid SSH port number specified (0-65535).")),
            null);
    fSshTunnelValue = new WritableValue(false, Boolean.TYPE);
    dbc.bindValue(SWTObservables.observeSelection(fSshTunnelControl), fSshTunnelValue, null, null);

    fCommandValue = new WritableValue("", String.class);
    dbc.bindValue(SWTObservables.observeText(fCommandControl, SWT.Modify), fCommandValue, null, null);

    fSshAddressValue = new WritableValue();
    dbc.bindValue(SWTObservables.observeText(fSshAddress, SWT.Modify), fSshAddressValue, null, null);

    fAddressValue.addValueChangeListener(fUpdateJob);
    fUserValue.addValueChangeListener(fUpdateJob);
    fSshPortValue.addValueChangeListener(fUpdateJob);

    dbc.addValidationStatusProvider(validator);
    validator.observeValidatedValue(getTypeValue());
}

From source file:de.walware.statet.r.internal.debug.ui.breakpoints.RLineBreakpointDetailEditor.java

License:Open Source License

@Override
protected void addBindings(final DataBindingContext dbc, final Realm realm) {
    super.addBindings(dbc, realm);

    fConditionEnabledValue = new WritableValue(realm, Boolean.FALSE, Boolean.class);
    fConditionCodeValue = new WritableValue(realm, "", String.class);

    enableAutosave(//from w w  w  .  j a  va  2  s.c  om
            dbc.bindValue(SWTObservables.observeSelection(fConditionEnabledControl), fConditionEnabledValue));
    dbc.bindValue(SWTObservables.observeText(fConditionCodeEditor.getTextControl(), SWT.Modify),
            fConditionCodeValue);
    dbc.bindValue(SWTObservables.observeEnabled(fConditionCodeEditor.getTextControl()), fConditionEnabledValue);
}

From source file:de.walware.statet.r.internal.debug.ui.preferences.REnvLocalConfigDialog.java

License:Open Source License

@Override
protected void addBindings(final DataBindingSupport db) {
    db.getContext().bindValue(SWTObservables.observeText(fNameControl, SWT.Modify),
            BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_NAME),
            new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
                @Override/* w  w w .j  ava 2 s. c o  m*/
                public IStatus validate(final Object value) {
                    String s = (String) value;
                    s = s.trim();
                    if (s.isEmpty()) {
                        return ValidationStatus.error(Messages.REnv_Detail_Name_error_Missing_message);
                    }
                    if (fExistingNames.contains(s)) {
                        return ValidationStatus.error(Messages.REnv_Detail_Name_error_Duplicate_message);
                    }
                    if (s.contains("/")) { //$NON-NLS-1$
                        return ValidationStatus.error(Messages.REnv_Detail_Name_error_InvalidChar_message);
                    }
                    return ValidationStatus.ok();
                }
            }), null);
    if (fRHomeControl != null) {
        final Binding rHomeBinding = db.getContext().bindValue(fRHomeControl.getObservable(),
                BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_RHOME),
                new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
                    @Override
                    public IStatus validate(final Object value) {
                        final IStatus status = fRHomeControl.getValidator().validate(value);
                        if (!status.isOK()) {
                            return status;
                        }
                        if (!fConfigModel.isValidRHomeLocation(fRHomeControl.getResourceAsFileStore())) {
                            return ValidationStatus.error(Messages.REnv_Detail_Location_error_NoRHome_message);
                        }
                        updateArchs(!fIsNewConfig);
                        return ValidationStatus.ok();
                    }
                }), null);
        rHomeBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener() {
            @Override
            public void handleValueChange(final ValueChangeEvent event) {
                final IStatus status = (IStatus) event.diff.getNewValue();
                fLoadButton.setEnabled(status.isOK());
            }
        });
        rHomeBinding.validateTargetToModel();
    }
    db.getContext().bindValue(SWTObservables.observeText(fRArchControl),
            BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_SUBARCH));

    if (fRDocDirectoryControl != null) {
        db.getContext().bindValue(fRDocDirectoryControl.getObservable(),
                BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_RDOC_DIRECTORY));
        db.getContext().bindValue(fRShareDirectoryControl.getObservable(),
                BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_RSHARE_DIRECTORY));
        db.getContext().bindValue(fRIncludeDirectoryControl.getObservable(),
                BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_RINCLUDE_DIRECTORY));
    }
}

From source file:de.walware.statet.r.internal.debug.ui.preferences.REnvRemoteConfigDialog.java

License:Open Source License

@Override
protected void addBindings(final DataBindingSupport db) {
    db.getContext().bindValue(SWTObservables.observeText(fNameControl, SWT.Modify),
            BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_NAME),
            new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
                @Override/* ww w  . j a  v a  2s.c  o  m*/
                public IStatus validate(final Object value) {
                    String s = (String) value;
                    s = s.trim();
                    if (s.isEmpty()) {
                        return ValidationStatus.error(Messages.REnv_Detail_Name_error_Missing_message);
                    }
                    if (fExistingNames.contains(s)) {
                        return ValidationStatus.error(Messages.REnv_Detail_Name_error_Duplicate_message);
                    }
                    if (s.contains("/")) { //$NON-NLS-1$
                        return ValidationStatus.error(Messages.REnv_Detail_Name_error_InvalidChar_message);
                    }
                    return ValidationStatus.ok();
                }
            }), null);
    db.getContext().bindValue(fIndexDirectoryControl.getObservable(),
            BeansObservables.observeValue(fConfigModel, IREnvConfiguration.PROP_INDEX_DIRECTORY));
}