incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1520309 - in /sling/trunk/tooling/ide: eclipse-core/src/org/apache/sling/ide/eclipse/core/ eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/
Date Thu, 05 Sep 2013 13:40:34 GMT
Author: stefanegli
Date: Thu Sep  5 13:40:34 2013
New Revision: 1520309

URL: http://svn.apache.org/r1520309
Log:
SLING-2985 : improvements in the content-browser : double click on a jcr node opens the corresponding
.content.xml in the editor - editing and saving the .content.xml updates the tree in the project
explorer automatically

Modified:
    sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/PackageExplorerOpenActionProvider.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
    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/SyncDir.java

Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java?rev=1520309&r1=1520308&r2=1520309&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
(original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
Thu Sep  5 13:40:34 2013
@@ -17,7 +17,10 @@
 package org.apache.sling.ide.eclipse.core;
 
 import org.apache.sling.ide.eclipse.core.internal.Activator;
+import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.QualifiedName;
@@ -28,6 +31,26 @@ public abstract class ProjectUtil {
     private static final String PROPERTY_SYNC_ROOT = "sync_root";
     private static final String PROPERTY_SYNC_ROOT_DEFAULT_VALUE = "jcr_root";
 
+    public static IFolder getSyncDirectory(IProject project) {
+    	if (project==null) {
+    		return null;
+    	}
+		if (!project.isOpen()) {
+			return null;
+		} else if (!ProjectHelper.isContentProject(project)) {
+			return null;
+		}
+		String syncDirectoryValue = ProjectUtil.getSyncDirectoryValue(project);
+		if (syncDirectoryValue==null || syncDirectoryValue.length()==0) {
+			return null;
+		}
+		IResource syncDir = project.findMember(syncDirectoryValue);
+		if (syncDir==null || !(syncDir instanceof IFolder)) {
+			return null;
+		}
+		return (IFolder) syncDir;
+    }
+    
     /**
      * Returns the value of the sync directory configured for a project.
      * 

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java?rev=1520309&r1=1520308&r2=1520309&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
Thu Sep  5 13:40:34 2013
@@ -18,17 +18,27 @@ package org.apache.sling.ide.eclipse.ui.
 
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.sling.ide.eclipse.core.ProjectUtil;
 import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
 import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
 import org.apache.sling.ide.eclipse.ui.nav.model.SyncDir;
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jdt.core.IPackageFragmentRoot;
 import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.navigator.ICommonContentExtensionSite;
@@ -37,16 +47,60 @@ import org.eclipse.ui.navigator.Pipeline
 import org.eclipse.ui.navigator.PipelinedViewerUpdate;
 
 /** WIP: content provider for content package view in project explorer **/
-public class JcrContentContentProvider implements ITreeContentProvider, IPipelinedTreeContentProvider2
{
+public class JcrContentContentProvider implements ITreeContentProvider, IPipelinedTreeContentProvider2,
IResourceChangeListener {
+
+	private Object input;
+	private TreeViewer viewer;
 
 	@Override
+	public void resourceChanged(IResourceChangeEvent event) {
+		try {
+			final List<IResource> toBeRefreshed = new LinkedList<IResource>();
+			event.getDelta().accept(new IResourceDeltaVisitor() {
+				
+				@Override
+				public boolean visit(IResourceDelta delta) throws CoreException {
+					if (delta.getResource() instanceof IContainer) {
+						return true;
+					}
+					IProject p = delta.getResource().getProject();
+					IFolder syncDir = getSyncDir(p);
+					if (syncDir==null) {
+						return false;
+					}
+					toBeRefreshed.add(syncDir.getProject());
+					return true;
+				}
+			});
+			if (toBeRefreshed.size()==0) {
+				return;
+			}
+			for (Iterator<IResource> it = toBeRefreshed.iterator(); it
+					.hasNext();) {
+				final IResource iResource = it.next();
+				viewer.getTree().getDisplay().asyncExec(new Runnable() {
+
+					@Override
+					public void run() {
+						viewer.refresh(iResource.getProject(), true);
+					}
+				});
+			}
+		} catch (CoreException e) {
+			//TODO proper logging
+			e.printStackTrace();
+		}
+	}
+	
+	@Override
 	public void dispose() {
 		// nothing to be done here
 	}
 
 	@Override
 	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-		// nothing to be done here
+		this.input = newInput;
+		this.viewer = (TreeViewer)viewer;
 	}
 
 	@Override
@@ -106,13 +160,7 @@ public class JcrContentContentProvider i
 	}
 
 	private IFolder getSyncDir(IProject project) {
-		if (!project.isOpen()) {
-			return null;
-		} else if (!ProjectHelper.isContentProject(project)) {
-			return null;
-		}
-		IResource syncDir = project.findMember(ProjectUtil.getSyncDirectoryValue(project));
-		return (IFolder) syncDir;
+		return ProjectUtil.getSyncDirectory(project);
 	}
 
 	@Override
@@ -165,7 +213,9 @@ public class JcrContentContentProvider i
 
 	@Override
 	public void init(ICommonContentExtensionSite aConfig) {
-		// nothing to do here
+		ResourcesPlugin.getWorkspace().addResourceChangeListener(
+				this,
+				IResourceChangeEvent.POST_CHANGE);
 	}
 
 

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/PackageExplorerOpenActionProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/PackageExplorerOpenActionProvider.java?rev=1520309&r1=1520308&r2=1520309&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/PackageExplorerOpenActionProvider.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/PackageExplorerOpenActionProvider.java
Thu Sep  5 13:40:34 2013
@@ -17,6 +17,7 @@
 package org.apache.sling.ide.eclipse.ui.nav;
 
 import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -25,9 +26,11 @@ import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.ActionContext;
 import org.eclipse.ui.actions.OpenFileAction;
+import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.navigator.CommonActionProvider;
 import org.eclipse.ui.navigator.ICommonActionConstants;
 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
@@ -57,12 +60,22 @@ private TreeViewer treeViewer;
 			if (selection instanceof IStructuredSelection) {
 				IStructuredSelection iss = (IStructuredSelection)selection;
 				if (iss.getFirstElement() instanceof JcrNode) {
-					JcrNode node = (JcrNode)iss.getFirstElement();
-					if (node.canBeOpenedInEditor()) {
-						actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, action);
-					} else {
-						return;
+					final JcrNode node = (JcrNode)iss.getFirstElement();
+					final IFile file = node.getFileForEditor();
+					if (file!=null) {
+						actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, new OpenFileAction(getActivePage())
{
+							@Override
+							public void run() {
+								try {
+									IDE.openEditor(getActivePage(), file, true);
+								} catch (PartInitException e) {
+									// TODO Auto-generated catch block
+									e.printStackTrace();
+								}
+							}
+						});
 					}
+					return;
 				}
 			}
 //			fOpenGroup.fillActionBars(actionBars);

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java?rev=1520309&r1=1520308&r2=1520309&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
Thu Sep  5 13:40:34 2013
@@ -21,6 +21,7 @@ import java.util.Iterator;
 import java.util.Set;
 
 import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
 import org.w3c.dom.Node;
@@ -82,8 +83,8 @@ public class DirNode extends JcrNode {
 	}
 	
 	@Override
-	public boolean canBeOpenedInEditor() {
-		return false;
+	public IFile getFileForEditor() {
+		return null;
 	}
 	
 	@Override

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java?rev=1520309&r1=1520308&r2=1520309&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
Thu Sep  5 13:40:34 2013
@@ -178,10 +178,10 @@ public class GenericJcrRootFile extends 
 	}
 	
 	@Override
-	public boolean canBeOpenedInEditor() {
-		return false;
+	public IFile getFileForEditor() {
+		return file;
 	}
-
+	
 	public void save() {
 		try {
 			TransformerFactory transformerFactory = TransformerFactory.newInstance();

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=1520309&r1=1520308&r2=1520309&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
Thu Sep  5 13:40:34 2013
@@ -32,6 +32,7 @@ import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.sling.ide.eclipse.ui.WhitelabelSupport;
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -292,12 +293,16 @@ public class JcrNode implements IAdaptab
 			
 			return filterHiddenChildren(resultMap.values());
 		} catch (CoreException e) {
+			e.printStackTrace();
 			return new Object[0];
 		} catch (ParserConfigurationException e) {
+			e.printStackTrace();
 			return new Object[0];
 		} catch (SAXException e) {
+			e.printStackTrace();
 			return new Object[0];
 		} catch (IOException e) {
+			e.printStackTrace();
 			return new Object[0];
 		}
 	}
@@ -434,9 +439,9 @@ public class JcrNode implements IAdaptab
 				return null;
 			}
 		} else if (adapter == IContributorResourceAdapter.class) {
-			if (resource==null) {
-				return null;
-			}
+			//if (resource==null) {
+			//	return null;
+			//}
 			return new IContributorResourceAdapter() {
 				
 				@Override
@@ -447,34 +452,46 @@ public class JcrNode implements IAdaptab
 					JcrNode node = (JcrNode)adaptable;
 					if (node.resource!=null) {
 						return node.resource;
+					} else {
+						return node.underlying.file;
 					}
-					return null;
+//					return null;
 				}
 			};
 		} else if (adapter == IResource.class) {
-			return resource;		
+			if (resource!=null) {
+				return resource;
+			} else {
+				return null;//underlying.file;
+			}
 		} else if (adapter == ResourceMapping.class) { 
 			boolean t = true;
 			if (!t) {
 				return null;
 			}
-			if (resource==null) {
-				return null;
-			}
+//			if (resource==null) {
+//				return null;
+//			}
 			return new ResourceMapping() {
 				
 				@Override
 				public ResourceTraversal[] getTraversals(ResourceMappingContext context,
 						IProgressMonitor monitor) throws CoreException {
-					return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { resource },
IResource.DEPTH_INFINITE, IResource.NONE) };
+					if (resource!=null) {
+						return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { resource },
IResource.DEPTH_INFINITE, IResource.NONE) };
+					} else {
+						return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { underlying.file
}, IResource.DEPTH_INFINITE, IResource.NONE) };
+					}
 				}
 				
 				@Override
 				public IProject[] getProjects() {
 					if (resource!=null) {
 						return new IProject[] {resource.getProject()};
+					} else {
+						return new IProject[] {underlying.file.getProject()};
 					}
-					return null;
+//					return null;
 				}
 				
 				@Override
@@ -484,42 +501,28 @@ public class JcrNode implements IAdaptab
 				
 				@Override
 				public Object getModelObject() {
-					return resource;
+					if (resource!=null) {
+						return resource;
+					} else {
+						return underlying.file;
+					}
 				}
 			};
 		}
 		return null;
 	}
 
-	public boolean canBeOpenedInEditor() {
-		if (resource==null) {
-			return false;
-		}
-		
-		if (resource instanceof IFolder) {
-			return false;
+	public IFile getFileForEditor() {
+		if (resource instanceof IFile) {
+//			if (!isVaultFile(resource)) {
+			return (IFile)resource;
+		} else if (resource instanceof IContainer) {
+			return null;
+		} else if (underlying!=null && underlying.file!=null) {
+			return underlying.file;
 		} else {
-			try {
-				if (!isVaultFile(resource)) {
-					return true;
-				} else {
-					return false;
-				}
-			} catch (ParserConfigurationException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (SAXException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (CoreException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+			return null;
 		}
-		return false;
 	}
 
 	public void rename(String string) {

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java?rev=1520309&r1=1520308&r2=1520309&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java
Thu Sep  5 13:40:34 2013
@@ -17,6 +17,7 @@
 package org.apache.sling.ide.eclipse.ui.nav.model;
 
 import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.swt.graphics.Image;
 
@@ -71,8 +72,8 @@ public class SyncDir extends JcrNode {
 	}
 	
 	@Override
-	public boolean canBeOpenedInEditor() {
-		return false;
+	public IFile getFileForEditor() {
+		return null;
 	}
 
 }



Mime
View raw message