use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.
the class MarketplaceViewer method doQuery.
private IStatus doQuery(final QueryData queryData, final Set<? extends INode> nodes) {
try {
final ContentType queryType = contentType;
queryContentType = queryType;
final IStatus[] result = new IStatus[1];
context.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
switch(queryType) {
case POPULAR:
result[0] = getCatalog().popular(monitor);
break;
case RECENT:
result[0] = getCatalog().recent(monitor);
break;
case RELATED:
result[0] = getCatalog().related(monitor);
break;
case INSTALLED:
result[0] = getCatalog().installed(monitor);
break;
case FAVORITES:
result[0] = getCatalog().userFavorites(false, monitor);
break;
case SELECTION:
Set<String> nodeIds = new HashSet<String>();
for (CatalogItem item : getSelectionModel().getItemToSelectedOperation().keySet()) {
nodeIds.add(((INode) item.getData()).getId());
}
result[0] = getCatalog().performQuery(monitor, nodeIds);
break;
case SEARCH:
case FEATURED_MARKET:
default:
if (nodes != null && !nodes.isEmpty()) {
result[0] = getCatalog().performNodeQuery(monitor, nodes);
} else if (queryData.queryText != null && queryData.queryText.length() > 0) {
String tag = getTagQuery(queryData.queryText);
if (tag != null) {
result[0] = getCatalog().tagged(tag, monitor);
} else {
result[0] = getCatalog().performQuery(queryData.queryMarket, queryData.queryCategory, queryData.queryText, monitor);
}
} else {
result[0] = getCatalog().featured(monitor, queryData.queryMarket, queryData.queryCategory);
}
break;
}
if (!monitor.isCanceled() && result[0] != null && result[0].getSeverity() != IStatus.CANCEL) {
getCatalog().checkForUpdates(monitor);
}
MarketplaceViewer.this.getControl().getDisplay().syncExec(new Runnable() {
public void run() {
updateViewer(queryData.queryText);
}
});
}
});
if (result[0] != null && !result[0].isOK() && result[0].getSeverity() != IStatus.CANCEL) {
MarketplaceClientUi.handle(result[0], (result[0].getSeverity() > IStatus.WARNING ? StatusManager.SHOW | StatusManager.BLOCK : 0) | StatusManager.LOG);
return result[0];
} else {
verifyUpdateSiteAvailability();
return Status.OK_STATUS;
}
} catch (InvocationTargetException e) {
IStatus status = computeStatus(e, Messages.MarketplaceViewer_unexpectedException);
MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
return status;
} catch (InterruptedException e) {
// cancelled by user so nothing to do here.
return Status.CANCEL_STATUS;
}
}
use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.
the class MarketplaceViewer method setFindText.
private void setFindText(String tag) {
try {
// $NON-NLS-1$
Field filterTextField = FilteredViewer.class.getDeclaredField("filterText");
filterTextField.setAccessible(true);
TextSearchControl textSearchControl = (TextSearchControl) filterTextField.get(this);
textSearchControl.getTextControl().setText(tag);
} catch (Exception e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceViewer_Could_not_change_find_text, e);
}
}
use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.
the class ComboTagFilter method createControl.
@Override
public void createControl(Composite parent) {
if (getChoices() == null) {
throw new IllegalStateException();
}
combo = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
combo.setData(this);
listener = new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
int selectionIndex = combo.getSelectionIndex();
if (selectionIndex > 0) {
Tag tag = getChoices().get(selectionIndex - 1);
setSelected(Collections.singleton(tag));
} else {
setSelected(Collections.<Tag>emptySet());
}
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
};
combo.addSelectionListener(listener);
rebuildChoicesUi();
}
use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method handleSearchResult.
protected void handleSearchResult(MarketplaceCategory catalogCategory, ISearchResult result, final IProgressMonitor monitor) {
List<CatalogItem> items = getItems();
if (items != null && !result.getNodes().isEmpty()) {
int nodeWork = 1000;
int favoritesWork = catalogCategory.getContents() == Contents.USER_FAVORITES ? 0 : 1000;
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_loadingResources, result.getNodes().size() * nodeWork + favoritesWork);
try {
boolean userFavoritesSupported = false;
if (catalogCategory.getContents() == Contents.USER_FAVORITES) {
userFavoritesSupported = true;
} else if (hasUserFavoritesService()) {
try {
applyShellProvider();
marketplaceService.userFavorites(result.getNodes(), progress.newChild(favoritesWork));
userFavoritesSupported = true;
} catch (NotAuthorizedException e1) {
// user is not logged in. we just ignore this.
} catch (UnsupportedOperationException e1) {
// ignore
} catch (Exception e1) {
// something went wrong. log and proceed.
MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, e1);
}
}
for (final INode node : result.getNodes()) {
String id = node.getId();
try {
final MarketplaceNodeCatalogItem catalogItem = new MarketplaceNodeCatalogItem();
catalogItem.setMarketplaceUrl(catalogDescriptor.getUrl());
catalogItem.setId(id);
catalogItem.setName(getCatalogItemName(node));
catalogItem.setCategoryId(catalogCategory.getId());
ICategories categories = node.getCategories();
if (categories != null) {
for (ICategory category : categories.getCategory()) {
catalogItem.addTag(new Tag(ICategory.class, category.getId(), category.getName()));
}
}
catalogItem.setData(node);
catalogItem.setSource(source);
catalogItem.setLicense(node.getLicense());
catalogItem.setUserFavorite(userFavoritesSupported ? node.getUserFavorite() : null);
IIus ius = node.getIus();
if (ius != null) {
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = new ArrayList<MarketplaceNodeInstallableUnitItem>();
for (IIu iu : ius.getIuElements()) {
MarketplaceNodeInstallableUnitItem iuItem = new MarketplaceNodeInstallableUnitItem();
iuItem.init(iu);
installableUnitItems.add(iuItem);
}
catalogItem.setInstallableUnitItems(installableUnitItems);
}
if (node.getShortdescription() == null && node.getBody() != null) {
// bug 306653 <!--break--> marks the end of the short description.
String descriptionText = node.getBody();
Matcher matcher = BREAK_PATTERN.matcher(node.getBody());
if (matcher.find()) {
int start = matcher.start();
if (start > 0) {
String shortDescriptionText = descriptionText.substring(0, start).trim();
if (shortDescriptionText.length() > 0) {
descriptionText = shortDescriptionText;
}
}
}
catalogItem.setDescription(descriptionText);
} else {
catalogItem.setDescription(node.getShortdescription());
}
catalogItem.setProvider(node.getCompanyname());
String updateurl = node.getUpdateurl();
if (updateurl != null) {
try {
// trim is important!
updateurl = updateurl.trim();
URLUtil.toURL(updateurl);
catalogItem.setSiteUrl(updateurl);
} catch (MalformedURLException e) {
// don't use malformed URLs
}
}
if (catalogItem.getInstallableUnits() == null || catalogItem.getInstallableUnits().isEmpty() || catalogItem.getSiteUrl() == null) {
catalogItem.setAvailable(false);
}
if (node.getImage() != null) {
if (!source.getResourceProvider().containsResource(node.getImage())) {
cacheResource(source.getResourceProvider(), catalogItem, node.getImage());
}
createIcon(catalogItem, node);
}
if (node.getBody() != null || node.getScreenshot() != null) {
final Overview overview = new Overview();
overview.setItem(catalogItem);
overview.setSummary(node.getBody());
overview.setUrl(node.getUrl());
catalogItem.setOverview(overview);
if (node.getScreenshot() != null) {
if (!source.getResourceProvider().containsResource(node.getScreenshot())) {
cacheResource(source.getResourceProvider(), catalogItem, node.getScreenshot());
}
overview.setScreenshot(node.getScreenshot());
}
}
items.add(catalogItem);
marketplaceInfo.map(catalogItem.getMarketplaceUrl(), node);
marketplaceInfo.computeInstalled(computeInstalledFeatures(progress.newChild(nodeWork)), catalogItem);
} catch (RuntimeException ex) {
MarketplaceClientUi.error(NLS.bind(Messages.MarketplaceDiscoveryStrategy_ParseError, // $NON-NLS-1$
node == null ? "null" : id), ex);
}
}
} finally {
progress.done();
}
if (result.getMatchCount() != null) {
catalogCategory.setMatchCount(result.getMatchCount());
if (result.getMatchCount() > result.getNodes().size()) {
// add an item here to indicate that the search matched more items than were returned by the server
addCatalogItem(catalogCategory);
}
}
}
}
use of org.eclipse.equinox.internal.p2.discovery.model.Tag in project epp.mpc by eclipse.
the class MarketplaceCatalog method performDiscovery.
protected IStatus performDiscovery(DiscoveryOperation operation, boolean refresh, IProgressMonitor monitor) {
MultiStatus status = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, 0, Messages.MarketplaceCatalog_queryFailed, null);
if (getDiscoveryStrategies().isEmpty()) {
throw new IllegalStateException();
}
// reset, keeping no items but the same tags, categories and certifications
List<CatalogItem> items = new ArrayList<CatalogItem>();
List<CatalogCategory> categories = new ArrayList<CatalogCategory>(getCategories());
List<Certification> certifications = new ArrayList<Certification>(getCertifications());
List<Tag> tags = new ArrayList<Tag>(getTags());
if (!refresh) {
for (CatalogCategory catalogCategory : categories) {
catalogCategory.getItems().clear();
}
}
final int totalTicks = 100000;
final int discoveryTicks = totalTicks - (totalTicks / 10);
monitor.beginTask(Messages.MarketplaceCatalog_queryingMarketplace, totalTicks);
try {
int strategyTicks = discoveryTicks / getDiscoveryStrategies().size();
for (AbstractDiscoveryStrategy discoveryStrategy : getDiscoveryStrategies()) {
if (monitor.isCanceled()) {
status.add(Status.CANCEL_STATUS);
break;
}
if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
List<CatalogCategory> oldCategories = discoveryStrategy.getCategories();
List<CatalogItem> oldItems = discoveryStrategy.getItems();
List<Certification> oldCertifications = discoveryStrategy.getCertifications();
List<Tag> oldTags = discoveryStrategy.getTags();
discoveryStrategy.setCategories(categories);
discoveryStrategy.setItems(items);
discoveryStrategy.setCertifications(certifications);
discoveryStrategy.setTags(tags);
try {
MarketplaceDiscoveryStrategy marketplaceStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
operation.run(marketplaceStrategy, new SubProgressMonitor(monitor, strategyTicks));
} catch (CoreException e) {
IStatus error = MarketplaceClientCore.computeWellknownProblemStatus(e);
if (error == null) {
error = new Status(e.getStatus().getSeverity(), DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_failedWithError, discoveryStrategy.getClass().getSimpleName()), e);
}
status.add(error);
} finally {
// remove everything from strategy again, so it can't accidentally mess with the results later
discoveryStrategy.setCategories(oldCategories);
discoveryStrategy.setItems(oldItems);
discoveryStrategy.setCertifications(oldCertifications);
discoveryStrategy.setTags(oldTags);
// make sure strategy didn't misbehave
if (items.contains(null)) {
while (items.remove(null)) {
}
IStatus error = new Status(IStatus.WARNING, DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_addedNullEntry, discoveryStrategy.getClass().getSimpleName()));
status.add(error);
}
}
}
}
update(categories, items, certifications, tags);
} finally {
monitor.done();
}
return computeStatus(status);
}
Aggregations