Search in sources :

Example 1 with ObservableTreeItem2ModelConverter

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter in project jbosstools-openshift by jbosstools.

the class DeployImagePage method createDockerConnectionControl.

private void createDockerConnectionControl(Composite parent, DataBindingContext dbc) {
    createDockerConnectionLabel(parent);
    StructuredViewer connectionViewer = new ComboViewer(parent);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(NUM_COLUMS - 2, 1).applyTo(connectionViewer.getControl());
    connectionViewer.setContentProvider(new ObservableListContentProvider());
    connectionViewer.setLabelProvider(new ObservableTreeItemLabelProvider() {

        @Override
        public String getText(Object element) {
            return (element instanceof IDockerConnection) ? dockerConnectionToString((IDockerConnection) element) : "";
        }
    });
    connectionViewer.setInput(BeanProperties.list(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTIONS).observe(model));
    IObservableValue<IDockerConnection> dockerConnectionObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model);
    DockerConnectionStatusProvider validator = new DockerConnectionStatusProvider(dockerConnectionObservable);
    IObservableValue<?> selectedConnectionObservable = ViewerProperties.singleSelection().observe(connectionViewer);
    Binding selectedConnectionBinding = ValueBindingBuilder.bind(selectedConnectionObservable).converting(new ObservableTreeItem2ModelConverter(IDockerConnection.class)).validatingAfterConvert(validator).to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).in(dbc);
    ControlDecorationSupport.create(selectedConnectionBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Button newDockerConnectionButton = new Button(parent, SWT.PUSH);
    newDockerConnectionButton.setText("New...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newDockerConnectionButton);
    UIUtils.setDefaultButtonWidth(newDockerConnectionButton);
    newDockerConnectionButton.addSelectionListener(onNewDockerConnectionClicked());
    dbc.addValidationStatusProvider(validator);
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableTreeItemLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Example 2 with ObservableTreeItem2ModelConverter

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter in project jbosstools-openshift by jbosstools.

the class AbstractProjectPage method createProjectControls.

private void createProjectControls(Composite parent, DataBindingContext dbc) {
    Label projectLabel = new Label(parent, SWT.NONE);
    projectLabel.setText("OpenShift project: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(projectLabel);
    StructuredViewer projectsViewer = new ComboViewer(parent);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(projectsViewer.getControl());
    final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider();
    projectsViewer.setContentProvider(new ObservableListContentProvider());
    projectsViewer.setLabelProvider(new ObservableTreeItemLabelProvider());
    projectsViewer.setInput(BeanProperties.list(IProjectPageModel.PROPERTY_PROJECT_ITEMS).observe(model));
    projectsViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter(labelProvider));
    model.setProjectsComparator(new ProjectViewerComparator(labelProvider).asItemComparator());
    IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(projectsViewer);
    Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable).converting(new ObservableTreeItem2ModelConverter(IProject.class)).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value instanceof IProject) {
                return ValidationStatus.ok();
            }
            return ValidationStatus.cancel("Please choose an OpenShift project.");
        }
    }).to(BeanProperties.value(IProjectPageModel.PROPERTY_PROJECT).observe(model)).converting(new Model2ObservableTreeItemConverter(null)).in(dbc);
    ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    IObservableValue connectionObservable = BeanProperties.value(IProjectPageModel.PROPERTY_CONNECTION).observe(model);
    DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(), connectionObservable, projectsViewer.getControl());
    Button newProjectButton = new Button(parent, SWT.PUSH);
    newProjectButton.setText("New...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.FILL).applyTo(newProjectButton);
    UIUtils.setDefaultButtonWidth(newProjectButton);
    newProjectButton.addSelectionListener(onNewProjectClicked());
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableTreeItemLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) IProject(com.openshift.restclient.model.IProject) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IValidator(org.eclipse.core.databinding.validation.IValidator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) Button(org.eclipse.swt.widgets.Button) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 3 with ObservableTreeItem2ModelConverter

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createResourceDetails.

private void createResourceDetails(IViewerObservableValue selectedResourceTreeItem, Composite parent, DataBindingContext dbc) {
    ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    ExpandableComposite expandable = new ExpandableComposite(scrolledComposite, SWT.None);
    scrolledComposite.setContent(expandable);
    expandable.setText("Resource Details");
    expandable.setExpanded(true);
    expandable.setLayout(new FillLayout());
    Composite detailsContainer = new Composite(expandable, SWT.NONE);
    expandable.setClient(detailsContainer);
    expandable.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            getControl().update();
            ((Composite) getControl()).layout(true);
        }
    });
    IObservableValue<IResource> selectedResource = new WritableValue<>();
    ValueBindingBuilder.bind(selectedResourceTreeItem).converting(new ObservableTreeItem2ModelConverter()).to(selectedResource).notUpdatingParticipant().in(dbc);
    new ResourceDetailViews(selectedResource, detailsContainer, dbc).createControls();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) FillLayout(org.eclipse.swt.layout.FillLayout) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) IResource(com.openshift.restclient.model.IResource)

Example 4 with ObservableTreeItem2ModelConverter

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter in project jbosstools-openshift by jbosstools.

the class BuildConfigWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(parent);
    GridLayoutFactory.fillDefaults().applyTo(parent);
    Group buildConfigsGroup = new Group(parent, SWT.NONE);
    buildConfigsGroup.setText("Existing Build Configs:");
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(buildConfigsGroup);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(buildConfigsGroup);
    // build configs tree
    TreeViewer buildConfigsViewer = createBuildConfigsViewer(new Tree(buildConfigsGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL), model, dbc);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, 200).span(1, 2).applyTo(buildConfigsViewer.getControl());
    final IObservableValue selectedItem = BeanProperties.value(IBuildConfigPageModel.PROPERTY_SELECTED_ITEM).observe(model);
    Binding selectedBuildConfigBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(buildConfigsViewer)).converting(new ObservableTreeItem2ModelConverter()).to(selectedItem).converting(new Model2ObservableTreeItemConverter()).in(dbc);
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            if (!(selectedItem.getValue() instanceof IBuildConfig)) {
                return ValidationStatus.cancel("Please select the existing build config that you want to import");
            } else {
                return ValidationStatus.ok();
            }
        }
    });
    IObservableValue connectionObservable = BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONNECTION).observe(model);
    DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(buildConfigsViewer, model), connectionObservable, buildConfigsViewer.getTree());
    ControlDecorationSupport.create(selectedBuildConfigBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // refresh button
    Button refreshButton = new Button(buildConfigsGroup, SWT.PUSH);
    refreshButton.setText("&Refresh");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(100, SWT.DEFAULT).applyTo(refreshButton);
    refreshButton.addSelectionListener(onRefresh(buildConfigsViewer, model));
    // filler
    Label fillerLabel = new Label(buildConfigsGroup, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(fillerLabel);
    // details
    ExpandableComposite expandable = new ExpandableComposite(buildConfigsGroup, SWT.None);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(expandable);
    expandable.setText("Build config Details");
    expandable.setExpanded(true);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(0, 0).applyTo(expandable);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(expandable);
    Composite detailsContainer = new Composite(expandable, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(detailsContainer);
    IObservableValue selectedService = new WritableValue();
    ValueBindingBuilder.bind(selectedItem).to(selectedService).notUpdatingParticipant().in(dbc);
    new BuildConfigDetailViews(selectedService, detailsContainer, dbc).createControls();
    expandable.setClient(detailsContainer);
    expandable.addExpansionListener(new IExpansionListener() {

        @Override
        public void expansionStateChanging(ExpansionEvent e) {
        }

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            buildConfigsGroup.update();
            buildConfigsGroup.layout(true);
        }
    });
    loadBuildConfigs(model);
}
Also used : Binding(org.eclipse.core.databinding.Binding) Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) IExpansionListener(org.eclipse.ui.forms.events.IExpansionListener) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) BuildConfigDetailViews(org.jboss.tools.openshift.internal.ui.server.BuildConfigDetailViews) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.wizard.importapp.BuildConfigTreeItems.Model2ObservableTreeItemConverter) IBuildConfig(com.openshift.restclient.model.IBuildConfig) Button(org.eclipse.swt.widgets.Button) Tree(org.eclipse.swt.widgets.Tree) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent)

Example 5 with ObservableTreeItem2ModelConverter

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter in project jbosstools-openshift by jbosstools.

the class DeployImagePage method createProjectControl.

private void createProjectControl(Composite parent, DataBindingContext dbc) {
    Label lblProject = new Label(parent, SWT.NONE);
    lblProject.setText("OpenShift Project: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblProject);
    StructuredViewer cmboProject = new ComboViewer(parent);
    GridDataFactory.fillDefaults().span(NUM_COLUMS - 2, 1).applyTo(cmboProject.getControl());
    final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider();
    cmboProject.setContentProvider(new ObservableListContentProvider());
    cmboProject.setLabelProvider(labelProvider);
    cmboProject.setInput(BeanProperties.list(IDeployImagePageModel.PROPERTY_PROJECTS).observe(model));
    ProjectViewerComparator comparator = new ProjectViewerComparator(labelProvider);
    cmboProject.setComparator(comparator);
    model.setProjectsComparator(comparator.asProjectComparator());
    IObservableValue<IProject> projectObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_PROJECT).observe(model);
    ProjectStatusProvider validator = new ProjectStatusProvider(projectObservable);
    IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(cmboProject);
    Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable).converting(new ObservableTreeItem2ModelConverter(IProject.class)).validatingAfterConvert(validator).to(projectObservable).in(dbc);
    ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Button newProjectButton = new Button(parent, SWT.PUSH);
    newProjectButton.setText("New...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newProjectButton);
    UIUtils.setDefaultButtonWidth(newProjectButton);
    newProjectButton.addSelectionListener(onNewProjectClicked());
    dbc.addValidationStatusProvider(validator);
    cmboProject.getControl().forceFocus();
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) IProject(com.openshift.restclient.model.IProject) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Aggregations

ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)8 Binding (org.eclipse.core.databinding.Binding)5 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)5 Button (org.eclipse.swt.widgets.Button)5 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)5 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)4 ComboViewer (org.eclipse.jface.viewers.ComboViewer)4 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)3 IStatus (org.eclipse.core.runtime.IStatus)3 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)3 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)3 ProjectViewerComparator (org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)3 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)2 IProject (com.openshift.restclient.model.IProject)2 IResource (com.openshift.restclient.model.IResource)2 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2