Search in sources :

Example 26 with CatalogDescriptor

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

the class MarketplaceViewer method updateContent.

private void updateContent(final ContentType contentType, final Runnable queryCall) {
    final ContentType oldContentType = this.contentType;
    this.contentType = contentType;
    final boolean hadQuery = showQueryHeader(oldContentType);
    final boolean hasQuery = showQueryHeader(contentType);
    ContentType oldQueryType = oldContentType;
    if (oldQueryType == ContentType.SELECTION) {
        oldQueryType = ContentType.SEARCH;
    }
    ContentType queryType = contentType;
    if (queryType == ContentType.SELECTION) {
        queryType = ContentType.SEARCH;
    }
    if (oldQueryType != queryType || hasQuery != hadQuery) {
        if (hadQuery) {
            initQueryFromFilters();
            tabQueries.put(oldQueryType, queryData);
        }
        if (hasQuery) {
            QueryData newQueryData = tabQueries.get(queryType);
            if (newQueryData == null) {
                newQueryData = new QueryData();
                if (queryType == ContentType.FEATURED_MARKET) {
                    CatalogDescriptor catalogDescriptor = this.getWizard().getConfiguration().getCatalogDescriptor();
                    ICatalogBranding catalogBranding = catalogDescriptor.getCatalogBranding();
                    if (catalogBranding != null) {
                        boolean hasFeaturedMarketTab = catalogBranding.hasFeaturedMarketTab();
                        if (hasFeaturedMarketTab) {
                            String marketName = catalogBranding.getFeaturedMarketTabName();
                            if (marketName != null) {
                                for (CatalogFilter filter : getConfiguration().getFilters()) {
                                    if (filter instanceof AbstractTagFilter) {
                                        AbstractTagFilter tagFilter = (AbstractTagFilter) filter;
                                        if (tagFilter.getTagClassification() == ICategory.class) {
                                            for (Tag tag : tagFilter.getChoices()) {
                                                if (tag.getTagClassifier() != IMarket.class) {
                                                    break;
                                                }
                                                IMarket market = (IMarket) tag.getData();
                                                if (marketName.equals(market.getName())) {
                                                    // tagFilter.setSelected(Collections.singleton(tag));
                                                    newQueryData.queryMarket = market;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (newQueryData.queryMarket == null) {
                                    // TODO remove/disable tab?
                                    setContentType(oldContentType);
                                    return;
                                }
                            }
                        }
                    }
                }
                tabQueries.put(queryType, newQueryData);
            }
            setFilters(newQueryData);
        }
    }
    runUpdate(new Runnable() {

        public void run() {
            fireContentTypeChange(oldContentType, contentType);
            setHeaderVisible(hasQuery);
            queryCall.run();
        }
    });
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) ICatalogBranding(org.eclipse.epp.mpc.core.model.ICatalogBranding) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) IMarket(org.eclipse.epp.mpc.core.model.IMarket) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 27 with CatalogDescriptor

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

the class MarketplaceWizard method resumeWizard.

public static void resumeWizard(Display display, Object state, boolean proceedWithInstall) {
    String catalogUrl = (String) state;
    if (proceedWithInstall) {
        org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo installInfo = MarketplaceUrlHandler.createSolutionInstallInfo(catalogUrl);
        if (installInfo != null) {
            MarketplaceUrlHandler.triggerInstall(installInfo);
            return;
        }
    }
    CatalogDescriptor descriptor = catalogUrl == null ? null : CatalogRegistry.getInstance().findCatalogDescriptor(catalogUrl);
    final MarketplaceWizardCommand command = new MarketplaceWizardCommand();
    if (descriptor != null) {
        descriptor = new CatalogDescriptor(descriptor);
        descriptor.setLabel(MarketplaceUrlHandler.DESCRIPTOR_HINT);
        command.setSelectedCatalogDescriptor(descriptor);
    }
    String mpcState = MarketplaceUrlHandler.getMPCState(catalogUrl);
    if (mpcState != null && mpcState.length() > 0) {
        try {
            // $NON-NLS-1$
            command.setWizardState(URLDecoder.decode(mpcState, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // should never happen
            throw new IllegalStateException(e);
        }
        if (!proceedWithInstall) {
            WizardState wizardState = new WizardState();
            wizardState.setProceedWithInstallation(false);
            command.setWizardDialogState(wizardState);
        }
    }
    display.asyncExec(new Runnable() {

        public void run() {
            try {
                command.execute(new ExecutionEvent());
            } catch (ExecutionException e) {
                IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceBrowserIntegration_cannotOpenMarketplaceWizard);
                MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MarketplaceUrlHandler(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler) SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ExecutionException(org.eclipse.core.commands.ExecutionException) MarketplaceWizardCommand(org.eclipse.epp.internal.mpc.ui.commands.MarketplaceWizardCommand) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 28 with CatalogDescriptor

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

the class MarketplaceWizard method updateNews.

protected void updateNews() {
    CatalogDescriptor catalogDescriptor = getConfiguration().getCatalogDescriptor();
    INews news = null;
    if (Boolean.parseBoolean(Platform.getDebugOption(DEBUG_NEWS_FLAG))) {
        // use debug override values
        String debugNewsUrl = Platform.getDebugOption(DEBUG_NEWS_URL);
        if (debugNewsUrl != null && debugNewsUrl.length() > 0) {
            News debugNews = new News();
            news = debugNews;
            debugNews.setUrl(debugNewsUrl);
            String debugNewsTitle = Platform.getDebugOption(DEBUG_NEWS_TITLE);
            if (debugNewsTitle == null || debugNewsTitle.length() == 0) {
                // $NON-NLS-1$
                debugNews.setShortTitle("Debug News");
            } else {
                debugNews.setShortTitle(debugNewsTitle);
            }
            debugNews.setTimestamp(System.currentTimeMillis());
        }
    }
    if (news == null) {
        // try requesting news from marketplace
        try {
            final INews[] result = new INews[1];
            getContainer().run(true, true, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    IStatus status = getCatalog().performNewsDiscovery(monitor);
                    if (!status.isOK() && status.getSeverity() != IStatus.CANCEL) {
                        // don't bother user with missing news
                        MarketplaceClientUi.handle(status, StatusManager.LOG);
                    }
                    result[0] = getCatalog().getNews();
                }
            });
            if (result[0] != null) {
                news = result[0];
            }
        } catch (InvocationTargetException e) {
            final IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceViewer_unexpectedException);
            MarketplaceClientUi.handle(status, StatusManager.LOG);
        } catch (InterruptedException e) {
        // cancelled by user
        }
    }
    if (news == null) {
        // use news from catalog
        news = CatalogRegistry.getInstance().getCatalogNews(catalogDescriptor);
    }
    CatalogRegistry.getInstance().addCatalogNews(catalogDescriptor, news);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) INews(org.eclipse.epp.mpc.core.model.INews) News(org.eclipse.epp.internal.mpc.core.model.News) INews(org.eclipse.epp.mpc.core.model.INews) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 29 with CatalogDescriptor

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

the class MarketplaceWizard method getCatalogUrl.

protected String getCatalogUrl() {
    CatalogDescriptor catalogDescriptor = getConfiguration().getCatalogDescriptor();
    URL catalogUrl = catalogDescriptor.getUrl();
    URI catalogUri;
    try {
        catalogUri = catalogUrl.toURI();
    } catch (URISyntaxException e) {
        // should never happen
        throw new IllegalStateException(e);
    }
    return catalogUri.toString();
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 30 with CatalogDescriptor

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

the class MarketplaceWizard method openUrl.

public void openUrl(String url) {
    String catalogUrl = getCatalogUrl();
    if (WorkbenchBrowserSupport.getInstance().isInternalWebBrowserAvailable() && url.toLowerCase().startsWith(catalogUrl.toLowerCase())) {
        int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR;
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        String browserId = "MPC-" + catalogUrl.replaceAll("[^a-zA-Z0-9_-]", "_");
        try {
            CatalogDescriptor catalogDescriptor = getConfiguration().getCatalogDescriptor();
            IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, browserId, catalogDescriptor.getLabel(), catalogDescriptor.getDescription());
            final String originalUrl = url;
            url = appendWizardState(url);
            // ORDER DEPENDENCY //don't encode/validate URL - browser can be quite lenient
            browser.openURL(new URL(url));
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setActive();
            if (!hookLocationListener(browser)) {
                // ORDER DEPENDENCY
                browser.openURL(new URL(originalUrl));
            }
        } catch (PartInitException e) {
            MarketplaceClientUi.handle(e.getStatus(), StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
        } catch (MalformedURLException e) {
            IStatus status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.MarketplaceWizard_cannotOpenUrl, new Object[] { url, e.getMessage() }), e);
            MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
        }
    } else {
        WorkbenchUtil.openUrl(url, IWorkbenchBrowserSupport.AS_EXTERNAL);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MalformedURLException(java.net.MalformedURLException) IStatus(org.eclipse.core.runtime.IStatus) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Aggregations

CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)37 URL (java.net.URL)18 Test (org.junit.Test)10 IStatus (org.eclipse.core.runtime.IStatus)7 CatalogRegistry (org.eclipse.epp.internal.mpc.ui.CatalogRegistry)7 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)4 MarketplaceUrlHandler (org.eclipse.epp.mpc.ui.MarketplaceUrlHandler)4 Before (org.junit.Before)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Status (org.eclipse.core.runtime.Status)3 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)3 INode (org.eclipse.epp.mpc.core.model.INode)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2