Search in sources :

Example 41 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class OpenShiftResourceDocumentProvider method doSaveDocument.

@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
    OpenShiftResourceInput input = getInput(element);
    if (input == null) {
        return;
    }
    IResource resource = input.getResource();
    IClient client = ResourceUtils.getClient(resource);
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    Connection connection = input.getConnection();
    String resourceName = input.getName();
    IResource newResource = connection.getResourceFactory().create(document.get());
    final Exception[] exceptions = new Exception[1];
    Job updateResourceJob = new Job("Update " + resourceName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                client.update(newResource);
            } catch (Exception e) {
                exceptions[0] = e;
                Display.getDefault().asyncExec(() -> setDirty(element));
                String problem = e.getMessage();
                if (e instanceof OpenShiftException) {
                    OpenShiftException oe = (OpenShiftException) e;
                    if (oe.getStatus() != null) {
                        problem = oe.getStatus().getMessage();
                    }
                }
                IStatus error = OpenShiftUIActivator.statusFactory().errorStatus(NLS.bind("Could not update \"{0}\" for project \"{1}\" : {2}", new String[] { resourceName, resource.getNamespaceName(), problem }), e);
                return error;
            }
            return Status.OK_STATUS;
        }
    };
    updateResourceJob.schedule();
    Shell shell = Display.getCurrent().getActiveShell();
    service.showInDialog(shell, updateResourceJob);
    // we need to ensure the dirty flag stays set to true
    if (exceptions[0] != null) {
        throw new CoreException(OpenShiftUIActivator.statusFactory().errorStatus(exceptions[0]));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IClient(com.openshift.restclient.IClient) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftException(com.openshift.restclient.OpenShiftException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IProgressService(org.eclipse.ui.progress.IProgressService) Job(org.eclipse.core.runtime.jobs.Job) IResource(com.openshift.restclient.model.IResource)

Example 42 with IResource

use of com.openshift.restclient.model.IResource 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 43 with IResource

use of com.openshift.restclient.model.IResource 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 44 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createResourceDetails.

private void createResourceDetails(IViewerObservableValue selectedResourceTreeItem, Composite parent, DataBindingContext dbc) {
    ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    ExpandableComposite expandable = new ExpandableComposite(scrolledComposite, SWT.None);
    scrolledComposite.setContent(expandable);
    expandable.setText("Resource Details");
    expandable.setExpanded(true);
    expandable.setLayout(new FillLayout());
    Composite detailsContainer = new Composite(expandable, SWT.NONE);
    expandable.setClient(detailsContainer);
    expandable.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            getControl().update();
            ((Composite) getControl()).layout(true);
        }
    });
    IObservableValue<IResource> selectedResource = new WritableValue<>();
    ValueBindingBuilder.bind(selectedResourceTreeItem).converting(new ObservableTreeItem2ModelConverter()).to(selectedResource).notUpdatingParticipant().in(dbc);
    new ResourceDetailViews(selectedResource, detailsContainer, dbc).createControls();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) FillLayout(org.eclipse.swt.layout.FillLayout) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) IResource(com.openshift.restclient.model.IResource)

Example 45 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class ResourceLabelFilter method select.

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    this.viewer = viewer;
    if (!(element instanceof IResource)) {
        return false;
    }
    IResource resource = (IResource) element;
    return ResourceUtils.hasMatchingLabels(labelFilter.getValue(), resource);
}
Also used : IResource(com.openshift.restclient.model.IResource)

Aggregations

IResource (com.openshift.restclient.model.IResource)101 Test (org.junit.Test)32 Connection (org.jboss.tools.openshift.core.connection.Connection)27 IProject (com.openshift.restclient.model.IProject)14 IStatus (org.eclipse.core.runtime.IStatus)12 Collection (java.util.Collection)10 ServerResourceViewModel (org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel)9 IReplicationController (com.openshift.restclient.model.IReplicationController)8 IService (com.openshift.restclient.model.IService)8 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)7 Status (org.eclipse.core.runtime.Status)7 ISelection (org.eclipse.jface.viewers.ISelection)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IPod (com.openshift.restclient.model.IPod)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IBuildConfig (com.openshift.restclient.model.IBuildConfig)5