Search in sources :

Example 1 with IProjectWrapper

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) };
    }
}
Also used : IReplicationControllerWrapper(org.jboss.tools.openshift.internal.ui.models.IReplicationControllerWrapper) Arrays(java.util.Arrays) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) HashMap(java.util.HashMap) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) ArrayList(java.util.ArrayList) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IPod(com.openshift.restclient.model.IPod) Map(java.util.Map) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) Viewer(org.eclipse.jface.viewers.Viewer) ResourceKind(com.openshift.restclient.ResourceKind) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) OpenshiftUIModel(org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel) IReplicationControllerWrapper(org.jboss.tools.openshift.internal.ui.models.IReplicationControllerWrapper) Collectors(java.util.stream.Collectors) LoadingStub(org.jboss.tools.openshift.internal.common.ui.explorer.BaseExplorerContentProvider.LoadingStub) IResourceContainer(org.jboss.tools.openshift.internal.ui.models.IResourceContainer) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) Connection(org.jboss.tools.openshift.core.connection.Connection) List(java.util.List) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IRoute(com.openshift.restclient.model.route.IRoute) BaseExplorerContentProvider(org.jboss.tools.openshift.internal.common.ui.explorer.BaseExplorerContentProvider) IProjectWrapper(org.jboss.tools.openshift.internal.ui.models.IProjectWrapper) ConnectionsRegistrySingleton(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistrySingleton) IElementListener(org.jboss.tools.openshift.internal.ui.models.IElementListener) IOpenshiftUIElement(org.jboss.tools.openshift.internal.ui.models.IOpenshiftUIElement) Control(org.eclipse.swt.widgets.Control) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) LoadingStub(org.jboss.tools.openshift.internal.common.ui.explorer.BaseExplorerContentProvider.LoadingStub) IPod(com.openshift.restclient.model.IPod)

Example 2 with IProjectWrapper

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;
    }
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IProjectWrapper(org.jboss.tools.openshift.internal.ui.models.IProjectWrapper)

Example 3 with IProjectWrapper

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());
}
Also used : JobGroup(org.eclipse.core.runtime.jobs.JobGroup) Connection(org.jboss.tools.openshift.core.connection.Connection) IProject(com.openshift.restclient.model.IProject) IProjectWrapper(org.jboss.tools.openshift.internal.ui.models.IProjectWrapper) Test(org.junit.Test)

Aggregations

IProjectWrapper (org.jboss.tools.openshift.internal.ui.models.IProjectWrapper)3 Connection (org.jboss.tools.openshift.core.connection.Connection)2 IResourceWrapper (org.jboss.tools.openshift.internal.ui.models.IResourceWrapper)2 ResourceKind (com.openshift.restclient.ResourceKind)1 IBuild (com.openshift.restclient.model.IBuild)1 IPod (com.openshift.restclient.model.IPod)1 IProject (com.openshift.restclient.model.IProject)1 IRoute (com.openshift.restclient.model.route.IRoute)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 JobGroup (org.eclipse.core.runtime.jobs.JobGroup)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1