Search in sources :

Example 1 with FeatureEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry in project epp.mpc by eclipse.

the class MarketplaceWizard method computeNewInstallCatalogItems.

private Set<CatalogItem> computeNewInstallCatalogItems() {
    Set<CatalogItem> items = new HashSet<CatalogItem>();
    Map<CatalogItem, Collection<String>> iusByCatalogItem = new HashMap<CatalogItem, Collection<String>>();
    for (CatalogItemEntry entry : getSelectionModel().getCatalogItemEntries()) {
        List<FeatureEntry> features = entry.getChildren();
        Collection<String> featureIds = new ArrayList<String>(features.size());
        for (FeatureEntry feature : features) {
            if (feature.computeChangeOperation() == Operation.INSTALL) {
                featureIds.add(feature.getFeatureDescriptor().getId());
            }
        }
        if (!featureIds.isEmpty()) {
            iusByCatalogItem.put(entry.getItem(), featureIds);
        }
    }
    for (IInstallableUnit unit : operationIUs) {
        for (Entry<CatalogItem, Collection<String>> entry : iusByCatalogItem.entrySet()) {
            if (entry.getValue().contains(unit.getId())) {
                items.add(entry.getKey());
            }
        }
    }
    return items;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) Collection(java.util.Collection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 2 with FeatureEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry in project epp.mpc by eclipse.

the class FeatureSelectionWizardPage method computeCheckedViewerState.

public void computeCheckedViewerState() {
    // compute which ones should be checked. (update scenario where only part of a feature is installed)
    List<Object> checkedElements = new ArrayList<Object>();
    List<Object> grayCheckedElements = new ArrayList<Object>();
    for (CatalogItemEntry entry : getWizard().getSelectionModel().getCatalogItemEntries()) {
        int childCheckCount = 0;
        boolean childGrayed = false;
        for (FeatureEntry child : entry.getChildren()) {
            if (child.isChecked()) {
                checkedElements.add(child);
                ++childCheckCount;
            }
        }
        if (childCheckCount > 0) {
            for (FeatureEntry child : entry.getChildren()) {
                if (!child.isChecked() && !child.getInstallableUnitItem().isOptional()) {
                    child.setChecked(true);
                    checkedElements.add(child);
                    ++childCheckCount;
                }
            }
        }
        for (FeatureEntry child : entry.getChildren()) {
            if (child.isGrayed()) {
                checkedElements.add(child);
                grayCheckedElements.add(child);
                childGrayed = true;
            }
        }
        if (childCheckCount == entry.getChildren().size()) {
            checkedElements.add(entry);
        } else if (childCheckCount > 0 || childGrayed) {
            grayCheckedElements.add(entry);
            checkedElements.add(entry);
        }
    }
    viewer.setCheckedElements(checkedElements.toArray());
    viewer.setGrayedElements(grayCheckedElements.toArray());
    viewer.refresh(true);
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) ArrayList(java.util.ArrayList) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry)

Example 3 with FeatureEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry in project epp.mpc by eclipse.

the class FeatureSelectionWizardPage method updateSelectionModel.

private void updateSelectionModel(Set<FeatureDescriptor> featureDescriptors) {
    Map<String, FeatureDescriptor> descriptorById = new HashMap<String, FeatureDescriptor>();
    for (FeatureDescriptor fd : featureDescriptors) {
        descriptorById.put(fd.getId(), fd);
    }
    SelectionModel selectionModel = getWizard().getSelectionModel();
    for (CatalogItemEntry entry : selectionModel.getCatalogItemEntries()) {
        for (FeatureEntry child : entry.getChildren()) {
            FeatureDescriptor descriptor = descriptorById.get(child.getFeatureDescriptor().getId());
            if (descriptor != null) {
                child.setFeatureDescriptor(descriptor);
            }
        }
    }
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) FeatureDescriptor(org.eclipse.epp.internal.mpc.ui.operations.FeatureDescriptor) HashMap(java.util.HashMap) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) StyledString(org.eclipse.jface.viewers.StyledString)

Example 4 with FeatureEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry 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 5 with FeatureEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry in project epp.mpc by eclipse.

the class ProfileChangeOperationComputer method pruneNonInstall.

private void pruneNonInstall(List<IInstallableUnit> installableUnits) {
    Set<String> installableFeatureIds = new HashSet<String>();
    for (FeatureEntry featureEntry : featureEntries) {
        Operation operation = featureEntry.computeChangeOperation();
        if (operation == Operation.INSTALL || operation == Operation.UPDATE) {
            installableFeatureIds.add(featureEntry.getFeatureDescriptor().getId());
        }
    }
    Iterator<IInstallableUnit> it = installableUnits.iterator();
    while (it.hasNext()) {
        IInstallableUnit iu = it.next();
        if (!installableFeatureIds.contains(iu.getId())) {
            it.remove();
        }
    }
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) 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) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) HashSet(java.util.HashSet)

Aggregations

FeatureEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry)8 HashSet (java.util.HashSet)5 CatalogItemEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry)4 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 HashMap (java.util.HashMap)3 Operation (org.eclipse.epp.mpc.ui.Operation)3 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)3 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)3 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)3 UninstallOperation (org.eclipse.equinox.p2.operations.UninstallOperation)3 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 InstallOperation (org.eclipse.equinox.p2.operations.InstallOperation)2 StyledString (org.eclipse.jface.viewers.StyledString)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1