Search in sources :

Example 21 with ISearchResult

use of org.eclipse.epp.mpc.core.model.ISearchResult in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method userFavorites.

public void userFavorites(boolean promptLogin, IProgressMonitor monitor) throws CoreException {
    final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieve, 1001);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.USER_FAVORITES);
        IUserFavoritesService userFavoritesService = marketplaceService.getUserFavoritesService();
        if (userFavoritesService != null) {
            try {
                applyShellProvider();
                ISearchResult result;
                if (promptLogin) {
                    IMarketplaceStorageService storageService = userFavoritesService.getStorageService();
                    result = storageService.runWithLogin(new Callable<ISearchResult>() {

                        public ISearchResult call() throws Exception {
                            return marketplaceService.userFavorites(progress.newChild(500));
                        }
                    });
                } else {
                    result = marketplaceService.userFavorites(progress.newChild(500));
                }
                if (result.getNodes().isEmpty()) {
                    catalogCategory = addPopularItems(progress.newChild(500));
                    addNoFavoritesItem(catalogCategory);
                } else {
                    handleSearchResult(catalogCategory, result, progress.newChild(500));
                }
            } catch (NotAuthorizedException e) {
                catalogCategory = addPopularItems(progress.newChild(500));
                addUserStorageLoginItem(catalogCategory, e.getLocalizedMessage());
            } catch (UnsupportedOperationException ex) {
                catalogCategory = addPopularItems(progress.newChild(500));
                addFavoritesNotSupportedItem(catalogCategory);
            } catch (Exception ex) {
                // FIXME we should use the wizard page's status line to show errors, but that's unreachable from here...
                MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, ex);
                addRetryErrorItem(catalogCategory, ex);
            }
        } else {
            catalogCategory = addPopularItems(progress.newChild(1000));
            addFavoritesNotSupportedItem(catalogCategory);
        }
    } finally {
        monitor.done();
    }
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SubMonitor(org.eclipse.core.runtime.SubMonitor) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Callable(java.util.concurrent.Callable) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)21 SubMonitor (org.eclipse.core.runtime.SubMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 Test (org.junit.Test)6 CoreException (org.eclipse.core.runtime.CoreException)5 INode (org.eclipse.epp.mpc.core.model.INode)5 NoSuchElementException (java.util.NoSuchElementException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Node (org.eclipse.epp.internal.mpc.core.model.Node)2 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 IMarket (org.eclipse.epp.mpc.core.model.IMarket)2 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1