use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method computeInstalled.
protected SearchResult computeInstalled(IProgressMonitor monitor) throws CoreException {
SearchResult result = new SearchResult();
result.setNodes(new ArrayList<Node>());
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_ComputingInstalled, 1000);
Map<String, IInstallableUnit> installedIUs = computeInstalledIUs(progress.newChild(500));
if (!monitor.isCanceled()) {
Set<INode> catalogNodes = marketplaceInfo.computeInstalledNodes(catalogDescriptor.getUrl(), installedIUs);
if (!catalogNodes.isEmpty()) {
List<INode> resolvedNodes = marketplaceService.getNodes(catalogNodes, progress.newChild(490));
SubMonitor nodeProgress = SubMonitor.convert(progress.newChild(10), resolvedNodes.size());
for (INode node : resolvedNodes) {
// compute real installed state based on optional/required state
if (marketplaceInfo.computeInstalled(installedIUs.keySet(), node)) {
result.getNodes().add((Node) node);
}
nodeProgress.worked(1);
}
} else {
monitor.worked(500);
}
}
return result;
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class ImportFavoritesPage method performImport.
public void performImport() {
setErrorMessage(null);
saveInstallSelected();
List<MarketplaceNodeCatalogItem> importFavorites = getSelection();
if (importFavorites.isEmpty()) {
return;
}
final IUserFavoritesService userFavoritesService = findUserFavoritesService();
if (userFavoritesService == null) {
return;
}
final List<INode> importNodes = new ArrayList<INode>();
for (MarketplaceNodeCatalogItem item : importFavorites) {
importNodes.add(item.getData());
}
try {
getContainer().run(true, false, new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
userFavoritesService.getStorageService().runWithLogin(new Callable<Void>() {
public Void call() throws Exception {
try {
userFavoritesService.addFavorites(importNodes, monitor);
} catch (NotAuthorizedException e) {
setErrorMessage(Messages.ImportFavoritesPage_unauthorizedErrorMessage);
} catch (ConflictException e) {
setErrorMessage(Messages.ImportFavoritesPage_conflictErrorMessage);
}
return null;
}
});
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
MarketplaceClientCore.error(cause);
setErrorMessage(NLS.bind(Messages.ImportFavoritesPage_unknownErrorMessage, cause));
} catch (InterruptedException e) {
// ignore
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class DiscoverFileSupportJob method orderNodesByTagSubExtensionCount.
/**
* Sorts the given list of tags by number of sub extension dividers(.) and uses the sorted list to return an ordered
* list of the nodes by first occurrence of highest sub extension tag in fileExtensionTags.
*
* @param nodes
* @param fileExtensionTags
* @return nodes ordered by first occurrence of highest sub extension count found in fileExtensionTags
*/
private static List<? extends INode> orderNodesByTagSubExtensionCount(List<? extends INode> nodes, List<String> fileExtensionTags) {
Collections.sort(fileExtensionTags, new Comparator<String>() {
public int compare(String s1, String s2) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
return (s2.length() - s2.replace(".", "").length()) - (s1.length() - s1.replace(".", "").length());
}
});
Map<String, List<INode>> nodesByTags = new HashMap<String, List<INode>>();
for (INode iNode : nodes) {
for (ITag nodeTag : iNode.getTags().getTags()) {
boolean foundTag = false;
for (String tag : fileExtensionTags) {
if (nodeTag.getName().equals(tag)) {
if (nodesByTags.containsKey(tag)) {
nodesByTags.get(tag).add(iNode);
} else {
List<INode> newNodeList = new ArrayList<INode>();
newNodeList.add(iNode);
nodesByTags.put(tag, newNodeList);
}
foundTag = true;
break;
}
}
if (foundTag) {
break;
}
}
}
List<INode> ordered = new ArrayList<INode>();
for (String tag : fileExtensionTags) {
if (nodesByTags.containsKey(tag)) {
ordered.addAll(nodesByTags.get(tag));
}
}
return nodes;
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class ShowFileSupportProposalsJob method runInUIThread.
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
final Shell shell = WorkbenchUtil.getShell();
String fileExtensionLabel = DiscoverFileSupportJob.getFileExtensionLabel(fileName);
final ShowFileSupportProposalsDialog dialog = new ShowFileSupportProposalsDialog(shell, fileExtensionLabel, defaultDescriptor);
if (dialog.open() == IDialogConstants.OK_ID) {
if (dialog.isShowProposals()) {
IMarketplaceClientService marketplaceClientService = MarketplaceClient.getMarketplaceClientService();
IMarketplaceClientConfiguration config = marketplaceClientService.newConfiguration();
marketplaceClientService.open(config, new LinkedHashSet<INode>(nodes));
} else if (dialog.isAssociateToExtension()) {
List<String> fileExtensions = DiscoverFileSupportJob.getFileExtensions(fileName);
IFileEditorMapping newMapping = createDefaultDescriptorMapping(fileExtensions.get(fileExtensions.size() - 1));
addEditorMapping(newMapping);
}
return Status.OK_STATUS;
} else {
return Status.CANCEL_STATUS;
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class ShowNatureProposalsJob method runInUIThread.
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
ShowNatureProposalsDialog dialog = new ShowNatureProposalsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), candidates);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return Status.CANCEL_STATUS;
}
Set<String> natureIds = dialog.getSelectedNatures();
IMarketplaceClientService marketplaceClientService = MarketplaceClient.getMarketplaceClientService();
IMarketplaceClientConfiguration config = marketplaceClientService.newConfiguration();
Set<INode> allNodes = new HashSet<INode>();
for (String natureId : natureIds) {
allNodes.addAll(candidates.get(natureId));
}
if (!allNodes.isEmpty()) {
marketplaceClientService.open(config, allNodes);
}
return Status.OK_STATUS;
}
Aggregations