Search in sources :

Example 1 with ProjectViewerComparator

use of org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator in project jbosstools-openshift by jbosstools.

the class ProjectViewerComparatorTest method setUp.

@Before
public void setUp() throws Exception {
    comparator = new ProjectViewerComparator();
    when(projectOne.getName()).thenReturn("mmmm");
    when(projectTwo.getName()).thenReturn("gggg");
}
Also used : ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) Before(org.junit.Before)

Example 2 with ProjectViewerComparator

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

use of org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator 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 4 with ProjectViewerComparator

use of org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator in project jbosstools-openshift by jbosstools.

the class ManageProjectsWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
    Group group = new Group(parent, SWT.NONE);
    group.setText("OpenShift Projects");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(group);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(group);
    // table
    Composite tableContainer = new Composite(group, SWT.NONE);
    this.viewer = createTable(tableContainer);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
    viewer.setContentProvider(new ObservableListContentProvider());
    viewer.setInput(BeanProperties.list(ManageProjectsWizardPageModel.PROPERTY_PROJECTS).observe(pageModel));
    loadProjects(dbc);
    initialProjects = getProjects();
    viewer.setComparator(new ProjectViewerComparator());
    IObservableValue viewerSingleSelection = ViewerProperties.singleSelection().observe(viewer);
    ValueBindingBuilder.bind(viewerSingleSelection).to(BeanProperties.value(ManageProjectsWizardPageModel.PROPERTY_SELECTED_PROJECT).observe(pageModel)).in(dbc);
    // new
    Button newButton = new Button(group, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(newButton);
    newButton.setText("New...");
    newButton.addSelectionListener(onNew());
    UIUtils.setDefaultButtonWidth(newButton);
    // remove
    Button removeButton = new Button(group, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(removeButton);
    removeButton.setText("Remove...");
    removeButton.addSelectionListener(onRemove(dbc));
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(removeButton)).notUpdatingParticipant().to(viewerSingleSelection).converting(new IsNotNull2BooleanConverter()).in(dbc);
    UIUtils.setDefaultButtonWidth(removeButton);
    Composite filler = new Composite(group, SWT.None);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(filler);
    // refresh
    Button refreshButton = new Button(group, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.END).applyTo(refreshButton);
    refreshButton.setText("Refresh...");
    refreshButton.addSelectionListener(onRefresh(dbc));
    UIUtils.setDefaultButtonWidth(refreshButton);
}
Also used : Group(org.eclipse.swt.widgets.Group) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)

Example 5 with ProjectViewerComparator

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

ProjectViewerComparator (org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)6 OpenShiftExplorerLabelProvider (org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider)4 IProject (com.openshift.restclient.model.IProject)3 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)3 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)3 Button (org.eclipse.swt.widgets.Button)3 Binding (org.eclipse.core.databinding.Binding)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)2 Label (org.eclipse.swt.widgets.Label)2 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)2 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)2 Test (org.junit.Test)2 IValidator (org.eclipse.core.databinding.validation.IValidator)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 IsNotNull2BooleanConverter (org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)1 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)1 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)1