Search in sources :

Example 6 with CatalogFilter

use of org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter 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 7 with CatalogFilter

use of org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter in project epp.mpc by eclipse.

the class MarketplaceViewer method setFilters.

private void setFilters(QueryData queryData) {
    // $NON-NLS-1$
    setFindText(queryData.queryText == null ? "" : queryData.queryText);
    for (CatalogFilter filter : getConfiguration().getFilters()) {
        if (filter instanceof AbstractTagFilter) {
            AbstractTagFilter tagFilter = (AbstractTagFilter) filter;
            if (tagFilter.getTagClassification() == ICategory.class) {
                List<Tag> choices = tagFilter.getChoices();
                Tag tag = choices.isEmpty() ? null : choices.get(0);
                if (tag != null) {
                    IIdentifiable data = null;
                    if (tag.getTagClassifier() == IMarket.class) {
                        data = queryData.queryMarket;
                    } else if (tag.getTagClassifier() == ICategory.class) {
                        data = queryData.queryCategory;
                    } else {
                        continue;
                    }
                    tag = null;
                    if (data != null) {
                        for (Tag choice : choices) {
                            final Object choiceData = choice.getData();
                            if (choiceData == data || matches(data, choiceData)) {
                                tag = choice;
                                break;
                            }
                        }
                    }
                    tagFilter.setSelected(tag == null ? Collections.<Tag>emptySet() : Collections.singleton(tag));
                    // we expect a query to happen next, so don't fire a property change resulting in an additional query
                    tagFilter.updateUi();
                }
            }
        }
    }
    initQueryFromFilters();
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) ICategory(org.eclipse.epp.mpc.core.model.ICategory) IIdentifiable(org.eclipse.epp.mpc.core.model.IIdentifiable) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag)

Aggregations

CatalogFilter (org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter)7 Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)5 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 IMarket (org.eclipse.epp.mpc.core.model.IMarket)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 ArrayList (java.util.ArrayList)1 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)1 MarketplaceCategory (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory)1 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)1 AbstractTagFilter (org.eclipse.epp.internal.mpc.ui.wizards.AbstractTagFilter)1 ComboTagFilter (org.eclipse.epp.internal.mpc.ui.wizards.ComboTagFilter)1 MarketplaceCatalogConfiguration (org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceCatalogConfiguration)1 MarketplaceFilter (org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceFilter)1 ICatalogBranding (org.eclipse.epp.mpc.core.model.ICatalogBranding)1 IIdentifiable (org.eclipse.epp.mpc.core.model.IIdentifiable)1 CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)1 AbstractDiscoveryStrategy (org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy)1 CatalogCategory (org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)1 TextSearchControl (org.eclipse.equinox.internal.p2.ui.discovery.util.TextSearchControl)1