Search in sources :

Example 1 with Starter

use of org.jboss.tools.openshift.core.odo.Starter in project jbosstools-openshift by jbosstools.

the class CreateComponentWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent);
    Label componentNameLabel = new Label(parent, SWT.NONE);
    componentNameLabel.setText("Name:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(componentNameLabel);
    Text componentNameText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(componentNameText);
    ISWTObservableValue<String> componentNameObservable = WidgetProperties.text(SWT.Modify).observe(componentNameText);
    Binding componentNameBinding = ValueBindingBuilder.bind(componentNameObservable).validatingAfterGet(new MandatoryStringValidator("Please specify a name")).to(BeanProperties.value(ComponentModel.PROPERTY_COMPONENT_NAME).observe(model)).in(dbc);
    ControlDecorationSupport.create(componentNameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    IObservableValue<Object> projectObservable = BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT).observe(model);
    SelectProjectComponentBuilder builder = new SelectProjectComponentBuilder();
    builder.setTextLabel("Use existing workspace project:").setRequired(true).setEclipseProjectObservable(projectObservable).setSelectionListener(SelectionListener.widgetSelectedAdapter(this::onBrowseProjects)).setButtonIndent(0).build(parent, dbc, 1);
    CLabel information = new CLabel(parent, SWT.NONE);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(information);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(information)).notUpdatingParticipant().to(BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_HAS_DEVFILE).observe(model)).converting(IConverter.create(flag -> (boolean) flag ? "Project has a devfile, component type selection is not required" : "")).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(information)).notUpdatingParticipant().to(BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_HAS_DEVFILE).observe(model)).converting(IConverter.create(flag -> (boolean) flag ? INFORMATION_IMAGE : null)).in(dbc);
    Label componentTypesLabel = new Label(parent, SWT.NONE);
    componentTypesLabel.setText("Component type:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(componentTypesLabel);
    org.eclipse.swt.widgets.List componentTypesList = new org.eclipse.swt.widgets.List(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(componentTypesList);
    ListViewer componentTypesListViewer = new ListViewer(componentTypesList);
    componentTypesListViewer.setContentProvider(ArrayContentProvider.getInstance());
    componentTypesListViewer.setLabelProvider(new ComponentTypeColumLabelProvider());
    componentTypesListViewer.setInput(model.getComponentTypes());
    Binding componentTypesBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(componentTypesListViewer)).validatingAfterGet(new ComponentTypeValidator(ValidationStatus.cancel("You have to select a component type."))).to(BeanProperties.value(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_TYPE, ComponentType.class).observe(model)).in(dbc);
    ControlDecorationSupport.create(componentTypesBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(componentTypesList)).to(BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_HAS_DEVFILE).observe(model)).converting(new InvertingBooleanConverter()).in(dbc);
    Label componentStartersLabel = new Label(parent, SWT.NONE);
    componentStartersLabel.setText("Project starter:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(componentStartersLabel);
    Combo componentStartersVersionsCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(componentStartersVersionsCombo);
    ComboViewer componentStartersComboViewer = new ComboViewer(componentStartersVersionsCombo);
    componentStartersComboViewer.setContentProvider(new ObservableListContentProvider<>());
    componentStartersComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof Starter) {
                return ((Starter) element).getName();
            }
            return "";
        }
    });
    componentStartersComboViewer.setInput(BeanProperties.list(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_STARTERS).observe(model));
    Binding componentStartersBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(componentStartersComboViewer)).to(BeanProperties.value(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_STARTER).observe(model)).in(dbc);
    IObservableValue<List> selectedStartersObservable = BeanProperties.value(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_STARTERS, List.class).observe(model);
    IObservableValue<Boolean> emptyProjectObservable = BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_EMPTY, Boolean.class).observe(model);
    IObservableValue<Boolean> computedObservable = ComputedValue.create(() -> {
        return !selectedStartersObservable.getValue().isEmpty() && emptyProjectObservable.getValue();
    });
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(componentStartersVersionsCombo)).to(computedObservable).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(information)).notUpdatingParticipant().to(computedObservable).converting(IConverter.create(flag -> (boolean) flag ? "Your project is empty, you can initialize it from starters (templates)" : "")).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(information)).notUpdatingParticipant().to(computedObservable).converting(IConverter.create(flag -> (boolean) flag ? INFORMATION_IMAGE : null)).in(dbc);
    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(CreateComponentModel.PROPERTY_APPLICATION_NAME).observe(model)).in(dbc);
    ControlDecorationSupport.create(applicationNameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    if (!model.isDefaultApplication()) {
        applicationNameText.setEnabled(false);
    }
    Label pushAfterCreateLabel = new Label(parent, SWT.NONE);
    pushAfterCreateLabel.setText("Push after create:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(pushAfterCreateLabel);
    Button pushAfterCreateButton = new Button(parent, SWT.CHECK);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(pushAfterCreateButton);
    ISWTObservableValue<Boolean> pushAfterCreateObservable = WidgetProperties.buttonSelection().observe(pushAfterCreateButton);
    Binding pushAfterCreateBinding = ValueBindingBuilder.bind(pushAfterCreateObservable).to(BeanProperties.value(CreateComponentModel.PROPERTY_PUSH_AFTER_CREATE).observe(model)).in(dbc);
    ControlDecorationSupport.create(pushAfterCreateBinding, SWT.LEFT | SWT.TOP);
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) MandatoryStringValidator(org.jboss.tools.common.ui.databinding.MandatoryStringValidator) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Starter(org.jboss.tools.openshift.core.odo.Starter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button) List(java.util.List) Binding(org.eclipse.core.databinding.Binding) ListViewer(org.eclipse.jface.viewers.ListViewer) ComponentType(org.jboss.tools.openshift.core.odo.ComponentType) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) SelectProjectComponentBuilder(org.jboss.tools.openshift.internal.common.ui.SelectProjectComponentBuilder) Text(org.eclipse.swt.widgets.Text) ComboViewer(org.eclipse.jface.viewers.ComboViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

List (java.util.List)1 Binding (org.eclipse.core.databinding.Binding)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 ListViewer (org.eclipse.jface.viewers.ListViewer)1 CLabel (org.eclipse.swt.custom.CLabel)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)1 MandatoryStringValidator (org.jboss.tools.common.ui.databinding.MandatoryStringValidator)1 ComponentType (org.jboss.tools.openshift.core.odo.ComponentType)1 Starter (org.jboss.tools.openshift.core.odo.Starter)1 SelectProjectComponentBuilder (org.jboss.tools.openshift.internal.common.ui.SelectProjectComponentBuilder)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1