use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.
the class DeleteResourcesHandler method deleteResources.
/**
* Resources are deleted with one job per resource and job are in a job group so
* that an error dialog will be displayed at the end of the job group.
*
* made protected for test purposes only
*
* @param uiResources
* the UI resources to delete
*/
protected void deleteResources(final IResourceWrapper<?, ?>[] uiResources) {
final JobGroup group = new JobGroup("Delete Openshift resources", 1, uiResources.length) {
/*
* Overridden because job group cancel job at first job error by default
*/
@Override
protected boolean shouldCancel(IStatus lastCompletedJobResult, int numberOfFailedJobs, int numberOfCanceledJobs) {
return false;
}
};
try (Stream<IResourceWrapper<?, ?>> stream = Arrays.stream(uiResources)) {
stream.forEach(uiResource -> {
DeleteResourceJob job = OpenShiftJobs.createDeleteResourceJob(uiResource.getWrapped());
job.setJobGroup(group);
job.schedule();
});
}
}
use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.
the class DeleteResourcesHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IResourceWrapper<?, ?>[] wrappers = UIUtils.getElements(UIUtils.getCurrentSelection(event), IResourceWrapper.class);
if (ArrayUtils.isEmpty(wrappers) || wrappers[0].getWrapped() == null) {
return OpenShiftUIActivator.statusFactory().cancelStatus("Could not delete resources: " + "No resource selected that we can get the connection and namespace from.");
}
IResource selectedResource = wrappers[0].getWrapped();
Connection connection = ConnectionsRegistryUtil.getConnectionFor(selectedResource);
if (connection == null) {
return OpenShiftUIActivator.statusFactory().cancelStatus(NLS.bind("Could not delete resources: No connection found for selected resource {0}", selectedResource.getName()));
}
String namespace = selectedResource.getNamespaceName();
openDialog(connection, namespace, HandlerUtil.getActiveShell(event));
return null;
}
use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper 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.IResourceWrapper in project jbosstools-openshift by jbosstools.
the class DeleteResourceHandler method deleteResources.
/**
* Resources are deleted with one job per resource and job are in a job
* group so that an error dialog will be displayed at the end of the job
* group.
*
* made protected for test purposes only
*
* @param uiResources
* the UI resources to delete
*/
protected JobGroup deleteResources(final IResourceWrapper<?, ?>[] uiResources) {
final JobGroup group = new JobGroup("Deleting OpenShift resources...", 1, uiResources.length) {
/*
* Overridden because job group cancel job at first job error by
* default
*/
@Override
protected boolean shouldCancel(IStatus lastCompletedJobResult, int numberOfFailedJobs, int numberOfCanceledJobs) {
return false;
}
};
try (Stream<IResourceWrapper<?, ?>> stream = Arrays.stream(uiResources)) {
stream.forEach(uiResource -> {
DeleteResourceJob job = OpenShiftJobs.createDeleteResourceJob(uiResource.getWrapped());
job.setJobGroup(group);
job.schedule();
});
}
return group;
}
use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.
the class RefreshTest method testRefreshConnection.
@Test
public void testRefreshConnection() throws InterruptedException, TimeoutException {
IProject project1 = stubProject("test1", 1);
IProject project2 = stubProject("test2", 1);
IProject project2prime = stubProject("test2", 2);
when(getConnectionMock().getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project1));
IConnectionWrapper connection = getConnection();
getConnection().load(IExceptionHandler.NULL_HANDLER);
UITestUtils.waitForState(connection, LoadingState.LOADED);
assertEquals(1, connection.getResources().size());
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project1, project2));
verify(listener).elementChanged(connection);
assertEquals(2, connection.getResources().size());
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project2.equals(projectWrapper.getWrapped())));
registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2));
verify(listener, times(2)).elementChanged(connection);
assertEquals(1, connection.getResources().size());
Optional<IResourceWrapper<?, ?>> project2Wrapper = connection.getResources().stream().filter(projectWrapper -> project2.equals(projectWrapper.getWrapped())).findFirst();
assertTrue(project2Wrapper.isPresent());
registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2prime));
verify(listener, times(2)).elementChanged(connection);
verify(listener).elementChanged(project2Wrapper.get());
assertEquals(1, connection.getResources().size());
assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> {
IResource resource = projectWrapper.getWrapped();
String version = resource.getResourceVersion();
return project2.equals(resource) && version.equals("2");
}));
}
Aggregations