Search in sources :

Example 51 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class ProvisioningJobListener method done.

@Override
public void done(IJobChangeEvent event) {
    if (event.getResult().isOK()) {
        Job job = new Job(Messages.ProvisioningJobListener_notificationTaskName) {

            {
                setPriority(Job.LONG);
                setSystem(true);
                setUser(true);
            }

            @Override
            protected IStatus run(final IProgressMonitor monitor) {
                ConcurrentTaskManager taskManager = new ConcurrentTaskManager(installItems.size(), Messages.ProvisioningJobListener_notificationTaskName);
                for (CatalogItem item : installItems) {
                    if (item instanceof MarketplaceNodeCatalogItem) {
                        final MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) item;
                        taskManager.submit(new Runnable() {

                            public void run() {
                                INode node = nodeItem.getData();
                                URL marketplaceUrl = nodeItem.getMarketplaceUrl();
                                IMarketplaceService marketplaceService = ServiceHelper.getMarketplaceServiceLocator().getMarketplaceService(marketplaceUrl.toString());
                                marketplaceService.reportInstallSuccess(node, new NullProgressMonitor() {

                                    @Override
                                    public boolean isCanceled() {
                                        return monitor.isCanceled();
                                    }
                                });
                            }
                        });
                    }
                }
                try {
                    taskManager.waitUntilFinished(monitor);
                } catch (CoreException e) {
                    return e.getStatus();
                }
                return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
            }
        };
        job.schedule();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) CoreException(org.eclipse.core.runtime.CoreException) ConcurrentTaskManager(org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager) Job(org.eclipse.core.runtime.jobs.Job) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) URL(java.net.URL)

Example 52 with INode

use of org.eclipse.epp.mpc.core.model.INode 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 53 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DiscoveryItem method getFavoriteCount.

private Integer getFavoriteCount() {
    if (connector.getData() instanceof INode) {
        INode node = (INode) connector.getData();
        IUserFavoritesService userFavoritesService = getUserFavoritesService();
        if (userFavoritesService != null) {
            return userFavoritesService.getFavoriteCount(node);
        }
        return node.getFavorited();
    }
    return null;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Example 54 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DiscoveryItem method toggleFavorite.

private void toggleFavorite() {
    final INode node = this.getCatalogItemNode();
    final IUserFavoritesService userFavoritesService = getUserFavoritesService();
    if (node != null && userFavoritesService != null) {
        final boolean newFavorited = !isFavorited();
        final Throwable[] error = new Throwable[] { null };
        BusyIndicator.showWhile(getDisplay(), new Runnable() {

            public void run() {
                try {
                    ModalContext.run(new IRunnableWithProgress() {

                        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            try {
                                userFavoritesService.getStorageService().runWithLogin(new Callable<Void>() {

                                    public Void call() throws Exception {
                                        userFavoritesService.setFavorite(node, newFavorited, monitor);
                                        return null;
                                    }
                                });
                            } catch (Exception e) {
                                error[0] = e;
                            }
                        }
                    }, true, new NullProgressMonitor(), getDisplay());
                } catch (InvocationTargetException e) {
                    error[0] = e.getCause();
                } catch (InterruptedException e) {
                    error[0] = e;
                }
            }
        });
        Throwable e = error[0];
        if (e != null) {
            if (e instanceof NotAuthorizedException) {
                // authentication was cancelled
                return;
            } else if (e instanceof ConflictException) {
                // silently ignored - service already tried to resolve this
                return;
            } else {
                IStatus status = MarketplaceClientCore.computeStatus(e, NLS.bind(Messages.DiscoveryItem_FavoriteActionFailed, this.getNameLabelText()));
                MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
                return;
            }
        }
        setFavorited(newFavorited);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) ConflictException(org.eclipse.userstorage.util.ConflictException) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) ConflictException(org.eclipse.userstorage.util.ConflictException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 55 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DiscoveryItem method createInstallInfo.

@Override
protected void createInstallInfo(Composite parent) {
    // prevent the button from changing the layout of the title
    Composite composite = new Composite(parent, SWT.NULL);
    GridDataFactory.fillDefaults().indent(DESCRIPTION_MARGIN_LEFT, BUTTONBAR_MARGIN_TOP).grab(true, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(composite);
    RowLayoutFactory.fillDefaults().type(SWT.HORIZONTAL).pack(true).applyTo(composite);
    Integer installsTotal = null;
    Integer installsRecent = null;
    if (connector.getData() instanceof INode) {
        INode node = (INode) connector.getData();
        installsTotal = node.getInstallsTotal();
        installsRecent = node.getInstallsRecent();
    }
    if (installsTotal != null || installsRecent != null) {
        StyledText installInfo = new StyledText(composite, SWT.READ_ONLY | SWT.SINGLE);
        setWidgetId(installInfo, WIDGET_ID_INSTALLS);
        String totalText = installsTotal == null ? Messages.DiscoveryItem_Unknown_Installs : MessageFormat.format(Messages.DiscoveryItem_Compact_Number, installsTotal.intValue(), installsTotal * 0.001, installsTotal * 0.000001);
        String recentText = installsRecent == null ? Messages.DiscoveryItem_Unknown_Installs : // $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        "{0, number}", installsRecent.intValue());
        String installInfoText = NLS.bind(Messages.DiscoveryItem_Installs, totalText, recentText);
        int formatTotalsStart = installInfoText.indexOf(totalText);
        if (formatTotalsStart == -1) {
            installInfo.append(installInfoText);
        } else {
            if (formatTotalsStart > 0) {
                installInfo.append(installInfoText.substring(0, formatTotalsStart));
            }
            StyledTextHelper.appendStyled(installInfo, totalText, new StyleRange(0, 0, null, null, SWT.BOLD));
            installInfo.append(installInfoText.substring(formatTotalsStart + totalText.length()));
        }
    } else {
        if (shareSolutionLink != null) {
            shareSolutionLink.setShowText(true);
        }
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Aggregations

INode (org.eclipse.epp.mpc.core.model.INode)63 Node (org.eclipse.epp.internal.mpc.core.model.Node)13 ArrayList (java.util.ArrayList)12 CoreException (org.eclipse.core.runtime.CoreException)12 SubMonitor (org.eclipse.core.runtime.SubMonitor)12 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ICategory (org.eclipse.epp.mpc.core.model.ICategory)8 URISyntaxException (java.net.URISyntaxException)7 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)7 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 List (java.util.List)6 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)6 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)6