use of com.openshift.restclient.model.IProject 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();
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class DeployImageWizardModel method getDefaultProject.
private IProject getDefaultProject() {
IProject project;
if (projectsComparator != null) {
Collections.sort(projects, projectsComparator);
project = projects.get(0);
} else {
project = projects.get(0);
}
return project;
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ProjectTreeSorterTest method testProjectsWithLabelProvider.
@Test
public void testProjectsWithLabelProvider() {
final ViewerComparator comparator = new ProjectViewerComparator(new OpenShiftExplorerLabelProvider());
IProject p1 = mockProject("default", "z");
IProject p2 = mockProject("openshift", "y");
IProject p3 = mockProject("a", "c");
IProject p4 = mockProject("b2", null);
IProject p5 = mockProject("d", "b");
IProject[] projects = new IProject[] { p3, p5, p2, p1, p4 };
Arrays.sort(projects, new Comparator<IProject>() {
@Override
public int compare(IProject o1, IProject o2) {
return comparator.compare(null, o1, o2);
}
});
assertEquals(p1, projects[0]);
assertEquals(p2, projects[1]);
assertEquals(p5, projects[2]);
assertEquals(p4, projects[3]);
assertEquals(p3, projects[4]);
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection() {
// given
IResource selectedDeploymentConfig = model.getResource();
Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
ConnectionsRegistrySingleton.getInstance().add(connection);
try {
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IDeploymentConfig deploymentConfig = ResourceMocks.createResource(IDeploymentConfig.class, ResourceKind.DEPLOYMENT_CONFIG);
when(project.getResources(ResourceKind.DEPLOYMENT_CONFIG)).thenReturn(Collections.singletonList(deploymentConfig));
// when
model.loadResources(connection);
// then
IResource newSelectedDeploymentConfig = model.getResource();
assertThat(selectedDeploymentConfig).isNotEqualTo(newSelectedDeploymentConfig);
} finally {
ConnectionsRegistrySingleton.getInstance().remove(connection);
}
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithServiceTest method shouldReturnNewSelectedServiceIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewSelectedServiceIfLoadResourcesWithConnection() {
// given
IResource selectedService = model.getResource();
Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
ConnectionsRegistrySingleton.getInstance().add(connection);
try {
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
when(project.getResources(ResourceKind.SERVICE)).thenReturn(Collections.singletonList(service));
// when
model.loadResources(connection);
// then
IResource newSelectedService = model.getResource();
assertThat(selectedService).isNotEqualTo(newSelectedService);
} finally {
ConnectionsRegistrySingleton.getInstance().remove(connection);
}
}
Aggregations