Search in sources :

Example 1 with MarketplaceCategory

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory in project epp.mpc by eclipse.

the class MarketplaceCatalogTest method setupCatalog.

protected void setupCatalog() throws MalformedURLException {
    final SearchResult discoveryResult = new SearchResult();
    discoveryResult.setNodes(discoveryNodes);
    CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
    catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
    MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {

        final MarketplaceCategory category = new MarketplaceCategory();

        {
            category.setId("<root>");
        }

        @Override
        public void performDiscovery(IProgressMonitor monitor) throws CoreException {
            if (!categories.contains(category)) {
                categories.add(category);
            }
            handleSearchResult(category, discoveryResult, new NullProgressMonitor());
        }

        @Override
        protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
            Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
            for (INode node : installedNodes) {
                IIus ius = node.getIus();
                if (ius != null) {
                    for (IIu iu : ius.getIuElements()) {
                        String featureId = iu.getId() + ".feature.group";
                        InstallableUnit installableUnit = new InstallableUnit();
                        installableUnit.setId(featureId);
                        installedIus.put(featureId, installableUnit);
                    }
                }
            }
            return installedIus;
        }

        @Override
        protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
            return category;
        }
    };
    catalog = new MarketplaceCatalog() {

        @Override
        protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
            for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
                checkedForUpdate.add(item.getData());
                List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                boolean hasUpdate = updateAvailable.contains(item.getData());
                for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                    iuItem.setUpdateAvailable(hasUpdate);
                }
            }
            return Status.OK_STATUS;
        }
    };
    catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit) URL(java.net.URL) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IIu(org.eclipse.epp.mpc.core.model.IIu) MarketplaceNodeInstallableUnitItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ArrayList(java.util.ArrayList) List(java.util.List) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IIus(org.eclipse.epp.mpc.core.model.IIus) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 2 with MarketplaceCategory

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory in project epp.mpc by eclipse.

the class MarketplaceViewer method catalogUpdated.

@Override
protected void catalogUpdated(final boolean wasCancelled, final boolean wasError) {
    MarketplaceCatalog catalog = getCatalog();
    List<AbstractDiscoveryStrategy> discoveryStrategies = catalog.getDiscoveryStrategies();
    for (AbstractDiscoveryStrategy discoveryStrategy : discoveryStrategies) {
        if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
            MarketplaceDiscoveryStrategy marketplaceDiscoveryStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
            marketplaceDiscoveryStrategy.addLoginListener(loginListener);
            for (CatalogCategory catalogCategory : catalog.getCategories()) {
                if (catalogCategory instanceof MarketplaceCategory) {
                    MarketplaceCategory marketplaceCategory = (MarketplaceCategory) catalogCategory;
                    if (marketplaceCategory.getContents() == Contents.FEATURED && getWizard().shouldShowOpenFavoritesBanner()) {
                        marketplaceDiscoveryStrategy.addOpenFavoritesItem(marketplaceCategory);
                    }
                }
            }
        }
    }
    runUpdate(new Runnable() {

        public void run() {
            MarketplaceViewer.super.catalogUpdated(wasCancelled, wasError);
            for (CatalogFilter filter : getConfiguration().getFilters()) {
                if (filter instanceof MarketplaceFilter) {
                    ((MarketplaceFilter) filter).catalogUpdated(wasCancelled);
                }
            }
            setFilters(queryData);
        }
    });
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory)

Example 3 with MarketplaceCategory

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory in project epp.mpc by eclipse.

the class NewsUrlHandler method handleSearch.

@Override
protected boolean handleSearch(CatalogDescriptor descriptor, String url, String searchString, Map<String, String> params) {
    MarketplaceWizard marketplaceWizard = viewer.getWizard();
    // $NON-NLS-1$
    String filterParam = params.get("filter");
    // $NON-NLS-1$
    String[] filters = filterParam.split(" ");
    ICategory searchCategory = null;
    IMarket searchMarket = null;
    for (String filter : filters) {
        if (filter.startsWith("tid:")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String id = filter.substring("tid:".length());
            List<CatalogCategory> catalogCategories = marketplaceWizard.getCatalog().getCategories();
            for (CatalogCategory catalogCategory : catalogCategories) {
                if (catalogCategory instanceof MarketplaceCategory) {
                    MarketplaceCategory marketplaceCategory = (MarketplaceCategory) catalogCategory;
                    List<? extends IMarket> markets = marketplaceCategory.getMarkets();
                    for (IMarket market : markets) {
                        if (id.equals(market.getId())) {
                            searchMarket = market;
                        } else {
                            final List<? extends ICategory> categories = market.getCategory();
                            for (ICategory category : categories) {
                                if (id.equals(category.getId())) {
                                    searchCategory = category;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    marketplaceWizard.getCatalogPage().search(descriptor, searchMarket, searchCategory, searchString);
    return true;
}
Also used : ICategory(org.eclipse.epp.mpc.core.model.ICategory) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IMarket(org.eclipse.epp.mpc.core.model.IMarket)

Aggregations

MarketplaceCategory (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory)3 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)2 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)2 CatalogCategory (org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)1 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)1 MarketplaceNodeInstallableUnitItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem)1 ICategory (org.eclipse.epp.mpc.core.model.ICategory)1 IIu (org.eclipse.epp.mpc.core.model.IIu)1 IIus (org.eclipse.epp.mpc.core.model.IIus)1 IMarket (org.eclipse.epp.mpc.core.model.IMarket)1 INode (org.eclipse.epp.mpc.core.model.INode)1 CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)1