Search in sources :

Example 1 with ResourceFuture

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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) URISyntaxException(java.net.URISyntaxException) Image(org.eclipse.swt.graphics.Image) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) SWTException(org.eclipse.swt.SWTException) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) ResourceFuture(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MarketplaceCatalogSource(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 2 with ResourceFuture

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;
}
Also used : ResourceFuture(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture) ResourceProvider(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ResourceProviderImageDescriptor(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProviderImageDescriptor)

Aggregations

URISyntaxException (java.net.URISyntaxException)2 ResourceFuture (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture)2 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 MarketplaceCatalogSource (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource)1 ResourceProvider (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider)1 ResourceProviderImageDescriptor (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProviderImageDescriptor)1 DeviceResourceException (org.eclipse.jface.resource.DeviceResourceException)1 SWTException (org.eclipse.swt.SWTException)1 Image (org.eclipse.swt.graphics.Image)1