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

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

Introduction

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

Prototype

@Deprecated
public static ISWTObservableValue observeBackground(Control control) 

Source Link

Document

Returns an observable value tracking the background color of the given control

Usage

From source file:com.rcpcompany.uibindings.uiAttributes.SimpleUIAttribute.java

License:Open Source License

@Override
public IObservableValue getBackgroundValue() {
    Assert.isTrue(!isDisposed());//w w w .ja v  a 2s . c  om
    if (myWidget instanceof Control) {
        final Control c = (Control) myWidget;
        return addObservable(SWTObservables.observeBackground(c));
    }
    return null;
}

From source file:de.uniluebeck.itm.spyglass.plugin.gridpainter.GridPainterOptionsComposite.java

License:Open Source License

public void setDatabinding(final DataBindingContext dbc, final GridPainterXMLConfig config,
        final GridPainterPreferencePage page, final Spyglass spyglass) {

    this.page = page;
    this.config = config;
    this.dbc = dbc;

    IObservableValue obsModel;/* w ww.  j  a va2s. com*/
    ISWTObservableValue obsWidget;
    UpdateValueStrategy usTargetToModel;
    UpdateValueStrategy usModelToTarget;

    {
        obsWidget = SWTObservables.observeText(lowerLeftPointXText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_GRID_LOWER_LEFT_POINT_X);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(lowerLeftPointYText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_GRID_LOWER_LEFT_POINT_Y);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(gridElementHeightText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_GRID_ELEMENT_HEIGHT);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(gridElementWidthText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_GRID_ELEMENT_WIDTH);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(this.lineWidth, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_LINE_WIDTH);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeBackground(colorExample);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_LINE_COLOR_R_G_B);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setConverter(new ColorToArrayConverter());
        usModelToTarget = new UpdateValueStrategy();
        usModelToTarget.setConverter(new ArrayToColorConverter(this.getDisplay()));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, usModelToTarget);
    }
    {
        obsWidget = SWTObservables.observeText(numColsText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_NUM_COLS);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(numRowsText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                GridPainterXMLConfig.PROPERTYNAME_NUM_ROWS);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }

    final MetricsXMLConfig metrics = spyglass.getConfigStore().getSpyglassConfig().getGeneralSettings()
            .getMetrics();
    {
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), metrics,
                MetricsXMLConfig.PROPERTYNAME_UNIT);
        dbc.bindValue(SWTObservables.observeText(lowerLeftPointXUnitLabel), obsModel, null, null);
        dbc.bindValue(SWTObservables.observeText(lowerLeftPointYUnitLabel), obsModel, null, null);
        dbc.bindValue(SWTObservables.observeText(gridElementWidthUnitLabel), obsModel, null, null);
        dbc.bindValue(SWTObservables.observeText(gridElementHeightUnitLabel), obsModel, null, null);
    }

    updateGridElementsSquare();
    updateLockNumberOfRowsNCols();

}

From source file:de.uniluebeck.itm.spyglass.plugin.linepainter.LinePainterOptionsComposite.java

License:Open Source License

public void setDatabinding(final DataBindingContext dbc, final LinePainterXMLConfig config,
        final LinePainterPreferencePage page) {

    this.page = page;

    IObservableValue obsModel;//from ww  w . jav  a 2s . co  m
    ISWTObservableValue obsWidget;
    UpdateValueStrategy usTargetToModel;
    UpdateValueStrategy usModelToTarget;

    {
        obsWidget = SWTObservables.observeText(lineWidth, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                LinePainterXMLConfig.PROPERTYNAME_LINE_WIDTH);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeBackground(lineColor);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                LinePainterXMLConfig.PROPERTYNAME_LINE_COLOR_R_G_B);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setConverter(new ColorToArrayConverter());
        usModelToTarget = new UpdateValueStrategy();
        usModelToTarget.setConverter(new ArrayToColorConverter(this.getDisplay()));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, usModelToTarget);
    }
    {
        obsWidget = SWTObservables.observeText(ttl, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                PluginXMLConfig.PROPERTYNAME_TIMEOUT);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel
                .setAfterConvertValidator(new IntegerRangeValidator("Time To Live", 0, Integer.MAX_VALUE));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }

    stringFormatter.setDataBinding(dbc, config);

}

From source file:de.uniluebeck.itm.spyglass.plugin.mappainter.MapPainterPrefComposite.java

License:Open Source License

public void setDatabinding(final DataBindingContext dbc, final MapPainterXMLConfig config,
        final Spyglass spyglass, final MapPainterPreferencePage page) {

    this.page = page;
    this.config = config;
    this.dbc = dbc;

    {//from  w  ww .j  av a2s .  c o m
        dbc.bindValue(SWTObservables.observeText(this.lowerLeftX, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_LOWER_LEFT_X),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);
    }
    {
        dbc.bindValue(SWTObservables.observeText(this.lowerLeftY, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_LOWER_LEFT_Y),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);
    }
    {
        dbc.bindValue(SWTObservables.observeText(this.width, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_WIDTH),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Width", 1, Integer.MAX_VALUE)),
                null);
    }
    {

        dbc.bindValue(SWTObservables.observeText(this.height, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_HEIGHT),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Height", 1, Integer.MAX_VALUE)),
                null);
    }
    {

        dbc.bindValue(SWTObservables.observeText(this.blockWidth, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_GRID_ELEMENT_WIDTH),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Block width", 1, Integer.MAX_VALUE)),
                null);
    }
    {

        dbc.bindValue(SWTObservables.observeText(this.blockHeight, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_GRID_ELEMENT_HEIGHT),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Block height", 1, Integer.MAX_VALUE)),
                null);

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.minValue, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_MIN_VALUE),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.maxValue, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_MAX_VALUE),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.defaultValue, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_DEFAULT_VALUE),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.framePointsX, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_NUM_FRAME_POINTS_HORIZONTAL),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Framepoints x", 1, Integer.MAX_VALUE)),
                null);

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.framePointsY, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_NUM_FRAME_POINTS_VERTICAL),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Framepoints y", 1, Integer.MAX_VALUE)),
                null);

    }
    {
        dbc.bindValue(SWTObservables.observeBackground(minValueColor),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_MIN_COLOR_R_G_B),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                        .setConverter(new ColorToArrayConverter()),
                new UpdateValueStrategy().setConverter(new ArrayToColorConverter(this.getDisplay())));

    }
    {
        dbc.bindValue(SWTObservables.observeBackground(maxValueColor),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_MAX_COLOR_R_G_B),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                        .setConverter(new ColorToArrayConverter()),
                new UpdateValueStrategy().setConverter(new ArrayToColorConverter(this.getDisplay())));

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.kNN, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_K),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Neighbors (for kNN)", 1, Integer.MAX_VALUE)),
                null);

    }
    {
        dbc.bindValue(SWTObservables.observeText(this.text1, SWT.Modify),
                BeansObservables.observeValue(dbc.getValidationRealm(), config,
                        MapPainterXMLConfig.PROPERTYNAME_REFRESH_FREQUENCY),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator(
                        new IntegerRangeValidator("Update frequency (1/s)", 1, 25)),
                null);

    }
    {
        final MetricsXMLConfig mConf = spyglass.getConfigStore().getSpyglassConfig().getGeneralSettings()
                .getMetrics();
        dbc.bindValue(SWTObservables.observeText(this.label11space), BeansObservables
                .observeValue(dbc.getValidationRealm(), mConf, MetricsXMLConfig.PROPERTYNAME_UNIT), null, null);
        dbc.bindValue(SWTObservables.observeText(this.label3space), BeansObservables
                .observeValue(dbc.getValidationRealm(), mConf, MetricsXMLConfig.PROPERTYNAME_UNIT), null, null);
        dbc.bindValue(SWTObservables.observeText(this.label8space), BeansObservables
                .observeValue(dbc.getValidationRealm(), mConf, MetricsXMLConfig.PROPERTYNAME_UNIT), null, null);
        dbc.bindValue(SWTObservables.observeText(this.labelspace), BeansObservables
                .observeValue(dbc.getValidationRealm(), mConf, MetricsXMLConfig.PROPERTYNAME_UNIT), null, null);

    }
    updateScaleLinkBlock();
    updateScaleLinkDim();
}

From source file:de.uniluebeck.itm.spyglass.plugin.nodesensorrange.NodeSensorRangeOptionsComposite.java

License:Open Source License

public void setDatabinding(final DataBindingContext dbc, final NodeSensorRangeXMLConfig.Config config,
        final NodeSensorRangePreferencePage page) {

    this.page = page;
    defaultConfigClone = config.clone();
    defaultConfigClone.addPropertyChangeListener(dirtyListener);

    IObservableValue obsModel;//from   ww  w. j  a v a 2s  .  c om
    ISWTObservableValue obsWidget;
    UpdateValueStrategy usTargetToModel;
    UpdateValueStrategy usModelToTarget;
    final Realm realm = dbc.getValidationRealm();

    {
        obsWidget = SWTObservables.observeText(defaultLineWidth, SWT.Modify);
        obsModel = BeansObservables.observeValue(realm, defaultConfigClone,
                NodeSensorRangeXMLConfig.PROPERTYNAME_LINE_WIDTH);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setAfterConvertValidator(new IntegerRangeValidator("Line Width", 1, Integer.MAX_VALUE));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeSelection(defaultRangeType);
        obsModel = BeansObservables.observeValue(realm, defaultConfigClone,
                NodeSensorRangeXMLConfig.PROPERTYNAME_RANGE_TYPE);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                .setConverter(new NodeSensorRangeTypeConverter(String.class, Enum.class));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeBackground(defaultRangeForegroundColor);
        obsModel = BeansObservables.observeValue(realm, defaultConfigClone,
                NodeSensorRangeXMLConfig.PROPERTYNAME_COLOR_R_G_B);

        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setConverter(new ColorToRGBConverter());
        usModelToTarget = new UpdateValueStrategy();
        usModelToTarget.setConverter(new RGBToColorConverter());
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, usModelToTarget);
    }
    {
        obsWidget = SWTObservables.observeBackground(defaultRangeBackgroundColor);
        obsModel = BeansObservables.observeValue(realm, defaultConfigClone,
                NodeSensorRangeXMLConfig.PROPERTYNAME_BACKGROUND_R_G_B);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setConverter(new ColorToRGBConverter());
        usModelToTarget = new UpdateValueStrategy();
        usModelToTarget.setConverter(new RGBToColorConverter());
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, usModelToTarget);
    }
    {
        obsWidget = SWTObservables.observeText(defaultBackgroundAlphaTransparency, SWT.Modify);
        obsModel = BeansObservables.observeValue(realm, defaultConfigClone,
                NodeSensorRangeXMLConfig.PROPERTYNAME_BACKGROUND_ALPHA);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel
                .setAfterConvertValidator(new IntegerRangeValidator("Background Alpha Transparency", 0, 255));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }

    perNodeConfigurationComposite.setDataBinding(dbc, page);

}

From source file:de.uniluebeck.itm.spyglass.plugin.objectpainter.ObjectPainterOptionsComposite.java

License:Open Source License

public void setDatabinding(final DataBindingContext dbc, final ObjectPainterXMLConfig config,
        final Spyglass spyglass, final ObjectPainterPreferencePage page) {

    this.page = page;

    IObservableValue obsModel;/*from w  w w  . j  a  v a2  s  .  c  om*/
    ISWTObservableValue obsWidget;
    UpdateValueStrategy usTargetToModel;

    {
        obsWidget = SWTObservables.observeText(imageFileText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_IMAGE_FILE_NAME);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                .setAfterGetValidator(new FileReadableValidator());
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }

    {
        obsWidget = SWTObservables.observeText(imageSizeWidthText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_IMAGE_SIZE_X);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                .setAfterConvertValidator(new IntegerRangeValidator("Width", 0, Integer.MAX_VALUE));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(imageSizeHeightText, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_IMAGE_SIZE_Y);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                .setAfterConvertValidator(new IntegerRangeValidator("Height", 0, Integer.MAX_VALUE));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeSelection(this.drawLineCheckbox);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_DRAW_LINE);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeSelection(keepProportionsButton);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_KEEP_PROPORTIONS);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        final MetricsXMLConfig mConf = spyglass.getConfigStore().getSpyglassConfig().getGeneralSettings()
                .getMetrics();
        dbc.bindValue(SWTObservables.observeText(this.label3),
                BeansObservables.observeValue(dbc.getValidationRealm(), mConf, "unit"), null, null);
    }
    {
        final MetricsXMLConfig mConf = spyglass.getConfigStore().getSpyglassConfig().getGeneralSettings()
                .getMetrics();
        dbc.bindValue(SWTObservables.observeText(this.label3a),
                BeansObservables.observeValue(dbc.getValidationRealm(), mConf, "unit"), null, null);
    }
    // TODO:
    {
        final IObservableValue observableColor = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_LINE_COLOR);
        dbc.bindValue(SWTObservables.observeBackground(colorExample), observableColor,
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                        .setConverter(new ColorToArrayConverter()),
                new UpdateValueStrategy().setConverter(new ArrayToColorConverter(this.getDisplay())));
    }
    {
        final IObservableValue observable = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_PACKET_TYPE_3D);
        dbc.bindValue(SWTObservables.observeSelection(combo1), observable,
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                        .setConverter(new Converter("", true) {

                            @Override
                            public Object convert(final Object fromObject) {
                                return fromObject.equals("TrajectoryPacket3D");
                            }

                        }),
                new UpdateValueStrategy().setConverter(new Converter(true, "") {

                    @Override
                    public Object convert(final Object fromObject) {
                        return ((Boolean) fromObject) ? "TrajectoryPacket3D" : "TrajectoryPacket2D";
                    }
                }));
    }
    {
        obsWidget = SWTObservables.observeText(inteval, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                ObjectPainterXMLConfig.PROPERTYNAME_UPDATE_INTERVAL);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                .setAfterConvertValidator(new IntegerRangeValidator("Display update interval", 50, 10000));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }

}

From source file:de.uniluebeck.itm.spyglass.plugin.simplenodepainter.OptionsComposite.java

License:Open Source License

/**
 * Sets the parameters necessary for data binding
 * /*  w w  w . ja  v  a 2  s .  c  om*/
 * @param dbc
 *            the data binding context
 * @param config
 *            the configuration
 * @param page
 *            the plug-in's preference page
 */
public void setDatabinding(final DataBindingContext dbc, final PluginXMLConfig config,
        final SimpleNodePainterPreferencePage page) {

    this.page = page;

    // line width

    final IObservableValue modelObservable = BeansObservables.observeValue(dbc.getValidationRealm(), config,
            SimpleNodePainterXMLConfig.PROPERTYNAME_LINE_WIDTH);
    dbc.bindValue(SWTObservables.observeText(this.lineWidth, SWT.Modify), modelObservable,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

    // extended inf

    final IObservableValue observableExtInf = BeansObservables.observeValue(dbc.getValidationRealm(), config,
            SimpleNodePainterXMLConfig.PROPERTYNAME_EXTENDED_DEFAULT_VALUE);
    dbc.bindValue(SWTObservables.observeSelection(this.showExtInf), observableExtInf,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

    // node indertifier representation

    final IObservableValue observableNodeRepr = BeansObservables.observeValue(dbc.getValidationRealm(), config,
            SimpleNodePainterXMLConfig.PROPERTYNAME_NODE_IDS_AS_HEX);
    dbc.bindValue(SWTObservables.observeSelection(this.nodeIDsAsHex), observableNodeRepr,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

    // line color

    final IObservableValue observableColor = BeansObservables.observeValue(dbc.getValidationRealm(), config,
            SimpleNodePainterXMLConfig.PROPERTYNAME_LINE_COLOR_R_G_B);
    dbc.bindValue(SWTObservables.observeBackground(colorExample), observableColor,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                    .setConverter(new ColorToArrayConverter()),
            new UpdateValueStrategy().setConverter(new ArrayToColorConverter(this.getDisplay())));

    stringFormatter.setDataBinding(dbc, config);

}

From source file:de.uniluebeck.itm.spyglass.plugin.vectorsequencepainter.VectorSequencePainterOptionsComposite.java

License:Open Source License

public void setDatabinding(final DataBindingContext dbc, final VectorSequencePainterXMLConfig config,
        final VectorSequencePainterPreferencePage page) {

    this.page = page;

    IObservableValue obsModel;/*from  ww w .j a  v  a 2 s .c  om*/
    ISWTObservableValue obsWidget;
    UpdateValueStrategy usTargetToModel;
    UpdateValueStrategy usModelToTarget;

    {
        obsWidget = SWTObservables.observeText(lineWidth, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                VectorSequencePainterXMLConfig.PROPERTYNAME_LINE_WIDTH);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setAfterConvertValidator(new IntegerRangeValidator("Line Width", 1, Integer.MAX_VALUE));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeBackground(lineColor);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                VectorSequencePainterXMLConfig.PROPERTYNAME_LINE_COLOR_R_G_B);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setConverter(new ColorToArrayConverter());
        usModelToTarget = new UpdateValueStrategy();
        usModelToTarget.setConverter(new ArrayToColorConverter(this.getDisplay()));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, usModelToTarget);
    }
    {
        obsWidget = SWTObservables.observeText(ttl, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                PluginXMLConfig.PROPERTYNAME_TIMEOUT);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel
                .setAfterConvertValidator(new IntegerRangeValidator("Time To Live", 0, Integer.MAX_VALUE));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }
    {
        obsWidget = SWTObservables.observeText(dimension, SWT.Modify);
        obsModel = BeansObservables.observeValue(dbc.getValidationRealm(), config,
                VectorSequencePainterXMLConfig.PROPERTYNAME_DIMENSION);
        usTargetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
        usTargetToModel.setAfterConvertValidator(new IntegerRangeValidator("Dimension", 2, 3));
        dbc.bindValue(obsWidget, obsModel, usTargetToModel, null);
    }

}

From source file:org.eclipse.emf.ecp.view.template.controls.swt.TemplateColorControl.java

License:Open Source License

@Override
protected void fillControlComposite(final Composite composite) {
    final Composite main = new Composite(composite, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(main);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(main);
    super.fillControlComposite(main);

    final Label color = new Label(main, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(color);
    color.setText("Select Color");
    color.addMouseListener(new MouseListener() {

        public void mouseUp(MouseEvent e) {
            final ColorDialog cd = new ColorDialog(composite.getShell());
            cd.setText("Select Color");
            cd.setRGB(colors.get(getDomainModelReference().getIterator().next()).getRGB());
            final RGB rgb = cd.open();
            if (rgb == null) {
                return;
            }//from  w  w  w .j  a  v  a2  s. c  o  m

            final String red = Integer.toHexString(0x100 | rgb.red).substring(1);
            final String green = Integer.toHexString(0x100 | rgb.green).substring(1);
            final String blue = Integer.toHexString(0x100 | rgb.blue).substring(1);
            final String result = red + green + blue;
            getDomainModelReference().getIterator().next().set(result);
        }

        public void mouseDown(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseDoubleClick(MouseEvent e) {
            // TODO Auto-generated method stub

        }
    });
    final ISWTObservableValue observeBackground = SWTObservables.observeBackground(color);
    getDataBindingContext().bindValue(observeBackground, getModelValue(), new UpdateValueStrategy() {
        // targetToModel
        /**
         * {@inheritDoc}
         * 
         * @see org.eclipse.core.databinding.UpdateValueStrategy#convert(java.lang.Object)
         */
        @Override
        public Object convert(Object value) {
            if (value == null) {
                return "";
            }
            final Color color = (Color) value;
            final String red = Integer.toHexString(0x100 | color.getRed()).substring(1);
            final String green = Integer.toHexString(0x100 | color.getGreen()).substring(1);
            final String blue = Integer.toHexString(0x100 | color.getBlue()).substring(1);
            return red + green + blue;
        }

    }, new UpdateValueStrategy() {
        // ModelToTarget
        /**
         * {@inheritDoc}
         * 
         * @see org.eclipse.core.databinding.UpdateValueStrategy#convert(java.lang.Object)
         */
        @Override
        public Object convert(Object value) {
            if (value == null) {
                return null;
            }
            final String colorHex = (String) value;
            if (!colors.containsKey(value)) {
                final String redString = colorHex.substring(0, 2);
                final String greenString = colorHex.substring(2, 4);
                final String blueString = colorHex.substring(4, 6);
                final int red = Integer.parseInt(redString, 16);
                final int green = Integer.parseInt(greenString, 16);
                final int blue = Integer.parseInt(blueString, 16);
                colors.put(colorHex, new Color(Display.getDefault(), red, green, blue));
            }
            return colors.get(colorHex);
        }
    });
    color.setToolTipText("Press to select the color");
}

From source file:org.kalypso.ui.editor.styleeditor.fill.FillComposite.java

License:Open Source License

private void createColorControl(final FormToolkit toolkit, final Composite parent) {
    toolkit.createLabel(parent, Messages.getString("org.kalypso.ui.editor.sldEditor.FillEditorComposite.0")); //$NON-NLS-1$

    final Label colorLabel = toolkit.createLabel(parent, StringUtils.EMPTY, SWT.BORDER);
    final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gridData.widthHint = 16;//from   ww  w.java2 s .  c o m
    colorLabel.setLayoutData(gridData);
    colorLabel.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND));

    final IObservableValue target = SWTObservables.observeBackground(colorLabel);
    final IObservableValue model = new FillColorValue(m_input);

    m_binding.bindValue(target, model, new SwrToAwtColorConverter(),
            new AwtToSwtColorConverter(JFaceResources.getColorRegistry(), toString()));

    colorLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(final MouseEvent e) {
            final ColorDialog colorDialog = new ColorDialog(getShell());
            colorDialog.setRGB(ColorUtilities.toRGB((Color) model.getValue()));
            final RGB chosenColor = colorDialog.open();
            if (chosenColor != null)
                model.setValue(ColorUtilities.toAwtColor(chosenColor));
        }
    });
}