Author: stefanegli
Date: Fri Sep 20 08:44:28 2013
New Revision: 1524945

URL: http://svn.apache.org/r1524945
Log:
SLING-2985 : content-browser improvement: fixed ordering of nodes - it now 
respects the order as contained in .content.xml (vs alphabetic ordering before)

Added:
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/Sorter.java
   (with props)
Modified:
    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/JcrContentContentProvider.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
    
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/plugin.xml
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/plugin.xml?rev=1524945&r1=1524944&r2=1524945&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 20 
08:44:28 2013
@@ -220,6 +220,16 @@
            policy="InvokeAlwaysRegardlessOfSuppressedExt"
            suppressedExtensionId="org.eclipse.ui.navigator.resourceContent">
      </override>
+     <commonSorter
+           class="org.apache.sling.ide.eclipse.ui.nav.Sorter">
+        <parentExpression>
+           <or>
+              <adapt
+                    type="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+              </adapt>
+           </or>
+        </parentExpression>
+     </commonSorter>
         
       </navigatorContent>
    </extension>

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java?rev=1524945&r1=1524944&r2=1524945&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/JcrContentContentProvider.java
 Fri Sep 20 08:44:28 2013
@@ -114,7 +114,7 @@ public class JcrContentContentProvider i
                        return projectGetChildren((IProject)parentElement);
                } else if (parentElement instanceof JcrNode) {
                        JcrNode node = (JcrNode)parentElement;
-                       return node.getChildren();
+                       return node.getChildren(true);
                } else {
                        return null;
                }

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/Sorter.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/Sorter.java?rev=1524945&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/Sorter.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/Sorter.java
 Fri Sep 20 08:44:28 2013
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import java.text.Collator;
+
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+public class Sorter extends ViewerSorter {
+
+       public Sorter() {
+       }
+
+       public Sorter(Collator collator) {
+               super(collator);
+       }
+       
+       @Override
+       public int compare(Viewer viewer, Object e1, Object e2) {
+               if (!(e1 instanceof JcrNode) || !(e2 instanceof JcrNode)) {
+                       return super.compare(viewer, e1, e2);
+               }
+               JcrNode node1 = (JcrNode) e1;
+               JcrNode node2 = (JcrNode) e2;
+               JcrNode parent = node1.getParent();
+               Object[] children = parent.getChildren(false);
+               for (int i = 0; i < children.length; i++) {
+                       Object aChild = children[i];
+                       if (aChild==node1) {
+                               return -1;
+                       } else if (aChild==node2) {
+                               return 1;
+                       }
+               }
+               return 0;
+       }
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/Sorter.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/DirNode.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/DirNode.java?rev=1524945&r1=1524944&r2=1524945&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java
 Fri Sep 20 08:44:28 2013
@@ -85,7 +85,7 @@ public class DirNode extends JcrNode {
        @Override
        protected void addChild(JcrNode jcrNode) {
                JcrNode effectiveSibling = getEffectiveSibling();
-               if (effectiveSibling!=null) {
+               if (effectiveSibling!=this && effectiveSibling!=null) {
                        // excellent, the parent contains a child which 
                        // matches the .dir/_jcr_content pattern, so add this 
child there
                        effectiveSibling.addChild(jcrNode);
@@ -113,14 +113,7 @@ public class DirNode extends JcrNode {
                        }
                        nonDirNodeParent = nonDirNodeParent.parent;
                }
-               Set<JcrNode> c = new 
HashSet<JcrNode>(nonDirNodeParent.children);
-               for (Iterator<JcrNode> it = c.iterator(); it.hasNext();) {
-                       JcrNode node = it.next();
-                       if (node.getName().equals(decodedName)) {
-                               return node;
-                       }
-               }
-               return null;
+               return nonDirNodeParent.getChild(decodedName);
        }
 
        @Override

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.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/GenericJcrRootFile.java?rev=1524945&r1=1524944&r2=1524945&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
 Fri Sep 20 08:44:28 2013
@@ -148,14 +148,6 @@ public class GenericJcrRootFile extends 
                        // ignore
                        return;
                }
-               if (domNode.getAttributes().getLength() == 0) {
-                       // then ignore this empty node 
-                       // either there is a file or a folder corresponding to 
this element
-                       // (in which case it will show up again anyway) 
-                       // or just an empty node without any further attributes 
such
-                       // as primaryType doesn't help a lot
-                       return;
-               }
                JcrNode childJcrNode = new JcrNode(parent, domNode, this, null);
                handleProperties(domNode, childJcrNode.properties);
                NodeList children = domNode.getChildNodes();

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=1524945&r1=1524944&r2=1524945&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 20 08:44:28 2013
@@ -100,7 +100,7 @@ public class JcrNode implements IAdaptab
 
        JcrNode parent;
 
-       final Set<JcrNode> children = new HashSet<JcrNode>();
+       final List<JcrNode> children = new LinkedList<JcrNode>();
 
        Node domNode;
 
@@ -140,7 +140,7 @@ public class JcrNode implements IAdaptab
        
        @Override
        public String toString() {
-               return "JcrNode[dom:"+domNode+", file:"+resource+"]";
+               return "JcrNode[dom:"+domNode+", file:"+resource+", 
jcrPath:"+getJcrPath()+"]";
        }
        
        @Override
@@ -201,7 +201,19 @@ public class JcrNode implements IAdaptab
        }
 
        protected void addChild(JcrNode jcrNode) {
-               children.add(jcrNode);
+               if (!children.contains(jcrNode)) {
+                       // check to see if there is a same-named node though
+                       // that is the dom/resource case
+                       for (Iterator<JcrNode> it = children.iterator(); 
it.hasNext();) {
+                               JcrNode existingChild = it.next();
+                               if 
(existingChild.getName().equals(jcrNode.getName())) {
+                                       // then merge the two
+                                       
existingChild.setResource(jcrNode.resource);
+                                       return;
+                               }
+                       }
+                       children.add(jcrNode);
+               }
        }
 
        /** shown in the navigator (project explorer) as the label of this 
element **/
@@ -236,26 +248,60 @@ public class JcrNode implements IAdaptab
                hiddenChildren.add(node);
        }
 
-       Object[] filterHiddenChildren(final Collection<JcrNode> collection) {
-               final Collection<JcrNode> values = new 
HashSet<JcrNode>(collection);
+       Object[] filterHiddenChildren(final Collection<JcrNode> collection, 
boolean hideEmptyNodes) {
+               final Collection<JcrNode> values = new 
LinkedList<JcrNode>(collection);
                
                for (Iterator<JcrNode> it = hiddenChildren.iterator(); 
it.hasNext();) {
                        final JcrNode hiddenNode = it.next();
                        values.remove(hiddenNode);
                }
+               if (hideEmptyNodes) {
+                       for (Iterator<JcrNode> it = values.iterator(); 
it.hasNext();) {
+                               JcrNode jcrNode = it.next();
+                               if (jcrNode.isEmptyNode()) {
+                                       it.remove();
+                               }
+                       }
+               }
                
                return values.toArray();
        }
        
-       public Object[] getChildren() {
+       private boolean isEmptyNode() {
+               if (resource!=null) {
+                       return false;
+               }
+               if (children.size()!=0) {
+                       return false;
+               }
+               if (domNode==null) {
+                       return true;
+               }
+               if (domNode.hasChildNodes()) {
+                       return false;
+               }
+               if (domNode.getAttributes().getLength()!=0) {
+                       return false;
+               }
+               return true;
+       }
+
+       public Object[] getChildren(boolean hideEmptyNodes) {
+               if (!resourceChildrenAdded) {
+                       initChildren();
+               }
+               return filterHiddenChildren(children, true);
+       }
+       
+       void initChildren() {
                try {
                        if (resourceChildrenAdded) {
-                               return filterHiddenChildren(children);
+                               throw new IllegalStateException("Children 
already loaded");
                        }
-                       Map<String,JcrNode> resultMap = new HashMap<String, 
JcrNode>();
+                       Set<String> childrenNames = new HashSet<String>();
                        for (Iterator it = children.iterator(); it.hasNext();) {
                                JcrNode node = (JcrNode) it.next();
-                               resultMap.put(node.getName(), node);
+                               childrenNames.add(node.getName());
                        }
                        
                        if (resource!=null && resource instanceof IFolder) {
@@ -276,14 +322,15 @@ public class JcrNode implements IAdaptab
                                                        for (Iterator it3 = 
children.iterator(); it3
                                                                        
.hasNext();) {
                                                                JcrNode node = 
(JcrNode) it3.next();
-                                                               if 
(!resultMap.containsKey(node.getName())) {
-                                                                       
resultMap.put(node.getName(), node);
+                                                               if 
(!childrenNames.contains(node.getName())) {
+                                                                       
childrenNames.add(node.getName());
                                                                }
                                                        }
                                                        
                                                        continue outerLoop;
                                                }
                                        }
+                                       List<JcrNode> newNodes = new 
LinkedList<JcrNode>();
                                        for (Iterator it = 
membersList.iterator(); it.hasNext();) {
                                                IResource iResource = 
(IResource) it.next();
                                                JcrNode node;
@@ -292,29 +339,27 @@ public class JcrNode implements IAdaptab
                                                } 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();
-                                               resultMap.put(node.getName(), 
node);
+                                               
childrenNames.add(node.getName());
+                                               newNodes.add(node);
                                                it.remove();
                                        }
+                                       for (Iterator<JcrNode> it = 
newNodes.iterator(); it
+                                                       .hasNext();) {
+                                               JcrNode jcrNode = it.next();
+                                               // load the children - to make 
sure we get vault files loaded too
+                                               jcrNode.initChildren();
+                                       }
                                }
                        }
                        resourceChildrenAdded = true;
-                       
-                       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];
                }
        }
 
@@ -401,7 +446,7 @@ public class JcrNode implements IAdaptab
        }
 
        private String getJcrContentProperty(String propertyKey) {
-               final Object[] chldrn = getChildren();
+               final Object[] chldrn = getChildren(false);
                for (int i = 0; i < chldrn.length; i++) {
                        JcrNode jcrNode = (JcrNode) chldrn[i];
                        if ("jcr:content".equals(jcrNode.getName())) {
@@ -601,7 +646,17 @@ public class JcrNode implements IAdaptab
        public JcrNode getParent() {
                return parent;
        }
-       
+
+       JcrNode getChild(String name) {
+               for (Iterator<JcrNode> it = children.iterator(); it.hasNext();) 
{
+                       JcrNode aChild = it.next();
+                       if (aChild.getName().equals(name)) {
+                               return aChild;
+                       }
+               }
+               return null;
+       }
+
        IResource getResource() {
                return resource;
        }


Reply via email to