Search in sources :

Example 16 with IUserFavoritesService

use of org.eclipse.epp.mpc.core.service.IUserFavoritesService in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method addLoginListener.

public synchronized void addLoginListener(LoginListener loginListener) {
    IUserFavoritesService favoritesService = marketplaceService.getUserFavoritesService();
    if (favoritesService != null) {
        if (loginListeners == null) {
            loginListeners = new CopyOnWriteArrayList<LoginListener>();
        }
        if (!loginListeners.contains(loginListener)) {
            loginListeners.add(loginListener);
            IMarketplaceStorageService storageService = favoritesService.getStorageService();
            storageService.addLoginListener(loginListener);
        }
    }
}
Also used : LoginListener(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService.LoginListener) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Example 17 with IUserFavoritesService

use of org.eclipse.epp.mpc.core.service.IUserFavoritesService in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method applyShellProvider.

protected void applyShellProvider() {
    IUserFavoritesService userFavoritesService = marketplaceService.getUserFavoritesService();
    if (userFavoritesService == null) {
        return;
    }
    IMarketplaceStorageService storageService = userFavoritesService.getStorageService();
    if (storageService == null) {
        return;
    }
    IStorage storage = storageService.getStorage();
    ICredentialsProvider credentialsProvider = storage.getCredentialsProvider();
    if (credentialsProvider instanceof EclipseOAuthCredentialsProvider) {
        ((EclipseOAuthCredentialsProvider) credentialsProvider).setShell(shellProvider);
    }
}
Also used : ICredentialsProvider(org.eclipse.userstorage.spi.ICredentialsProvider) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IStorage(org.eclipse.userstorage.IStorage) EclipseOAuthCredentialsProvider(org.eclipse.userstorage.oauth.EclipseOAuthCredentialsProvider) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Example 18 with IUserFavoritesService

use of org.eclipse.epp.mpc.core.service.IUserFavoritesService in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method dispose.

@Override
public void dispose() {
    List<LoginListener> loginListeners = this.loginListeners;
    this.loginListeners = null;
    if (loginListeners != null) {
        IUserFavoritesService favoritesService = marketplaceService.getUserFavoritesService();
        if (favoritesService != null) {
            IMarketplaceStorageService storageService = favoritesService.getStorageService();
            for (LoginListener loginListener : loginListeners) {
                storageService.removeLoginListener(loginListener);
            }
        }
    }
    if (source != null) {
        source.dispose();
        source = null;
    }
    if (marketplaceInfo != null) {
        final MarketplaceInfo fMarketplaceInfo = marketplaceInfo;
        new Job(Messages.MarketplaceDiscoveryStrategy_saveMarketplaceInfoJobName) {

            {
                setSystem(true);
                setPriority(SHORT);
                setUser(false);
            }

            @Override
            public boolean belongsTo(Object family) {
                BundleContext bundleContext = MarketplaceClientUiPlugin.getBundleContext();
                MarketplaceClientUiPlugin plugin = MarketplaceClientUiPlugin.getInstance();
                return (bundleContext != null && (family == bundleContext || family == bundleContext.getBundle())) || (plugin != null && family == plugin);
            }

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    fMarketplaceInfo.save();
                } catch (Exception e) {
                    return MarketplaceClientCore.computeStatus(e, Messages.MarketplaceDiscoveryStrategy_failedToSaveMarketplaceInfo);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
        marketplaceInfo = null;
    }
    super.dispose();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) 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) MarketplaceClientUiPlugin(org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiPlugin) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LoginListener(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService.LoginListener) Job(org.eclipse.core.runtime.jobs.Job) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) BundleContext(org.osgi.framework.BundleContext)

Example 19 with IUserFavoritesService

use of org.eclipse.epp.mpc.core.service.IUserFavoritesService 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)

Example 20 with IUserFavoritesService

use of org.eclipse.epp.mpc.core.service.IUserFavoritesService in project epp.mpc by eclipse.

the class ImportFavoritesPage method findUserFavoritesService.

private IUserFavoritesService findUserFavoritesService() {
    IUserFavoritesService userFavoritesService = null;
    for (AbstractDiscoveryStrategy strategy : getCatalog().getDiscoveryStrategies()) {
        if (strategy instanceof FavoritesDiscoveryStrategy) {
            FavoritesDiscoveryStrategy favoritesStrategy = (FavoritesDiscoveryStrategy) strategy;
            userFavoritesService = favoritesStrategy.getMarketplaceService().getUserFavoritesService();
        }
    }
    return userFavoritesService;
}
Also used : FavoritesDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.FavoritesDiscoveryStrategy) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Aggregations

IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)20 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)7 MalformedURLException (java.net.MalformedURLException)6 INode (org.eclipse.epp.mpc.core.model.INode)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 CoreException (org.eclipse.core.runtime.CoreException)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NoSuchElementException (java.util.NoSuchElementException)2 Callable (java.util.concurrent.Callable)2 IStatus (org.eclipse.core.runtime.IStatus)2 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)2 LoginListener (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService.LoginListener)2