Search in sources :

Example 16 with INode

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;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 17 with INode

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
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ConflictException(org.eclipse.userstorage.util.ConflictException) ArrayList(java.util.ArrayList) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callable(java.util.concurrent.Callable) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) ConflictException(org.eclipse.userstorage.util.ConflictException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 18 with INode

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;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ITag(org.eclipse.epp.mpc.core.model.ITag) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with INode

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;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) INode(org.eclipse.epp.mpc.core.model.INode) IMarketplaceClientConfiguration(org.eclipse.epp.mpc.ui.IMarketplaceClientConfiguration) IMarketplaceClientService(org.eclipse.epp.mpc.ui.IMarketplaceClientService) List(java.util.List) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping)

Example 20 with INode

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;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IMarketplaceClientConfiguration(org.eclipse.epp.mpc.ui.IMarketplaceClientConfiguration) IMarketplaceClientService(org.eclipse.epp.mpc.ui.IMarketplaceClientService) HashSet(java.util.HashSet)

Aggregations

INode (org.eclipse.epp.mpc.core.model.INode)63 Node (org.eclipse.epp.internal.mpc.core.model.Node)13 ArrayList (java.util.ArrayList)12 CoreException (org.eclipse.core.runtime.CoreException)12 SubMonitor (org.eclipse.core.runtime.SubMonitor)12 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ICategory (org.eclipse.epp.mpc.core.model.ICategory)8 URISyntaxException (java.net.URISyntaxException)7 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)7 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 List (java.util.List)6 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)6 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)6