Search in sources :

Example 6 with Operation

use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.

the class SelectionModel method computeProvisioningOperationViability.

/**
 * Determine what message related to finishing the wizard should correspond to the current selection.
 *
 * @return the message, or null if there should be no message.
 */
public IStatus computeProvisioningOperationViability() {
    IStatus featureStatus = computeFeatureOperationViability();
    if (featureStatus == null || !featureStatus.isOK()) {
        return featureStatus;
    }
    Map<Operation, List<CatalogItem>> operationToItem = computeOperationToItem();
    if (operationToItem.size() == 0) {
        return new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.SelectionModel_Nothing_Selected);
    } else if (operationToItem.size() == 1) {
        Entry<Operation, List<CatalogItem>> entry = operationToItem.entrySet().iterator().next();
        return new Status(IStatus.INFO, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.SelectionModel_count_selectedFor_operation, entry.getValue().size() == 1 ? Messages.SelectionModel_oneSolution : NLS.bind(Messages.SelectionModel_countSolutions, entry.getValue().size()), entry.getKey().getLabel()));
    } else if (operationToItem.size() == 2 && operationToItem.containsKey(Operation.INSTALL) && operationToItem.containsKey(Operation.UPDATE)) {
        int count = 0;
        for (List<CatalogItem> items : operationToItem.values()) {
            count += items.size();
        }
        return new Status(IStatus.INFO, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.SelectionModel_countSolutionsSelectedForInstallUpdate, count));
    } else {
        return new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.SelectionModel_cannotInstallRemoveConcurrently);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) IStatus(org.eclipse.core.runtime.IStatus) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) Operation(org.eclipse.epp.mpc.ui.Operation)

Example 7 with Operation

use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.

the class SelectionModel method getFeatureEntryToOperation.

public Map<FeatureEntry, Operation> getFeatureEntryToOperation(boolean includeNone, boolean verify) {
    Map<FeatureEntry, Operation> featureEntries = new HashMap<FeatureEntry, Operation>();
    for (CatalogItemEntry entry : getCatalogItemEntries()) {
        for (FeatureEntry featureEntry : entry.getChildren()) {
            Operation operation = featureEntry.computeChangeOperation();
            if (operation != null && (includeNone || operation != Operation.NONE)) {
                Operation old = featureEntries.put(featureEntry, operation);
                if (old != null && old != Operation.NONE) {
                    if (operation == Operation.NONE) {
                        featureEntries.put(featureEntry, old);
                        old = null;
                    } else if (verify && !old.equals(operation)) {
                        IStatus error = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.SelectionModel_Inconsistent_Actions, new Object[] { featureEntry.getFeatureDescriptor().getName(), old, operation }));
                        throw new IllegalStateException(new CoreException(error));
                    }
                }
            }
        }
    }
    return Collections.unmodifiableMap(featureEntries);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) Operation(org.eclipse.epp.mpc.ui.Operation)

Example 8 with Operation

use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.

the class SelectionModel method select.

/**
 * Select the given item with the given operation.
 *
 * @param item
 *            the item to select
 * @param operation
 *            the operation to perform. Providing {@link Operation#NONE} removes the selection
 */
public boolean select(CatalogItem item, Operation operation) {
    boolean changed = false;
    Operation sanitizedOperation = operation;
    if (operation != null && Operation.NONE != operation && item instanceof MarketplaceNodeCatalogItem) {
        MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) item;
        List<Operation> availableOperations = nodeItem.getAvailableOperations();
        if (!availableOperations.contains(operation)) {
            sanitizedOperation = null;
            switch(operation) {
                case INSTALL:
                    if (availableOperations.contains(Operation.UPDATE)) {
                        sanitizedOperation = Operation.UPDATE;
                    }
                    break;
                case UPDATE:
                    if (availableOperations.contains(Operation.INSTALL)) {
                        sanitizedOperation = Operation.UPDATE;
                    }
                    break;
            }
        }
    }
    if (sanitizedOperation == null || Operation.NONE == sanitizedOperation) {
        if (itemToOperation.remove(item) != Operation.NONE) {
            changed = true;
        }
        if (entries != null) {
            Iterator<CatalogItemEntry> it = entries.iterator();
            while (it.hasNext()) {
                CatalogItemEntry entry = it.next();
                if (entry.getItem().equals(item)) {
                    it.remove();
                }
            }
        }
    } else {
        Operation previous = itemToOperation.put(item, sanitizedOperation);
        if (previous != sanitizedOperation) {
            changed = true;
            if (entries != null) {
                Iterator<CatalogItemEntry> it = entries.iterator();
                while (it.hasNext()) {
                    CatalogItemEntry entry = it.next();
                    if (entry.getItem().equals(item)) {
                        it.remove();
                    }
                }
                CatalogItemEntry itemEntry = createItemEntry(item, sanitizedOperation);
                entries.add(itemEntry);
            }
        }
    }
    if (changed) {
        selectionChanged();
    }
    return changed;
}
Also used : Operation(org.eclipse.epp.mpc.ui.Operation) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 9 with Operation

use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.

the class MarketplaceViewer method modifySelection.

protected void modifySelection(CatalogItem connector, Operation operation) {
    if (operation == null) {
        throw new IllegalArgumentException();
    }
    Operation selectedOperation = selectionModel.getSelectedOperation(connector);
    selectionModel.select(connector, operation);
    super.modifySelection(connector, operation != Operation.NONE);
    if (selectedOperation != operation) {
        getViewer().refresh(connector);
    }
}
Also used : Operation(org.eclipse.epp.mpc.ui.Operation)

Example 10 with Operation

use of org.eclipse.epp.mpc.ui.Operation 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)

Aggregations

Operation (org.eclipse.epp.mpc.ui.Operation)18 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)9 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)8 HashMap (java.util.HashMap)6 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)6 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)6 UninstallOperation (org.eclipse.equinox.p2.operations.UninstallOperation)6 IStatus (org.eclipse.core.runtime.IStatus)5 CoreException (org.eclipse.core.runtime.CoreException)4 Status (org.eclipse.core.runtime.Status)4 AbstractProvisioningOperation (org.eclipse.epp.internal.mpc.ui.operations.AbstractProvisioningOperation)4 FeatureEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Entry (java.util.Map.Entry)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 InstallOperation (org.eclipse.equinox.p2.operations.InstallOperation)2