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]));
}
}
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;
}
};
}
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());
}
};
}
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();
}
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);
}
Aggregations