1 /*******************************************************************************
\r
2 * Copyright (c) 2016 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * THTH ry - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.debug.browser.ui;
\r
14 import java.net.URL;
\r
16 import javax.inject.Named;
\r
18 import org.eclipse.core.runtime.IStatus;
\r
19 import org.eclipse.core.runtime.Platform;
\r
20 import org.eclipse.core.runtime.Status;
\r
21 import org.eclipse.e4.core.di.annotations.CanExecute;
\r
22 import org.eclipse.e4.core.di.annotations.Execute;
\r
23 import org.eclipse.e4.ui.services.IServiceConstants;
\r
24 import org.eclipse.jface.dialogs.ErrorDialog;
\r
25 import org.eclipse.jface.viewers.ISelection;
\r
26 import org.eclipse.swt.widgets.Shell;
\r
27 import org.eclipse.ui.PlatformUI;
\r
28 import org.eclipse.ui.browser.IWebBrowser;
\r
29 import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
\r
30 import org.simantics.db.Resource;
\r
31 import org.simantics.db.layer0.SelectionHints;
\r
32 import org.simantics.debug.browser.internal.DebugBrowserServer;
\r
33 import org.simantics.utils.ui.ISelectionUtils;
\r
36 * @author Jani Simomaa / Semantum Oy
\r
37 * @author Tuukka Lehtonen / Semantum Oy
\r
40 public class LaunchDebugBrowser {
\r
42 private static int browserCounter = 0;
\r
45 public boolean canExecute() {
\r
46 return Platform.inDevelopmentMode();
\r
50 public void execute(
\r
51 @Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell,
\r
52 @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection)
\r
55 // Start Jetty server for graph debugging
\r
56 DebugBrowserServer server = org.simantics.debug.browser.internal.Activator.getDefault().startDebugServer();
\r
57 URL url = server.getURL();
\r
59 // Get default input from current workbench selection
\r
60 Resource input = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class, true);
\r
61 URL inputUrl = input != null ? new URL(url.toExternalForm() + "/" + input.getResourceId()) : url;
\r
64 IWorkbenchBrowserSupport bs = PlatformUI.getWorkbench().getBrowserSupport();
\r
65 if (bs.isInternalWebBrowserAvailable()) {
\r
66 IWebBrowser browser = bs.createBrowser(
\r
67 IWorkbenchBrowserSupport.AS_EDITOR
\r
68 | IWorkbenchBrowserSupport.NAVIGATION_BAR
\r
69 | IWorkbenchBrowserSupport.LOCATION_BAR
\r
70 , "graph.debug.browser." + (browserCounter++),
\r
71 "Database Debug Browser",
\r
73 browser.openURL(inputUrl);
\r
75 bs.getExternalBrowser().openURL(inputUrl);
\r
77 } catch (Exception e) {
\r
78 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to open external browser.", e));
\r
79 ErrorDialog.openError(activeShell,
\r
80 "Failed to Open External Browser",
\r
81 "Failed to open debug browser in the default external web browser. See exception for details.",
\r
82 new Status(Status.ERROR, Activator.PLUGIN_ID, "", e));
\r