defaultHandler="org.argeo.jcr.ui.explorer.commands.SortChildNodes"
id="org.argeo.jcr.ui.explorer.sortChildNodes"
name="Sort node tree">
+ <!-- FIXME: default value does not work -->
<state
- id="org.argeo.jcr.ui.explorer.sortChildNodes.toggleState">
- <class class="org.eclipse.jface.commands.ToggleState">
+ id="org.argeo.jcr.ui.explorer.sortChildNodes.toggleState"
+ class="org.eclipse.ui.handlers.RegistryToggleState:true" >
+ <!-- <class class="org.eclipse.jface.commands.ToggleState">
<parameter
name="default"
value="true" />
- </class>
+ </class> -->
</state>
</command>
</extension>
<command
commandId="org.argeo.jcr.ui.explorer.sortChildNodes"
icon="icons/sort.gif"
- style="toggle"
+ style="toggle"
label="Sort child nodes"
tooltip="Warning: stopping to sort children nodes might enhance overall performances">
</command>
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Comparator;
import java.util.List;
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.UserJcrUtils;
import org.argeo.jcr.ui.explorer.model.RepositoriesElem;
import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
-import org.argeo.jcr.ui.explorer.utils.TreeObjectsComparator;
import org.argeo.util.security.Keyring;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
*/
final private Session userSession;
final private Keyring keyring;
- final private boolean sortChildren;
+ private boolean sortChildren;
// reference for cleaning
private SingleJcrNodeElem homeNode = null;
private RepositoriesElem repositoriesNode = null;
// Utils
- private TreeObjectsComparator itemComparator = new TreeObjectsComparator();
+ private TreeBrowserComparator itemComparator = new TreeBrowserComparator();
public NodeContentProvider(Session userSession, Keyring keyring,
RepositoryRegister repositoryRegister,
}
}
+ /**
+ * Sets whether the content provider should order the children nodes or not.
+ * It is user duty to call a full refresh of the tree after changing this
+ * parameter.
+ */
+ public void setSortChildren(boolean sortChildren) {
+ this.sortChildren = sortChildren;
+ }
+
public Object getParent(Object element) {
if (element instanceof TreeParent) {
return ((TreeParent) element).getParent();
}
}
-}
+ /**
+ * Specific comparator for this view. See spec in BUG :
+ * https://www.argeo.org/bugzilla/show_bug.cgi?id=139
+ */
+ private class TreeBrowserComparator implements Comparator<TreeParent> {
+
+ public int category(TreeParent element) {
+ if (element instanceof SingleJcrNodeElem) {
+ Node node = ((SingleJcrNodeElem) element).getNode();
+ try {
+ if (node.isNodeType(NodeType.NT_FOLDER))
+ return 5;
+ } catch (RepositoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return 10;
+ }
+
+ public int compare(TreeParent o1, TreeParent o2) {
+ int cat1 = category(o1);
+ int cat2 = category(o2);
+
+ if (cat1 != cat2) {
+ return cat1 - cat2;
+ }
+ return o1.getName().compareTo(o2.getName());
+ }
+ }
+}
\ No newline at end of file
*/
public class GenericJcrBrowser extends AbstractJcrBrowser {
public final static String ID = JcrExplorerPlugin.ID + ".browserView";
- private boolean sortChildNodes = false;
+ private boolean sortChildNodes = true;
/* DEPENDENCY INJECTION */
private Keyring keyring;
return nodesViewer;
}
+ /**
+ * Resets the tree content provider
+ *
+ * @param sortChildNodes
+ * if true the content provider will use a comparer to sort nodes
+ * that might slow down the display
+ * */
+ public void setSortChildNodes(boolean sortChildNodes) {
+ this.sortChildNodes = sortChildNodes;
+ ((NodeContentProvider) nodesViewer.getContentProvider())
+ .setSortChildren(sortChildNodes);
+ nodesViewer.setInput(getViewSite());
+ }
+
/** Notifies the current view that a node has been added */
public void nodeAdded(TreeParent parentNode) {
// insure that Ui objects have been correctly created:
getNodeViewer().expandToLevel(parentNode, 1);
}
- /** Notifies the current view that a node has been added */
+ /** Notifies the current view that a node has been removed */
public void nodeRemoved(TreeParent parentNode) {
IStructuredSelection newSel = new StructuredSelection(parentNode);
getNodeViewer().setSelection(newSel, true);
}
- public void setSortChildNodes(boolean sortChildNodes) {
- this.sortChildNodes = sortChildNodes;
- }
-
public boolean getSortChildNodes() {
return sortChildNodes;
}