Search in sources :

Example 1 with IResourceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.

the class ManageEnvironmentVariablesWizard method findReplicationController.

/**
 * If a replication controller is selected, method returns it.
 * If a deployment config is selected, method returns it.
 * If a deployment is selected, method finds a deployment config and returns it.
 * @param event
 * @return
 */
IReplicationController findReplicationController(ExecutionEvent event) {
    ISelection selection = UIUtils.getCurrentSelection(event);
    IDeploymentConfig dc = UIUtils.getFirstElement(selection, IDeploymentConfig.class);
    if (dc != null) {
        return dc;
    }
    IReplicationController rc = UIUtils.getFirstElement(selection, IReplicationController.class);
    if (rc != null) {
        return rc;
    }
    IServiceWrapper deployment = UIUtils.getFirstElement(selection, IServiceWrapper.class);
    Collection<IResourceWrapper<?, ?>> dcs = deployment.getResourcesOfKind(ResourceKind.DEPLOYMENT_CONFIG);
    if (!dcs.isEmpty()) {
        dc = (IDeploymentConfig) dcs.iterator().next().getWrapped();
        if (dc != null) {
            return dc;
        }
    }
    return null;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 2 with IResourceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.

the class EventsPropertySection method addColumns.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void addColumns(TableViewerBuilder tableViewerBuilder) {
    addCreatedColumn(tableViewerBuilder);
    ICellToolTipProvider toolTipProvider = new ICellToolTipProvider() {

        @Override
        public String getToolTipText(Object object) {
            if (object instanceof IResourceWrapper && ((IResourceWrapper) object).getWrapped() instanceof IEvent) {
                return ((IEvent) ((IResourceWrapper) object).getWrapped()).getMessage();
            }
            return null;
        }

        @Override
        public int getToolTipDisplayDelayTime(Object event) {
            return 0;
        }
    };
    tableViewerBuilder.column(model -> StringUtils.substringBefore(getResource(model).getName(), ".")).name("Name").align(SWT.LEFT).weight(1).minWidth(15).cellToolTipProvider(toolTipProvider).buildColumn().column(model -> ((IEvent) getResource(model)).getInvolvedObject().getKind()).name("Kind").align(SWT.LEFT).weight(1).minWidth(5).cellToolTipProvider(toolTipProvider).buildColumn().column(model -> ((IEvent) getResource(model)).getReason()).name("Reason").align(SWT.LEFT).weight(1).minWidth(5).cellToolTipProvider(toolTipProvider).buildColumn();
}
Also used : ICellToolTipProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) StringUtils(org.apache.commons.lang.StringUtils) ResourceKind(com.openshift.restclient.ResourceKind) SWT(org.eclipse.swt.SWT) IEvent(com.openshift.restclient.model.IEvent) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IEvent(com.openshift.restclient.model.IEvent) ICellToolTipProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider)

Example 3 with IResourceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.

the class OpenShiftResourcePropertySection method createCreationTimestampSorter.

protected ViewerComparator createCreationTimestampSorter(boolean descending) {
    return new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IResource r1 = ((IResourceWrapper<?, ?>) e1).getWrapped();
            IResource r2 = ((IResourceWrapper<?, ?>) e2).getWrapped();
            try {
                Date d1 = DateTimeUtils.parse(r1.getCreationTimeStamp());
                Date d2 = DateTimeUtils.parse(r2.getCreationTimeStamp());
                return descending ? d2.compareTo(d1) : d1.compareTo(d2);
            } catch (ParseException e) {
                OpenShiftUIActivator.log(IStatus.ERROR, "Unable to parse dates in OpenShift Resource Property Tab Section", e);
            }
            return 0;
        }
    };
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) ParseException(java.text.ParseException) IResource(com.openshift.restclient.model.IResource) Date(java.util.Date)

Example 4 with IResourceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper in project jbosstools-openshift by jbosstools.

the class OpenShiftResourcePropertySection method createNameSorter.

protected ViewerComparator createNameSorter() {
    return new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IResource r1 = ((IResourceWrapper<?, ?>) e1).getWrapped();
            IResource r2 = ((IResourceWrapper<?, ?>) e2).getWrapped();
            return r1.getName().compareTo(r2.getName());
        }
    };
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IResource(com.openshift.restclient.model.IResource)

Example 5 with IResourceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IResourceWrapper 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)

Aggregations

IResourceWrapper (org.jboss.tools.openshift.internal.ui.models.IResourceWrapper)11 IResource (com.openshift.restclient.model.IResource)4 ResourceKind (com.openshift.restclient.ResourceKind)3 ISelection (org.eclipse.jface.viewers.ISelection)3 Viewer (org.eclipse.jface.viewers.Viewer)3 IPod (com.openshift.restclient.model.IPod)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 JobGroup (org.eclipse.core.runtime.jobs.JobGroup)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)2 SWT (org.eclipse.swt.SWT)2 ConnectionsRegistry (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2 DeleteResourceJob (org.jboss.tools.openshift.internal.core.job.DeleteResourceJob)2 ResourceUtils (org.jboss.tools.openshift.internal.core.util.ResourceUtils)2 IConnectionWrapper (org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper)2 IElementListener (org.jboss.tools.openshift.internal.ui.models.IElementListener)2