Search in sources :

Example 6 with CatalogItem

use of org.eclipse.equinox.internal.p2.discovery.model.CatalogItem in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method createCategoryItem.

private CatalogItem createCategoryItem(MarketplaceCategory catalogCategory) {
    CatalogItem catalogItem = new CatalogItem();
    catalogItem.setSource(source);
    catalogItem.setData(catalogDescriptor);
    catalogItem.setId(catalogDescriptor.getUrl().toString());
    catalogItem.setCategoryId(catalogCategory.getId());
    return catalogItem;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)

Example 7 with CatalogItem

use of org.eclipse.equinox.internal.p2.discovery.model.CatalogItem in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method refreshUserFavorites.

public void refreshUserFavorites(IProgressMonitor monitor) throws CoreException {
    final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_FavoritesRefreshing, 1001);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        List<CatalogItem> items = catalogCategory.getItems();
        if (hasUserFavoritesService()) {
            Map<String, INode> nodes = new HashMap<String, INode>();
            for (CatalogItem item : items) {
                Object data = item.getData();
                if (data instanceof INode) {
                    INode node = (INode) data;
                    nodes.put(node.getId(), node);
                }
            }
            if (nodes.isEmpty()) {
                return;
            }
            try {
                applyShellProvider();
                marketplaceService.userFavorites(new ArrayList<INode>(nodes.values()), progress.newChild(500));
                for (CatalogItem catalogItem : items) {
                    if (catalogItem instanceof MarketplaceNodeCatalogItem) {
                        MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
                        INode node = nodes.get(nodeItem.getId());
                        nodeItem.setUserFavorite(node == null ? null : node.getUserFavorite());
                    }
                }
            } catch (NotAuthorizedException e) {
                catalogCategory = addPopularItems(progress.newChild(500));
                addUserStorageLoginItem(catalogCategory, e.getLocalizedMessage());
            } catch (UnsupportedOperationException ex) {
                catalogCategory = addPopularItems(progress.newChild(500));
                addFavoritesNotSupportedItem(catalogCategory);
            } catch (Exception ex) {
                // FIXME we should use the wizard page's status line to show errors, but that's unreachable from here...
                MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, ex);
                addRetryErrorItem(catalogCategory, ex);
            }
        } else {
            for (CatalogItem catalogItem : items) {
                if (catalogItem instanceof MarketplaceNodeCatalogItem) {
                    MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
                    nodeItem.setUserFavorite(null);
                }
            }
        }
    } finally {
        monitor.done();
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)

Example 8 with CatalogItem

use of org.eclipse.equinox.internal.p2.discovery.model.CatalogItem in project epp.mpc by eclipse.

the class FeatureSelectionWizardPage method updateFeatures.

private void updateFeatures() {
    SelectionModel selectionModel = getWizard().getSelectionModel();
    Set<CatalogItem> allSelectionCatalogItems = selectionModel.getItemToSelectedOperation().keySet();
    Set<CatalogItem> selectedCatalogItems = selectionModel.getSelectedCatalogItems();
    if (allSelectionCatalogItems.isEmpty() || selectedCatalogItems.isEmpty()) {
        showPreviousPage();
        return;
    }
    viewer.setInput(selectionModel);
    ResolveFeatureNamesOperation operation = new ResolveFeatureNamesOperation(new ArrayList<CatalogItem>(allSelectionCatalogItems)) {

        Display display = getControl().getDisplay();

        @Override
        public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
            super.run(progressMonitor);
            if (!display.isDisposed() && isActivePage()) {
                display.asyncExec(new Runnable() {

                    public void run() {
                        if (isActivePage()) {
                            updateFeatureDescriptors(getFeatureDescriptors(), getUnresolvedFeatureDescriptors());
                        }
                    }
                });
            }
        }
    };
    try {
        getContainer().run(true, true, operation);
    } catch (InvocationTargetException e) {
        // we only log here since any error will also be displayed when resolving the provisioning operation.
        int statusFlags = StatusManager.LOG;
        IStatus status;
        if (e.getCause() instanceof ProvisionException) {
            status = ((ProvisionException) e.getCause()).getStatus();
        } else {
            status = MarketplaceClientCore.computeStatus(e, Messages.FeatureSelectionWizardPage_unexpectedException_verifyingFeatures);
            statusFlags |= StatusManager.BLOCK | StatusManager.SHOW;
        }
        MarketplaceClientUi.handle(status, statusFlags);
    } catch (InterruptedException e) {
    // canceled
    } finally {
        if (!isActivePage()) {
            return;
        }
        refresh();
        // bug 470485: need to recompute button state, because run() resets that to previous state
        refreshState();
    }
// maybeUpdateProfileChangeOperation();
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) ResolveFeatureNamesOperation(org.eclipse.epp.internal.mpc.ui.operations.ResolveFeatureNamesOperation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display)

Example 9 with CatalogItem

use of org.eclipse.equinox.internal.p2.discovery.model.CatalogItem in project epp.mpc by eclipse.

the class FavoritesViewer method catalogUpdated.

@Override
protected void catalogUpdated(boolean wasCancelled, boolean wasError) {
    List<CatalogItem> items = getCatalog().getItems();
    Set<CatalogItem> selectedItems = new LinkedHashSet<CatalogItem>();
    for (CatalogItem catalogItem : items) {
        if (catalogItem.isSelected()) {
            selectedItems.add(catalogItem);
        }
    }
    setSelection(StructuredSelection.EMPTY);
    super.catalogUpdated(wasCancelled, wasError);
    setSelection(new StructuredSelection(new ArrayList<CatalogItem>(selectedItems)));
}
Also used : UserActionCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.UserActionCatalogItem) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) FavoriteListCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.FavoriteListCatalogItem) LinkedHashSet(java.util.LinkedHashSet) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList)

Example 10 with CatalogItem

use of org.eclipse.equinox.internal.p2.discovery.model.CatalogItem in project epp.mpc by eclipse.

the class InstallAllActionLink method installAll.

protected void installAll() {
    MarketplaceViewer viewer = marketplacePage.getViewer();
    List<CatalogItem> items = viewer.getCatalog().getItems();
    // We need to first select the items in the selection model and then
    // set the selection to the viewer. Otherwise the MarketplacePage listener
    // will advance the wizard on the first selected item.
    SelectionModel selectionModel = viewer.getSelectionModel();
    for (CatalogItem catalogItem : items) {
        if (catalogItem instanceof MarketplaceNodeCatalogItem) {
            MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
            if (selectionModel.getSelectedOperation(nodeItem) == Operation.NONE) {
                selectionModel.select(nodeItem, Operation.INSTALL);
            }
        }
    }
    // viewer.getCheckedItems() is based on the SelectionModel state, so it already has the
    // updated selection. Just let the viewer synchronize its remaining selection state with it.
    viewer.setSelection(new StructuredSelection(viewer.getCheckedItems()));
    if (!viewer.getSelection().isEmpty()) {
        marketplacePage.showNextPage();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Aggregations

CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)30 ArrayList (java.util.ArrayList)10 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)9 Operation (org.eclipse.epp.mpc.ui.Operation)9 HashSet (java.util.HashSet)7 INode (org.eclipse.epp.mpc.core.model.INode)7 CoreException (org.eclipse.core.runtime.CoreException)6 IStatus (org.eclipse.core.runtime.IStatus)6 HashMap (java.util.HashMap)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Status (org.eclipse.core.runtime.Status)4 FeatureEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry)4 URISyntaxException (java.net.URISyntaxException)3 Entry (java.util.Map.Entry)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 CatalogCategory (org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)3 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)3