Example usage for org.eclipse.jface.databinding.swt WidgetProperties background

List of usage examples for org.eclipse.jface.databinding.swt WidgetProperties background

Introduction

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

Prototype

public static IWidgetValueProperty background() 

Source Link

Document

Returns a value property for observing the background color of a Control .

Usage

From source file:com.github.n_i_e.deepfolderview.SwtDuplicateMenu.java

License:Apache License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ////from   ww  w.ja va2  s.  c  om
    IObservableValue observeBackgroundCompositeObserveWidget = WidgetProperties.background()
            .observe(compositeToolBar);
    IObservableValue backgroundShellObserveValue = PojoProperties.value("background").observe(shell);
    bindingContext.bindValue(observeBackgroundCompositeObserveWidget, backgroundShellObserveValue, null, null);
    //
    IObservableValue observeBackgroundLblStatusBarObserveWidget = WidgetProperties.background()
            .observe(lblStatusBar);
    bindingContext.bindValue(observeBackgroundLblStatusBarObserveWidget, backgroundShellObserveValue, null,
            null);
    //
    IObservableValue observeBackgroundCompositeStatusBarObserveWidget = WidgetProperties.background()
            .observe(compositeStatusBar);
    bindingContext.bindValue(observeBackgroundCompositeStatusBarObserveWidget, backgroundShellObserveValue,
            null, null);
    //
    return bindingContext;
}

From source file:org.eclipse.emf.ecp.view.template.internal.tooling.controls.HexColorSelectionControlSWTRenderer.java

License:Open Source License

/**
 * {@inheritDoc}//from w w w .  j  a v  a2s .  c o m
 *
 * @see org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTControlSWTRenderer#createBindings(org.eclipse.swt.widgets.Control,
 *      org.eclipse.emf.ecore.EStructuralFeature.Setting)
 */
@Override
protected Binding[] createBindings(Control control) throws DatabindingFailedException {
    final Composite composite = Composite.class.cast(control);
    final Control childControl = composite.getChildren()[0];
    final IObservableValue value = WidgetProperties.background().observe(childControl);
    final Binding binding = getDataBindingContext().bindValue(value, getModelValue(),
            new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    if (value == null) {
                        return null;
                    }
                    return getString(Color.class.cast(value).getRGB());
                }
            }, new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    final String hexString = (String) value;
                    if (hexString == null) {
                        return null;
                    }
                    final int red = Integer.parseInt(hexString.substring(0, 2), 16);
                    final int green = Integer.parseInt(hexString.substring(2, 4), 16);
                    final int blue = Integer.parseInt(hexString.substring(4, 6), 16);
                    final Color color = new Color(Display.getCurrent(), red, green, blue);
                    return color;
                }

            });
    final IObservableValue textValue = WidgetProperties.tooltipText().observe(childControl);
    final Binding textBinding = getDataBindingContext().bindValue(textValue, getModelValue());
    return new Binding[] { binding, textBinding };
}

From source file:org.goko.serial.SerialConsolePart.java

License:Open Source License

protected DataBindingContext initDataBindings(MPart part) throws GkException {
    DataBindingContext bindingContext = new DataBindingContext();

    getController().addTextDisplayBinding(styledText, "console");
    getController().addSelectionBinding(btnCheckButton, "enabled");
    getController().addSelectionBinding(lockScrollButton, "lockScroll");
    getController().addEnableBinding(styledText, "enabled");
    getController().addItemsBinding(endLineTokenCombo, "choiceEndLineToken");
    getController().addItemSelectionBinding(endLineTokenCombo, "endLineToken");
    getController().addTextModifyBinding(currentCommandTxt, "currentCommand");

    IObservableValue observeBackgroundStyledTextObserveWidget = WidgetProperties.background()
            .observe(styledText);/*from  w w  w  . ja  va 2  s  . co  m*/
    IObservableValue backgroundBindingsObserveValue = BeanProperties.value("background")
            .observe(getDataModel());
    bindingContext.bindValue(observeBackgroundStyledTextObserveWidget, backgroundBindingsObserveValue,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
    //

    Map<String, String> state = part.getPersistedState();
    String consoleEnabledStr = state.get(CONSOLE_ENABLED);
    if (StringUtils.isNotEmpty(consoleEnabledStr)) {
        getDataModel().setEnabled(BooleanUtils.toBoolean(consoleEnabledStr));
    }
    String consoleScrollStr = state.get(CONSOLE_SCROLL_LOCKED);
    if (StringUtils.isNotEmpty(consoleScrollStr)) {
        getDataModel().setLockScroll(BooleanUtils.toBoolean(consoleScrollStr));
    }
    return bindingContext;
}

From source file:uk.ac.gda.client.plotting.TraceStyleDialog.java

License:Open Source License

private void createColorName(Composite container) {
    Label lbtFirstName = new Label(container, SWT.NONE);
    lbtFirstName.setText("Color");

    GridData dataFirstName = new GridData();
    dataFirstName.grabExcessHorizontalSpace = true;
    dataFirstName.horizontalAlignment = GridData.FILL;

    final Label colorLabel = new Label(container, SWT.BORDER);
    dataBindingCtx.bindValue(WidgetProperties.background().observe(colorLabel),
            BeanProperties.value(TraceStyleDetails.COLOR_HAX_VALUE_PROP_NAME).observe(traceStyle),
            new UpdateValueStrategy() {
                @Override//w  ww  . j  av a 2 s  .  c o  m
                public Object convert(Object fromObject) {
                    return UIHelper.convertRGBToHexadecimal(((Color) fromObject).getRGB());
                }
            }, new UpdateValueStrategy() {
                @Override
                public Object convert(Object fromObject) {
                    return UIHelper.convertHexadecimalToColor(traceStyle.getColorHexValue(),
                            TraceStyleDialog.this.getShell().getDisplay());
                }
            });

    colorLabel.setLayoutData(dataFirstName);
    colorLabel.addMouseListener(new MouseListener() {
        @Override
        public void mouseUp(MouseEvent e) {
            ColorDialog colorDialog = new ColorDialog(TraceStyleDialog.this.getShell());
            colorDialog.setText("Select your favorite color");
            RGB selectedColor = colorDialog.open();
            if (selectedColor != null) {
                traceStyle.setColorHexValue(UIHelper.convertRGBToHexadecimal(selectedColor));
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
}

From source file:uk.ac.stfc.isis.ibex.ui.blocks.groups.Group.java

License:Open Source License

/**
 * Provides the display of groups./*from w w w.j  a v  a  2  s  . co  m*/
 * 
 * @param parent a widget which will be the parent of the new instance
 * @param style the style of widget to construct
 * @param group the group to be displayed
 * @param panel The panel that shows the groups and blocks. 
 */
public Group(Composite parent, int style, DisplayGroup group, GroupsPanel panel) {
    super(parent, style | SWT.BORDER);

    // Add the blocks to the list if they are visible, or if
    // showHiddenBlocks is true
    List<DisplayBlock> blocksList = new ArrayList<>();
    for (DisplayBlock block : group.blocks()) {
        if (block.getIsVisible() || panel.showHiddenBlocks()) {
            blocksList.add(block);
        }
    }

    // Calculate number of columns we need, each column holding one block
    // with a name and value
    int numberOfColumns = (blocksList.size() - 1) / NUMBER_OF_ROWS + 1;

    // For each block we need three columns in the grid layout, one for
    // name, one for value, one for
    // run control status, and for every column but the last we need a
    // divider label column
    GridLayout layout = new GridLayout(NUMBER_OF_FIELDS * numberOfColumns + (numberOfColumns - 1), false);
    layout.verticalSpacing = 5;
    this.setLayout(layout);
    this.setBackground(WHITE);

    // In the first column put the title in
    title = labelMaker(this, SWT.NONE, group.name(), "", null);
    Font titleFont = getEditedLabelFont(title, 10, SWT.BOLD);
    title.setFont(titleFont);

    // For the title row, fill with blanks
    for (int i = 0; i < (NUMBER_OF_FIELDS + 1) * numberOfColumns - 2; i++) {
        labelMaker(this, SWT.NONE, "", "", titleFont);
    }

    DataBindingContext bindingContext = new DataBindingContext();

    // Loop over the rows and columns. The GridLayout is filled with labels
    // across rows first, then moving on to
    // the next column. So blank labels need to be inserted so that columns
    // are always filled.
    for (int i = 0; i < NUMBER_OF_ROWS; i++) {
        for (int j = 0; j < numberOfColumns; j++) {
            int position = i + j * NUMBER_OF_ROWS;

            if (position >= blocksList.size()) {
                // put blank labels in these name and value columns
                for (int k = 0; k < NUMBER_OF_FIELDS; k++) {
                    labelMaker(this, SWT.NONE, "", "", null);
                }
                break;
            }

            DisplayBlock currentBlock = blocksList.get(position);

            GroupsMenu fullMenu = new GroupsMenu(panel, new BlocksMenu(currentBlock));

            Label blockName = labelMaker(this, SWT.NONE, currentBlock.getName() + ": ",
                    currentBlock.getDescription(), null);
            blockName.setMenu(fullMenu.get());
            blockName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

            // additional container to hold value label to draw a border around it
            Composite valueContainer = new Composite(this, SWT.CENTER);
            GridLayout valueContainerLayout = new GridLayout(1, false);
            valueContainerLayout.marginWidth = 2;
            valueContainerLayout.marginHeight = 2;
            valueContainerLayout.verticalSpacing = 0;
            valueContainerLayout.horizontalSpacing = 0;
            valueContainer.setLayout(valueContainerLayout);

            GridData gdValueContainer = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
            gdValueContainer.widthHint = 79;
            gdValueContainer.heightHint = 19;
            valueContainer.setLayoutData(gdValueContainer);

            Label blockValue = labelMaker(valueContainer, SWT.RIGHT, currentBlock.getValue(),
                    currentBlock.getDescription(), null);
            blockValue.setMenu(fullMenu.get());
            GridData gdValue = new GridData(SWT.CENTER, SWT.NONE, false, false, 1, 1);
            gdValue.widthHint = 75;
            blockValue.setLayoutData(gdValue);
            blockValue.setVisible(true);
            valueContainer.pack();

            Label blockStatus = labelMaker(this, SWT.CENTER, "", "Run Control Status", null);
            FontDescriptor boldDescriptor = FontDescriptor.createFrom(blockStatus.getFont()).setStyle(SWT.BOLD);
            Font boldFont = boldDescriptor.createFont(blockStatus.getDisplay());
            blockStatus.setFont(boldFont);
            GridData gdStatus = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
            gdStatus.widthHint = 17;
            blockStatus.setLayoutData(gdStatus);

            if (j < numberOfColumns - 1) {
                // insert divider label
                labelMaker(this, SWT.NONE, "   |   ", "", null);
            }

            bindingContext.bindValue(WidgetProperties.text().observe(blockValue),
                    BeanProperties.value("value").observe(currentBlock));

            bindingContext.bindValue(WidgetProperties.visible().observe(blockStatus),
                    BeanProperties.value("enabled").observe(currentBlock));

            UpdateValueStrategy symbolStrategy = new UpdateValueStrategy();
            symbolStrategy.setConverter(new RunControlSymbolConverter());

            bindingContext.bindValue(WidgetProperties.text().observe(blockStatus),
                    BeanProperties.value("runcontrolState").observe(currentBlock), null, symbolStrategy);

            UpdateValueStrategy fgColourStrategy = new UpdateValueStrategy();
            fgColourStrategy.setConverter(new RunControlForegroundColourConverter());

            bindingContext.bindValue(WidgetProperties.foreground().observe(blockStatus),
                    BeanProperties.value("runcontrolState").observe(currentBlock), null, fgColourStrategy);

            UpdateValueStrategy bgColourStrategy = new UpdateValueStrategy();
            bgColourStrategy.setConverter(new RunControlBackgroundColourConverter());

            bindingContext.bindValue(WidgetProperties.background().observe(blockStatus),
                    BeanProperties.value("runcontrolState").observe(currentBlock), null, bgColourStrategy);

            UpdateValueStrategy borderStrategy = new UpdateValueStrategy();
            borderStrategy.setConverter(new BlockStatusBorderColourConverter());

            bindingContext.bindValue(WidgetProperties.background().observe(valueContainer),
                    BeanProperties.value("blockState").observe(currentBlock), null, borderStrategy);
        }
    }
}

From source file:uk.ac.stfc.isis.ibex.ui.dashboard.widgets.Banner.java

License:Open Source License

private void bind(BannerModel model) {
    DataBindingContext bindingContext = new DataBindingContext();
    bindingContext.bindValue(WidgetProperties.text().observe(bannerText),
            BeanProperties.value("value").observe(model.bannerText()));
    bindingContext.bindValue(WidgetProperties.background().observe(this),
            BeanProperties.value("value").observe(model.background()));
    bindingContext.bindValue(WidgetProperties.text().observe(runNumber),
            BeanProperties.value("value").observe(model.runNumber()));
    bindingContext.bindValue(WidgetProperties.text().observe(shutter),
            BeanProperties.value("value").observe(model.shutter()));
    bindingContext.bindValue(WidgetProperties.visible().observe(simMode),
            BeanProperties.value("value").observe(model.daeSimMode()));
}

From source file:uk.ac.stfc.isis.ibex.ui.motor.views.MinimalMotorView.java

License:Open Source License

/**
 * Binds the model to the view.//from   ww  w.j a v  a  2s.co  m
 */
private void bind() {

    bindingContext.bindValue(WidgetProperties.text().observe(setpoint),
            BeanProperties.value("setpoint").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.text().observe(value),
            BeanProperties.value("value").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.text().observe(motorName),
            BeanProperties.value("motorName").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.font().observe(motorName),
            BeanProperties.value("font").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.background().observe(motorName),
            BeanProperties.value("color").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.background().observe(indicator),
            BeanProperties.value("color").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.background().observe(value),
            BeanProperties.value("color").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.background().observe(setpoint),
            BeanProperties.value("color").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.background().observe(this),
            BeanProperties.value("color").observe(minimalMotorViewModel));

    bindingContext.bindValue(WidgetProperties.tooltipText().observe(this),
            BeanProperties.value("tooltip").observe(minimalMotorViewModel));

}