Search in sources :

Example 1 with ContentType

use of org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType in project epp.mpc by eclipse.

the class MarketplacePage method setActiveTab.

private void setActiveTab(TabItem tab) {
    if (disableTabSelection) {
        return;
    }
    if (tab == newsTabItem) {
        final INews news = getNews();
        if (news == null) {
            setActiveTab(currentContentType != null ? currentContentType : previousContentType != null ? previousContentType : ContentType.SEARCH);
            updateNewsTab();
            return;
        }
        boolean wasUpdated = newsViewer.isUpdated(news);
        newsViewer.showNews(news);
        if (wasUpdated) {
            updateBranding();
            TabItem currentTabItem = getSelectedTabItem();
            if (currentTabItem != newsTabItem) {
                tabFolder.setSelection(newsTabItem);
                // required for Mac to not switch back to first tab
                getControl().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        tabFolder.setSelection(newsTabItem);
                    }
                });
            }
        }
        return;
    }
    ContentType currentContentType = getViewer().getContentType();
    if (currentContentType != null) {
        TabItem tabItem = getTabItem(currentContentType);
        if (tabItem == tab) {
            setActiveTab(currentContentType);
            return;
        }
    }
    for (ContentType contentType : ContentType.values()) {
        if (getTabItem(contentType) == tab) {
            setActiveTab(contentType);
            return;
        }
    }
    throw new IllegalArgumentException(tab.getText());
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) ContentType(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType) INews(org.eclipse.epp.mpc.core.model.INews)

Example 2 with ContentType

use of org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType in project epp.mpc by eclipse.

the class MarketplacePage method createControl.

@Override
public void createControl(final Composite parent) {
    currentBranding = getDefaultBranding();
    boolean needSwitchMarketplaceControl = configuration.getCatalogDescriptors().size() > 1;
    Composite pageContent = new Composite(parent, SWT.NULL);
    GridLayoutFactory.fillDefaults().numColumns(1).spacing(0, 5).applyTo(pageContent);
    tabFolder = new TabFolder(pageContent, SWT.TOP);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tabFolder);
    super.createControl(tabFolder);
    tabContent = getControl();
    searchTabItem = createCatalogTab(-1, ContentType.SEARCH, WIDGET_ID_TAB_SEARCH, currentBranding.getSearchTabName());
    recentTabItem = createCatalogTab(-1, ContentType.RECENT, WIDGET_ID_TAB_RECENT, currentBranding.getRecentTabName());
    popularTabItem = createCatalogTab(-1, ContentType.POPULAR, WIDGET_ID_TAB_POPULAR, currentBranding.getPopularTabName());
    favoritedTabItem = createCatalogTab(-1, ContentType.FAVORITES, WIDGET_ID_TAB_FAVORITES, getFavoritedTabName(currentBranding));
    installedTabItem = createCatalogTab(-1, ContentType.INSTALLED, WIDGET_ID_TAB_INSTALLED, Messages.MarketplacePage_installed);
    updateNewsTab();
    searchTabItem.setControl(tabContent);
    tabFolder.setSelection(searchTabItem);
    tabFolder.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (e.item.isDisposed()) {
                return;
            }
            setActiveTab((TabItem) e.item);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    {
        // TODO id
        contentListLinks = new Link(pageContent, SWT.NULL);
        contentListLinks.setToolTipText(Messages.MarketplacePage_showSelection);
        contentListLinks.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                String actionId = e.text;
                ActionLink actionLink = actions.get(actionId);
                if (actionLink != null) {
                    actionLink.selected();
                }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(contentListLinks);
        updateSelectionLink();
    }
    if (needSwitchMarketplaceControl) {
        createMarketplaceSwitcher(pageContent);
    }
    updateBranding();
    // bug 312411: a selection listener so that we can streamline install of single product
    getViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        private int previousSelectionSize = 0;

        public void selectionChanged(SelectionChangedEvent event) {
            if (!isCurrentPage()) {
                return;
            }
            SelectionModel selectionModel = getWizard().getSelectionModel();
            int newSelectionSize = selectionModel.getItemToSelectedOperation().size();
            // sets the empty selection whenever the catalog is updated.
            if (!event.getSelection().isEmpty()) {
                if (previousSelectionSize == 0 && newSelectionSize > 0 && selectionModel.computeProvisioningOperationViableForFeatureSelection()) {
                    showNextPage();
                }
            }
            previousSelectionSize = newSelectionSize;
        }
    });
    getViewer().addPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(MarketplaceViewer.CONTENT_TYPE_PROPERTY) && event.getNewValue() != null) {
                setActiveTab((ContentType) event.getNewValue());
            }
        }
    });
    setControl(pageContent);
    if (!tabContent.isDisposed()) {
        // bug 473031 - no clue how this can happen during createControl...
        MarketplaceClientUi.setDefaultHelp(tabContent);
    }
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ContentType(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TabFolder(org.eclipse.swt.widgets.TabFolder) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TabItem(org.eclipse.swt.widgets.TabItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Link(org.eclipse.swt.widgets.Link) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with ContentType

use of org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType in project epp.mpc by eclipse.

the class MarketplaceClientService method setInitialContentType.

private void setInitialContentType(IMarketplaceClientConfiguration configuration, WizardState wizardState) {
    if (configuration instanceof MarketplaceCatalogConfiguration) {
        MarketplaceCatalogConfiguration catalogConfiguration = (MarketplaceCatalogConfiguration) configuration;
        ContentType initialContentType = catalogConfiguration.getInitialContentType();
        if (initialContentType != null) {
            wizardState.setContentType(initialContentType);
        }
    }
}
Also used : ContentType(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType)

Example 4 with ContentType

use of org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType in project epp.mpc by eclipse.

the class BrowseCatalogItem method getMarketplaceUrl.

private static String getMarketplaceUrl(CatalogDescriptor catalogDescriptor, MarketplaceViewer viewer) throws URISyntaxException {
    URL url = catalogDescriptor.getUrl();
    try {
        ContentType contentType = viewer.getQueryContentType();
        if (contentType == ContentType.SEARCH) {
            String queryText = viewer.getQueryText();
            ICategory queryCategory = viewer.getQueryCategory();
            IMarket queryMarket = viewer.getQueryMarket();
            String path = new DefaultMarketplaceService(url).computeRelativeSearchUrl(queryMarket, queryCategory, queryText, false);
            if (path != null) {
                url = new URL(url, path);
            }
        }
    } catch (IllegalArgumentException e) {
        // should never happen
        MarketplaceClientUi.error(e);
    } catch (MalformedURLException e) {
        // should never happen
        MarketplaceClientUi.error(e);
    }
    URI uri = url.toURI();
    return uri.toString();
}
Also used : MalformedURLException(java.net.MalformedURLException) ContentType(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType) ICategory(org.eclipse.epp.mpc.core.model.ICategory) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) IMarket(org.eclipse.epp.mpc.core.model.IMarket) URI(java.net.URI) URL(java.net.URL)

Aggregations

ContentType (org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType)4 TabItem (org.eclipse.swt.widgets.TabItem)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 DefaultMarketplaceService (org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService)1 ICategory (org.eclipse.epp.mpc.core.model.ICategory)1 IMarket (org.eclipse.epp.mpc.core.model.IMarket)1 INews (org.eclipse.epp.mpc.core.model.INews)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Composite (org.eclipse.swt.widgets.Composite)1 Link (org.eclipse.swt.widgets.Link)1 TabFolder (org.eclipse.swt.widgets.TabFolder)1