You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2015/02/21 21:57:50 UTC

svn commit: r1661440 - in /sling/trunk/tooling/ide/eclipse-ui: ./ META-INF/ src/org/apache/sling/ide/eclipse/ui/actions/ src/org/apache/sling/ide/eclipse/ui/browser/ src/org/apache/sling/ide/eclipse/ui/editors/ src/org/apache/sling/ide/eclipse/ui/nav/m...

Author: rombert
Date: Sat Feb 21 20:57:50 2015
New Revision: 1661440

URL: http://svn.apache.org/r1661440
Log:
SLING-4451 - Opening a resource in the browser does not obey the user's
preferences

- use IWorkbenchBrowserSupport
- use the browser icon for this action instead of the generic Sling one

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/browser/
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/browser/AbstractOpenInBrowserAction.java
Removed:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java
Modified:
    sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Modified: sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF?rev=1661440&r1=1661439&r2=1661440&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF Sat Feb 21 20:57:50 2015
@@ -91,6 +91,7 @@ Require-Bundle: org.eclipse.wst.common.p
  org.eclipse.swt
 Service-Component: OSGI-INF/*.xml
 Export-Package: org.apache.sling.ide.eclipse.ui,
+ org.apache.sling.ide.eclipse.ui.browser,
  org.apache.sling.ide.eclipse.ui.console,
  org.apache.sling.ide.eclipse.ui.internal;x-friends:="org.apache.sling.ide.eclipse-test",
  org.apache.sling.ide.eclipse.ui.nav;x-friends:="org.apache.sling.ide.eclipse-test",

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1661440&r1=1661439&r2=1661440&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Sat Feb 21 20:57:50 2015
@@ -456,7 +456,7 @@
             objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
          <action
                class="org.apache.sling.ide.eclipse.ui.actions.OpenHtmlInBrowserAction"
-               icon="icons/obj16/sling_misc.gif"
+               icon="platform:/plugin/org.eclipse.ui.browser/icons/obj16/internal_browser.gif"
                id="org.apache.sling.ide.eclipse.ui.actionsOpenHtmlInBrowserAction"
                label="&amp;Open .html (on server) in browser"
                menubarPath="jcr">
@@ -535,7 +535,7 @@
          </action>
          <action
                class="org.apache.sling.ide.eclipse.ui.actions.OpenHtmlInBrowserAction"
-               icon="icons/obj16/sling_misc.gif"
+               icon="platform:/plugin/org.eclipse.ui.browser/icons/obj16/internal_browser.gif"
                id="org.apache.sling.ide.eclipse.ui.actionsOpenHtmlInBrowserAction"
                label="&amp;Open .html (on server) in browser"
                toolbarPath="common.open.menu/jcr">

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java?rev=1661440&r1=1661439&r2=1661440&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java Sat Feb 21 20:57:50 2015
@@ -16,74 +16,20 @@
  */
 package org.apache.sling.ide.eclipse.ui.actions;
 
-import org.apache.sling.ide.eclipse.ui.editors.WebBrowserEditorInput;
-import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
+import org.apache.sling.ide.eclipse.ui.browser.AbstractOpenInBrowserAction;
 import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.ServerUtil;
 
-public class OpenHtmlInBrowserAction implements IObjectActionDelegate {
+public class OpenHtmlInBrowserAction extends AbstractOpenInBrowserAction {
+
+	protected URL getUrlToOpen(JcrNode node, IServer server) throws MalformedURLException {
 
-	private ISelection selection;
-	private Shell shell;
-	private IWorkbenchPart targetPart;
-
-	public OpenHtmlInBrowserAction() {
-	}
-
-	@Override
-	public void run(IAction action) {
-		if (selection==null || !(selection instanceof IStructuredSelection)) {
-			return;
-		}
-		IStructuredSelection ss = (IStructuredSelection)selection;
-		JcrNode node = (JcrNode) ss.getFirstElement();
-		
-        IWorkbenchPage page = targetPart.getSite().getPage();
-        IModule module = ServerUtil.getModule(node.getProject());
-        if (module==null) {
-			MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
-        	return;
-        }
-        IServer[] servers = ServerUtil.getServersByModule(module, new NullProgressMonitor());
-        if (servers==null || servers.length==0) {
-			MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
-        	return;
-        }
-        IServer server = servers[0];
-        final String url = node.getURLForBrowser(server)+".html";
-		try {
-			IEditorInput input = new WebBrowserEditorInput(url);
-			page.openEditor(input, "org.apache.sling.ide.eclipse.ui.editors.WebBrowser", true);
-		} catch (PartInitException e1) {
-			//TODO proper logging
-			e1.printStackTrace();
-			MessageDialog.openWarning(shell, "Cannot open browser", "Opening caused an exception: "+e1.getMessage());
-		}
-	}
-
-	@Override
-	public void selectionChanged(IAction action, ISelection selection) {
-		this.selection = selection;
-		action.setEnabled(true);
-	}
-
-	@Override
-	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
-		this.targetPart = targetPart;
-		this.shell = targetPart.getSite().getWorkbenchWindow().getShell();
-	}
+        return new URL("http", server.getHost(), server.getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080),
+                node.getJcrPath() + ".html");
+    }
 
 }

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/browser/AbstractOpenInBrowserAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/browser/AbstractOpenInBrowserAction.java?rev=1661440&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/browser/AbstractOpenInBrowserAction.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/browser/AbstractOpenInBrowserAction.java Sat Feb 21 20:57:50 2015
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.browser;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.sling.ide.eclipse.ui.internal.Activator;
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerUtil;
+
+/**
+ * The <tt>AbstractOpenInBrowserAction</tt> offers support for easily opening a node in a browser
+ *
+ */
+public abstract class AbstractOpenInBrowserAction implements IObjectActionDelegate {
+
+    private ISelection selection;
+    private Shell shell;
+    private IWorkbenchPart targetPart;
+
+    @Override
+    public void run(IAction action) {
+    	if (selection==null || !(selection instanceof IStructuredSelection)) {
+    		return;
+    	}
+    	IStructuredSelection ss = (IStructuredSelection)selection;
+    	JcrNode node = (JcrNode) ss.getFirstElement();
+    	
+        IModule module = ServerUtil.getModule(node.getProject());
+        if (module==null) {
+    		MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
+        	return;
+        }
+        IServer[] servers = ServerUtil.getServersByModule(module, new NullProgressMonitor());
+        if (servers==null || servers.length==0) {
+    		MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
+        	return;
+        }
+        IServer server = servers[0];
+        URL url;
+        try {
+            url = getUrlToOpen(node, server);
+        } catch (MalformedURLException e) {
+            StatusManager.getManager().handle(new Status(Status.WARNING, Activator.PLUGIN_ID, "Url is invalid", e),
+                    StatusManager.SHOW);
+            return;
+        }
+    	try {
+            IWorkbenchBrowserSupport browserSupport = targetPart.getSite().getWorkbenchWindow().getWorkbench()
+                    .getBrowserSupport();
+            browserSupport.createBrowser("org.apache.sling.ide.openOnServer").openURL(url);
+        } catch (PartInitException e) {
+            StatusManager.getManager().handle(
+                    new Status(Status.WARNING, Activator.PLUGIN_ID, "Failed creating browser instance", e),
+                    StatusManager.SHOW | StatusManager.LOG);
+        }
+    }
+
+    @Override
+    public void selectionChanged(IAction action, ISelection selection) {
+    	this.selection = selection;
+    	action.setEnabled(true);
+    }
+
+    @Override
+    public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+    	this.targetPart = targetPart;
+    	this.shell = targetPart.getSite().getWorkbenchWindow().getShell();
+    }
+
+    protected abstract URL getUrlToOpen(JcrNode node, IServer server) throws MalformedURLException;
+
+}
\ No newline at end of file

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1661440&r1=1661439&r2=1661440&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java Sat Feb 21 20:57:50 2015
@@ -37,7 +37,6 @@ import javax.xml.parsers.ParserConfigura
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.util.ISO9075;
-import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
 import org.apache.sling.ide.eclipse.core.ProjectUtil;
 import org.apache.sling.ide.eclipse.core.ServerUtil;
 import org.apache.sling.ide.eclipse.core.internal.Activator;
@@ -89,7 +88,6 @@ import org.eclipse.ui.model.WorkbenchLab
 import org.eclipse.ui.part.ResourceTransfer;
 import org.eclipse.ui.views.properties.IPropertySource;
 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
-import org.eclipse.wst.server.core.IServer;
 import org.xml.sax.SAXException;
 
 import de.pdark.decentxml.Attribute;
@@ -1086,13 +1084,6 @@ public class JcrNode implements IAdaptab
 		return null;
 	}
 
-	public String getURLForBrowser(IServer server) {
-		final String host = server.getHost();
-		final int port = server.getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080);
-        final String url = "http://"+host+":"+port+""+getJcrPath();
-		return url;
-	}
-
     public boolean isInContentXml() {
         return domElement!=null;
     }