X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.debug.browser.ui%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fbrowser%2Fui%2FLaunchDebugBrowser.java;h=d3a16abb3e2159ff11371e7259d16a0f1ed7fd0e;hb=refs%2Fchanges%2F38%2F238%2F2;hp=e7041539c359cbf421d06c30e8fac3a087420d5c;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.debug.browser.ui/src/org/simantics/debug/browser/ui/LaunchDebugBrowser.java b/bundles/org.simantics.debug.browser.ui/src/org/simantics/debug/browser/ui/LaunchDebugBrowser.java index e7041539c..d3a16abb3 100644 --- a/bundles/org.simantics.debug.browser.ui/src/org/simantics/debug/browser/ui/LaunchDebugBrowser.java +++ b/bundles/org.simantics.debug.browser.ui/src/org/simantics/debug/browser/ui/LaunchDebugBrowser.java @@ -1,86 +1,86 @@ -/******************************************************************************* - * Copyright (c) 2016 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * THTH ry - initial API and implementation - *******************************************************************************/ -package org.simantics.debug.browser.ui; - -import java.net.URL; - -import javax.inject.Named; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.e4.core.di.annotations.CanExecute; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.browser.IWebBrowser; -import org.eclipse.ui.browser.IWorkbenchBrowserSupport; -import org.simantics.db.Resource; -import org.simantics.db.layer0.SelectionHints; -import org.simantics.debug.browser.internal.DebugBrowserServer; -import org.simantics.utils.ui.ISelectionUtils; - -/** - * @author Jani Simomaa / Semantum Oy - * @author Tuukka Lehtonen / Semantum Oy - * @since 1.22 - */ -public class LaunchDebugBrowser { - - private static int browserCounter = 0; - - @CanExecute - public boolean canExecute() { - return Platform.inDevelopmentMode(); - } - - @Execute - public void execute( - @Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell, - @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) - { - try { - // Start Jetty server for graph debugging - DebugBrowserServer server = org.simantics.debug.browser.internal.Activator.getDefault().startDebugServer(); - URL url = server.getURL(); - - // Get default input from current workbench selection - Resource input = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class, true); - URL inputUrl = input != null ? new URL(url.toExternalForm() + "/" + input.getResourceId()) : url; - - // Open browser - IWorkbenchBrowserSupport bs = PlatformUI.getWorkbench().getBrowserSupport(); - if (bs.isInternalWebBrowserAvailable()) { - IWebBrowser browser = bs.createBrowser( - IWorkbenchBrowserSupport.AS_EDITOR - | IWorkbenchBrowserSupport.NAVIGATION_BAR - | IWorkbenchBrowserSupport.LOCATION_BAR - , "graph.debug.browser." + (browserCounter++), - "Database Debug Browser", - url.toString()); - browser.openURL(inputUrl); - } else { - bs.getExternalBrowser().openURL(inputUrl); - } - } catch (Exception e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to open external browser.", e)); - ErrorDialog.openError(activeShell, - "Failed to Open External Browser", - "Failed to open debug browser in the default external web browser. See exception for details.", - new Status(Status.ERROR, Activator.PLUGIN_ID, "", e)); - } - } - -} +/******************************************************************************* + * Copyright (c) 2016 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * THTH ry - initial API and implementation + *******************************************************************************/ +package org.simantics.debug.browser.ui; + +import java.net.URL; + +import javax.inject.Named; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.browser.IWebBrowser; +import org.eclipse.ui.browser.IWorkbenchBrowserSupport; +import org.simantics.db.Resource; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.debug.browser.internal.DebugBrowserServer; +import org.simantics.utils.ui.ISelectionUtils; + +/** + * @author Jani Simomaa / Semantum Oy + * @author Tuukka Lehtonen / Semantum Oy + * @since 1.22 + */ +public class LaunchDebugBrowser { + + private static int browserCounter = 0; + + @CanExecute + public boolean canExecute() { + return Platform.inDevelopmentMode(); + } + + @Execute + public void execute( + @Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell, + @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) + { + try { + // Start Jetty server for graph debugging + DebugBrowserServer server = org.simantics.debug.browser.internal.Activator.getDefault().startDebugServer(); + URL url = server.getURL(); + + // Get default input from current workbench selection + Resource input = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class, true); + URL inputUrl = input != null ? new URL(url.toExternalForm() + "/" + input.getResourceId()) : url; + + // Open browser + IWorkbenchBrowserSupport bs = PlatformUI.getWorkbench().getBrowserSupport(); + if (bs.isInternalWebBrowserAvailable()) { + IWebBrowser browser = bs.createBrowser( + IWorkbenchBrowserSupport.AS_EDITOR + | IWorkbenchBrowserSupport.NAVIGATION_BAR + | IWorkbenchBrowserSupport.LOCATION_BAR + , "graph.debug.browser." + (browserCounter++), + "Database Debug Browser", + url.toString()); + browser.openURL(inputUrl); + } else { + bs.getExternalBrowser().openURL(inputUrl); + } + } catch (Exception e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to open external browser.", e)); + ErrorDialog.openError(activeShell, + "Failed to Open External Browser", + "Failed to open debug browser in the default external web browser. See exception for details.", + new Status(Status.ERROR, Activator.PLUGIN_ID, "", e)); + } + } + +}