Search in sources :

Example 1 with JsonSchemaWidget

use of org.jboss.tools.openshift.internal.ui.widgets.JsonSchemaWidget in project jbosstools-openshift by jbosstools.

the class CreateServiceWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent);
    Label serviceNameLabel = new Label(parent, SWT.NONE);
    serviceNameLabel.setText("Name:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(serviceNameLabel);
    Text serviceNameText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(serviceNameText);
    ISWTObservableValue<String> serviceNameObservable = WidgetProperties.text(SWT.Modify).observe(serviceNameText);
    Binding serviceNameBinding = ValueBindingBuilder.bind(serviceNameObservable).validatingAfterGet(new MandatoryStringValidator("Please specify a name")).to(BeanProperties.value(CreateServiceModel.PROPERTY_SERVICE_NAME).observe(model)).in(dbc);
    ControlDecorationSupport.create(serviceNameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Label serviceTemplatesLabel = new Label(parent, SWT.NONE);
    serviceTemplatesLabel.setText("Service:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(serviceTemplatesLabel);
    Combo serviceTemplatesCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(serviceTemplatesCombo);
    ComboViewer serviceTemplatesComboViewer = new ComboViewer(serviceTemplatesCombo);
    serviceTemplatesComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    serviceTemplatesComboViewer.setLabelProvider(new ServiceTemplateColumLabelProvider());
    serviceTemplatesComboViewer.setInput(model.getServiceTemplates());
    Binding serviceTemplatesBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(serviceTemplatesComboViewer)).validatingAfterGet(new IsNotNullValidator(ValidationStatus.cancel("You have to select a template."))).to(BeanProperties.value(CreateServiceModel.PROPERTY_SELECTED_SERVICE_TEMPLATE, ServiceTemplate.class).observe(model)).in(dbc);
    ControlDecorationSupport.create(serviceTemplatesBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    Label serviceCRDsLabel = new Label(parent, SWT.NONE);
    serviceCRDsLabel.setText("Type:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(serviceCRDsLabel);
    Combo serviceCRDsCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(serviceCRDsCombo);
    ComboViewer serviceCRDsComboViewer = new ComboViewer(serviceCRDsCombo);
    serviceCRDsComboViewer.setContentProvider(new ObservableListContentProvider<>());
    serviceCRDsComboViewer.setLabelProvider(new ServiceTemplateCRDColumLabelProvider());
    serviceCRDsComboViewer.setInput(BeanProperties.list(CreateServiceModel.PROPERTY_SELECTED_SERVICE_TEMPLATE_CRDS).observe(model));
    Binding serviceCRDsBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(serviceCRDsComboViewer)).validatingAfterGet(new IsNotNullValidator(ValidationStatus.cancel("You have to select a type."))).to(BeanProperties.value(CreateServiceModel.PROPERTY_SELECTED_SERVICE_TEMPLATE_CRD, OperatorCRD.class).observe(model)).in(dbc);
    ControlDecorationSupport.create(serviceCRDsBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    ScrolledComposite schemaParentComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, 1).applyTo(schemaParentComposite);
    schemaParentComposite.setExpandHorizontal(true);
    schemaParentComposite.setExpandVertical(true);
    schemaWidget = new JsonSchemaWidget(schemaParentComposite, ERROR, schemaParentComposite);
    schemaParentComposite.setContent(schemaWidget);
    schemaParentComposite.setMinHeight(250);
    serviceCRDsComboViewer.addSelectionChangedListener(e -> {
        initSchemaWidget();
    });
    initSchemaWidget();
    Label applicationLabel = new Label(parent, SWT.NONE);
    applicationLabel.setText("Application:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(applicationLabel);
    Text applicationNameText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(applicationNameText);
    ISWTObservableValue<String> applicationNameObservable = WidgetProperties.text(SWT.Modify).observe(applicationNameText);
    Binding applicationNameBinding = ValueBindingBuilder.bind(applicationNameObservable).validatingAfterGet(new MandatoryStringValidator("Please specify an application")).to(BeanProperties.value(CreateServiceModel.PROPERTY_APPLICATION_NAME).observe(model)).in(dbc);
    ControlDecorationSupport.create(applicationNameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    if (StringUtils.isNotBlank(model.getApplicationName())) {
        applicationNameText.setEnabled(false);
    }
}
Also used : Binding(org.eclipse.core.databinding.Binding) MandatoryStringValidator(org.jboss.tools.common.ui.databinding.MandatoryStringValidator) ServiceTemplate(org.jboss.tools.openshift.core.odo.ServiceTemplate) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) OperatorCRD(org.jboss.tools.openshift.core.odo.OperatorCRD) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) ComboViewer(org.eclipse.jface.viewers.ComboViewer) JsonSchemaWidget(org.jboss.tools.openshift.internal.ui.widgets.JsonSchemaWidget) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IsNotNullValidator(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNullValidator)

Aggregations

Binding (org.eclipse.core.databinding.Binding)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 Combo (org.eclipse.swt.widgets.Combo)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 MandatoryStringValidator (org.jboss.tools.common.ui.databinding.MandatoryStringValidator)1 OperatorCRD (org.jboss.tools.openshift.core.odo.OperatorCRD)1 ServiceTemplate (org.jboss.tools.openshift.core.odo.ServiceTemplate)1 IsNotNullValidator (org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNullValidator)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1 JsonSchemaWidget (org.jboss.tools.openshift.internal.ui.widgets.JsonSchemaWidget)1