incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1520007 - in /sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model: JcrNode.java LinkHelper.java
Date Wed, 04 Sep 2013 13:11:22 GMT
Author: stefanegli
Date: Wed Sep  4 13:11:21 2013
New Revision: 1520007

URL: http://svn.apache.org/r1520007
Log:
SLING-2985 : link-with-editor support (part 2) added for content browser (selection change
in project explorer activates corresponding editor if that's already open)

Modified:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/LinkHelper.java

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=1520007&r1=1520006&r2=1520007&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
Wed Sep  4 13:11:21 2013
@@ -525,5 +525,9 @@ public class JcrNode implements IAdaptab
 	public JcrNode getParent() {
 		return parent;
 	}
+	
+	IResource getResource() {
+		return resource;
+	}
 
 }

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/LinkHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/LinkHelper.java?rev=1520007&r1=1520006&r2=1520007&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/LinkHelper.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/LinkHelper.java
Wed Sep  4 13:11:21 2013
@@ -27,7 +27,10 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.ide.ResourceUtil;
 import org.eclipse.ui.navigator.ILinkHelper;
 import org.w3c.dom.Node;
@@ -83,8 +86,45 @@ public class LinkHelper implements ILink
 	@Override
 	public void activateEditor(IWorkbenchPage aPage,
 			IStructuredSelection aSelection) {
-		// nothing done here at the moment. 
-		// PackageExplorerOpenActionProvider currently takes care of opening jcr nodes in an editor
+		final Object selectedElement = aSelection.getFirstElement();
+		if (!(selectedElement instanceof JcrNode)) {
+			return;
+		}
+		final JcrNode node = (JcrNode) selectedElement;
+		final IResource resource = node.getResource();
+		if (resource==null || !(resource instanceof IFile)) {
+			return;
+		}
+		final IFile selectedFile = (IFile)resource;
+		final IEditorReference[] editorReferences = aPage.getEditorReferences();
+		for (int i = 0; i < editorReferences.length; i++) {
+			final IEditorReference reference = editorReferences[i];
+			if (reference==null) {
+				continue;
+			}
+			final IEditorInput editorInput;
+			try {
+				editorInput = reference.getEditorInput();
+			} catch (PartInitException e) {
+				//TODO proper logging
+				e.printStackTrace();
+				continue;
+			}
+			if (editorInput==null) {
+				continue;
+			}
+			if (!(editorInput instanceof IFileEditorInput)) {
+				continue;
+			}
+			final IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
+			final IFile file = fileEditorInput.getFile();
+			if (file==null) {
+				continue;
+			}
+			if (file.equals(selectedFile)) {
+				aPage.activate(reference.getEditor(true));
+			}
+		}
 	}
 
 }



Mime
View raw message