use of org.eclipse.userstorage.util.ConflictException in project epp.mpc by eclipse.
the class UserFavoritesService method alterFavorites.
private void alterFavorites(Collection<? extends INode> nodes, boolean favorite, IProgressMonitor monitor) throws NotAuthorizedException, ConflictException, IOException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.UserFavoritesService_SettingUserFavorites, 1000);
ConflictException conflictException = null;
for (int i = 0; i < RETRY_COUNT; i++) {
try {
progress.setWorkRemaining(1000);
doAlterFavorites(nodes, favorite, progress.newChild(800));
progress.done();
return;
} catch (ConflictException e) {
conflictException = e;
} catch (OperationCanceledException ex) {
throw processProtocolException(ex);
} catch (ProtocolException ex) {
throw processProtocolException(ex);
}
}
if (conflictException != null) {
throw conflictException;
}
}
use of org.eclipse.userstorage.util.ConflictException in project epp.mpc by eclipse.
the class ImportFavoritesPage method performImport.
public void performImport() {
setErrorMessage(null);
saveInstallSelected();
List<MarketplaceNodeCatalogItem> importFavorites = getSelection();
if (importFavorites.isEmpty()) {
return;
}
final IUserFavoritesService userFavoritesService = findUserFavoritesService();
if (userFavoritesService == null) {
return;
}
final List<INode> importNodes = new ArrayList<INode>();
for (MarketplaceNodeCatalogItem item : importFavorites) {
importNodes.add(item.getData());
}
try {
getContainer().run(true, false, new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
userFavoritesService.getStorageService().runWithLogin(new Callable<Void>() {
public Void call() throws Exception {
try {
userFavoritesService.addFavorites(importNodes, monitor);
} catch (NotAuthorizedException e) {
setErrorMessage(Messages.ImportFavoritesPage_unauthorizedErrorMessage);
} catch (ConflictException e) {
setErrorMessage(Messages.ImportFavoritesPage_conflictErrorMessage);
}
return null;
}
});
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
MarketplaceClientCore.error(cause);
setErrorMessage(NLS.bind(Messages.ImportFavoritesPage_unknownErrorMessage, cause));
} catch (InterruptedException e) {
// ignore
}
}
use of org.eclipse.userstorage.util.ConflictException 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);
}
}
Aggregations