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.linuxtools.internal.docker.ui.wizards.ContainerLinkDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    final int COLUMNS = 2;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false)
            .applyTo(container);//from www.j  a v a  2 s  .  co m
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(10, 10).applyTo(container);
    final Label explanationLabel = new Label(container, SWT.NONE);
    explanationLabel.setText(WizardMessages.getString("ContainerLinkDialog.explanationLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(false, false)
            .applyTo(explanationLabel);
    final Label containerLabel = new Label(container, SWT.NONE);
    containerLabel.setText(WizardMessages.getString("ContainerLinkDialog.containerLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(containerLabel);
    final Combo containerSelectionCombo = new Combo(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(containerSelectionCombo);
    final ComboViewer containerSelectionComboViewer = new ComboViewer(containerSelectionCombo);
    containerSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    containerSelectionComboViewer.setInput(model.getContainerNames());
    new ContentProposalAdapter(containerSelectionCombo, 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);
        }
    }, getContainerNameContentProposalProvider(containerSelectionCombo), null, null);
    final Label aliasLabel = new Label(container, SWT.NONE);
    aliasLabel.setText(WizardMessages.getString("ContainerLinkDialog.aliasLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(aliasLabel);
    final Text containerAliasText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(containerAliasText);
    // error message
    final Label errorMessageLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false)
            .applyTo(errorMessageLabel);

    final ISWTObservableValue containerNameObservable = WidgetProperties.selection()
            .observe(containerSelectionComboViewer.getCombo());

    dbc.bindValue(containerNameObservable, BeanProperties
            .value(ContainerLinkDialogModel.class, ContainerLinkDialogModel.CONTAINER_NAME).observe(model));
    final ISWTObservableValue containerAliasObservable = WidgetProperties.text(SWT.Modify)
            .observe(containerAliasText);

    dbc.bindValue(containerAliasObservable, BeanProperties
            .value(ContainerLinkDialogModel.class, ContainerLinkDialogModel.CONTAINER_ALIAS).observe(model));
    containerNameObservable.addValueChangeListener(onContainerLinkSettingsChanged());
    containerAliasObservable.addValueChangeListener(onContainerLinkSettingsChanged());
    return container;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.EditDockerConnectionPage.java

License:Open Source License

/**
 * Creates the connection settings container, where the user can choose how
 * to connect to the docker daemon (using sockets or TCP with SSL - or not)
 * /*from ww  w.ja  v a 2s  . co m*/
 * @param parent
 *            the parent container (ie, the main container in the preference
 *            page)
 */
@SuppressWarnings("unchecked")
private void createConnectionSettingsContainer(final Composite parent) {
    final int COLUMNS = 3;
    final int INDENT = 20;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).spacing(10, 2).applyTo(container);

    // Connection name
    final Label connectionNameLabel = new Label(container, SWT.NONE);
    connectionNameLabel.setText(WizardMessages.getString("DockerConnectionPage.nameLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(connectionNameLabel);
    final Text connectionNameText = new Text(container, SWT.BORDER);
    connectionNameText.setToolTipText(WizardMessages.getString("DockerConnectionPage.nameTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1)
            .applyTo(connectionNameText);

    // Unix socket
    final Button unixSocketBindingModeButton = new Button(container, SWT.RADIO);
    unixSocketBindingModeButton.setText(WizardMessages.getString("DockerConnectionPage.unixSocket")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(0, 10).span(COLUMNS, 1)
            .applyTo(unixSocketBindingModeButton);

    final Label unixSocketPathLabel = new Label(container, SWT.NONE);
    unixSocketPathLabel.setText(WizardMessages.getString("DockerConnectionPage.location")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).applyTo(unixSocketPathLabel);
    final Text unixSocketPathText = new Text(container, SWT.BORDER);
    unixSocketPathText.setToolTipText(WizardMessages.getString("DockerConnectionPage.unixPathTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(unixSocketPathText);

    final Button unixSocketPathBrowseButton = new Button(container, SWT.BUTTON1);
    unixSocketPathBrowseButton.setText(WizardMessages.getString("DockerConnectionPage.browseButton")); //$NON-NLS-1$
    unixSocketPathBrowseButton.addSelectionListener(onBrowseUnixSocketPath());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(unixSocketPathBrowseButton);

    // TCP connection
    final Button tcpConnectionBindingModeButton = new Button(container, SWT.RADIO);
    tcpConnectionBindingModeButton.setText(WizardMessages.getString("DockerConnectionPage.tcpConnection")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1)
            .applyTo(tcpConnectionBindingModeButton);

    final Label tcpHostLabel = new Label(container, SWT.NONE);
    tcpHostLabel.setText(WizardMessages.getString("DockerConnectionPage.hostLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).applyTo(tcpHostLabel);

    final Text tcpHostText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false)
            .applyTo(tcpHostText);

    final Button tcpAuthButton = new Button(container, SWT.CHECK);
    tcpAuthButton.setText(WizardMessages.getString("DockerConnectionPage.tcpAuthButton")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).span(3, 1)
            .applyTo(tcpAuthButton);

    final Label tcpCertPathLabel = new Label(container, SWT.NONE);
    tcpCertPathLabel.setText(WizardMessages.getString("DockerConnectionPage.tcpPathLabel")); //$NON-NLS-1$
    tcpCertPathLabel.setToolTipText(WizardMessages.getString("DockerConnectionPage.tcpPathTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT * 2, 0).applyTo(tcpCertPathLabel);
    final Text tcpCertPathText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(tcpCertPathText);
    final Button tcpCertPathBrowseButton = new Button(container, SWT.BUTTON1);
    tcpCertPathBrowseButton.setText(WizardMessages.getString("DockerConnectionPage.browseButton")); //$NON-NLS-1$
    tcpCertPathBrowseButton.addSelectionListener(onBrowseTcpCertPath());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(tcpCertPathBrowseButton);

    // the 'test connection' button
    final Button testConnectionButton = new Button(container, SWT.NONE);
    testConnectionButton.setText(WizardMessages.getString("DockerConnectionPage.testConnection")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().span(3, 1).indent(0, 10).align(SWT.END, SWT.CENTER)
            .applyTo(testConnectionButton);
    testConnectionButton.addSelectionListener(onTestConnectionButtonSelection());

    // observe
    final IObservableValue<String> connectionNameModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class, EditDockerConnectionPageModel.CONNECTION_NAME)
            .observe(model);
    final IObservableValue<Boolean> unixSocketBindingModeModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class, EditDockerConnectionPageModel.UNIX_SOCKET_BINDING_MODE)
            .observe(model);
    final IObservableValue<String> unixSocketPathModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class, EditDockerConnectionPageModel.UNIX_SOCKET_PATH)
            .observe(model);

    final IObservableValue<Boolean> tcpConnectionBindingModeModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class,
                    EditDockerConnectionPageModel.TCP_CONNECTION_BINDING_MODE)
            .observe(model);
    final IObservableValue<String> tcpCertPathModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class, EditDockerConnectionPageModel.TCP_CERT_PATH)
            .observe(model);
    final IObservableValue<Boolean> tcpTlsVerifyModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class, EditDockerConnectionPageModel.TCP_TLS_VERIFY)
            .observe(model);
    final IObservableValue<String> tcpHostModelObservable = BeanProperties
            .value(EditDockerConnectionPageModel.class, EditDockerConnectionPageModel.TCP_HOST).observe(model);

    // group controls to easily enable/disable them
    final Control[] unixSocketControls = new Control[] { unixSocketPathText, unixSocketPathLabel,
            unixSocketPathBrowseButton };
    final Control[] tcpConnectionControls = new Control[] { tcpHostText, tcpHostLabel, tcpAuthButton };
    final Control[] tcpAuthControls = new Control[] { tcpCertPathText, tcpCertPathLabel,
            tcpCertPathBrowseButton };
    unixSocketBindingModeModelObservable.addChangeListener(onUnixSocketBindingSelection(unixSocketControls));
    tcpConnectionBindingModeModelObservable
            .addChangeListener(onTcpConnectionBindingSelection(tcpConnectionControls, tcpAuthControls));
    tcpTlsVerifyModelObservable.addValueChangeListener(onTcpAuthSelection(tcpAuthControls));

    // bind controls to model
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(connectionNameText), connectionNameModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(unixSocketBindingModeButton),
            unixSocketBindingModeModelObservable);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(unixSocketPathText), unixSocketPathModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(tcpConnectionBindingModeButton),
            tcpConnectionBindingModeModelObservable);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(tcpHostText), tcpHostModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(tcpAuthButton), tcpTlsVerifyModelObservable);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(tcpCertPathText), tcpCertPathModelObservable);
    // validations will be performed when the user changes the value
    // only, not at the dialog opening
    dbc.addValidationStatusProvider(
            new ConnectionNameValidator(connectionNameModelObservable, this.model.getInitialConnectionName()));
    dbc.addValidationStatusProvider(
            new UnixSocketValidator(unixSocketBindingModeModelObservable, unixSocketPathModelObservable));
    dbc.addValidationStatusProvider(
            new TcpHostValidator(tcpConnectionBindingModeModelObservable, tcpHostModelObservable));
    dbc.addValidationStatusProvider(new TcpCertificatesValidator(tcpConnectionBindingModeModelObservable,
            tcpTlsVerifyModelObservable, tcpCertPathModelObservable));

    // give focus to connectionName text at first
    connectionNameText.setFocus();
    // set widgets initial state
    updateWidgetsState(unixSocketControls, tcpConnectionControls, tcpAuthControls);
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImageBuildDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    final int COLUMNS = 2;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false)
            .applyTo(container);//from  www .  j  av a  2 s  .c  om
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(10, 10).applyTo(container);
    final Label explanationLabel = new Label(container, SWT.NONE);
    explanationLabel.setText(WizardMessages.getString("ImageBuildDialog.explanationLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(false, false)
            .applyTo(explanationLabel);
    final Label containerLabel = new Label(container, SWT.NONE);
    containerLabel.setText(WizardMessages.getString("ImageBuildDialog.connectionLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(containerLabel);
    final Combo containerSelectionCombo = new Combo(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(containerSelectionCombo);
    final ComboViewer connectionSelectionComboViewer = new ComboViewer(containerSelectionCombo);
    connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    final List<String> connectionNames = model.getConnectionNames();
    connectionSelectionComboViewer.setInput(connectionNames);
    new ContentProposalAdapter(containerSelectionCombo, 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);
        }
    }, getConnectionNameContentProposalProvider(containerSelectionCombo), null, null);
    final Label repoNameLabel = new Label(container, SWT.NONE);
    repoNameLabel.setText(WizardMessages.getString("ImageBuildDialog.repoNameLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(repoNameLabel);
    final Text repoNameText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(repoNameText);
    final ISWTObservableValue connnectionNameObservable = WidgetProperties.selection()
            .observe(connectionSelectionComboViewer.getCombo());
    // pre-select with first connection
    if (!connectionNames.isEmpty()) {
        model.setConnectionName(connectionNames.get(0));
    }
    // error message
    final Composite errorContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, true)
            .applyTo(errorContainer);
    GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(errorContainer);

    final Label errorMessageIcon = new Label(errorContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(20, SWT.DEFAULT).applyTo(errorMessageIcon);
    final Label errorMessageLabel = new Label(errorContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(errorMessageLabel);
    dbc.bindValue(connnectionNameObservable, BeanProperties
            .value(ImageBuildDialogModel.class, ImageBuildDialogModel.CONNECTION_NAME).observe(model));
    final ISWTObservableValue repoNameObservable = WidgetProperties.text(SWT.Modify).observe(repoNameText);

    dbc.bindValue(repoNameObservable,
            BeanProperties.value(ImageBuildDialogModel.class, ImageBuildDialogModel.REPO_NAME).observe(model));
    // must be called after bindings were set
    setupValidationSupport(errorMessageIcon, errorMessageLabel);
    return container;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImagePushPage.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w  ww.  ja  va  2s .  c  o  m*/
public void createControl(final Composite parent) {
    parent.setLayout(new GridLayout());
    final Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(container);

    // registry selection
    final IObservableValue<IRegistry> registryAccountObservable = super.createRegistrySelectionControls(
            container);
    // image selection
    final IObservableValue<String> imageNameObservable = createImageSelectionControls(container);

    // force tagging
    final Button forceTaggingButton = new Button(container, SWT.CHECK);
    forceTaggingButton.setText(WizardMessages.getString("ImagePushPage.forcetagging.label")); //$NON-NLS-1$ );
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1)
            .applyTo(forceTaggingButton);
    dbc.bindValue(WidgetProperties.selection().observe(forceTaggingButton), BeanProperties
            .value(ImagePushPageModel.class, ImagePushPageModel.FORCE_TAGGING).observe(getModel()));

    // keep tagged image upon completion
    final Button keepTaggedImageButton = new Button(container, SWT.CHECK);
    keepTaggedImageButton.setText(WizardMessages.getString("ImagePushPage.keeptaggedimage.label")); //$NON-NLS-1$ );
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1)
            .applyTo(keepTaggedImageButton);
    dbc.bindValue(WidgetProperties.selection().observe(keepTaggedImageButton), BeanProperties
            .value(ImagePushPageModel.class, ImagePushPageModel.KEEP_TAGGED_IMAGE).observe(getModel()));

    // setup validation support
    WizardPageSupport.create(this, dbc);
    dbc.addValidationStatusProvider(
            getModel().new ImagePushValidator(imageNameObservable, registryAccountObservable));
    setControl(container);
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImagePushPage.java

License:Open Source License

@SuppressWarnings("unchecked")
private IObservableValue<String> createImageSelectionControls(final Composite container) {
    final Label nameLabel = new Label(container, SWT.NULL);
    nameLabel.setText(WizardMessages.getString("ImagePullPushPage.name.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(nameLabel);
    final Combo imageNameCombo = new Combo(container, SWT.DROP_DOWN);
    imageNameCombo.setToolTipText(WizardMessages.getString("ImagePushName.toolTip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameCombo);
    final ComboViewer imageNameComboViewer = new ComboViewer(imageNameCombo);
    imageNameComboViewer.setContentProvider(new ArrayContentProvider());
    imageNameComboViewer.setInput(getModel().getImage().repoTags());
    // binding must take place after the input is set, so that default
    // repo/name can be selected.
    final IObservableValue<String> imageNameObservable = BeanProperties
            .value(ImagePushPageModel.class, ImagePullPushPageModel.SELECTED_IMAGE_NAME).observe(getModel());
    dbc.bindValue(WidgetProperties.selection().observe(imageNameCombo), imageNameObservable);
    // filler for the last column
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(new Label(container, SWT.NONE));
    return imageNameObservable;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunResourceVolumesVariablesPage.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);//  www.j ava 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);
    final int COLUMNS = 5;
    final int INDENT = 20;
    final Composite subContainer = new Composite(container, SWT.NONE);
    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);
    bindButton(lowCPULimitationButton, ImageRunResourceVolumesVariablesModel.CPU_LOW);
    lowCPULimitationButton.setText(WizardMessages.getString("ImageRunResourceVolVarPage.lowButton")); //$NON-NLS-1$
    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));
    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.wizards.ImageRunSelectionPage.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.
 * /* w  w  w  . ja  v a 2s.c  om*/
 * @param container
 *            the parent {@link Composite}
 */
private void createImageSettingsSection(final Composite container) {
    // Image selection name
    final Label imageSelectionLabel = new Label(container, SWT.NONE);
    imageSelectionLabel.setText(WizardMessages.getString("ImageRunSelectionPage.imageName")); //$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)
            .applyTo(searchImageButton);
    searchImageButton.addSelectionListener(onSearchImage());
    // link to pull image
    final Label fillerLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(fillerLabel);
    final Link pullImageLink = new Link(container, SWT.NONE);
    pullImageLink.setText(WizardMessages.getString("ImageRunSelectionPage.pullImage")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS - 1, 1)
            .applyTo(pullImageLink);
    pullImageLink.addSelectionListener(onPullImage());
    dbc.bindValue(WidgetProperties.enabled().observe(pullImageLink),
            BeanProperties
                    .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NEEDS_PULLING)
                    .observe(model));
    // bind combo with model (for values and selection)
    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(WizardMessages.getString("ImageRunSelectionPage.containerName")); //$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.wizards.ImageRunSelectionPage.java

License:Open Source License

private void createPortSettingsSection(final Composite container) {
    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 w  w  . j a  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));
    checkAllElements(exposedPortsTableViewer);

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

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

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.NewDockerConnectionPage.java

License:Open Source License

/**
 * Creates the connection settings container, where the user can choose how
 * to connect to the docker daemon (using sockets or TCP with SSL - or not)
 * //from ww  w .  j  a  va  2  s . c om
 * @param parent
 *            the parent container (ie, the main container in the preference
 *            page)
 */
private void createConnectionSettingsContainer(final Composite parent) {
    final int COLUMNS = 3;
    final int INDENT = 20;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).spacing(10, 2).applyTo(container);

    // Connection name
    final Label connectionNameLabel = new Label(container, SWT.NONE);
    connectionNameLabel.setText(WizardMessages.getString("DockerConnectionPage.nameLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(connectionNameLabel);
    final Text connectionNameText = new Text(container, SWT.BORDER);
    connectionNameText.setToolTipText(WizardMessages.getString("DockerConnectionPage.nameTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(connectionNameText);

    // the 'Search' button
    final Button searchButton = new Button(container, SWT.NONE);
    searchButton.setText(WizardMessages.getString("DockerConnectionPage.searchButton")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).align(SWT.BEGINNING, SWT.CENTER)
            .grab(false, false).applyTo(searchButton);
    searchButton.addSelectionListener(onSearchButtonSelection());

    // custom settings checkbox
    final Button customConnectionSettingsButton = new Button(container, SWT.CHECK);
    customConnectionSettingsButton.setText(WizardMessages.getString("DockerConnectionPage.customLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).indent(0, 10).span(COLUMNS, 1)
            .applyTo(customConnectionSettingsButton);
    final Group customSettingsGroup = new Group(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false)
            .applyTo(customSettingsGroup);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).spacing(10, 2)
            .applyTo(customSettingsGroup);

    // Unix socket
    final Button unixSocketBindingModeButton = new Button(customSettingsGroup, SWT.RADIO);
    unixSocketBindingModeButton.setText(WizardMessages.getString("DockerConnectionPage.unixSocket")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1)
            .applyTo(unixSocketBindingModeButton);

    final Label unixSocketPathLabel = new Label(customSettingsGroup, SWT.NONE);
    unixSocketPathLabel.setText(WizardMessages.getString("DockerConnectionPage.location")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).applyTo(unixSocketPathLabel);
    final Text unixSocketPathText = new Text(customSettingsGroup, SWT.BORDER);
    unixSocketPathText.setToolTipText(WizardMessages.getString("DockerConnectionPage.unixPathTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(unixSocketPathText);

    final Button unixSocketPathBrowseButton = new Button(customSettingsGroup, SWT.BUTTON1);
    unixSocketPathBrowseButton.setText(WizardMessages.getString("DockerConnectionPage.browseButton")); //$NON-NLS-1$
    unixSocketPathBrowseButton.addSelectionListener(onBrowseUnixSocketPath());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(unixSocketPathBrowseButton);

    // TCP connection
    final Button tcpConnectionBindingModeButton = new Button(customSettingsGroup, SWT.RADIO);
    tcpConnectionBindingModeButton.setText(WizardMessages.getString("DockerConnectionPage.tcpConnection")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1)
            .applyTo(tcpConnectionBindingModeButton);

    final Label tcpHostLabel = new Label(customSettingsGroup, SWT.NONE);
    tcpHostLabel.setText(WizardMessages.getString("DockerConnectionPage.hostLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).applyTo(tcpHostLabel);

    final Text tcpHostText = new Text(customSettingsGroup, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false)
            .applyTo(tcpHostText);

    final Button tcpAuthButton = new Button(customSettingsGroup, SWT.CHECK);
    tcpAuthButton.setText(WizardMessages.getString("DockerConnectionPage.tcpAuthButton")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).span(3, 1)
            .applyTo(tcpAuthButton);

    final Label tcpCertPathLabel = new Label(customSettingsGroup, SWT.NONE);
    tcpCertPathLabel.setText(WizardMessages.getString("DockerConnectionPage.tcpPathLabel")); //$NON-NLS-1$
    tcpCertPathLabel.setToolTipText(WizardMessages.getString("DockerConnectionPage.tcpPathTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT * 2, 0).applyTo(tcpCertPathLabel);
    final Text tcpCertPathText = new Text(customSettingsGroup, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(tcpCertPathText);
    final Button tcpCertPathBrowseButton = new Button(customSettingsGroup, SWT.BUTTON1);
    tcpCertPathBrowseButton.setText(WizardMessages.getString("DockerConnectionPage.browseButton")); //$NON-NLS-1$
    tcpCertPathBrowseButton.addSelectionListener(onBrowseTcpCertPath());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(tcpCertPathBrowseButton);

    // the 'test connection' button
    final Button testConnectionButton = new Button(container, SWT.NONE);
    testConnectionButton.setText(WizardMessages.getString("DockerConnectionPage.testConnection")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(3, 1).align(SWT.END, SWT.CENTER)
            .applyTo(testConnectionButton);
    testConnectionButton.addSelectionListener(onTestConnectionButtonSelection());

    // observe
    final IObservableValue<String> connectionNameModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.CONNECTION_NAME)
            .observe(model);
    final IObservableValue<Boolean> unixSocketBindingModeModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.UNIX_SOCKET_BINDING_MODE)
            .observe(model);
    final IObservableValue<String> unixSocketPathModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.UNIX_SOCKET_PATH)
            .observe(model);

    final IObservableValue customConnectionSettingsModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.CUSTOM_SETTINGS)
            .observe(model);
    final IObservableValue<Boolean> tcpConnectionBindingModeModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.TCP_CONNECTION_BINDING_MODE)
            .observe(model);
    final IObservableValue<String> tcpCertPathModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.TCP_CERT_PATH)
            .observe(model);
    final IObservableValue<Boolean> tcpTlsVerifyModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.TCP_TLS_VERIFY)
            .observe(model);
    final IObservableValue<String> tcpHostModelObservable = BeanProperties
            .value(NewDockerConnectionPageModel.class, NewDockerConnectionPageModel.TCP_HOST).observe(model);

    // group controls to easily enable/disable them
    final Control[] bindingModeSelectionControls = new Control[] { unixSocketBindingModeButton,
            tcpConnectionBindingModeButton };
    final Control[] unixSocketControls = new Control[] { unixSocketPathText, unixSocketPathLabel,
            unixSocketPathBrowseButton };
    final Control[] tcpConnectionControls = new Control[] { tcpHostText, tcpHostLabel, tcpAuthButton };
    final Control[] tcpAuthControls = new Control[] { tcpCertPathText, tcpCertPathLabel,
            tcpCertPathBrowseButton };
    customConnectionSettingsModelObservable.addValueChangeListener(onCustomConnectionSettingsSelection(
            bindingModeSelectionControls, unixSocketControls, tcpAuthControls, tcpConnectionControls));
    unixSocketBindingModeModelObservable.addChangeListener(onUnixSocketBindingSelection(unixSocketControls));
    tcpConnectionBindingModeModelObservable
            .addChangeListener(onTcpConnectionBindingSelection(tcpConnectionControls, tcpAuthControls));
    tcpTlsVerifyModelObservable.addValueChangeListener(onTcpAuthSelection(tcpAuthControls));

    // bind controls to model
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(connectionNameText), connectionNameModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(customConnectionSettingsButton),
            customConnectionSettingsModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(unixSocketBindingModeButton),
            unixSocketBindingModeModelObservable);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(unixSocketPathText), unixSocketPathModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(tcpConnectionBindingModeButton),
            tcpConnectionBindingModeModelObservable);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(tcpHostText), tcpHostModelObservable);
    dbc.bindValue(WidgetProperties.selection().observe(tcpAuthButton), tcpTlsVerifyModelObservable);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(tcpCertPathText), tcpCertPathModelObservable);
    // validations will be performed when the user changes the value
    // only, not at the dialog opening
    dbc.addValidationStatusProvider(new ConnectionNameValidator(connectionNameModelObservable));
    dbc.addValidationStatusProvider(
            new UnixSocketValidator(unixSocketBindingModeModelObservable, unixSocketPathModelObservable));
    dbc.addValidationStatusProvider(
            new TcpHostValidator(tcpConnectionBindingModeModelObservable, tcpHostModelObservable));
    dbc.addValidationStatusProvider(new TcpCertificatesValidator(tcpConnectionBindingModeModelObservable,
            tcpTlsVerifyModelObservable, tcpCertPathModelObservable));

    // give focus to connectionName text at first
    connectionNameText.setFocus();
    // set widgets initial state
    updateWidgetsState(bindingModeSelectionControls, unixSocketControls, tcpConnectionControls,
            tcpAuthControls);
}

From source file:org.eclipse.linuxtools.internal.vagrant.ui.wizards.CreateVMPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    ScrolledComposite scrollTop = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scrollTop.setExpandVertical(true);//from  w  w w .  ja  v a 2s  .  co m
    scrollTop.setExpandHorizontal(true);

    final Composite container = new Composite(scrollTop, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(container);

    // VM Name
    final Label vmNameLabel = new Label(container, SWT.NONE);
    vmNameLabel.setText(WizardMessages.getString("CreateVM.name.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(vmNameLabel);

    final Text vmNameText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(vmNameText);
    vmNameText.setToolTipText(WizardMessages.getString("CreateVMPage.name.tooltip")); //$NON-NLS-1$
    // VM Name binding
    final IObservableValue<String> vmmNameObservable = BeanProperties
            .value(CreateVMPageModel.class, CreateVMPageModel.VM_NAME).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(vmNameText), vmmNameObservable);

    // Box name
    final Label boxRefLabel = new Label(container, SWT.NONE);
    boxRefLabel.setText(WizardMessages.getString("CreateVMPage.boxRef.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(boxRefLabel);

    final Text boxRefText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(boxRefText);
    boxRefText.setToolTipText(WizardMessages.getString("CreateVMPage.boxRef.tooltip")); //$NON-NLS-1$
    // Box Name binding
    final IObservableValue<String> boxRefObservable = BeanProperties
            .value(CreateVMPageModel.class, CreateVMPageModel.BOX_REF).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(boxRefText), boxRefObservable);

    // Box name search
    final Button boxSearchButton = new Button(container, SWT.NONE);
    boxSearchButton.setText(WizardMessages.getString("CreateVMPage.search.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(boxSearchButton);
    boxSearchButton.addSelectionListener(onSearchImage());

    // VM File Checkbox
    final Button customVMFileButton = new Button(container, SWT.CHECK);
    customVMFileButton.setText(WizardMessages.getString("CreateVMPage.File.CheckBox")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(3, 1)
            .applyTo(customVMFileButton);
    final IObservableValue<String> customVMFileObservable = BeanProperties
            .value(CreateVMPageModel.class, CreateVMPageModel.V_FILE_MODE).observe(model);
    dbc.bindValue(WidgetProperties.selection().observe(customVMFileButton), customVMFileObservable);

    // VM File
    final Label boxLocLabel = new Label(container, SWT.NONE);
    boxLocLabel.setText(WizardMessages.getString("CreateVMPage.loc.label")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(boxLocLabel);

    final Text boxLocText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(boxLocText);
    boxLocText.setToolTipText(WizardMessages.getString("CreateVMPage.loc.tooltip")); //$NON-NLS-1$
    boxLocText.setEnabled(false);
    // Location binding
    final IObservableValue<String> boxLocObservable = BeanProperties
            .value(CreateVMPageModel.class, CreateVMPageModel.VM_FILE).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(boxLocText), boxLocObservable);
    boxLocText.addModifyListener(e -> vmFileChanged(boxLocText.getText()));

    // Vagrantfile search
    final Button vgFilesearchButton = new Button(container, SWT.NONE);
    vgFilesearchButton.setText(WizardMessages.getString("CreateVMPage.search.label")); //$NON-NLS-1$
    vgFilesearchButton.setEnabled(false);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(vgFilesearchButton);
    vgFilesearchButton.addSelectionListener(onSearchVMFile());

    customVMFileButton.addSelectionListener(
            onCheckCustomVMFile(vmNameText, boxRefText, boxLocText, vgFilesearchButton, boxSearchButton));

    dbc.addValidationStatusProvider(
            new CreateVMValidationStatusProvider(vmmNameObservable, boxRefObservable, boxLocObservable));

    advanced = new CreateVMAdvancedComposite(container, scrollTop, model);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(3, 1).grab(true, false).applyTo(advanced);

    // setup validation support
    WizardPageSupport.create(this, dbc);

    scrollTop.setContent(container);
    Point point = container.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    scrollTop.setSize(point);
    scrollTop.setMinSize(point);
    setControl(container);
}