use of org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture in project epp.mpc by eclipse.
the class MarketplaceDiscoveryResources method setImage.
public void setImage(final ImageReceiver receiver, final AbstractCatalogSource discoverySource, final String imagePath, Image fallbackImage) {
if (imagePath != null && imagePath.length() > 0) {
Image image = null;
if (discoverySource instanceof MarketplaceCatalogSource) {
MarketplaceCatalogSource marketplaceSource = (MarketplaceCatalogSource) discoverySource;
ResourceFuture resource = marketplaceSource.getResourceProvider().getResource(imagePath);
if (resource != null) {
URL localURL = resource.getLocalURL();
if (localURL != null) {
try {
File imageFile = new File(new URI(localURL.getProtocol(), null, localURL.getPath(), null, null));
if (imageFile.exists()) {
image = safeCreateImage(imagePath, localURL);
}
} catch (URISyntaxException e) {
logFailedLoadingImage(imagePath, localURL, e);
}
}
}
}
if (image != null) {
receiver.setImage(image);
} else if (fallbackImage != null) {
receiver.setImage(fallbackImage);
}
new Job(Messages.MarketplaceDiscoveryResources_retrievingImage) {
{
setPriority(INTERACTIVE);
setUser(false);
setSystem(true);
}
@Override
protected IStatus run(IProgressMonitor monitor) {
if (!display.isDisposed()) {
try {
if (imagePath != null && imagePath.length() > 0) {
final URL resource = discoverySource.getResource(imagePath);
if (resource != null) {
display.asyncExec(new Runnable() {
public void run() {
final Image image = safeCreateImage(imagePath, resource);
if (image != null) {
receiver.setImage(image);
}
}
});
}
}
} catch (Exception e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceDiscoveryResources_FailedCreatingImage, imagePath, discoverySource.getId(), e);
// we don't want any additional logging or error popups...
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
}.schedule();
} else if (fallbackImage != null) {
receiver.setImage(fallbackImage);
}
}
use of org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture in project epp.mpc by eclipse.
the class CatalogDescriptor method imageDescriptorForUrl.
private static ImageDescriptor imageDescriptorForUrl(ICatalog catalog, String imageUrl) throws MalformedURLException {
if (imageUrl != null && imageUrl.length() > 0) {
ResourceProvider resourceProvider = MarketplaceClientUiPlugin.getInstance().getResourceProvider();
ResourceFuture resource = resourceProvider.getResource(imageUrl);
if (resource == null) {
String requestSource = NLS.bind(Messages.CatalogDescriptor_requestCatalog, catalog.getName(), catalog.getId());
try {
resource = resourceProvider.retrieveResource(requestSource, imageUrl);
} catch (URISyntaxException e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.CatalogDescriptor_badUri, catalog.getName(), catalog.getId(), resource, e);
} catch (IOException e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.CatalogDescriptor_downloadError, catalog.getName(), catalog.getId(), resource, e);
}
}
if (resource != null) {
return new ResourceProviderImageDescriptor(resourceProvider, imageUrl);
}
return ImageDescriptor.createFromURL(URLUtil.toURL(imageUrl));
}
return null;
}
Aggregations