Search in sources :

Example 11 with Operation

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

the class MarketplaceWizard method handleInstallRequest.

protected boolean handleInstallRequest(final SolutionInstallationInfo installInfo, String url) {
    final String installId = installInfo.getInstallId();
    if (installId == null) {
        return false;
    }
    try {
        final MarketplacePage catalogPage = getCatalogPage();
        IStatus showingDescriptor = catalogPage.showMarketplace(installInfo.getCatalogDescriptor());
        if (!showingDescriptor.isOK()) {
            return true;
        }
        final SelectionModel selectionModel = getSelectionModel();
        final Map<String, Operation> nodeIdToOperation = new HashMap<String, Operation>();
        nodeIdToOperation.putAll(getSelectionModel().getItemIdToSelectedOperation());
        try {
            nodeIdToOperation.put(URLDecoder.decode(installId, UTF_8), Operation.INSTALL);
        } catch (UnsupportedEncodingException e) {
            // should be unreachable
            throw new IllegalStateException();
        }
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                SelectionModelStateSerializer stateSerializer = new SelectionModelStateSerializer(getCatalog(), selectionModel);
                stateSerializer.deserialize(installInfo.getState(), nodeIdToOperation, monitor);
            }
        });
        if (selectionModel.getItemToSelectedOperation().size() > 0) {
            Display display = getShell().getDisplay();
            if (!display.isDisposed()) {
                display.asyncExec(new Runnable() {

                    public void run() {
                        MarketplacePage catalogPage = getCatalogPage();
                        IWizardPage currentPage = getContainer().getCurrentPage();
                        if (catalogPage == currentPage) {
                            catalogPage.getViewer().setSelection(new StructuredSelection(selectionModel.getSelectedCatalogItems().toArray()));
                            catalogPage.show(installInfo.getCatalogDescriptor(), ContentType.SELECTION);
                            IWizardPage nextPage = catalogPage.getNextPage();
                            if (nextPage != null && catalogPage.isPageComplete()) {
                                getContainer().showPage(nextPage);
                            }
                        }
                    }
                });
            }
        }
        return true;
    } catch (InvocationTargetException e) {
        IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceViewer_unexpectedException);
        MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
    } catch (InterruptedException e) {
        // action canceled, but this still counts as handled
        return true;
    }
    return false;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWizardPage(org.eclipse.jface.wizard.IWizardPage) Display(org.eclipse.swt.widgets.Display)

Example 12 with Operation

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

the class SelectionModel method computeInitiallyChecked.

private Boolean computeInitiallyChecked(FeatureEntry featureEntry) {
    CatalogItemEntry parent = featureEntry.getParent();
    Operation selectedOperation = parent.getSelectedOperation();
    switch(selectedOperation) {
        case INSTALL:
            if (!featureEntry.isInstalled()) {
                return featureEntry.isRequiredInstall() || featureEntry.getInstallableUnitItem().isDefaultSelected();
            }
            return featureEntry.hasUpdateAvailable();
        case UNINSTALL:
            return featureEntry.isInstalled();
        case UPDATE:
            return featureEntry.hasUpdateAvailable() || featureEntry.isRequiredInstall();
        case CHANGE:
            return featureEntry.isInstalled();
    }
    return false;
}
Also used : Operation(org.eclipse.epp.mpc.ui.Operation)

Example 13 with Operation

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

the class SelectionModel method getCatalogItemEntries.

public List<CatalogItemEntry> getCatalogItemEntries() {
    if (entries == null) {
        List<CatalogItemEntry> entries = new ArrayList<CatalogItemEntry>();
        for (Entry<CatalogItem, Operation> entry : itemToOperation.entrySet()) {
            CatalogItem item = entry.getKey();
            Operation operation = entry.getValue();
            CatalogItemEntry itemEntry = createItemEntry(item, operation);
            entries.add(itemEntry);
        }
        this.entries = entries;
    }
    return entries;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) ArrayList(java.util.ArrayList) Operation(org.eclipse.epp.mpc.ui.Operation)

Example 14 with Operation

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

the class SelectionModelStateSerializer method serialize.

public String serialize() {
    StringBuilder state = new StringBuilder(1024);
    for (Map.Entry<CatalogItem, Operation> entry : selectionModel.getItemToSelectedOperation().entrySet()) {
        if (entry.getValue() != Operation.NONE) {
            if (state.length() > 0) {
                state.append(' ');
            }
            INode data = (INode) entry.getKey().getData();
            state.append(data.getId());
            state.append('=');
            state.append(entry.getValue().name());
        }
    }
    return state.toString();
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) INode(org.eclipse.epp.mpc.core.model.INode) Operation(org.eclipse.epp.mpc.ui.Operation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with Operation

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

the class SelectionModelStateSerializer method deserialize.

/**
 * @param state
 *            the state to restore
 * @param operationByNodeExtras
 *            additional operations to include
 * @param monitor
 */
public void deserialize(String state, Map<String, Operation> operationByNodeExtras, IProgressMonitor monitor) {
    Map<String, Operation> operationByNodeId = new HashMap<String, Operation>();
    if (state != null && state.length() > 0) {
        // $NON-NLS-1$
        Pattern pattern = Pattern.compile("([^\\s=]+)=(\\S+)");
        Matcher matcher = pattern.matcher(state);
        while (matcher.find()) {
            String nodeId = matcher.group(1);
            String operationName = matcher.group(2);
            Operation operation = Operation.valueOf(operationName);
            operationByNodeId.put(nodeId, operation);
        }
    }
    if (operationByNodeExtras != null) {
        operationByNodeId.putAll(operationByNodeExtras);
    }
    if (!operationByNodeId.isEmpty()) {
        catalog.performQuery(monitor, operationByNodeId.keySet());
        for (CatalogItem item : catalog.getItems()) {
            if (item instanceof MarketplaceNodeCatalogItem) {
                MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) item;
                Operation operation = operationByNodeId.get(nodeItem.getData().getId());
                if (operation != null && operation != Operation.NONE) {
                    if (nodeItem.isInstalled() && operation == Operation.INSTALL) {
                        operation = Operation.UPDATE;
                    }
                    selectionModel.select(nodeItem, operation);
                }
            }
        }
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Operation(org.eclipse.epp.mpc.ui.Operation) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

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