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