Search in sources :

Example 11 with CatalogDescriptor

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

the class MarketplacePage method updateBranding.

private void updateBranding() {
    disableTabSelection = true;
    updateTitle();
    CatalogDescriptor descriptor = configuration.getCatalogDescriptor();
    ICatalogBranding oldBranding = currentBranding;
    ICatalogBranding branding = descriptor == null ? null : descriptor.getCatalogBranding();
    if (branding == null) {
        branding = getDefaultBranding();
    }
    currentBranding = branding;
    TabItem selectedTabItem = getSelectedTabItem();
    int tabIndex = 0;
    boolean hasTab = branding.hasSearchTab();
    searchTabItem = updateTab(searchTabItem, ContentType.SEARCH, WIDGET_ID_TAB_SEARCH, branding.getSearchTabName(), hasTab, oldBranding.hasSearchTab(), tabIndex);
    if (hasTab) {
        tabIndex++;
    }
    hasTab = hasFeaturedMarketTab(branding);
    featuredMarketTabItem = updateTab(featuredMarketTabItem, ContentType.SEARCH, WIDGET_ID_TAB_FEATURED_MARKET, branding.getFeaturedMarketTabName(), hasTab, hasFeaturedMarketTab(oldBranding), tabIndex);
    if (hasTab) {
        tabIndex++;
    }
    hasTab = branding.hasRecentTab();
    recentTabItem = updateTab(recentTabItem, ContentType.SEARCH, WIDGET_ID_TAB_RECENT, branding.getRecentTabName(), hasTab, oldBranding.hasRecentTab(), tabIndex);
    if (hasTab) {
        tabIndex++;
    }
    hasTab = branding.hasPopularTab();
    popularTabItem = updateTab(popularTabItem, ContentType.SEARCH, WIDGET_ID_TAB_POPULAR, branding.getPopularTabName(), hasTab, oldBranding.hasPopularTab(), tabIndex);
    if (hasTab) {
        tabIndex++;
    }
    hasTab = branding.hasRelatedTab();
    relatedTabItem = updateTab(relatedTabItem, ContentType.SEARCH, WIDGET_ID_TAB_RELATED, branding.getRelatedTabName(), hasTab, oldBranding.hasRelatedTab(), tabIndex);
    if (hasTab) {
        tabIndex++;
    }
    hasTab = hasFavoritedTab(branding);
    favoritedTabItem = updateTab(favoritedTabItem, ContentType.SEARCH, WIDGET_ID_TAB_FAVORITES, getFavoritedTabName(branding), hasTab, hasFavoritedTab(oldBranding), tabIndex);
    if (hasTab) {
        tabIndex++;
    }
    updateNewsTab();
    if (selectedTabItem == null || selectedTabItem.isDisposed()) {
        tabFolder.setSelection(0);
    }
    final ImageDescriptor defaultWizardIconDescriptor = DiscoveryImages.BANNER_DISOVERY;
    if (branding.getWizardIcon() == null) {
        setImageDescriptor(defaultWizardIconDescriptor);
    } else {
        final Display display = Display.getCurrent();
        MarketplaceClientUiPlugin.getInstance().getResourceProvider().provideResource(new ResourceReceiver<ImageDescriptor>() {

            public ImageDescriptor processResource(URL resource) {
                return ImageDescriptor.createFromURL(resource);
            }

            public void setResource(final ImageDescriptor resource) {
                display.asyncExec(new Runnable() {

                    public void run() {
                        try {
                            setImageDescriptor(resource);
                        } catch (SWTException ex) {
                            // broken image
                            setImageDescriptor(defaultWizardIconDescriptor);
                        }
                    }
                });
            }
        }, branding.getWizardIcon(), defaultWizardIconDescriptor);
    }
    disableTabSelection = false;
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) SWTException(org.eclipse.swt.SWTException) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ICatalogBranding(org.eclipse.epp.mpc.core.model.ICatalogBranding) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Display(org.eclipse.swt.widgets.Display)

Example 12 with CatalogDescriptor

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

the class MarketplacePage method hasFavoritedTab.

private boolean hasFavoritedTab(ICatalogBranding branding) {
    if (branding.hasFavoritesTab()) {
        return true;
    }
    CatalogDescriptor catalogDescriptor = this.configuration.getCatalogDescriptor();
    if (catalogDescriptor == null) {
        return false;
    }
    URL url = catalogDescriptor.getUrl();
    IUserFavoritesService favoritesService = url == null ? null : ServiceHelper.getMarketplaceServiceLocator().getFavoritesService(url.toString());
    return favoritesService != null;
}
Also used : IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 13 with CatalogDescriptor

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

the class MarketplaceWizardDialog method configureShell.

@Override
protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    // make jface dialog accessible for swtbot
    newShell.setData(this);
    new MarketplaceDropAdapter() {

        @Override
        protected void proceedInstallation(String url) {
            SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(url);
            CatalogDescriptor catalogDescriptor = info.getCatalogDescriptor();
            String installItem = info.getInstallId();
            // we ignore previous wizard state here, since the wizard is still open...
            if (installItem != null && installItem.length() > 0) {
                info.setState(null);
                getWizard().handleInstallRequest(info, url);
            }
        }

        @Override
        protected void proceedFavorites(String url) {
            getWizard().importFavorites(url);
        }
    }.installDropTarget(newShell);
    final IWorkbenchListener workbenchListener = new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
            Shell wizardShell = wizardDialog.getShell();
            if (wizardShell != null && !wizardShell.isDisposed()) {
                if (!forced) {
                    MarketplaceWizard wizard = wizardDialog.getWizard();
                    boolean hasPendingActions = false;
                    IWizardPage currentPage = wizardDialog.getCurrentPage();
                    if (currentPage != null && wizard != null) {
                        if (currentPage == wizard.getCatalogPage()) {
                            hasPendingActions = !wizard.getSelectionModel().getSelectedCatalogItems().isEmpty();
                        } else {
                            hasPendingActions = true;
                        }
                    }
                    if (hasPendingActions) {
                        Shell parentShell = activate(wizardDialog.getShell());
                        MessageDialog messageDialog = new MessageDialog(parentShell, Messages.MarketplaceWizardDialog_PromptPendingActionsTitle, null, Messages.MarketplaceWizardDialog_PromptPendingActionsMessage, MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, SWT.NONE);
                        int result = messageDialog.open();
                        switch(result) {
                            case // yes
                            0:
                                finishWizard();
                                return false;
                            case // no
                            1:
                                break;
                            // cancel
                            case 3:
                            // [x]
                            case SWT.DEFAULT:
                            default:
                                return false;
                        }
                    }
                }
                if (forced) {
                    wizardShell.close();
                } else {
                    boolean closed = wizardDialog.close();
                    return closed;
                }
            }
            return true;
        }

        private void finishWizard() {
            MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
            MarketplaceWizard wizard = wizardDialog.getWizard();
            IWizardPage currentPage = wizardDialog.getCurrentPage();
            if (currentPage == wizard.getCatalogPage()) {
                ((MarketplacePage) currentPage).showNextPage();
            }
        }

        private Shell activate(Shell shell) {
            Shell activeShell = shell.getDisplay().getActiveShell();
            if (activeShell != shell) {
                Shell[] childShells = shell.getShells();
                if (childShells.length == 0 || !Arrays.asList(childShells).contains(activeShell)) {
                    shell.forceActive();
                    shell.forceFocus();
                }
            }
            if (activeShell == null) {
                activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
                if (activeShell == null) {
                    activeShell = shell;
                }
            }
            return activeShell;
        }

        public void postShutdown(IWorkbench workbench) {
        }
    };
    PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
    newShell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener);
        }
    });
    if (newShell.getParent() == null) {
        // bug 500379 - root shells don't handle escape traversal by default
        newShell.addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                if (e.keyCode == SWT.ESC) {
                    Shell shell = (Shell) e.widget;
                    if (shell != null && !shell.isDisposed() && shell.isVisible() && shell.isEnabled()) {
                        shell.close();
                    }
                }
            }
        });
    }
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) DisposeListener(org.eclipse.swt.events.DisposeListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) IWizardPage(org.eclipse.jface.wizard.IWizardPage) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 14 with CatalogDescriptor

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

the class CatalogSwitcher method setSelection.

public void setSelection(ISelection newSelection) {
    if (newSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) newSelection;
        CatalogDescriptor oldDescriptor = this.selection;
        CatalogDescriptor newDescriptor = (CatalogDescriptor) structuredSelection.getFirstElement();
        this.selection = newDescriptor;
        refreshSelection();
        if (newDescriptor != oldDescriptor) {
            fireSelectionChanged();
        }
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 15 with CatalogDescriptor

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

the class CatalogSwitcher method createContents.

private void createContents(final Composite parent) {
    createHeader(parent);
    final ScrolledComposite scrollArea = new ScrolledComposite(parent, SWT.V_SCROLL);
    scrollArea.setLayout(new FillLayout());
    marketplaceArea = new Composite(scrollArea, SWT.NONE);
    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    layout.marginLeft = layout.marginRight = layout.marginTop = layout.marginBottom = layout.marginHeight = layout.marginWidth = 0;
    marketplaceArea.setLayout(layout);
    Color listBackground = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    setBackground(listBackground);
    marketplaceArea.setBackground(listBackground);
    scrollArea.setBackground(listBackground);
    List<CatalogDescriptor> catalogDescriptors = configuration.getCatalogDescriptors();
    for (CatalogDescriptor catalogDescriptor : catalogDescriptors) {
        createMarketplace(marketplaceArea, catalogDescriptor);
    }
    scrollArea.setContent(marketplaceArea);
    scrollArea.setExpandVertical(true);
    scrollArea.setExpandHorizontal(true);
    scrollArea.setMinHeight(MIN_SCROLL_HEIGHT);
    scrollArea.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = parent.getClientArea();
            int scrollBarWidth = scrollArea.getVerticalBar().getSize().x;
            scrollArea.setMinSize(marketplaceArea.computeSize(r.width - scrollBarWidth, SWT.DEFAULT));
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FillLayout(org.eclipse.swt.layout.FillLayout) ControlEvent(org.eclipse.swt.events.ControlEvent) 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