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");
}
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]);
}
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());
}
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);
}
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();
}
Aggregations