Search in sources :

Example 1 with CatalogFilter

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

the class AbstractMarketplaceWizardBotTest method findFilter.

private AbstractTagFilter findFilter(Class<?> classifier) {
    List<CatalogFilter> filters = getWizard().getConfiguration().getFilters();
    for (CatalogFilter filter : filters) {
        if (filter instanceof AbstractTagFilter) {
            AbstractTagFilter tagFilter = (AbstractTagFilter) filter;
            List<Tag> choices = tagFilter.getChoices();
            Object classification = choices.isEmpty() ? null : choices.get(0).getTagClassifier();
            if (classification == classifier) {
                return tagFilter;
            }
        }
    }
    fail("No filter found for " + classifier.getName());
    // unreachable
    return null;
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) AbstractTagFilter(org.eclipse.epp.internal.mpc.ui.wizards.AbstractTagFilter)

Example 2 with CatalogFilter

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

the class MarketplaceViewer method initQueryFromFilters.

private void initQueryFromFilters() {
    queryData = new QueryData();
    findText = getFilterText();
    AbstractTagFilter marketFilter = null;
    for (CatalogFilter filter : getConfiguration().getFilters()) {
        if (filter instanceof AbstractTagFilter) {
            AbstractTagFilter tagFilter = (AbstractTagFilter) filter;
            if (tagFilter.getTagClassification() == ICategory.class) {
                Tag tag = tagFilter.getSelected().isEmpty() ? null : tagFilter.getSelected().iterator().next();
                if (tag != null) {
                    if (tag.getTagClassifier() == IMarket.class) {
                        marketFilter = tagFilter;
                        queryData.queryMarket = (IMarket) tag.getData();
                    } else if (tag.getTagClassifier() == ICategory.class) {
                        queryData.queryCategory = (ICategory) tag.getData();
                    }
                }
            }
        }
    }
    if (marketFilter != null) {
        setFilterEnabled(marketFilter, contentType != ContentType.FEATURED_MARKET);
    }
    queryData.queryText = findText;
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) ICategory(org.eclipse.epp.mpc.core.model.ICategory) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag)

Example 3 with CatalogFilter

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

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

the class MarketplaceWizardCommand method createConfiguration.

@Override
protected MarketplaceCatalogConfiguration createConfiguration(final MarketplaceCatalog catalog, ExecutionEvent event) {
    MarketplaceCatalogConfiguration configuration = super.createConfiguration(catalog, event);
    if (configuration == null) {
        // errors have already been logged, just return
        return null;
    }
    configuration.getFilters().clear();
    final ComboTagFilter marketFilter = new ComboTagFilter() {

        @Override
        public void catalogUpdated(boolean wasCancelled) {
            List<Tag> choices = new ArrayList<Tag>();
            List<IMarket> markets = catalog.getMarkets();
            for (IMarket market : markets) {
                Tag marketTag = new Tag(IMarket.class, market.getId(), market.getName());
                marketTag.setData(market);
                choices.add(marketTag);
            }
            setChoices(choices);
        }
    };
    marketFilter.setSelectAllOnNoSelection(true);
    marketFilter.setNoSelectionLabel(Messages.MarketplaceWizardCommand_allMarkets);
    marketFilter.setTagClassification(ICategory.class);
    marketFilter.setChoices(new ArrayList<Tag>());
    final ComboTagFilter marketCategoryTagFilter = new ComboTagFilter() {

        @Override
        public void catalogUpdated(boolean wasCancelled) {
            updateCategoryChoices(this, marketFilter);
        }
    };
    marketCategoryTagFilter.setSelectAllOnNoSelection(true);
    marketCategoryTagFilter.setNoSelectionLabel(Messages.MarketplaceWizardCommand_allCategories);
    marketCategoryTagFilter.setTagClassification(ICategory.class);
    marketCategoryTagFilter.setChoices(new ArrayList<Tag>());
    final IPropertyChangeListener marketListener = new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            final String property = event.getProperty();
            if (AbstractTagFilter.PROP_SELECTED.equals(property)) {
                updateCategoryChoices(marketCategoryTagFilter, marketFilter);
            }
        }
    };
    marketFilter.addPropertyChangeListener(marketListener);
    configuration.getFilters().add(marketFilter);
    configuration.getFilters().add(marketCategoryTagFilter);
    configuration.setInitialState(wizardState);
    if (operations != null && !operations.isEmpty()) {
        configuration.setInitialOperations(operations);
    }
    for (CatalogFilter filter : configuration.getFilters()) {
        ((MarketplaceFilter) filter).setCatalog(catalog);
    }
    return configuration;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) MarketplaceFilter(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceFilter) ArrayList(java.util.ArrayList) CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) MarketplaceCatalogConfiguration(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceCatalogConfiguration) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) ComboTagFilter(org.eclipse.epp.internal.mpc.ui.wizards.ComboTagFilter) IMarket(org.eclipse.epp.mpc.core.model.IMarket)

Example 5 with CatalogFilter

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

the class MarketplaceViewer method doCreateHeaderControls.

@Override
protected void doCreateHeaderControls(Composite parent) {
    header = parent;
    final int originalChildCount = parent.getChildren().length;
    for (CatalogFilter filter : getConfiguration().getFilters()) {
        if (filter instanceof MarketplaceFilter) {
            MarketplaceFilter marketplaceFilter = (MarketplaceFilter) filter;
            marketplaceFilter.createControl(parent);
            marketplaceFilter.addPropertyChangeListener(new IPropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent event) {
                    if (AbstractTagFilter.PROP_SELECTED.equals(event.getProperty())) {
                        doQuery();
                    }
                }
            });
        }
    }
    Control[] children = parent.getChildren();
    for (int x = originalChildCount; x < children.length; ++x) {
        Control child = children[x];
        GridDataFactory.swtDefaults().hint(135, SWT.DEFAULT).applyTo(child);
    }
    Button goButton = new Button(parent, SWT.PUSH);
    goButton.setText(Messages.MarketplaceViewer_go);
    goButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doQuery();
        }
    });
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) TextSearchControl(org.eclipse.equinox.internal.p2.ui.discovery.util.TextSearchControl) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

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