Search in sources :

Example 1 with Tag

use of org.eclipse.equinox.internal.p2.discovery.model.Tag 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 Tag

use of org.eclipse.equinox.internal.p2.discovery.model.Tag 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 Tag

use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.

the class CheckboxTagFilter method rebuildChoicesUi.

protected void rebuildChoicesUi() {
    if (buttonContainer != null) {
        for (Control control : buttonContainer.getChildren()) {
            control.dispose();
        }
        for (final Tag choice : getChoices()) {
            final Button checkbox = new Button(buttonContainer, SWT.CHECK);
            checkbox.setData(choice);
            checkbox.setSelection(getSelected().contains(choice));
            checkbox.setText(choice.getLabel());
            checkbox.addSelectionListener(new SelectionListener() {

                public void widgetDefaultSelected(SelectionEvent e) {
                    widgetSelected(e);
                }

                public void widgetSelected(SelectionEvent e) {
                    boolean selection = checkbox.getSelection();
                    if (selection) {
                        getSelected().add(choice);
                    } else {
                        getSelected().remove(choice);
                    }
                    selectionUpdated();
                }
            });
        }
        GridLayoutFactory.fillDefaults().numColumns(buttonContainer.getChildren().length).applyTo(buttonContainer);
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with Tag

use of org.eclipse.equinox.internal.p2.discovery.model.Tag 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 Tag

use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.

the class MarketplaceWizardCommand method updateCategoryChoices.

private void updateCategoryChoices(final ComboTagFilter marketCategoryTagFilter, final ComboTagFilter marketFilter) {
    Set<Tag> newChoices = new HashSet<Tag>();
    List<Tag> choices = new ArrayList<Tag>();
    Set<IMarket> selectedMarkets = new HashSet<IMarket>();
    for (Tag marketTag : marketFilter.getSelected()) {
        selectedMarkets.add((IMarket) marketTag.getData());
    }
    final MarketplaceCatalog catalog = (MarketplaceCatalog) marketCategoryTagFilter.getCatalog();
    List<IMarket> markets = catalog.getMarkets();
    for (IMarket market : markets) {
        if (selectedMarkets.isEmpty() || selectedMarkets.contains(market)) {
            for (ICategory marketCategory : market.getCategory()) {
                Tag categoryTag = new Tag(ICategory.class, marketCategory.getId(), marketCategory.getName());
                categoryTag.setData(marketCategory);
                if (newChoices.add(categoryTag)) {
                    choices.add(categoryTag);
                }
            }
        }
    }
    Collections.sort(choices, new Comparator<Tag>() {

        public int compare(Tag o1, Tag o2) {
            return o1.getLabel().compareTo(o2.getLabel());
        }
    });
    marketCategoryTagFilter.setChoices(choices);
}
Also used : ICategory(org.eclipse.epp.mpc.core.model.ICategory) ArrayList(java.util.ArrayList) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IMarket(org.eclipse.epp.mpc.core.model.IMarket) HashSet(java.util.HashSet)

Aggregations

Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)14 CatalogFilter (org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter)5 ArrayList (java.util.ArrayList)4 ICategory (org.eclipse.epp.mpc.core.model.ICategory)4 CoreException (org.eclipse.core.runtime.CoreException)3 IMarket (org.eclipse.epp.mpc.core.model.IMarket)3 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 IStatus (org.eclipse.core.runtime.IStatus)2 INode (org.eclipse.epp.mpc.core.model.INode)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1