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

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

Introduction

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

Prototype

public static IWidgetValueProperty selection() 

Source Link

Document

Returns a value property for observing the selection state of a Button , CCombo , Combo , DateTime , List , MenuItem (since 1.5), Scale , Slider (since 1.5) or Spinner .

Usage

From source file:org.eclipse.gmf.tooling.simplemap.diagram.properties.figure.ElementWithLabelPropertySection.java

License:Open Source License

/**
 * @param object/*from w  ww.ja v a  2  s .  c  om*/
 *            The eObject to set.
 */
protected void setEObject(EObject object) {
    this.eObject = object;

    bindingContext.bindValue(WidgetProperties.selection().observe(fontFamilyCombo),
            EMFProperties.value(GMFGraphPackage.eINSTANCE.getBasicFont_FaceName()).observe(eObject));

    bindingContext.bindValue(WidgetProperties.selection().observe(fontSizeCombo),
            EMFProperties.value(GMFGraphPackage.eINSTANCE.getBasicFont_Height()).observe(eObject),
            new UpdateSizeTargetToModel(), new UpdateSizeModelToTarget());

    bindingContext.bindValue(WidgetProperties.selection().observe(fontBoldButton),
            EMFProperties.value(GMFGraphPackage.eINSTANCE.getBasicFont_Style()).observe(eObject),
            new UpdateBoldButtonTargetToModel(), new UpdateBoldButtonModelToTarget());

}

From source file:org.eclipse.ice.client.widgets.geometry.TransformationView.java

License:Open Source License

/**
 * //from  w w  w  .ja  v a  2 s .  co m
 */
private void createListeners() {

    IWidgetValueProperty property = WidgetProperties.selection();

    // Create anonymous listener

    RealSpinnerListener listener = new RealSpinnerListener() {

        @Override
        public void update(RealSpinner realSpinner) {

            // Handle a null currentShape

            if (currentShape == null) {
                return;
            }
            // Get all the spinner values

            double size = sizeSpinner.getValue();

            double scaleX = scaleSpinners[0].getValue();
            double scaleY = scaleSpinners[1].getValue();
            double scaleZ = scaleSpinners[2].getValue();

            double rotationX = rotationSpinners[0].getValue();
            double rotationY = rotationSpinners[1].getValue();
            double rotationZ = rotationSpinners[2].getValue();

            double translationX = translateSpinners[0].getValue();
            double translationY = translateSpinners[1].getValue();
            double translationZ = translateSpinners[2].getValue();

            // Convert rotation from degrees to radians if needed

            if (degrees) {
                rotationX = Math.toRadians(rotationX);
                rotationY = Math.toRadians(rotationY);
                rotationZ = Math.toRadians(rotationZ);
            }

            // Reset the Transformation to the new parameters

            Transformation transformation = new Transformation();
            transformation.setSize(size);
            transformation.setScale(scaleX, scaleY, scaleZ);
            transformation.setRotation(rotationX, rotationY, rotationZ);
            transformation.setTranslation(translationX, translationY, translationZ);

            // Reset the shape's transformation

            currentShape.setTransformation(transformation);
        }
    };

    // Add the listener to each spinner

    sizeSpinner.listen(listener);

    for (RealSpinner spinner : scaleSpinners) {
        spinner.listen(listener);
    }

    for (RealSpinner spinner : rotationSpinners) {
        spinner.listen(listener);
    }
    for (RealSpinner spinner : translateSpinners) {
        spinner.listen(listener);
    }
}

From source file:org.eclipse.incquery.tooling.ui.wizards.NewEiqGenmodelPage.java

License:Open Source License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ///*from  w  w  w  .j  av a  2 s  .  co m*/
    IObservableValue observeSelectionBtnInitializeGeneratorModelObserveWidget = WidgetProperties.selection()
            .observe(btnInitializeGeneratorModel);
    IObservableValue enabledReferencedGenmodelsObserveValue = PojoProperties.value("enabled")
            .observe(referencedGenmodels);
    bindingContext.bindValue(observeSelectionBtnInitializeGeneratorModelObserveWidget,
            enabledReferencedGenmodelsObserveValue, null, null);
    //
    IObservableValue observeEnabledAddGenmodelObserveWidget = WidgetProperties.enabled().observe(addGenmodel);
    IObservableValue observeSelectionBtnInitializeGeneratorModelObserveWidget_1 = WidgetProperties.selection()
            .observe(btnInitializeGeneratorModel);
    bindingContext.bindValue(observeEnabledAddGenmodelObserveWidget,
            observeSelectionBtnInitializeGeneratorModelObserveWidget_1, null, null);
    //
    return bindingContext;
}

From source file:org.eclipse.jubula.client.ui.rcp.search.page.AbstractSearchPage.java

License:Open Source License

/**
 * @param dbc// w ww  . j  ava2s . c o m
 *            the data binding context
 * @param parent
 *            the parent
 * @param searchableType
 *            the type to search for
 */
private void createTypeCheck(DataBindingContext dbc, Composite parent, TypeName searchableType) {
    Button check = new Button(parent, SWT.CHECK);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    check.setLayoutData(gd);
    check.setText(searchableType.getName());

    IObservableValue guiElement = WidgetProperties.selection().observe(check);
    IObservableValue modelElement = PojoObservables.observeValue(searchableType, "selected"); //$NON-NLS-1$
    dbc.bindValue(guiElement, modelElement);
}

From source file:org.eclipse.jubula.client.ui.rcp.search.page.AbstractSearchPage.java

License:Open Source License

/**
 * @param dbc//from w ww.  j ava 2  s  .c  o m
 *            the data binding context
 * @param parent
 *            the parent
 * @param searchableField
 *            the type to search for
 */
private void createFieldCheck(DataBindingContext dbc, Composite parent, FieldName searchableField) {
    Button check = new Button(parent, SWT.CHECK);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    check.setLayoutData(gd);
    check.setText(searchableField.getDescName());

    IObservableValue guiElement = WidgetProperties.selection().observe(check);
    IObservableValue modelElement = PojoObservables.observeValue(searchableField, "selected"); //$NON-NLS-1$
    dbc.bindValue(guiElement, modelElement);
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageMainTab.java

License:Open Source License

/**
 * Creates the {@link Composite} container that will display widgets to
 * select an {@link IDockerImage}, name it and specify the command to run.
 *
 * @param container//from  w  ww  .  j  a v  a  2  s  .  c  o  m
 *            the parent {@link Composite}
 */
private void createImageSettingsSection(final Composite container) {
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(3, 1)
            .applyTo(new Label(container, SWT.NONE));
    final Label connectionSelectionLabel = new Label(container, SWT.NONE);
    connectionSelectionLabel.setText(WizardMessages.getString("Connection.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(connectionSelectionLabel);
    final Combo connectionSelectionCombo = new Combo(container, SWT.BORDER);
    connectionSelectionCombo.setToolTipText(LaunchMessages.getString("RunMainTabSelectConnection.tooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(connectionSelectionCombo);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    new ControlDecoration(connectionSelectionCombo, SWT.TOP | SWT.LEFT);
    final ComboViewer connectionSelectionComboViewer = new ComboViewer(connectionSelectionCombo);
    connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    connectionSelectionComboViewer.setInput(getConnectionNames());
    dbc.bindValue(WidgetProperties.selection().observe(connectionSelectionCombo),
            BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_CONNECTION_NAME)
                    .observe(model));
    // Image selection name
    final Label imageSelectionLabel = new Label(container, SWT.NONE);
    imageSelectionLabel.setText(WizardMessages.getString("Image.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    final Combo imageSelectionCombo = new Combo(container, SWT.BORDER);
    final ComboViewer imageSelectionComboViewer = new ComboViewer(imageSelectionCombo);
    imageSelectionCombo.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.selectTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(imageSelectionCombo);
    new ControlDecoration(imageSelectionCombo, SWT.TOP | SWT.LEFT);
    new ContentProposalAdapter(imageSelectionCombo, new ComboContentAdapter() {
        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Combo combo = (Combo) control;
            final Point selection = combo.getSelection();
            combo.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            combo.setSelection(selection);
        }
    }, getImageNameContentProposalProvider(imageSelectionCombo), null, null);
    // image search
    final Button searchImageButton = new Button(container, SWT.NONE);
    searchImageButton.setText(WizardMessages.getString("ImageRunSelectionPage.search")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .hint(LaunchConfigurationUtils.getButtonWidthHint(searchImageButton), SWT.DEFAULT)
            .applyTo(searchImageButton);
    searchImageButton.addSelectionListener(onSearchImage());
    imageSelectionComboViewer.setContentProvider(new ObservableListContentProvider());
    dbc.bindList(WidgetProperties.items().observe(imageSelectionCombo), BeanProperties
            .list(ImageRunSelectionModel.class, ImageRunSelectionModel.IMAGE_NAMES).observe(model));
    dbc.bindValue(WidgetProperties.selection().observe(imageSelectionCombo), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NAME).observe(model));
    // Container name (optional)
    final Label containerNameLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    containerNameLabel.setText("Name:"); //$NON-NLS-1$
    final Text containerNameText = new Text(container, SWT.BORDER);
    containerNameText.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.containerTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(containerNameText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerNameText), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.CONTAINER_NAME).observe(model));
    // EntryPoint (optional)
    final Label entrypointLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    entrypointLabel.setText(WizardMessages.getString("ImageRunSelectionPage.entrypoint")); //$NON-NLS-1$
    // TODO: include SWT.SEARCH | SWT.ICON_SEARCH to support value reset
    final Text entrypointText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(entrypointText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(entrypointText), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.ENTRYPOINT).observe(model));

    // Command (optional)
    final Label commandLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    commandLabel.setText(WizardMessages.getString("ImageRunSelectionPage.command")); //$NON-NLS-1$
    final Text commandText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(commandText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(commandText),
            BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.COMMAND).observe(model));
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageMainTab.java

License:Open Source License

private void createRunOptionsSection(final Composite container) {
    // interactive/show in console mode
    final Button interactiveButton = new Button(container, SWT.CHECK);
    interactiveButton.setText(WizardMessages.getString("ImageRunSelectionPage.openStdin")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false)
            .applyTo(interactiveButton);
    dbc.bindValue(WidgetProperties.selection().observe(interactiveButton), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.INTERACTIVE_MODE).observe(model));
    // allocate pseudo-TTY
    final Button allocatePseudoTTY = new Button(container, SWT.CHECK);
    allocatePseudoTTY.setText(WizardMessages.getString("ImageRunSelectionPage.tty")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false)
            .applyTo(allocatePseudoTTY);
    dbc.bindValue(WidgetProperties.selection().observe(allocatePseudoTTY), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.ALLOCATE_PSEUDO_TTY).observe(model));

    // remove when exits
    final Button removeWhenExitsButton = new Button(container, SWT.CHECK);
    removeWhenExitsButton.setText(WizardMessages.getString("ImageRunSelectionPage.autoRemove")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false)
            .applyTo(removeWhenExitsButton);
    dbc.bindValue(WidgetProperties.selection().observe(removeWhenExitsButton), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.REMOVE_WHEN_EXITS).observe(model));

    // privileged
    final Button privilegedButton = new Button(container, SWT.CHECK);
    privilegedButton.setText(WizardMessages.getString("ImageRunSelectionPage.privileged")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false)
            .applyTo(privilegedButton);//from  w w w. j a v  a 2 s.c  o m
    dbc.bindValue(WidgetProperties.selection().observe(privilegedButton), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.PRIVILEGED).observe(model));
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImagePortsTab.java

License:Open Source License

private void createPortSettingsSection(final Composite container) {
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(3, 1)
            .applyTo(new Label(container, SWT.NONE));
    final Button publishAllPortsButton = new Button(container, SWT.CHECK);
    publishAllPortsButton.setText(WizardMessages.getString("ImageRunSelectionPage.publishAllPorts")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false)
            .applyTo(publishAllPortsButton);
    dbc.bindValue(WidgetProperties.selection().observe(publishAllPortsButton), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.PUBLISH_ALL_PORTS).observe(model));
    // specify ports
    final Label portSettingsLabel = new Label(container, SWT.NONE);
    portSettingsLabel.setText(WizardMessages.getString("ImageRunSelectionPage.portSettings")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS, 1)
            .indent(INDENT, 0).applyTo(portSettingsLabel);
    final CheckboxTableViewer exposedPortsTableViewer = createPortSettingsTable(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(COLUMNS - 1, 1)
            .indent(INDENT, 0).hint(200, 70).applyTo(exposedPortsTableViewer.getTable());
    // buttons/*w  ww  .  ja v  a  2 s  .c  o m*/
    final Composite buttonsContainers = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(false, false).applyTo(buttonsContainers);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(SWT.DEFAULT, 0)
            .applyTo(buttonsContainers);

    final Button addButton = new Button(buttonsContainers, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(addButton);
    addButton.setText(WizardMessages.getString("ImageRunSelectionPage.add")); //$NON-NLS-1$
    addButton.addSelectionListener(onAddPort(exposedPortsTableViewer));
    final Button editButton = new Button(buttonsContainers, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(editButton);
    editButton.setText(WizardMessages.getString("ImageRunSelectionPage.editButton")); //$NON-NLS-1$
    editButton.setEnabled(false);
    editButton.addSelectionListener(onEditPort(exposedPortsTableViewer));
    final Button removeButton = new Button(buttonsContainers, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(removeButton);
    removeButton.setText(WizardMessages.getString("ImageRunSelectionPage.remove")); //$NON-NLS-1$
    removeButton.addSelectionListener(onRemovePorts(exposedPortsTableViewer));
    BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.PUBLISH_ALL_PORTS).observe(model)
            .addValueChangeListener(
                    onPublishAllPortsChange(exposedPortsTableViewer.getTable(), addButton, removeButton));
    ViewerSupport.bind(exposedPortsTableViewer, model.getExposedPorts(),
            BeanProperties.values(ExposedPortModel.class, new String[] { ExposedPortModel.CONTAINER_PORT,
                    ExposedPortModel.PORT_TYPE, ExposedPortModel.HOST_ADDRESS, ExposedPortModel.HOST_PORT }));
    dbc.bindSet(ViewersObservables.observeCheckedElements(exposedPortsTableViewer, ExposedPortModel.class),
            BeanProperties.set(ImageRunSelectionModel.SELECTED_PORTS).observe(model));

    // disable the edit and removeButton if the table is empty
    exposedPortsTableViewer.addSelectionChangedListener(onSelectionChanged(editButton, removeButton));
    exposedPortsTableViewer.addCheckStateListener(onCheckStateChanged());

    togglePortMappingControls(exposedPortsTableViewer.getTable(), addButton, removeButton);
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageResourcesTab.java

License:Open Source License

private void createResourceSettingsContainer(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false)
            .applyTo(container);/*from w  w w.  j a v a 2  s  . c  om*/
    GridLayoutFactory.fillDefaults().spacing(10, 2).applyTo(container);
    final Button enableResourceLimitationButton = new Button(container, SWT.CHECK);
    enableResourceLimitationButton
            .setText(WizardMessages.getString("ImageRunResourceVolVarPage.enableLimitationButton")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(enableResourceLimitationButton);
    dbc.bindValue(WidgetProperties.selection().observe(enableResourceLimitationButton),
            BeanProperties.value(ImageRunResourceVolumesVariablesModel.class,
                    ImageRunResourceVolumesVariablesModel.ENABLE_RESOURCE_LIMITATIONS).observe(model));

    final int COLUMNS = 5;
    final int INDENT = 20;
    final Composite subContainer = new Composite(container, SWT.NONE);
    setContainer(subContainer);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).indent(INDENT, 0).span(COLUMNS, 1)
            .grab(true, false).applyTo(subContainer);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).spacing(10, 2).applyTo(subContainer);

    // specify CPU limitation
    final Label cpuPriorityLabel = new Label(subContainer, SWT.NONE);
    cpuPriorityLabel.setText(WizardMessages.getString("ImageRunResourceVolVarPage.cpuPriorityLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(cpuPriorityLabel);
    final Button lowCPULimitationButton = new Button(subContainer, SWT.RADIO);
    lowCPULimitationButton.setText(WizardMessages.getString("ImageRunResourceVolVarPage.lowButton")); //$NON-NLS-1$
    bindButton(lowCPULimitationButton, ImageRunResourceVolumesVariablesModel.CPU_LOW);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lowCPULimitationButton);
    final Button mediumCPULimitationButton = new Button(subContainer, SWT.RADIO);
    mediumCPULimitationButton.setText(WizardMessages.getString("ImageRunResourceVolVarPage.mediumButton")); //$NON-NLS-1$
    bindButton(mediumCPULimitationButton, ImageRunResourceVolumesVariablesModel.CPU_MEDIUM);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(mediumCPULimitationButton);
    final Button highCPULimitationButton = new Button(subContainer, SWT.RADIO);
    highCPULimitationButton.setText(WizardMessages.getString("ImageRunResourceVolVarPage.highButton")); //$NON-NLS-1$
    bindButton(highCPULimitationButton, ImageRunResourceVolumesVariablesModel.CPU_HIGH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).applyTo(highCPULimitationButton);

    // Memory limitation
    final Label memoryLimitLabel = new Label(subContainer, SWT.NONE);
    memoryLimitLabel.setText(WizardMessages.getString("ImageRunResourceVolVarPage.memoryLimit")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(memoryLimitLabel);
    final Scale memoryLimitSpinner = new Scale(subContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(2, 1)
            .applyTo(memoryLimitSpinner);
    memoryLimitSpinner.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
    memoryLimitSpinner.setMinimum(0);
    memoryLimitSpinner.setMaximum(this.model.getTotalMemory());
    memoryLimitSpinner.setPageIncrement(64);
    dbc.bindValue(WidgetProperties.selection().observe(memoryLimitSpinner),
            BeanProperties.value(ImageRunResourceVolumesVariablesModel.class,
                    ImageRunResourceVolumesVariablesModel.MEMORY_LIMIT).observe(model));

    final Text memoryLimitValueText = new Text(subContainer, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).hint(50, SWT.DEFAULT)
            .applyTo(memoryLimitValueText);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(memoryLimitValueText),
            BeanProperties.value(ImageRunResourceVolumesVariablesModel.class,
                    ImageRunResourceVolumesVariablesModel.MEMORY_LIMIT).observe(model));
    dbc.bindValue(WidgetProperties.selection().observe(memoryLimitSpinner),
            BeanProperties.value(ImageRunResourceVolumesVariablesModel.class,
                    ImageRunResourceVolumesVariablesModel.MEMORY_LIMIT).observe(model));
    final Label memoryLimitValueLabel = new Label(subContainer, SWT.NONE);
    memoryLimitValueLabel.setText("MB"); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(memoryLimitValueLabel);

    // enable/disable controls
    final IObservableValue enableResourceLimitationsObservable = BeanProperties
            .value(ImageRunResourceVolumesVariablesModel.class,
                    ImageRunResourceVolumesVariablesModel.ENABLE_RESOURCE_LIMITATIONS)
            .observe(model);
    dbc.bindValue(WidgetProperties.selection().observe(enableResourceLimitationButton),
            enableResourceLimitationsObservable);
    enableResourceLimitationsObservable.addChangeListener(onEnableResourceLimitation(subContainer));
    toggleResourceLimitationControls(subContainer);

}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageResourcesTab.java

License:Open Source License

/**
 * Binds the given <code>cpuShares</code> value to the given {@link Button}
 * when it is selected./* w w w  .  ja va  2s .com*/
 * 
 * @param button
 *            the {@link Button} to bind
 * @param cpuShares
 *            the <code>cpuShares</code> to bind to the {@link Button}
 * @return
 */
private Binding bindButton(final Button button, final long cpuShares) {
    return dbc.bindValue(WidgetProperties.selection().observe(button),
            BeanProperties.value(ImageRunResourceVolumesVariablesModel.class,
                    ImageRunResourceVolumesVariablesModel.CPU_SHARE_WEIGHT).observe(model),
            new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    if (value.equals(Boolean.TRUE)) {
                        return cpuShares;
                    }
                    return 0l;
                }

            }, new UpdateValueStrategy() {
                @Override
                public Object convert(final Object value) {
                    return value.equals(cpuShares);
                }
            });
}