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