Search in sources :

Example 1 with IsNotNull2BooleanConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter in project jbosstools-openshift by jbosstools.

the class EnvironmentVariablePage method createEnvVariableControl.

@SuppressWarnings("unchecked")
protected void createEnvVariableControl(Composite parent, DataBindingContext dbc, String label, String tooltip) {
    Composite envContainer = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(envContainer);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(2, 2).applyTo(envContainer);
    Label lblEnvVars = new Label(envContainer, SWT.NONE);
    lblEnvVars.setText(label);
    lblEnvVars.setToolTipText(tooltip);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(lblEnvVars);
    Composite tableContainer = envTableContainer = new Composite(envContainer, SWT.NONE);
    this.envViewer = createEnvVarTable(tableContainer);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, 150).applyTo(tableContainer);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(envViewer)).to(BeanProperties.value(IDeploymentConfigPageModel.PROPERTY_SELECTED_ENVIRONMENT_VARIABLE).observe(model)).in(dbc);
    envViewer.setContentProvider(new ObservableListContentProvider());
    envViewer.setInput(BeanProperties.list(IDeploymentConfigPageModel.PROPERTY_ENVIRONMENT_VARIABLES).observe(model));
    Button addButton = new Button(envContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(addButton);
    addButton.setText("Add...");
    addButton.setToolTipText("Add an environment variable declared by the docker image.");
    addButton.addSelectionListener(onAdd());
    UIUtils.setDefaultButtonWidth(addButton);
    heightScale = addButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    Button editExistingButton = new Button(envContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(editExistingButton);
    editExistingButton.setText("Edit...");
    editExistingButton.setToolTipText("Edit the environment variable declared by the docker image.");
    editExistingButton.addSelectionListener(new EditHandler());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(editExistingButton)).notUpdatingParticipant().to(BeanProperties.value(IDeploymentConfigPageModel.PROPERTY_SELECTED_ENVIRONMENT_VARIABLE).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
    UIUtils.setDefaultButtonWidth(editExistingButton);
    Button btnReset = new Button(envContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(btnReset);
    btnReset.setText("Reset");
    btnReset.setToolTipText("Reset to the value declared by the docker image.");
    btnReset.addSelectionListener(onResetEnvVar());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnReset)).notUpdatingParticipant().to(BeanProperties.value(IDeploymentConfigPageModel.PROPERTY_SELECTED_ENVIRONMENT_VARIABLE).observe(model)).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            Boolean notNull = (Boolean) super.convert(fromObject);
            return notNull && !((EnvironmentVariable) fromObject).isNew() && model.isEnvironmentVariableModified((EnvironmentVariable) fromObject);
        }
    }).in(dbc);
    UIUtils.setDefaultButtonWidth(btnReset);
    Button btnResetAll = new Button(envContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(btnResetAll);
    btnResetAll.setText("Reset All");
    btnResetAll.setToolTipText("Reset all variables to the value declared by the docker image.");
    btnResetAll.addSelectionListener(onResetEnvVars());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnResetAll)).notUpdatingParticipant().to(BeanProperties.value(IDeploymentConfigPageModel.PROPERTY_SELECTED_ENVIRONMENT_VARIABLE).observe(model)).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            List<EnvironmentVariable> vars = model.getEnvironmentVariables();
            return vars != null && !vars.isEmpty() && vars.stream().anyMatch(v -> !v.isNew() && model.isEnvironmentVariableModified(v));
        }
    }).in(dbc);
    UIUtils.setDefaultButtonWidth(btnResetAll);
    Button btnRemove = new Button(envContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(btnRemove);
    btnRemove.setText("Remove");
    btnRemove.setToolTipText("Remove the environment variable added here.");
    btnRemove.addSelectionListener(onRemoveEnvVar());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnRemove)).notUpdatingParticipant().to(BeanProperties.value(IDeploymentConfigPageModel.PROPERTY_SELECTED_ENVIRONMENT_VARIABLE).observe(model)).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            Boolean notNull = (Boolean) super.convert(fromObject);
            return notNull && (canDeleteAnyVar || ((EnvironmentVariable) fromObject).isNew()) && !model.isEnvironmentVariableDeleted((EnvironmentVariable) fromObject);
        }
    }).in(dbc);
    UIUtils.setDefaultButtonWidth(btnRemove);
}
Also used : EnvironmentVarKeyValidator(org.jboss.tools.openshift.internal.ui.validator.EnvironmentVarKeyValidator) TableViewer(org.eclipse.jface.viewers.TableViewer) IWizard(org.eclipse.jface.wizard.IWizard) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Table(org.eclipse.swt.widgets.Table) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IColumnLabelProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.IColumnLabelProvider) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) KeyValueWizard(org.jboss.tools.openshift.internal.common.ui.wizard.KeyValueWizard) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ValueBindingBuilder(org.jboss.tools.common.ui.databinding.ValueBindingBuilder) KeyValueItem(org.jboss.tools.openshift.internal.common.ui.wizard.KeyValueItem) IDeploymentConfigPageModel(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeploymentConfigPageModel) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) AbstractOpenShiftWizardPage(org.jboss.tools.openshift.internal.common.ui.wizard.AbstractOpenShiftWizardPage) IKeyValueItem(org.jboss.tools.openshift.internal.common.ui.wizard.IKeyValueItem) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Set(java.util.Set) ViewerProperties(org.eclipse.jface.databinding.viewers.ViewerProperties) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) IKeyValueWizardModel(org.jboss.tools.openshift.internal.common.ui.wizard.IKeyValueWizardModel) KeyValueWizardModelBuilder(org.jboss.tools.openshift.internal.common.ui.wizard.KeyValueWizardModelBuilder) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) OkCancelButtonWizardDialog(org.jboss.tools.openshift.internal.common.ui.wizard.OkCancelButtonWizardDialog) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)

Example 2 with IsNotNull2BooleanConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter in project jbosstools-openshift by jbosstools.

the class DeployImagePage method createImageNameControls.

private void createImageNameControls(final Composite parent, final DataBindingContext dbc) {
    // Image
    final Label imageNameLabel = new Label(parent, SWT.NONE);
    imageNameLabel.setText("Image Name: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(imageNameLabel);
    final Text imageNameText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameText);
    final IObservableValue<String> imageNameTextObservable = WidgetProperties.text(SWT.Modify).observeDelayed(500, imageNameText);
    final IObservableValue<String> imageNameObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_IMAGE_NAME).observe(model);
    Binding imageBinding = ValueBindingBuilder.bind(imageNameTextObservable).converting(new TrimmingStringConverter()).validatingAfterConvert(new DockerImageValidator()).to(imageNameObservable).in(dbc);
    ControlDecorationSupport.create(imageBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    imageNameProposalAdapter = new ContentProposalAdapter(imageNameText, // move the cursor to the end of the selected value
    new TextContentAdapter() {

        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Text imageNameText = (Text) control;
            final Point selection = imageNameText.getSelection();
            imageNameText.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            imageNameText.setSelection(selection);
        }
    }, getImageNameContentProposalProvider(imageNameText), null, null);
    // List local Docker images
    Button btnDockerBrowse = new Button(parent, SWT.NONE);
    btnDockerBrowse.setText("Browse...");
    btnDockerBrowse.setToolTipText("Look-up an image by browsing the Docker daemon");
    btnDockerBrowse.addSelectionListener(onBrowseImage());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerBrowse);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerBrowse)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
    // search on Docker registry (Docker Hub)
    Button btnDockerSearch = new Button(parent, SWT.NONE);
    btnDockerSearch.setText("Search...");
    btnDockerSearch.setToolTipText("Search an image on the Docker registry");
    btnDockerSearch.addSelectionListener(onSearchImage(imageNameText));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerSearch);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerSearch)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
}
Also used : Binding(org.eclipse.core.databinding.Binding) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) ResourceNameControl(org.jboss.tools.openshift.internal.ui.wizard.common.ResourceNameControl) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter) DockerImageValidator(org.jboss.tools.openshift.internal.ui.validator.DockerImageValidator)

Example 3 with IsNotNull2BooleanConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter in project jbosstools-openshift by jbosstools.

the class ServicesAndRoutingPage method createExposedPortsControl.

private void createExposedPortsControl(Composite parent, DataBindingContext dbc) {
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(container);
    Label label = new Label(container, SWT.NONE);
    label.setText("Service Ports:");
    label.setToolTipText("The exposed ports of the image.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(label);
    Composite tableContainer = new Composite(container, SWT.NONE);
    IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
    portsViewer = createTable(tableContainer);
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    portsViewer.setContentProvider(contentProvider);
    ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(Properties.observeEach(contentProvider.getKnownElements(), BeanProperties.values(ServicePortAdapter.NAME, ServicePortAdapter.PORT, ServicePortAdapter.TARGET_PORT, /* ROUTE_PORT_COLUMN_INDEX = 3 */
    ServicePortAdapter.ROUTE_PORT))) {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == ROUTE_PORT_COLUMN_INDEX) {
                Object selected = attributeMaps[columnIndex].get(element);
                return selected != null && (boolean) selected ? OpenShiftImages.CHECKED_IMG : OpenShiftImages.UNCHECKED_IMG;
            }
            return null;
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex != ROUTE_PORT_COLUMN_INDEX) {
                Object result = attributeMaps[columnIndex].get(element);
                // $NON-NLS-1$
                return result == null ? "" : result.toString();
            }
            return null;
        }
    };
    portsViewer.setLabelProvider(labelProvider);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(portsViewer)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).in(dbc);
    portsViewer.setInput(portsObservable);
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            if (portsObservable.isEmpty()) {
                return ValidationStatus.error("At least 1 port is required when generating the service for the deployed image");
            }
            return Status.OK_STATUS;
        }
    });
    portsViewer.getTable().addMouseListener(onTableCellClicked());
    Button btnEdit = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnEdit);
    btnEdit.setText("Edit...");
    btnEdit.setToolTipText("Edit a port to be exposed by the service.");
    btnEdit.addSelectionListener(new EditHandler());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnEdit)).notUpdatingParticipant().to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
    UIUtils.setDefaultButtonWidth(btnEdit);
    Button btnReset = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnReset);
    btnReset.setText("Reset");
    btnReset.setToolTipText("Resets the list of ports to the exposed ports of the image.");
    btnReset.addSelectionListener(onReset());
    UIUtils.setDefaultButtonWidth(btnReset);
}
Also used : ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ObservableMapLabelProvider(org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) IServicePort(com.openshift.restclient.model.IServicePort) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)

Example 4 with IsNotNull2BooleanConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter in project jbosstools-openshift by jbosstools.

the class ManageProjectsWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
    Group group = new Group(parent, SWT.NONE);
    group.setText("OpenShift Projects");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(group);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(group);
    // table
    Composite tableContainer = new Composite(group, SWT.NONE);
    this.viewer = createTable(tableContainer);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
    viewer.setContentProvider(new ObservableListContentProvider());
    viewer.setInput(BeanProperties.list(ManageProjectsWizardPageModel.PROPERTY_PROJECTS).observe(pageModel));
    loadProjects(dbc);
    initialProjects = getProjects();
    viewer.setComparator(new ProjectViewerComparator());
    IObservableValue viewerSingleSelection = ViewerProperties.singleSelection().observe(viewer);
    ValueBindingBuilder.bind(viewerSingleSelection).to(BeanProperties.value(ManageProjectsWizardPageModel.PROPERTY_SELECTED_PROJECT).observe(pageModel)).in(dbc);
    // new
    Button newButton = new Button(group, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(newButton);
    newButton.setText("New...");
    newButton.addSelectionListener(onNew());
    UIUtils.setDefaultButtonWidth(newButton);
    // remove
    Button removeButton = new Button(group, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(removeButton);
    removeButton.setText("Remove...");
    removeButton.addSelectionListener(onRemove(dbc));
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(removeButton)).notUpdatingParticipant().to(viewerSingleSelection).converting(new IsNotNull2BooleanConverter()).in(dbc);
    UIUtils.setDefaultButtonWidth(removeButton);
    Composite filler = new Composite(group, SWT.None);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(filler);
    // refresh
    Button refreshButton = new Button(group, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.END).applyTo(refreshButton);
    refreshButton.setText("Refresh...");
    refreshButton.addSelectionListener(onRefresh(dbc));
    UIUtils.setDefaultButtonWidth(refreshButton);
}
Also used : Group(org.eclipse.swt.widgets.Group) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)

Example 5 with IsNotNull2BooleanConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter in project jbosstools-openshift by jbosstools.

the class TemplateParametersPage method doCreateControls.

@Override
@SuppressWarnings("unchecked")
protected void doCreateControls(Composite container, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(container);
    // parameters table
    Composite tableContainer = new Composite(container, SWT.NONE);
    IObservableList<IParameter> parametersObservable = BeanProperties.list(ITemplateParametersPageModel.PROPERTY_PARAMETERS).observe(model);
    this.viewer = createTable(tableContainer, parametersObservable, dbc);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).hint(500, 300).applyTo(tableContainer);
    viewer.setInput(parametersObservable);
    IObservableValue<IParameter> selectedParameter = BeanProperties.value(ITemplateParametersPageModel.PROPERTY_SELECTED_PARAMETER).observe(model);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(viewer)).to(selectedParameter).in(dbc);
    viewer.addDoubleClickListener(onDoubleClick());
    // edit button
    Button editExistingButton = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(editExistingButton);
    editExistingButton.setText("Edit...");
    UIUtils.setDefaultButtonWidth(editExistingButton);
    editExistingButton.addSelectionListener(onEdit());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(editExistingButton)).notUpdatingParticipant().to(selectedParameter).converting(new IsNotNull2BooleanConverter()).in(dbc);
    // reset button
    Button resetButton = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(resetButton);
    resetButton.setText("Reset");
    UIUtils.setDefaultButtonWidth(resetButton);
    resetButton.addSelectionListener(onReset());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(resetButton)).notUpdatingParticipant().to(selectedParameter).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            return fromObject instanceof IParameter && ((ApplicationSourceFromTemplateModel) model).isParameterModified((IParameter) fromObject);
        }
    }).in(dbc);
    // reset all button
    Button resetAllButton = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(resetAllButton);
    resetAllButton.setText("Reset All");
    UIUtils.setDefaultButtonWidth(resetAllButton);
    resetAllButton.addSelectionListener(onResetAll());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(resetAllButton)).notUpdatingParticipant().to(selectedParameter).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            return model.getParameters().stream().anyMatch(p -> ((ApplicationSourceFromTemplateModel) model).isParameterModified(p));
        }
    }).in(dbc);
    // required explanation
    Label requiredExplanationLabel = new Label(container, SWT.None);
    requiredExplanationLabel.setText("* = value required, click the 'Edit...' button or double-click on a value to edit it.");
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(requiredExplanationLabel);
    // selected parameter details
    final Group detailsContainer = new Group(container, SWT.NONE);
    detailsContainer.setText("Details");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).hint(SWT.DEFAULT, 106).applyTo(detailsContainer);
    new TemplateParameterDetailViews(selectedParameter, detailsContainer, dbc).createControls();
    ((ApplicationSourceFromTemplateModel) model).addPropertyChangeListener(evt -> {
        if (ApplicationSourceFromTemplateModel.PROPERTY_MODIFIED_PARAMETER.equals(evt.getPropertyName())) {
            viewer.refresh(evt.getNewValue());
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) IParameter(com.openshift.restclient.model.template.IParameter) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)

Aggregations

Button (org.eclipse.swt.widgets.Button)5 IsNotNull2BooleanConverter (org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)5 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)3 Group (org.eclipse.swt.widgets.Group)2 IServicePort (com.openshift.restclient.model.IServicePort)1 IParameter (com.openshift.restclient.model.template.IParameter)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Binding (org.eclipse.core.databinding.Binding)1 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)1 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)1 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)1 IStatus (org.eclipse.core.runtime.IStatus)1 WidgetProperties (org.eclipse.jface.databinding.swt.WidgetProperties)1 ObservableMapLabelProvider (org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider)1 ViewerProperties (org.eclipse.jface.databinding.viewers.ViewerProperties)1