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