use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
// given
List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
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
List<ObservableTreeItem> newResourceItems = model.getResourceItems();
assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
// given
List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IReplicationController replicationController = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
when(project.getResources(ResourceKind.REPLICATION_CONTROLLER)).thenReturn(Collections.singletonList(replicationController));
// when
model.loadResources(connection);
// then
List<ObservableTreeItem> newResourceItems = model.getResourceItems();
assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createResourceTree.
@SuppressWarnings("unchecked")
private IViewerObservableValue createResourceTree(ServerSettingsWizardPageModel model, SashForm resourceControlsContainer, DataBindingContext dbc) {
Composite resourceTreeContainer = new Composite(resourceControlsContainer, SWT.None);
GridLayoutFactory.fillDefaults().applyTo(resourceTreeContainer);
// filter
Text selectorText = UIUtils.createSearchText(resourceTreeContainer);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(selectorText);
// resource tree
final TreeViewer resourcesViewer = createResourcesTreeViewer(resourceTreeContainer, model, selectorText);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(RESOURCE_TREE_WIDTH, RESOURCE_TREE_HEIGHT).applyTo(resourcesViewer.getControl());
resourcesViewer.addDoubleClickListener(onDoubleClickService());
IObservableList<ObservableTreeItem> resourceItemsObservable = BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_RESOURCE_ITEMS).observe(model);
DataBindingUtils.addDisposableListChangeListener(onResourceItemsChanged(resourcesViewer), resourceItemsObservable, resourcesViewer.getTree());
selectorText.addModifyListener(onFilterTextModified(resourcesViewer));
IViewerObservableValue selectedResourceTreeItem = ViewerProperties.singleSelection().observe(resourcesViewer);
ValueBindingBuilder.bind(selectedResourceTreeItem).converting(new ObservableTreeItem2ModelConverter(IResource.class)).validatingAfterConvert(value -> {
if ((value instanceof IResource) && OpenShiftServerUtils.isAllowedForServerAdapter((IResource) value)) {
return ValidationStatus.ok();
}
return ValidationStatus.cancel("Please select a resource that this adapter will be bound to.");
}).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RESOURCE).observe(model)).converting(new Model2ObservableTreeItemConverter(new ServerSettingsWizardPageModel.ResourceTreeItemsFactory())).in(dbc);
return selectedResourceTreeItem;
}
use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createResourcesTreeViewer.
@SuppressWarnings("unchecked")
private TreeViewer createResourcesTreeViewer(Composite parent, ServerSettingsWizardPageModel model, Text selectorText) {
TreeViewer applicationTemplatesViewer = new TreeViewer(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
IListProperty<ServerSettingsWizardPageModel, ObservableTreeItem> childrenProperty = new MultiListProperty<>(new IListProperty[] { BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_RESOURCE_ITEMS), BeanProperties.list(ObservableTreeItem.PROPERTY_CHILDREN) });
ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(childrenProperty.listFactory(), null);
applicationTemplatesViewer.setContentProvider(contentProvider);
applicationTemplatesViewer.setLabelProvider(new ResourcesViewLabelProvider());
applicationTemplatesViewer.addFilter(new ServiceViewerFilter(selectorText));
applicationTemplatesViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter());
applicationTemplatesViewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
applicationTemplatesViewer.setInput(model);
return applicationTemplatesViewer;
}
use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModel method loadServices.
protected List<ObservableTreeItem> loadServices(Connection connection) {
if (connection == null) {
return null;
}
ObservableTreeItem connectionItem = ResourceTreeItemsFactory.INSTANCE.create(connection);
connectionItem.load();
return connectionItem.getChildren();
}
Aggregations