Search in sources :

Example 6 with CatalogCategory

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();
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) 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) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)

Example 7 with CatalogCategory

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);
}
Also used : CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) DiscoveryResources(org.eclipse.equinox.internal.p2.ui.discovery.wizards.DiscoveryResources) CategoryItem(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CategoryItem)

Example 8 with CatalogCategory

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);
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)

Example 9 with CatalogCategory

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);
    }
}
Also used : CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)

Example 10 with CatalogCategory

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;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Aggregations

CatalogCategory (org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)8 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)8 CoreException (org.eclipse.core.runtime.CoreException)3 SubMonitor (org.eclipse.core.runtime.SubMonitor)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)2 MarketplaceCategory (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 INode (org.eclipse.epp.mpc.core.model.INode)2 AbstractDiscoveryStrategy (org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy)2 Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)2 HashMap (java.util.HashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Matcher (java.util.regex.Matcher)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1