use of org.jboss.tools.openshift.internal.ui.models.IProjectWrapper in project jbosstools-openshift by jbosstools.
the class OpenShiftExplorerContentProvider method getProjectChildren.
protected Object[] getProjectChildren(IProjectWrapper project) {
switch(project.getState()) {
case LOADED:
removeStub(project);
Collection<IResourceWrapper<?, ?>> services = project.getResourcesOfKind(ResourceKind.SERVICE);
Collection<IReplicationControllerWrapper> dcs = project.getResourcesOfType(IReplicationControllerWrapper.class);
services.addAll(dcs);
Collection<IResourceWrapper<?, ?>> pods = project.getResourcesOfKind(ResourceKind.POD).stream().filter(wrapper -> ResourceUtils.isRuntimePod((IPod) wrapper.getWrapped()) && !((IPod) wrapper.getWrapped()).isAnnotatedWith(OpenShiftAPIAnnotations.DEPLOYMENT_NAME)).collect(Collectors.toList());
services.addAll(pods);
return services.toArray();
case LOAD_STOPPED:
LoadingStub stub = removeStub(project);
if (stub != null) {
return stub.getChildren();
}
default:
project.load(e -> {
handleLoadingException(project, e);
});
return new Object[] { makeStub(project) };
}
}
use of org.jboss.tools.openshift.internal.ui.models.IProjectWrapper in project jbosstools-openshift by jbosstools.
the class DeleteResourceHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = UIUtils.getCurrentSelection(event);
IResourceWrapper<?, ?>[] resources = UIUtils.getElements(selection, IResourceWrapper.class);
if (resources == null || resources.length == 0) {
// $NON-NLS-1$
return OpenShiftUIActivator.statusFactory().cancelStatus("No resource selected that we can delete.");
}
try (Stream<IResourceWrapper<?, ?>> stream = Arrays.stream(resources)) {
boolean hasProject = stream.anyMatch(resource -> resource instanceof IProjectWrapper);
String title = getDialogTitle(hasProject);
String message = getDialogMessage(resources, hasProject);
boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), title, message);
if (confirm) {
deleteResources(resources);
}
return null;
}
}
use of org.jboss.tools.openshift.internal.ui.models.IProjectWrapper in project jbosstools-openshift by jbosstools.
the class DeleteResourceHandlerTest method testStopWatchProject.
@Test
public void testStopWatchProject() throws Exception {
IProject project = mock(IProject.class);
when(project.getName()).thenReturn("ProjectName");
when(project.getKind()).thenReturn(ResourceKind.PROJECT);
IProjectWrapper projectWrapper = mock(IProjectWrapper.class);
when(projectWrapper.getWrapped()).thenReturn(project);
Connection connection = mock(Connection.class);
ConnectionsRegistrySingleton.getInstance().add(connection);
when(connection.ownsResource(project)).thenReturn(true);
WatchManager.getInstance().startWatch(project, connection);
assertEquals(WatchManager.KINDS.length, WatchManager.getInstance()._getWatches().size());
DeleteResourceHandlerTestExtension handler = new DeleteResourceHandlerTestExtension();
JobGroup deleteResourcesJobGroup = handler.deleteResources(new IResourceWrapper<?, ?>[] { projectWrapper });
deleteResourcesJobGroup.join(500, null);
assertEquals(0, WatchManager.getInstance()._getWatches().size());
}
Aggregations