Search in sources :

Example 6 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class ImportFavoritesWizard method openFavoritesInMarketplace.

private void openFavoritesInMarketplace(List<MarketplaceNodeCatalogItem> selection) {
    final IMarketplaceClientService clientService = MarketplaceClient.getMarketplaceClientService();
    final IMarketplaceClientConfiguration config = clientService.newConfiguration();
    MarketplaceCatalogConfiguration catalogConfiguration = getConfiguration();
    config.setCatalogDescriptors(catalogConfiguration.getCatalogDescriptors());
    config.setCatalogDescriptor(catalogConfiguration.getCatalogDescriptor());
    Map<String, Operation> initialOperations = new HashMap<String, Operation>();
    for (MarketplaceNodeCatalogItem item : selection) {
        initialOperations.put(item.getData().getId(), Operation.INSTALL);
    }
    config.setInitialOperations(initialOperations);
    Display.getCurrent().asyncExec(new Runnable() {

        public void run() {
            clientService.openFavorites(config);
        }
    });
}
Also used : IMarketplaceClientConfiguration(org.eclipse.epp.mpc.ui.IMarketplaceClientConfiguration) HashMap(java.util.HashMap) IMarketplaceClientService(org.eclipse.epp.mpc.ui.IMarketplaceClientService) Operation(org.eclipse.epp.mpc.ui.Operation) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 7 with MarketplaceNodeCatalogItem

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

Example 8 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class ItemButtonController method updateButtonState.

private void updateButtonState() {
    primaryState = ButtonState.DISABLED;
    selectableStates = Collections.emptyList();
    MarketplaceNodeCatalogItem catalogItem = (MarketplaceNodeCatalogItem) item.getData();
    if (catalogItem.getInstallableUnits().isEmpty()) {
        return;
    }
    List<Operation> availableOperations = catalogItem.getAvailableOperations();
    if (availableOperations.isEmpty()) {
        return;
    }
    Operation selectedOperation = item.getSelectedOperation();
    Operation primaryOperation = selectedOperation;
    switch(selectedOperation) {
        case UPDATE:
            primaryState = ButtonState.UPDATE_PENDING;
            break;
        case UNINSTALL:
            primaryState = ButtonState.UNINSTALL_PENDING;
            break;
        case CHANGE:
            primaryState = ButtonState.CHANGE_PENDING;
            break;
        case INSTALL:
            primaryState = ButtonState.INSTALL_PENDING;
            break;
        case NONE:
            primaryOperation = availableOperations.get(0);
            primaryState = ButtonState.forOperation(primaryOperation);
            break;
    }
    if (availableOperations.size() > 1) {
        selectableStates = new ArrayList<ButtonState>(availableOperations.size() - 1);
        for (Operation operation : availableOperations) {
            if (operation != primaryOperation) {
                ButtonState selectableState = ButtonState.forOperation(operation);
                if (selectableState != ButtonState.DISABLED) {
                    selectableStates.add(selectableState);
                }
            }
        }
    }
}
Also used : Operation(org.eclipse.epp.mpc.ui.Operation) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 9 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem 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 10 with MarketplaceNodeCatalogItem

use of org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem in project epp.mpc by eclipse.

the class MarketplaceInfoSerializationTest method saveAndLoad.

@Test
public void saveAndLoad() throws Exception {
    MarketplaceNodeCatalogItem item = MarketplaceInfoTest.createTestItem();
    catalogRegistry.map(item.getMarketplaceUrl(), item.getData());
    new MarketplaceInfo(catalogRegistry).save(getUserHomeRegistryFile());
    File registryFile = getUserHomeRegistryFile();
    assertTrue(MessageFormat.format("Registry file ''{0}'' does not exist", registryFile.getAbsolutePath()), registryFile.exists());
    assertTrue(MessageFormat.format("Registry file ''{0}'' is empty", registryFile.getAbsolutePath()), registryFile.length() > 0);
    MarketplaceInfo loaded = loadMarketplaceInfo();
    assertNotNull(loaded);
    assertFalse(loaded.getIuToNodeKey().isEmpty());
    assertFalse(loaded.getNodeKeyToIU().isEmpty());
    assertEquals(catalogRegistry.getIuToNodeKey(), loaded.getIuToNodeKey());
    assertEquals(catalogRegistry.getNodeKeyToIU(), loaded.getNodeKeyToIU());
}
Also used : MarketplaceInfo(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceInfo) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) File(java.io.File) Test(org.junit.Test)

Aggregations

MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)18 Operation (org.eclipse.epp.mpc.ui.Operation)5 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)5 ArrayList (java.util.ArrayList)4 INode (org.eclipse.epp.mpc.core.model.INode)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Test (org.junit.Test)3 File (java.io.File)2 MarketplaceInfo (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceInfo)2 MarketplaceNodeInstallableUnitItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Callable (java.util.concurrent.Callable)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CoreException (org.eclipse.core.runtime.CoreException)1