Search in sources :

Example 1 with SolutionInstallationInfo

use of org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo in project epp.mpc by eclipse.

the class MarketplaceUrlHandlerTest method testGetInstallationInfo.

@Test
public void testGetInstallationInfo() throws Exception {
    String url = "http://marketplace.eclipse.org/mpc/install?x=19&y=17&mpc_state=&mpc_install=953";
    SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(url);
    assertEquals("http://marketplace.eclipse.org", info.getCatalogDescriptor().getUrl().toExternalForm());
    assertEquals("953", info.getInstallId());
    assertNull(info.getState());
}
Also used : SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) Test(org.junit.Test)

Example 2 with SolutionInstallationInfo

use of org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo in project epp.mpc by eclipse.

the class MarketplaceUrlHandlerTest method testGetInstallationInfoWithState.

@Test
public void testGetInstallationInfoWithState() throws Exception {
    String statefulUrl = "http://marketplace.eclipse.org/mpc/install?mpc_install=953";
    SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(statefulUrl);
    assertEquals("http://marketplace.eclipse.org", info.getCatalogDescriptor().getUrl().toExternalForm());
    assertEquals("953", info.getInstallId());
    assertNull(info.getState());
}
Also used : SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) Test(org.junit.Test)

Example 3 with SolutionInstallationInfo

use of org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo 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 4 with SolutionInstallationInfo

use of org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo in project epp.mpc by eclipse.

the class MarketplaceUrlHandlerTest method testGetInstallationInfoNoValidUrl.

@Test
public void testGetInstallationInfoNoValidUrl() throws Exception {
    SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(null);
    assertNull(info);
    info = MarketplaceUrlHandler.createSolutionInstallInfo("");
    assertNull(info);
    info = MarketplaceUrlHandler.createSolutionInstallInfo("http://www.eclipse.org");
    assertNull(info);
    String missingInstallId = "http://marketplace.eclipse.org/mpc/install?mpc_install=";
    info = MarketplaceUrlHandler.createSolutionInstallInfo(missingInstallId);
}
Also used : SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) Test(org.junit.Test)

Aggregations

SolutionInstallationInfo (org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo)4 Test (org.junit.Test)3 CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 IWizardPage (org.eclipse.jface.wizard.IWizardPage)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchListener (org.eclipse.ui.IWorkbenchListener)1