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;
}
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;
}
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);
}
});
}
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;
}
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();
}
});
}
Aggregations