Search in sources :

Example 11 with IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService 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 12 with IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService 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 13 with IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService 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 14 with IMarketplaceStorageService

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

IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)14 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)7 Test (org.junit.Test)6 IStorageService (org.eclipse.userstorage.IStorageService)5 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchElementException (java.util.NoSuchElementException)2 CoreException (org.eclipse.core.runtime.CoreException)2 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)2 UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)2 LoginListener (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService.LoginListener)2 BundleContext (org.osgi.framework.BundleContext)2 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1 Callable (java.util.concurrent.Callable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1