You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2013/09/04 13:21:52 UTC

svn commit: r1519984 - in /sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model: DirNode.java JcrNode.java

Author: stefanegli
Date: Wed Sep  4 11:21:52 2013
New Revision: 1519984

URL: http://svn.apache.org/r1519984
Log:
SLING-2985 : support <file> <file>.dir serialization format of vault and show a file with a child (typically jcr:content) in the content browser

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java   (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Added: 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=1519984&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java Wed Sep  4 11:21:52 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.nav.model;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.w3c.dom.Node;
+
+public class DirNode extends JcrNode {
+
+	static boolean isDirNode(IResource resource) {
+		if (resource==null) {
+			return false;
+		}
+		final String resourceName = resource.getName();
+		if (!resourceName.endsWith(".dir")) {
+			return false;
+		}
+		if (!(resource instanceof IFolder)) {
+			return false;
+		}
+		final IFolder folder = (IFolder)resource;
+		final IContainer container = folder.getParent();
+		if (container==null || !container.exists()) {
+			return false;
+		}
+		final IResource peerNode = container.findMember(resourceName.substring(0, resourceName.length()-4));
+		if (peerNode==null || !peerNode.exists()) {
+			return false;
+		}
+		final IResource dotContextXml = folder.findMember(".content.xml");
+		if (dotContextXml==null || !dotContextXml.exists()) {
+			return false;
+		}
+		// then it is likely the pattern that corresponds to the case
+		// which we want to handle with this DirNode
+		return true;
+	}
+	
+	DirNode(JcrNode parent, Node domNode, IResource resource) {
+		super(parent, domNode, resource);
+		if (!isDirNode(resource)) {
+			throw new IllegalArgumentException("resource is not a DirNode: "+resource);
+		}
+	}
+	
+	@Override
+	protected void addChild(JcrNode jcrNode) {
+		final String shortName = getName().substring(0, getName().length()-4);
+		Set<JcrNode> c = new HashSet<JcrNode>(parent.children);
+		for (Iterator<JcrNode> it = c.iterator(); it.hasNext();) {
+			JcrNode node = it.next();
+			if (node.getName().equals(shortName)) {
+				// excellent, the parent contains a child which 
+				// matches the .dir pattern, so add this child there
+				node.addChild(jcrNode);
+				// but also hide this node from my parent
+				parent.hide(this);
+				return;
+			}
+		}
+		super.addChild(jcrNode);
+	}
+	
+	@Override
+	public boolean canBeOpenedInEditor() {
+		return false;
+	}
+	
+	@Override
+	public boolean canBeRenamed() {
+		return false;
+	}
+	
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1519984&r1=1519983&r2=1519984&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 11:21:52 2013
@@ -18,6 +18,7 @@ package org.apache.sling.ide.eclipse.ui.
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -97,6 +98,8 @@ public class JcrNode implements IAdaptab
 	private boolean resourceChildrenAdded = false;
 	
 	final ModifiableProperties properties = new ModifiableProperties(this);
+
+	final Set<JcrNode> hiddenChildren = new HashSet<JcrNode>();
 	
 	JcrNode() {
 		// for subclass use only
@@ -214,11 +217,26 @@ public class JcrNode implements IAdaptab
 		}
 		return children.size()>0 || members;
 	}
+	
+	public void hide(JcrNode node) {
+		hiddenChildren.add(node);
+	}
 
+	Object[] filterHiddenChildren(final Collection<JcrNode> collection) {
+		final Collection<JcrNode> values = new HashSet<JcrNode>(collection);
+		
+		for (Iterator<JcrNode> it = hiddenChildren.iterator(); it.hasNext();) {
+			final JcrNode hiddenNode = it.next();
+			values.remove(hiddenNode);
+		}
+		
+		return values.toArray();
+	}
+	
 	public Object[] getChildren() {
 		try {
 			if (resourceChildrenAdded) {
-				return children.toArray();
+				return filterHiddenChildren(children);
 			}
 			Map<String,JcrNode> resultMap = new HashMap<String, JcrNode>();
 			for (Iterator it = children.iterator(); it.hasNext();) {
@@ -254,7 +272,12 @@ public class JcrNode implements IAdaptab
 					}
 					for (Iterator it = membersList.iterator(); it.hasNext();) {
 						IResource iResource = (IResource) it.next();
-						JcrNode node = new JcrNode(this, (Node)null, iResource);
+						JcrNode node;
+						if (DirNode.isDirNode(iResource)) {
+							node = new DirNode(this, (Node)null, iResource);
+						} else {
+							node = new JcrNode(this, (Node)null, iResource);
+						}
 //						node.setResource(iResource);
 						// load the children - to make sure we get vault files loaded too
 						node.getChildren();
@@ -265,7 +288,7 @@ public class JcrNode implements IAdaptab
 			}
 			resourceChildrenAdded = true;
 			
-			return resultMap.values().toArray();
+			return filterHiddenChildren(resultMap.values());
 		} catch (CoreException e) {
 			return new Object[0];
 		} catch (ParserConfigurationException e) {