Search in sources :

Example 16 with CatalogItem

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

the class NodeMatcher method doMatch.

@Override
protected boolean doMatch(Object obj) {
    if (obj instanceof Widget) {
        Widget w = (Widget) obj;
        Object data = w.getData();
        INode node = null;
        if (data instanceof CatalogItem) {
            data = ((CatalogItem) data).getData();
        }
        if (data instanceof INode) {
            node = (INode) data;
        }
        return node != null && matcher.matches(node);
    }
    return false;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) INode(org.eclipse.epp.mpc.core.model.INode) Widget(org.eclipse.swt.widgets.Widget)

Example 17 with CatalogItem

use of org.eclipse.equinox.internal.p2.discovery.model.CatalogItem 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;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) INode(org.eclipse.epp.mpc.core.model.INode) Set(java.util.Set) HashSet(java.util.HashSet) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) UserActionCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.UserActionCatalogItem) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 18 with CatalogItem

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

the class MarketplaceWizard method notifyNonInstallableItems.

protected void notifyNonInstallableItems(final List<CatalogItem> noninstallableItems) {
    MessageDialog dialog = new MessageDialog(getShell(), Messages.MarketplaceWizard_UnableToInstallSolutions, null, Messages.MarketplaceWizard_IncompatibleSolutionsMessage, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0) {

        @Override
        protected Control createCustomArea(Composite parent) {
            parent.setLayout(new GridLayout());
            TableViewer tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            tableViewer.setLabelProvider(createLabelProvider());
            tableViewer.setContentProvider(createContentProvider());
            tableViewer.setInput(noninstallableItems);
            Control tableControl = tableViewer.getControl();
            GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, Math.max(40, Math.min(120, tableControl.computeSize(SWT.DEFAULT, SWT.DEFAULT).y))).applyTo(tableControl);
            return tableControl;
        }

        private LabelProvider createLabelProvider() {
            return new LabelProvider() {

                @Override
                public String getText(Object element) {
                    // we could show that with an IStyledLabelProvider behind the name
                    return ((CatalogItem) element).getName();
                }

                @Override
                public Image getImage(Object element) {
                    return MarketplaceClientUiPlugin.getInstance().getImageRegistry().get(MarketplaceClientUiPlugin.IU_ICON_ERROR);
                }
            };
        }

        private IStructuredContentProvider createContentProvider() {
            return new IStructuredContentProvider() {

                public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
                }

                public void dispose() {
                }

                public Object[] getElements(Object inputElement) {
                    return ((List<?>) inputElement).toArray();
                }
            };
        }
    };
    dialog.open();
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) List(java.util.List) ArrayList(java.util.ArrayList) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 19 with CatalogItem

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

the class MarketplaceWizard method updateProfileChangeOperation.

public void updateProfileChangeOperation() {
    removeAddedRepositoryLocations();
    addedRepositoryLocations = null;
    profileChangeOperation = null;
    operationIUs = null;
    IWizardContainer wizardContainer = getContainer();
    if (getSelectionModel().computeProvisioningOperationViable()) {
        ProfileChangeOperationComputer provisioningOperation = null;
        try {
            final Map<CatalogItem, Operation> itemToOperation = getSelectionModel().getItemToSelectedOperation();
            final Set<CatalogItem> selectedItems = getSelectionModel().getSelectedCatalogItems();
            OperationType operationType = null;
            for (Map.Entry<CatalogItem, Operation> entry : itemToOperation.entrySet()) {
                if (!selectedItems.contains(entry.getKey())) {
                    continue;
                }
                OperationType entryOperationType = OperationType.map(entry.getValue());
                if (entryOperationType != null) {
                    if (operationType == null || operationType == OperationType.UPDATE || entryOperationType == OperationType.CHANGE) {
                        operationType = entryOperationType;
                    }
                }
            }
            Map<FeatureEntry, Operation> featureEntries = getSelectionModel().getFeatureEntryToOperation(false, false);
            if (operationType == OperationType.CHANGE || operationType == OperationType.UPDATE) {
                Set<OperationType> featureOperations = EnumSet.noneOf(OperationType.class);
                for (Entry<FeatureEntry, Operation> entry : featureEntries.entrySet()) {
                    OperationType operation = OperationType.map(entry.getValue());
                    if (operation != null) {
                        featureOperations.add(operation);
                    }
                }
                if (featureOperations.contains(OperationType.INSTALL) && featureOperations.contains(OperationType.UPDATE)) {
                    // just perform install instead, which covers update
                    featureOperations.remove(OperationType.UPDATE);
                }
                if (featureOperations.size() == 1) {
                    operationType = featureOperations.iterator().next();
                }
            }
            URI dependenciesRepository = null;
            if (getConfiguration().getCatalogDescriptor().getDependenciesRepository() != null) {
                try {
                    dependenciesRepository = getConfiguration().getCatalogDescriptor().getDependenciesRepository().toURI();
                } catch (URISyntaxException e) {
                    throw new InvocationTargetException(e);
                }
            }
            provisioningOperation = new ProfileChangeOperationComputer(operationType, selectedItems, featureEntries.keySet(), dependenciesRepository, getConfiguration().getCatalogDescriptor().isInstallFromAllRepositories() ? ProfileChangeOperationComputer.ResolutionStrategy.FALLBACK_STRATEGY : ProfileChangeOperationComputer.ResolutionStrategy.SELECTED_REPOSITORIES, withRemediation);
            wizardContainer.run(true, true, provisioningOperation);
            profileChangeOperation = provisioningOperation.getOperation();
            operationIUs = provisioningOperation.getIus();
            addedRepositoryLocations = provisioningOperation.getAddedRepositoryLocations();
            operationNewInstallItems = computeNewInstallCatalogItems();
            errorMessage = provisioningOperation.getErrorMessage();
            final IStatus result = profileChangeOperation.getResolutionResult();
            if (result != null && operationIUs != null && operationIUs.length > 0 && operationType == OperationType.INSTALL) {
                switch(result.getSeverity()) {
                    case IStatus.ERROR:
                        Job job = new Job(Messages.MarketplaceWizard_errorNotificationJob) {

                            IStatus r = result;

                            Set<CatalogItem> items = new HashSet<CatalogItem>(itemToOperation.keySet());

                            IInstallableUnit[] ius = operationIUs;

                            String details = profileChangeOperation.getResolutionDetails();

                            {
                                setSystem(false);
                                setUser(false);
                                setPriority(LONG);
                            }

                            @Override
                            protected IStatus run(IProgressMonitor monitor) {
                                getCatalog().installErrorReport(monitor, r, items, ius, details);
                                return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
                            }
                        };
                        job.schedule();
                }
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            IStatus status;
            if (cause instanceof CoreException) {
                status = ((CoreException) cause).getStatus();
            } else {
                status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.MarketplaceWizard_problemsPerformingProvisioningOperation, new Object[] { cause.getMessage() }), cause);
            }
            MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
        } catch (InterruptedException e) {
            // canceled
            MarketplaceClientUi.log(IStatus.CANCEL, MarketplaceClientUi.BUNDLE_ID, Messages.MarketplaceWizard_ProvisioningOperationCancelled, e);
        } finally {
            if (provisioningOperation != null) {
                addedRepositoryLocations = provisioningOperation.getAddedRepositoryLocations();
            }
        }
    }
    // re-get the container - in case the wizard was closed in the meantime, this will be null...
    wizardContainer = getContainer();
    if (wizardContainer != null && wizardContainer.getCurrentPage() == featureSelectionWizardPage) {
        featureSelectionWizardPage.updateMessage();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) AbstractProvisioningOperation(org.eclipse.epp.internal.mpc.ui.operations.AbstractProvisioningOperation) RemediationOperation(org.eclipse.equinox.p2.operations.RemediationOperation) ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) UninstallOperation(org.eclipse.equinox.p2.operations.UninstallOperation) Operation(org.eclipse.epp.mpc.ui.Operation) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) Job(org.eclipse.core.runtime.jobs.Job) ProvisioningJob(org.eclipse.equinox.p2.operations.ProvisioningJob) ProfileChangeOperationComputer(org.eclipse.epp.internal.mpc.ui.operations.ProfileChangeOperationComputer) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationType(org.eclipse.epp.internal.mpc.ui.operations.ProfileChangeOperationComputer.OperationType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with CatalogItem

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

the class MarketplaceViewerSorter method compare.

@Override
public int compare(Viewer viewer, Object o1, Object o2) {
    if (o1 == o2) {
        return 0;
    }
    CatalogCategory cat1 = getCategory(o1);
    CatalogCategory cat2 = getCategory(o2);
    // FIXME filter uncategorized items?
    if (cat1 == null) {
        return (cat2 != null) ? 1 : 0;
    } else if (cat2 == null) {
        return 1;
    }
    int i = categoryComparator.compare(cat1, cat2);
    if (i == 0) {
        if (o1 instanceof CatalogCategory) {
            return -1;
        }
        if (o2 instanceof CatalogCategory) {
            return 1;
        }
        CatalogItem i1 = (CatalogItem) o1;
        CatalogItem i2 = (CatalogItem) o2;
        // catalog descriptor comes last
        if (i1.getData() instanceof CatalogDescriptor) {
            i = 1;
        } else if (i2.getData() instanceof CatalogDescriptor) {
            i = -1;
        } else {
            // otherwise we sort by name
            String n1 = i1.getName();
            String n2 = i2.getName();
            if (n1 == null) {
                // $NON-NLS-1$
                n1 = "";
            }
            if (n2 == null) {
                // $NON-NLS-1$
                n2 = "";
            }
            i = n1.compareToIgnoreCase(n2);
            if (i == 0) {
                i = n1.compareTo(n2);
                if (i == 0) {
                    // same name, so we sort by id.
                    String id1 = i1.getId();
                    String id2 = i2.getId();
                    if (id1 == null) {
                        // $NON-NLS-1$
                        id1 = "";
                    }
                    if (id2 == null) {
                        // $NON-NLS-1$
                        id2 = "";
                    }
                    i = id1.compareTo(id2);
                }
            }
        }
    }
    return i;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

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