Search in sources :

Example 1 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class MarketplaceCatalogTest method setupCatalog.

protected void setupCatalog() throws MalformedURLException {
    final SearchResult discoveryResult = new SearchResult();
    discoveryResult.setNodes(discoveryNodes);
    CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
    catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
    MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {

        final MarketplaceCategory category = new MarketplaceCategory();

        {
            category.setId("<root>");
        }

        @Override
        public void performDiscovery(IProgressMonitor monitor) throws CoreException {
            if (!categories.contains(category)) {
                categories.add(category);
            }
            handleSearchResult(category, discoveryResult, new NullProgressMonitor());
        }

        @Override
        protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
            Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
            for (INode node : installedNodes) {
                IIus ius = node.getIus();
                if (ius != null) {
                    for (IIu iu : ius.getIuElements()) {
                        String featureId = iu.getId() + ".feature.group";
                        InstallableUnit installableUnit = new InstallableUnit();
                        installableUnit.setId(featureId);
                        installedIus.put(featureId, installableUnit);
                    }
                }
            }
            return installedIus;
        }

        @Override
        protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
            return category;
        }
    };
    catalog = new MarketplaceCatalog() {

        @Override
        protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
            for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
                checkedForUpdate.add(item.getData());
                List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                boolean hasUpdate = updateAvailable.contains(item.getData());
                for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                    iuItem.setUpdateAvailable(hasUpdate);
                }
            }
            return Status.OK_STATUS;
        }
    };
    catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit) URL(java.net.URL) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IIu(org.eclipse.epp.mpc.core.model.IIu) MarketplaceNodeInstallableUnitItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ArrayList(java.util.ArrayList) List(java.util.List) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IIus(org.eclipse.epp.mpc.core.model.IIus) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 2 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class MarketplacePage method canSkipFeatureSelection.

protected boolean canSkipFeatureSelection() {
    SelectionModel selectionModel = getWizard().getSelectionModel();
    Map<CatalogItem, Operation> selectedOperations = selectionModel.getItemToSelectedOperation();
    Set<Entry<CatalogItem, Operation>> entrySet = selectedOperations.entrySet();
    Operation mode = null;
    for (Entry<CatalogItem, Operation> entry : entrySet) {
        if (!(entry.getKey() instanceof MarketplaceNodeCatalogItem)) {
            return false;
        }
        MarketplaceNodeCatalogItem item = (MarketplaceNodeCatalogItem) entry.getKey();
        Operation value = entry.getValue();
        switch(value) {
            case NONE:
                continue;
            case INSTALL:
            case UPDATE:
                if (mode == null) {
                    mode = Operation.INSTALL;
                } else if (mode == Operation.UNINSTALL) {
                    return false;
                }
                if (hasOptionalFeatures(item)) {
                    return false;
                }
                break;
            case UNINSTALL:
                if (mode == null) {
                    mode = Operation.UNINSTALL;
                } else if (mode == Operation.INSTALL) {
                    return false;
                }
                if (hasOptionalFeatures(item)) {
                    return false;
                }
                break;
            case CHANGE:
                return false;
        }
    }
    if (mode == null) {
        return false;
    }
    return true;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) Entry(java.util.Map.Entry) Operation(org.eclipse.epp.mpc.ui.Operation) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 3 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem 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 4 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class DiscoveryItem method isFavorited.

private boolean isFavorited() {
    MarketplaceNodeCatalogItem nodeConnector = (MarketplaceNodeCatalogItem) connector;
    Boolean favorited = nodeConnector.getUserFavorite();
    return Boolean.TRUE.equals(favorited);
}
Also used : MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 5 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class ImportFavoritesWizard method selectForInstallation.

private void selectForInstallation(List<MarketplaceNodeCatalogItem> selection) {
    MarketplacePage catalogPage = parent.getCatalogPage();
    if (catalogPage.getActiveTab() != ContentType.FAVORITES) {
        catalogPage.setActiveTab(ContentType.FAVORITES);
    }
    for (MarketplaceNodeCatalogItem item : selection) {
        parent.getSelectionModel().select(item, Operation.INSTALL);
    }
    parent.getContainer().showPage(catalogPage);
}
Also used : MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Aggregations

MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)18 Operation (org.eclipse.epp.mpc.ui.Operation)5 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)5 ArrayList (java.util.ArrayList)4 INode (org.eclipse.epp.mpc.core.model.INode)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Test (org.junit.Test)3 File (java.io.File)2 MarketplaceInfo (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceInfo)2 MarketplaceNodeInstallableUnitItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Callable (java.util.concurrent.Callable)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CoreException (org.eclipse.core.runtime.CoreException)1