Search in sources :

Example 11 with IMarket

use of org.eclipse.epp.mpc.core.model.IMarket in project epp.mpc by eclipse.

the class UnmarshallerTest method marketplaceRoot.

@Test
public void marketplaceRoot() throws IOException, UnmarshalException {
    // from http://www.eclipseplugincentral.net/xml
    Object model = processResource("resources/marketplace-root.xml");
    assertNotNull(model);
    assertTrue(model instanceof Marketplace);
    Marketplace marketplace = (Marketplace) model;
    assertEquals(4, marketplace.getMarket().size());
    IMarket market = marketplace.getMarket().get(0);
    assertEquals("31", market.getId());
    assertEquals("Tools", market.getName());
    assertEquals("http://www.eclipseplugincentral.net/category/markets/tools", market.getUrl());
    assertEquals(36, market.getCategory().size());
    ICategory category = market.getCategory().get(10);
    assertEquals("24", category.getId());
    assertEquals("IDE", category.getName());
    assertEquals("http://www.eclipseplugincentral.net/taxonomy/term/24%2C31", category.getUrl());
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) ICategory(org.eclipse.epp.mpc.core.model.ICategory) IMarket(org.eclipse.epp.mpc.core.model.IMarket) Test(org.junit.Test)

Example 12 with IMarket

use of org.eclipse.epp.mpc.core.model.IMarket in project epp.mpc by eclipse.

the class MarketplaceViewer method updateContent.

private void updateContent(final ContentType contentType, final Runnable queryCall) {
    final ContentType oldContentType = this.contentType;
    this.contentType = contentType;
    final boolean hadQuery = showQueryHeader(oldContentType);
    final boolean hasQuery = showQueryHeader(contentType);
    ContentType oldQueryType = oldContentType;
    if (oldQueryType == ContentType.SELECTION) {
        oldQueryType = ContentType.SEARCH;
    }
    ContentType queryType = contentType;
    if (queryType == ContentType.SELECTION) {
        queryType = ContentType.SEARCH;
    }
    if (oldQueryType != queryType || hasQuery != hadQuery) {
        if (hadQuery) {
            initQueryFromFilters();
            tabQueries.put(oldQueryType, queryData);
        }
        if (hasQuery) {
            QueryData newQueryData = tabQueries.get(queryType);
            if (newQueryData == null) {
                newQueryData = new QueryData();
                if (queryType == ContentType.FEATURED_MARKET) {
                    CatalogDescriptor catalogDescriptor = this.getWizard().getConfiguration().getCatalogDescriptor();
                    ICatalogBranding catalogBranding = catalogDescriptor.getCatalogBranding();
                    if (catalogBranding != null) {
                        boolean hasFeaturedMarketTab = catalogBranding.hasFeaturedMarketTab();
                        if (hasFeaturedMarketTab) {
                            String marketName = catalogBranding.getFeaturedMarketTabName();
                            if (marketName != null) {
                                for (CatalogFilter filter : getConfiguration().getFilters()) {
                                    if (filter instanceof AbstractTagFilter) {
                                        AbstractTagFilter tagFilter = (AbstractTagFilter) filter;
                                        if (tagFilter.getTagClassification() == ICategory.class) {
                                            for (Tag tag : tagFilter.getChoices()) {
                                                if (tag.getTagClassifier() != IMarket.class) {
                                                    break;
                                                }
                                                IMarket market = (IMarket) tag.getData();
                                                if (marketName.equals(market.getName())) {
                                                    // tagFilter.setSelected(Collections.singleton(tag));
                                                    newQueryData.queryMarket = market;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (newQueryData.queryMarket == null) {
                                    // TODO remove/disable tab?
                                    setContentType(oldContentType);
                                    return;
                                }
                            }
                        }
                    }
                }
                tabQueries.put(queryType, newQueryData);
            }
            setFilters(newQueryData);
        }
    }
    runUpdate(new Runnable() {

        public void run() {
            fireContentTypeChange(oldContentType, contentType);
            setHeaderVisible(hasQuery);
            queryCall.run();
        }
    });
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) ICatalogBranding(org.eclipse.epp.mpc.core.model.ICatalogBranding) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) IMarket(org.eclipse.epp.mpc.core.model.IMarket) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 13 with IMarket

use of org.eclipse.epp.mpc.core.model.IMarket 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)

Example 14 with IMarket

use of org.eclipse.epp.mpc.core.model.IMarket in project epp.mpc by eclipse.

the class BrowseCatalogItem method getMarketplaceUrl.

private static String getMarketplaceUrl(CatalogDescriptor catalogDescriptor, MarketplaceViewer viewer) throws URISyntaxException {
    URL url = catalogDescriptor.getUrl();
    try {
        ContentType contentType = viewer.getQueryContentType();
        if (contentType == ContentType.SEARCH) {
            String queryText = viewer.getQueryText();
            ICategory queryCategory = viewer.getQueryCategory();
            IMarket queryMarket = viewer.getQueryMarket();
            String path = new DefaultMarketplaceService(url).computeRelativeSearchUrl(queryMarket, queryCategory, queryText, false);
            if (path != null) {
                url = new URL(url, path);
            }
        }
    } catch (IllegalArgumentException e) {
        // should never happen
        MarketplaceClientUi.error(e);
    } catch (MalformedURLException e) {
        // should never happen
        MarketplaceClientUi.error(e);
    }
    URI uri = url.toURI();
    return uri.toString();
}
Also used : MalformedURLException(java.net.MalformedURLException) ContentType(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType) ICategory(org.eclipse.epp.mpc.core.model.ICategory) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) IMarket(org.eclipse.epp.mpc.core.model.IMarket) URI(java.net.URI) URL(java.net.URL)

Example 15 with IMarket

use of org.eclipse.epp.mpc.core.model.IMarket in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method performQuery.

public void performQuery(IMarket market, ICategory category, String queryText, IProgressMonitor monitor) throws CoreException {
    final int totalWork = 1001;
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, totalWork);
    try {
        ISearchResult result;
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.QUERY);
        SubMonitor nodeQueryProgress = progress.newChild(500);
        try {
            // check if the query matches a node url and just retrieve that node
            result = performNodeQuery(queryText, nodeQueryProgress);
        } catch (CoreException ex) {
            // node not found, continue with regular query
            result = null;
            // no work was done
            nodeQueryProgress.setWorkRemaining(0);
        }
        if (result == null) {
            // regular query
            // resolve market and category if necessary
            IMarket resolvedMarket;
            ICategory resolvedCategory;
            try {
                resolvedMarket = resolve(market, catalogCategory.getMarkets());
                resolvedCategory = resolveCategory(category, catalogCategory.getMarkets());
            } catch (IllegalArgumentException ex) {
                throw new CoreException(MarketplaceClientCore.computeStatus(ex, Messages.MarketplaceDiscoveryStrategy_invalidFilter));
            } catch (NoSuchElementException ex) {
                throw new CoreException(MarketplaceClientCore.computeStatus(ex, Messages.MarketplaceDiscoveryStrategy_unknownFilter));
            }
            progress.setWorkRemaining(totalWork - 1);
            result = marketplaceService.search(resolvedMarket, resolvedCategory, queryText, progress.newChild(500));
        }
        handleSearchResult(catalogCategory, result, progress.newChild(500));
        if (result.getNodes().isEmpty()) {
            catalogCategory.setMatchCount(0);
            addCatalogItem(catalogCategory);
        }
    } finally {
        progress.done();
    }
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) CoreException(org.eclipse.core.runtime.CoreException) ICategory(org.eclipse.epp.mpc.core.model.ICategory) SubMonitor(org.eclipse.core.runtime.SubMonitor) IMarket(org.eclipse.epp.mpc.core.model.IMarket) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

IMarket (org.eclipse.epp.mpc.core.model.IMarket)16 ICategory (org.eclipse.epp.mpc.core.model.ICategory)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 DefaultMarketplaceService (org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService)2 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)2 CatalogFilter (org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)1 Node (org.eclipse.epp.internal.mpc.core.model.Node)1 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)1