Search in sources :

Example 1 with MarketplaceCatalogSource

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource 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 MarketplaceCatalogSource

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource in project epp.mpc by eclipse.

the class DiscoveryItem method getUserFavoritesService.

private IUserFavoritesService getUserFavoritesService() {
    MarketplaceCatalogSource source = (MarketplaceCatalogSource) this.getData().getSource();
    IUserFavoritesService userFavoritesService = source.getMarketplaceService().getUserFavoritesService();
    return userFavoritesService;
}
Also used : MarketplaceCatalogSource(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Aggregations

MarketplaceCatalogSource (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource)2 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)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 ResourceFuture (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture)1 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)1 DeviceResourceException (org.eclipse.jface.resource.DeviceResourceException)1 SWTException (org.eclipse.swt.SWTException)1 Image (org.eclipse.swt.graphics.Image)1