Search in sources :

Example 11 with IUserFavoritesService

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

the class DefaultMarketplaceService method userFavorites.

public ISearchResult userFavorites(IProgressMonitor monitor) throws CoreException, NotAuthorizedException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_FavoritesRetrieve, 10000);
    IUserFavoritesService userFavoritesService = getUserFavoritesService();
    if (userFavoritesService == null) {
        throw new UnsupportedOperationException();
    }
    final List<INode> favorites;
    try {
        favorites = userFavoritesService.getFavorites(progress.newChild(1000));
    } catch (NotAuthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new CoreException(MarketplaceClientCore.computeStatus(e, Messages.DefaultMarketplaceService_FavoritesErrorRetrieving));
    }
    progress.setWorkRemaining(9000);
    return resolveFavoriteNodes(favorites, progress.newChild(9000), true);
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 12 with IUserFavoritesService

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

the class DiscoveryItem method getFavoriteCount.

private Integer getFavoriteCount() {
    if (connector.getData() instanceof INode) {
        INode node = (INode) connector.getData();
        IUserFavoritesService userFavoritesService = getUserFavoritesService();
        if (userFavoritesService != null) {
            return userFavoritesService.getFavoriteCount(node);
        }
        return node.getFavorited();
    }
    return null;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Example 13 with IUserFavoritesService

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

the class DiscoveryItem method getUserFavoritesService.

private IUserFavoritesService getUserFavoritesService() {
    MarketplaceCatalogSource source = (MarketplaceCatalogSource) this.getData().getSource();
    IUserFavoritesService userFavoritesService = source.getMarketplaceService().getUserFavoritesService();
    return userFavoritesService;
}
Also used : MarketplaceCatalogSource(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalogSource) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Example 14 with IUserFavoritesService

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

the class DiscoveryItem method toggleFavorite.

private void toggleFavorite() {
    final INode node = this.getCatalogItemNode();
    final IUserFavoritesService userFavoritesService = getUserFavoritesService();
    if (node != null && userFavoritesService != null) {
        final boolean newFavorited = !isFavorited();
        final Throwable[] error = new Throwable[] { null };
        BusyIndicator.showWhile(getDisplay(), new Runnable() {

            public void run() {
                try {
                    ModalContext.run(new IRunnableWithProgress() {

                        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            try {
                                userFavoritesService.getStorageService().runWithLogin(new Callable<Void>() {

                                    public Void call() throws Exception {
                                        userFavoritesService.setFavorite(node, newFavorited, monitor);
                                        return null;
                                    }
                                });
                            } catch (Exception e) {
                                error[0] = e;
                            }
                        }
                    }, true, new NullProgressMonitor(), getDisplay());
                } catch (InvocationTargetException e) {
                    error[0] = e.getCause();
                } catch (InterruptedException e) {
                    error[0] = e;
                }
            }
        });
        Throwable e = error[0];
        if (e != null) {
            if (e instanceof NotAuthorizedException) {
                // authentication was cancelled
                return;
            } else if (e instanceof ConflictException) {
                // silently ignored - service already tried to resolve this
                return;
            } else {
                IStatus status = MarketplaceClientCore.computeStatus(e, NLS.bind(Messages.DiscoveryItem_FavoriteActionFailed, this.getNameLabelText()));
                MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
                return;
            }
        }
        setFavorited(newFavorited);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) ConflictException(org.eclipse.userstorage.util.ConflictException) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) ConflictException(org.eclipse.userstorage.util.ConflictException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 15 with IUserFavoritesService

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

the class DiscoveryItem method refreshFavoriteButton.

private void refreshFavoriteButton() {
    if (favoriteButton == null || this.isDisposed() || favoriteButton.isDisposed()) {
        return;
    }
    if (Display.getCurrent() != this.getDisplay()) {
        this.getDisplay().asyncExec(new Runnable() {

            public void run() {
                refreshFavoriteButton();
            }
        });
        return;
    }
    boolean favorited = isFavorited();
    Object lastFavorited = favoriteButton.getData(FAVORITED_BUTTON_STATE_DATA);
    if (lastFavorited == null || (favorited != Boolean.TRUE.equals(lastFavorited))) {
        favoriteButton.setData(FAVORITED_BUTTON_STATE_DATA, lastFavorited);
        String imageId = favorited ? MarketplaceClientUiPlugin.ITEM_ICON_STAR_SELECTED : MarketplaceClientUiPlugin.ITEM_ICON_STAR;
        favoriteButton.setImage(MarketplaceClientUiPlugin.getInstance().getImageRegistry().get(imageId));
        IUserFavoritesService userFavoritesService = getUserFavoritesService();
        favoriteButton.setEnabled(userFavoritesService != null);
        favoriteButton.removeSelectionListener(toggleFavoritesListener);
        if (userFavoritesService != null) {
            favoriteButton.addSelectionListener(toggleFavoritesListener);
        }
    }
    refreshFavoriteCount();
}
Also used : 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