Search in sources :

Example 1 with ObservableTreeItemLabelProvider

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider 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 ObservableTreeItemLabelProvider

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider 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)

Aggregations

Binding (org.eclipse.core.databinding.Binding)2 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)2 Button (org.eclipse.swt.widgets.Button)2 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)2 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)2 ObservableTreeItemLabelProvider (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider)2 IProject (com.openshift.restclient.model.IProject)1 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)1 IValidator (org.eclipse.core.databinding.validation.IValidator)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 Label (org.eclipse.swt.widgets.Label)1 ProjectViewerComparator (org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)1 OpenShiftExplorerLabelProvider (org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider)1 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)1