Search in sources :

Example 21 with RequiredControlDecorationUpdater

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

the class ServerSettingsWizardPage method createSourcePathControls.

@SuppressWarnings("unchecked")
private void createSourcePathControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Label sourcePathLabel = new Label(parent, SWT.NONE);
    sourcePathLabel.setText("Source Path: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(sourcePathLabel);
    Text sourcePathText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sourcePathText);
    Binding sourcePathBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(sourcePathText)).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            String path = (String) value;
            if (StringUtils.isEmpty(path)) {
                return ValidationStatus.cancel("Please provide a local path to deploy from.");
            }
            String provideValidPathMessage = "Please provide a valid local path to deploy from.";
            try {
                path = VariablesHelper.replaceVariables(path);
            } catch (OpenShiftCoreException e) {
                String message = org.apache.commons.lang.StringUtils.substringAfter(e.getMessage(), "Exception:");
                return ValidationStatus.error(provideValidPathMessage + "\nError: " + message);
            }
            if (!isReadableFile(path)) {
                return ValidationStatus.error(provideValidPathMessage);
            }
            return ValidationStatus.ok();
        }

        private boolean isReadableFile(String path) {
            return new File(path).canRead();
        }
    }).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SOURCE_PATH).observe(model)).in(dbc);
    ControlDecorationSupport.create(sourcePathBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Button browseSourceButton = new Button(parent, SWT.PUSH);
    browseSourceButton.setText("Browse...");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(10, SWT.DEFAULT).applyTo(browseSourceButton);
    browseSourceButton.addSelectionListener(onBrowseSource(browseSourceButton.getShell()));
    Button browseWorkspaceSourceButton = new Button(parent, SWT.PUSH | SWT.READ_ONLY);
    browseWorkspaceSourceButton.setText("Workspace...");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(browseWorkspaceSourceButton);
    browseWorkspaceSourceButton.addSelectionListener(onBrowseWorkspace(browseWorkspaceSourceButton.getShell()));
    UIUtils.setEqualButtonWidth(browseSourceButton, browseWorkspaceSourceButton);
}
Also used : Binding(org.eclipse.core.databinding.Binding) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IStatus(org.eclipse.core.runtime.IStatus) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) OpenShiftCoreException(org.jboss.tools.openshift.common.core.OpenShiftCoreException) File(java.io.File)

Example 22 with RequiredControlDecorationUpdater

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

the class ServerSettingsWizardPage method createDebuggingPortControls.

@SuppressWarnings("unchecked")
private void createDebuggingPortControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Label debugPortLabel = new Label(parent, SWT.None);
    debugPortLabel.setText("Debugging Port:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(debugPortLabel);
    // use image key & value checkbox
    Button useImageDebugPortKeyButton = new Button(parent, SWT.CHECK);
    useImageDebugPortKeyButton.setText("use image provided key and value");
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).applyTo(useImageDebugPortKeyButton);
    IObservableValue<Boolean> useImageDebugPortKey = BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_IMAGE_DEBUG_PORT_KEY).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useImageDebugPortKeyButton)).to(useImageDebugPortKey).in(dbc);
    // filler
    new Label(parent, SWT.NONE);
    // key text field
    // filler
    new Label(parent, SWT.NONE);
    Label keyLabel = new Label(parent, SWT.NONE);
    keyLabel.setText("Key:");
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(keyLabel);
    Text debugPortKeyText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(debugPortKeyText);
    IObservableValue<String> debugPortKeyTextObservable = WidgetProperties.text(SWT.Modify).observe(debugPortKeyText);
    ValueBindingBuilder.bind(debugPortKeyTextObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEBUG_PORT_KEY).observe(model)).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(debugPortKeyText)).notUpdating(useImageDebugPortKey).converting(new InvertingBooleanConverter()).in(dbc);
    ValidationStatusProvider debugPortKeyValidator = new DisableableMultiValitdator<String>(useImageDebugPortKey, debugPortKeyTextObservable, new OpenShiftIdentifierValidator());
    dbc.addValidationStatusProvider(debugPortKeyValidator);
    ControlDecorationSupport.create(debugPortKeyValidator, SWT.LEFT | SWT.TOP, parent, new RequiredControlDecorationUpdater(true));
    // port text field
    IObservableValue<Boolean> useImageDebugPortValue = BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_IMAGE_DEBUG_PORT_VALUE).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useImageDebugPortKeyButton)).to(useImageDebugPortValue).in(dbc);
    Label portLabel = new Label(parent, SWT.NONE);
    portLabel.setText("Port:");
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(portLabel);
    Text debugPortText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(debugPortText);
    IObservableValue<String> debugPortValueObservable = WidgetProperties.text(SWT.Modify).observe(debugPortText);
    ValueBindingBuilder.bind(debugPortValueObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEBUG_PORT_VALUE).observe(model)).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(debugPortText)).notUpdating(useImageDebugPortValue).converting(new InvertingBooleanConverter()).in(dbc);
    ValidationStatusProvider debugPortValueValidator = new DisableableMultiValitdator<String>(useImageDebugPortValue, debugPortValueObservable, new NumericValidator("integer", Integer::parseInt, true));
    dbc.addValidationStatusProvider(debugPortValueValidator);
    ControlDecorationSupport.create(debugPortValueValidator, SWT.LEFT | SWT.TOP, parent, new RequiredControlDecorationUpdater(true));
}
Also used : OpenShiftIdentifierValidator(org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DisableableMultiValitdator(org.jboss.tools.openshift.internal.common.ui.databinding.DisableableMultiValitdator) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button)

Example 23 with RequiredControlDecorationUpdater

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

the class ServerSettingsWizardPage method createResourcePathControls.

@SuppressWarnings("unchecked")
private void createResourcePathControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, true).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).applyTo(container);
    Button useInferredPodPathButton = new Button(container, SWT.CHECK);
    useInferredPodPathButton.setText("&Use inferred Pod Deployment Path");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).applyTo(useInferredPodPathButton);
    ISWTObservableValue useInferredPodPathObservable = WidgetProperties.selection().observe(useInferredPodPathButton);
    ValueBindingBuilder.bind(useInferredPodPathObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_INFERRED_POD_PATH).observe(model)).in(dbc);
    Label podPathLabel = new Label(container, SWT.NONE);
    podPathLabel.setText("Pod Deployment Path: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(podPathLabel);
    Text podPathText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(podPathText);
    ISWTObservableValue podPathObservable = WidgetProperties.text(SWT.Modify).observe(podPathText);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(podPathText)).notUpdatingParticipant().to(useInferredPodPathObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(podPathLabel)).notUpdatingParticipant().to(useInferredPodPathObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValueBindingBuilder.bind(podPathObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_POD_PATH).observe(model)).in(dbc);
    PodPathValidator podPathValidator = new PodPathValidator(useInferredPodPathObservable, podPathObservable);
    ControlDecorationSupport.create(podPathValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    dbc.addValidationStatusProvider(podPathValidator);
}
Also used : RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Button(org.eclipse.swt.widgets.Button) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text)

Aggregations

RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)23 Label (org.eclipse.swt.widgets.Label)18 Button (org.eclipse.swt.widgets.Button)15 Binding (org.eclipse.core.databinding.Binding)14 Text (org.eclipse.swt.widgets.Text)13 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)9 IStatus (org.eclipse.core.runtime.IStatus)8 Composite (org.eclipse.swt.widgets.Composite)8 IValidator (org.eclipse.core.databinding.validation.IValidator)5 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)5 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)5 ComboViewer (org.eclipse.jface.viewers.ComboViewer)5 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)5 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)5 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)4 Group (org.eclipse.swt.widgets.Group)4 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)3 TrimmingStringConverter (org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter)3 IProject (com.openshift.restclient.model.IProject)2 Converter (org.eclipse.core.databinding.conversion.Converter)2