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);
}
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);
}
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);
}
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);
}
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());
}
});
}
Aggregations