Search in sources :

Example 1 with ResourceProvider

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

the class AbstractMarketplaceWizardCommand method installRemoteCatalogs.

public IStatus installRemoteCatalogs() {
    try {
        final AtomicReference<List<? extends ICatalog>> result = new AtomicReference<List<? extends ICatalog>>();
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    ICatalogService catalogService = ServiceHelper.getMarketplaceServiceLocator().getCatalogService();
                    final List<? extends ICatalog> catalogs = catalogService.listCatalogs(monitor);
                    result.set(catalogs);
                } catch (CoreException e) {
                    if (e.getStatus().getSeverity() == IStatus.CANCEL) {
                        throw new InterruptedException();
                    }
                    throw new InvocationTargetException(e);
                }
            }
        });
        List<? extends ICatalog> catalogs = result.get();
        for (ICatalog catalog : catalogs) {
            ResourceProvider resourceProvider = MarketplaceClientUiPlugin.getInstance().getResourceProvider();
            String catalogName = catalog.getName();
            String requestSource = NLS.bind(Messages.MarketplaceWizardCommand_requestCatalog, catalogName, catalog.getId());
            String catalogImageUrl = catalog.getImageUrl();
            if (catalogImageUrl != null) {
                try {
                    resourceProvider.retrieveResource(requestSource, catalogImageUrl);
                } catch (Exception e) {
                    MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceWizardCommand_FailedRetrievingCatalogImage, catalogName, catalogImageUrl, e);
                }
            }
            if (catalog.getBranding() != null && catalog.getBranding().getWizardIcon() != null) {
                String wizardIconUrl = catalog.getBranding().getWizardIcon();
                try {
                    resourceProvider.retrieveResource(requestSource, wizardIconUrl);
                } catch (Exception e) {
                    MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceWizardCommand_FailedRetrievingCatalogWizardIcon, catalogName, wizardIconUrl, e);
                }
            }
            CatalogDescriptor descriptor = new CatalogDescriptor(catalog);
            registerOrOverrideCatalog(descriptor);
        }
    } catch (InterruptedException ie) {
        if (ie.getMessage() == null || "".equals(ie.getMessage())) {
            InterruptedException ie1 = new InterruptedException("Operation cancelled");
            ie1.setStackTrace(ie.getStackTrace());
            if (ie.getCause() != null) {
                ie1.initCause(ie.getCause());
            }
            ie = ie1;
        }
        IStatus errorStatus = MarketplaceClientCore.computeStatus(ie, Messages.MarketplaceWizardCommand_CannotInstallRemoteLocations);
        return new Status(IStatus.CANCEL, MarketplaceClientCore.BUNDLE_ID, errorStatus.getMessage(), ie);
    } catch (Exception e) {
        IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceWizardCommand_CannotInstallRemoteLocations);
        return status;
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceProvider(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider) List(java.util.List) ICatalog(org.eclipse.epp.mpc.core.model.ICatalog) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 2 with ResourceProvider

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

the class OverviewToolTip method provideImage.

private void provideImage(final Label imageLabel, MarketplaceCatalogSource discoverySource, final String imagePath) {
    ResourceProvider resourceProvider = discoverySource.getResourceProvider();
    MarketplaceDiscoveryStrategy.cacheResource(resourceProvider, overview.getItem(), imagePath);
    resourceProvider.provideResource(new ResourceReceiver<ImageDescriptor>() {

        public ImageDescriptor processResource(URL resource) {
            return ImageDescriptor.createFromURL(resource);
        }

        public void setResource(final ImageDescriptor resource) {
            if (resource != null && imageLabel != null && !imageLabel.isDisposed()) {
                imageLabel.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        if (!imageLabel.isDisposed()) {
                            try {
                                Image image = resource.createImage();
                                if (image != null) {
                                    Rectangle imageBounds = image.getBounds();
                                    if (imageBounds.width > SCREENSHOT_WIDTH || imageBounds.height > SCREENSHOT_HEIGHT) {
                                        final Image scaledImage = Util.scaleImage(image, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
                                        Image originalImage = image;
                                        image = scaledImage;
                                        originalImage.dispose();
                                    }
                                    final Image fimage = image;
                                    imageLabel.addDisposeListener(new DisposeListener() {

                                        public void widgetDisposed(DisposeEvent e) {
                                            fimage.dispose();
                                        }
                                    });
                                    imageLabel.setImage(image);
                                }
                            } catch (SWTException e) {
                                // ignore, probably a bad image format
                                MarketplaceClientUi.error(NLS.bind(Messages.OverviewToolTip_cannotRenderImage_reason, imagePath, e.getMessage()), e);
                            }
                        }
                    }
                });
            }
        }
    }, imagePath, null);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SWTException(org.eclipse.swt.SWTException) ResourceProvider(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider) Rectangle(org.eclipse.swt.graphics.Rectangle) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) URL(java.net.URL)

Example 3 with ResourceProvider

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

Example 4 with ResourceProvider

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

the class MarketplaceClientUiPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    instance = this;
    super.start(context);
    MarketplaceClientUiPlugin.bundleContext = context;
    clientServiceTracker = new ServiceTracker<IMarketplaceClientService, IMarketplaceClientService>(context, IMarketplaceClientService.class, null);
    clientServiceTracker.open();
    resourceProvider = new ResourceProvider();
    Hashtable<String, String> props = new Hashtable<String, String>(2);
    props.put(org.eclipse.osgi.service.debug.DebugOptions.LISTENER_SYMBOLICNAME, MarketplaceClientUi.BUNDLE_ID);
    context.registerService(DebugOptionsListener.class.getName(), new DebugOptionsListener() {

        public void optionsChanged(DebugOptions options) {
            DebugTrace debugTrace = null;
            boolean debug = options.getBooleanOption(MarketplaceClientUi.BUNDLE_ID + DEBUG_OPTION, false);
            if (debug) {
                debugTrace = options.newDebugTrace(MarketplaceClientUi.BUNDLE_ID);
            }
            DEBUG = debug;
            MarketplaceClientUiPlugin.debugTrace = debugTrace;
        }
    }, props);
}
Also used : DebugTrace(org.eclipse.osgi.service.debug.DebugTrace) IMarketplaceClientService(org.eclipse.epp.mpc.ui.IMarketplaceClientService) Hashtable(java.util.Hashtable) ResourceProvider(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider) DebugOptionsListener(org.eclipse.osgi.service.debug.DebugOptionsListener) DebugOptions(org.eclipse.osgi.service.debug.DebugOptions)

Aggregations

ResourceProvider (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider)4 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ResourceFuture (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider.ResourceFuture)1 ResourceProviderImageDescriptor (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProviderImageDescriptor)1 ICatalog (org.eclipse.epp.mpc.core.model.ICatalog)1 ICatalogService (org.eclipse.epp.mpc.core.service.ICatalogService)1 CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)1 IMarketplaceClientService (org.eclipse.epp.mpc.ui.IMarketplaceClientService)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1