Search in sources :

Example 1 with OpenShiftExplorerLabelProvider

use of org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider in project jbosstools-openshift by jbosstools.

the class BuildConfigWizardPage method createBuildConfigsViewer.

private TreeViewer createBuildConfigsViewer(Tree tree, IBuildConfigPageModel model, DataBindingContext dbc) {
    TreeViewer buildConfigsViewer = new TreeViewer(tree);
    IListProperty childrenProperty = new MultiListProperty(new IListProperty[] { BeanProperties.list(IBuildConfigPageModel.PROPERTY_BUILDCONFIGS), BeanProperties.list(ObservableTreeItem.PROPERTY_CHILDREN) });
    ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(childrenProperty.listFactory(), null);
    buildConfigsViewer.setContentProvider(contentProvider);
    buildConfigsViewer.setLabelProvider(new ObservableTreeItemStyledCellLabelProvider());
    buildConfigsViewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    buildConfigsViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter(new OpenShiftExplorerLabelProvider()));
    buildConfigsViewer.setInput(model);
    return buildConfigsViewer;
}
Also used : IListProperty(org.eclipse.core.databinding.property.list.IListProperty) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ObservableListTreeContentProvider(org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider) ObservableTreeItemStyledCellLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemStyledCellLabelProvider) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) MultiListProperty(org.eclipse.core.databinding.property.list.MultiListProperty)

Example 2 with OpenShiftExplorerLabelProvider

use of org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider in project jbosstools-openshift by jbosstools.

the class ProjectTreeSorterTest method testProjectItemsWithLabelProvider.

@Test
public void testProjectItemsWithLabelProvider() {
    final Comparator<ObservableTreeItem> comparator = new ProjectViewerComparator(new OpenShiftExplorerLabelProvider()).asItemComparator();
    ObservableTreeItem p1 = new ObservableTreeItem(mockProject("default", "z"));
    ObservableTreeItem p2 = new ObservableTreeItem(mockProject("openshift", "y"));
    ObservableTreeItem p3 = new ObservableTreeItem(mockProject("a", "c"));
    ObservableTreeItem p4 = new ObservableTreeItem(mockProject("b2", null));
    ObservableTreeItem p5 = new ObservableTreeItem(mockProject("d", "b"));
    ObservableTreeItem[] projects = new ObservableTreeItem[] { p3, p5, p2, p1, p4 };
    Arrays.sort(projects, comparator);
    assertEquals(p1, projects[0]);
    assertEquals(p2, projects[1]);
    assertEquals(p5, projects[2]);
    assertEquals(p4, projects[3]);
    assertEquals(p3, projects[4]);
}
Also used : OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) Test(org.junit.Test)

Example 3 with OpenShiftExplorerLabelProvider

use of org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider in project jbosstools-openshift by jbosstools.

the class ProjectTreeSorterTest method testBuildConfigs.

@Test
public void testBuildConfigs() {
    ViewerComparator comparator = ProjectViewerComparator.createProjectTreeSorter(new OpenShiftExplorerLabelProvider());
    ObservableTreeItem i1 = new ObservableTreeItem(mockBuildConfig("n", "c1", "z"));
    ObservableTreeItem i2 = new ObservableTreeItem(mockBuildConfig("n", "c2", "x"));
    // compared by source uri!
    assertTrue(comparator.compare(null, i1, i2) < 0);
    assertTrue(comparator.compare(null, i2, i1) > 0);
    assertEquals(0, comparator.compare(null, i1, i1));
}
Also used : ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) Test(org.junit.Test)

Example 4 with OpenShiftExplorerLabelProvider

use of org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider 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 5 with OpenShiftExplorerLabelProvider

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

OpenShiftExplorerLabelProvider (org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider)7 ProjectViewerComparator (org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)5 IProject (com.openshift.restclient.model.IProject)3 Test (org.junit.Test)3 Binding (org.eclipse.core.databinding.Binding)2 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)2 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)2 Button (org.eclipse.swt.widgets.Button)2 Label (org.eclipse.swt.widgets.Label)2 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)2 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)2 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)2 URL (java.net.URL)1 IListProperty (org.eclipse.core.databinding.property.list.IListProperty)1 MultiListProperty (org.eclipse.core.databinding.property.list.MultiListProperty)1 IValidator (org.eclipse.core.databinding.validation.IValidator)1 ObservableListTreeContentProvider (org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider)1