Author: stefanegli
Date: Fri Sep 13 13:04:35 2013
New Revision: 1522910

URL: http://svn.apache.org/r1522910
Log:
SLING-2985 : 'open on server in browser' action added

Added:
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java
   (with props)
Modified:
    sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
    sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/plugin.xml
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF?rev=1522910&r1=1522909&r2=1522910&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF 
(original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF 
Fri Sep 13 13:04:35 2013
@@ -81,7 +81,10 @@ Require-Bundle: org.eclipse.wst.common.p
  org.eclipse.ui.console,
  org.eclipse.jdt.ui,
  org.apache.sling.ide.eclipse-core,
- org.eclipse.ui.views.properties.tabbed
+ org.eclipse.ui.views.properties.tabbed,
+ org.eclipse.ui.workbench,
+ org.eclipse.jface.text,
+ org.eclipse.ui.editors
 Service-Component: OSGI-INF/*.xml
 Export-Package: org.apache.sling.ide.eclipse.ui,
  org.apache.sling.ide.eclipse.ui.wizards

Modified: sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/plugin.xml
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/plugin.xml?rev=1522910&r1=1522909&r2=1522910&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/plugin.xml Fri Sep 13 
13:04:35 2013
@@ -337,11 +337,10 @@
    </extension>
 
    <extension
-         id="org.apache.sling.ide.eclipse.ui.pluginJcrNodeToolSet"
          point="org.eclipse.ui.popupMenus">
       <objectContribution
             adaptable="true"
-            id="org.apache.sling.ide.eclipse.ui.pluginJcrNodeToolSet"
+            id="org.apache.sling.ide.eclipse.ui.pluginDomNodeToolSet"
             objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
          <action
                class="org.apache.sling.ide.eclipse.ui.actions.JcrNewNodeAction"
@@ -374,6 +373,28 @@
    </extension>
 
    <extension
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            adaptable="true"
+            id="org.apache.sling.ide.eclipse.ui.pluginGeneralToolSet"
+            objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+         <action
+               
class="org.apache.sling.ide.eclipse.ui.actions.OpenHtmlInBrowserAction"
+               icon="icons/obj16/sling.gif"
+               
id="org.apache.sling.ide.eclipse.ui.actionsOpenHtmlInBrowserAction"
+               label="&amp;Open .html (on server) in browser"
+               menubarPath="jcr">
+         </action>
+         <visibility>
+               <objectState
+                     name="browseableNode"
+                     value="true">
+               </objectState>
+         </visibility>
+      </objectContribution>
+   </extension>
+
+   <extension
          id="org.apache.sling.ide.eclipse.ui.pluginNonJcrNodeToolSet"
          point="org.eclipse.ui.popupMenus">
       <objectContribution
@@ -401,6 +422,13 @@
                label="&amp;Delete JCR Node"
                toolbarPath="common.new.menu/jcr">
          </action>
+         <action
+               
class="org.apache.sling.ide.eclipse.ui.actions.OpenHtmlInBrowserAction"
+               icon="icons/obj16/sling.gif"
+               
id="org.apache.sling.ide.eclipse.ui.actionsOpenHtmlInBrowserAction"
+               label="&amp;Open .html (on server) in browser"
+               menubarPath="common.open.menu/jcr">
+         </action>
          <visibility>
                <objectState
                      name="nonDomNode"
@@ -450,6 +478,14 @@
                </instanceof>
          </selectionEnablement>
       </linkHelper>
+   </extension>
+   <extension
+         point="org.eclipse.ui.editors">
+      <editor
+            class="org.apache.sling.ide.eclipse.ui.editors.WebBrowser"
+            id="org.apache.sling.ide.eclipse.ui.editors.WebBrowser"
+            name="WebBrowser">
+      </editor>
    </extension> 
    
 </plugin>    

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java?rev=1522910&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
 Fri Sep 13 13:04:35 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.actions;
+
+import org.apache.sling.ide.eclipse.ui.editors.WebBrowserEditorInput;
+import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+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 {
+
+       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();
+       }
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/OpenHtmlInBrowserAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java?rev=1522910&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java
 Fri Sep 13 13:04:35 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.editors;
+
+import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+
+public class WebBrowser extends EditorPart {
+
+       private Browser browser;
+       private WebBrowserEditorInput in;
+
+       @Override
+       public void doSave(IProgressMonitor monitor) {
+               
+       }
+
+       @Override
+       public void doSaveAs() {
+               
+       }
+
+       @Override
+       public void init(IEditorSite site, IEditorInput input)
+                       throws PartInitException {
+               if (input instanceof WebBrowserEditorInput) {
+                       in = (WebBrowserEditorInput) input;
+                       setPartName(in.getUrl());
+               }
+               setInput(input);
+               setSite(site);
+               setTitleImage(SharedImages.SLING_ICON.createImage());
+       }
+
+       @Override
+       public boolean isDirty() {
+               return false;
+       }
+
+       @Override
+       public boolean isSaveAsAllowed() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public void createPartControl(Composite parent) {
+               Composite container = new Composite(parent, SWT.NONE);
+               GridLayout layout = new GridLayout();
+               layout.numColumns = 2;
+               layout.marginHeight = 0;
+               layout.marginWidth = 0;
+               container.setLayout(layout);
+               Button reload = new Button(container, SWT.NONE);
+               reload.setText("Reload");
+               GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 
+                               GridData.VERTICAL_ALIGN_FILL, false, false, 1, 
2);
+               reload.setLayoutData(gd);
+               reload.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               browser.setUrl(in.getUrl());
+                       }
+               });
+               Label urlLabel = new Label(container, SWT.NONE);
+               urlLabel.setText("URL: "+in.getUrl());
+               gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL, 
+                               GridData.VERTICAL_ALIGN_FILL, true, false, 1, 
2);
+               urlLabel.setLayoutData(gd);
+        browser = new Browser(container, SWT.NONE); 
+               browser.setUrl(in.getUrl());
+               gd = new GridData(GridData.FILL_BOTH);
+               gd.horizontalSpan = 2;
+               browser.setLayoutData(gd);
+       }
+
+       @Override
+       public void setFocus() {
+               browser.setFocus();
+       }
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java?rev=1522910&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java
 Fri Sep 13 13:04:35 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.editors;
+
+import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+public class WebBrowserEditorInput implements IEditorInput {
+       private final String url;
+
+       public WebBrowserEditorInput(String url) {
+               this.url = url;
+       }
+
+       @Override
+       public Object getAdapter(Class adapter) {
+               return null;
+       }
+
+       @Override
+       public String getToolTipText() {
+               return getUrl();
+       }
+
+       @Override
+       public IPersistableElement getPersistable() {
+               return null;
+       }
+
+       @Override
+       public String getName() {
+               return "the name";
+       }
+
+       @Override
+       public ImageDescriptor getImageDescriptor() {
+               return SharedImages.SLING_ICON;
+       }
+
+       @Override
+       public boolean exists() {
+               return true;
+       }
+
+       public String getUrl() {
+               return url;
+       }
+}
\ No newline at end of file

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/editors/WebBrowserEditorInput.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1522910&r1=1522909&r2=1522910&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
 Fri Sep 13 13:04:35 2013
@@ -32,6 +32,7 @@ import javax.xml.parsers.ParserConfigura
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
 import org.apache.sling.ide.eclipse.ui.WhitelabelSupport;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
@@ -56,6 +57,7 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.eclipse.ui.views.properties.IPropertySource;
 import 
org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.wst.server.core.IServer;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.xml.sax.Attributes;
@@ -154,6 +156,9 @@ public class JcrNode implements IAdaptab
                                return resource.getFullPath().hashCode();
                        }
                } else {
+                       if (domNode==null) {
+                               return underlying.hashCode();
+                       }
                        return underlying.hashCode() + 
domNode.toString().hashCode();
                }
        }
@@ -459,6 +464,9 @@ public class JcrNode implements IAdaptab
                                        if ("nonDomNode".equals(name)) {
                                                return node.domNode==null;      
                                        }
+                                       if ("browseableNode".equals(name)) {
+                                               return node.isBrowsable();
+                                       }
                                        return false;
                                }
                        };
@@ -553,6 +561,10 @@ public class JcrNode implements IAdaptab
                return null;
        }
 
+       protected boolean isBrowsable() {
+               return true;
+       }
+
        public IFile getFileForEditor() {
                if (resource instanceof IFile) {
 //                     if (!isVaultFile(resource)) {
@@ -637,4 +649,21 @@ public class JcrNode implements IAdaptab
                underlying.save();
        }
 
+       public IProject getProject() {
+               if (resource!=null) {
+                       return resource.getProject();
+               }
+               if (underlying!=null) {
+                       return underlying.file.getProject();
+               }
+               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;
+       }
+
 }


Reply via email to