use of org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method refreshUserFavorites.
public void refreshUserFavorites(IProgressMonitor monitor) throws CoreException {
final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_FavoritesRefreshing, 1001);
try {
MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
List<CatalogItem> items = catalogCategory.getItems();
if (hasUserFavoritesService()) {
Map<String, INode> nodes = new HashMap<String, INode>();
for (CatalogItem item : items) {
Object data = item.getData();
if (data instanceof INode) {
INode node = (INode) data;
nodes.put(node.getId(), node);
}
}
if (nodes.isEmpty()) {
return;
}
try {
applyShellProvider();
marketplaceService.userFavorites(new ArrayList<INode>(nodes.values()), progress.newChild(500));
for (CatalogItem catalogItem : items) {
if (catalogItem instanceof MarketplaceNodeCatalogItem) {
MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
INode node = nodes.get(nodeItem.getId());
nodeItem.setUserFavorite(node == null ? null : node.getUserFavorite());
}
}
} 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 {
for (CatalogItem catalogItem : items) {
if (catalogItem instanceof MarketplaceNodeCatalogItem) {
MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
nodeItem.setUserFavorite(null);
}
}
}
} finally {
monitor.done();
}
}
use of org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory in project epp.mpc by eclipse.
the class CatalogSwitcher method createHeader.
private void createHeader(Composite parent) {
CatalogCategory fakeCategory = new CatalogCategory();
fakeCategory.setName(Messages.CatalogSwitcher_Header);
CategoryItem<CatalogCategory> header = new CategoryItem<CatalogCategory>(parent, SWT.NONE, new DiscoveryResources(parent.getDisplay()), fakeCategory);
MarketplaceViewer.setSeparatorVisible(header, false);
MarketplaceViewer.fixLayout(header);
}
use of org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory in project epp.mpc by eclipse.
the class FavoritesDiscoveryStrategy method addInfoItem.
private void addInfoItem(CatalogCategory catalogCategory, String title, String description) {
MarketplaceCatalogSource source = getCatalogSource();
// $NON-NLS-1$
String id = catalogDescriptor.getUrl().toString() + "#info:" + title;
for (ListIterator<CatalogItem> i = items.listIterator(items.size()); i.hasPrevious(); ) {
CatalogItem item = i.previous();
if (item.getSource() == source && (item.getCategory() == catalogCategory || catalogCategory.getId().equals(item.getCategoryId())) && item instanceof UserActionCatalogItem) {
UserActionCatalogItem actionItem = (UserActionCatalogItem) item;
if (actionItem.getUserAction() == UserAction.INFO && id.equals(actionItem.getId())) {
return;
}
}
}
UserActionCatalogItem infoItem = new UserActionCatalogItem();
infoItem.setUserAction(UserAction.INFO);
infoItem.setDescription(description);
infoItem.setName(title);
infoItem.setId(id);
addItem(catalogCategory, infoItem);
}
use of org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory in project epp.mpc by eclipse.
the class MarketplaceCatalog method removeItem.
public void removeItem(CatalogItem item) {
getItems().remove(item);
getFilteredItems().remove(item);
for (CatalogCategory category : getCategories()) {
category.getItems().remove(item);
}
}
use of org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory in project epp.mpc by eclipse.
the class MarketplaceViewerSorter method compare.
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
if (o1 == o2) {
return 0;
}
CatalogCategory cat1 = getCategory(o1);
CatalogCategory cat2 = getCategory(o2);
// FIXME filter uncategorized items?
if (cat1 == null) {
return (cat2 != null) ? 1 : 0;
} else if (cat2 == null) {
return 1;
}
int i = categoryComparator.compare(cat1, cat2);
if (i == 0) {
if (o1 instanceof CatalogCategory) {
return -1;
}
if (o2 instanceof CatalogCategory) {
return 1;
}
CatalogItem i1 = (CatalogItem) o1;
CatalogItem i2 = (CatalogItem) o2;
// catalog descriptor comes last
if (i1.getData() instanceof CatalogDescriptor) {
i = 1;
} else if (i2.getData() instanceof CatalogDescriptor) {
i = -1;
} else {
// otherwise we sort by name
String n1 = i1.getName();
String n2 = i2.getName();
if (n1 == null) {
// $NON-NLS-1$
n1 = "";
}
if (n2 == null) {
// $NON-NLS-1$
n2 = "";
}
i = n1.compareToIgnoreCase(n2);
if (i == 0) {
i = n1.compareTo(n2);
if (i == 0) {
// same name, so we sort by id.
String id1 = i1.getId();
String id2 = i2.getId();
if (id1 == null) {
// $NON-NLS-1$
id1 = "";
}
if (id2 == null) {
// $NON-NLS-1$
id2 = "";
}
i = id1.compareTo(id2);
}
}
}
}
return i;
}
Aggregations