You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2006/11/30 18:48:58 UTC
svn commit: r481012 - in
/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component:
TreeModel.java UITreeNodes.java
Author: lofwyr
Date: Thu Nov 30 09:48:56 2006
New Revision: 481012
URL: http://svn.apache.org/viewvc?view=rev&rev=481012
Log:
resolving svn problems
Added:
myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java (with props)
Modified:
myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java
Added: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java?view=auto&rev=481012
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java (added)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java Thu Nov 30 09:48:56 2006
@@ -0,0 +1,83 @@
+package org.apache.myfaces.tobago.component;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Collections;
+
+// todo: make more general (e.g. support other trees)
+public class TreeModel {
+
+ private static final Log LOG = LogFactory.getLog(TreeModel.class);
+
+ Map<String, DefaultMutableTreeNode> nodes = new HashMap<String, DefaultMutableTreeNode>();
+ List<String> keys = new ArrayList<String>();
+
+ public TreeModel(DefaultMutableTreeNode node) {
+ putNodes(node, "", 0);
+ }
+
+ private void putNodes(
+ DefaultMutableTreeNode node, String position, int index) {
+
+ if (node == null) { // XXX hotfix
+ LOG.warn("node is null");
+ return;
+ }
+
+ position += "_" + index;
+
+ keys.add(position);
+ nodes.put(position, node);
+
+ index = 0;
+ for (Enumeration e = node.children(); e.hasMoreElements();) {
+ DefaultMutableTreeNode subNode = (DefaultMutableTreeNode) e.nextElement();
+ putNodes(subNode, position, index);
+ index++;
+ }
+ }
+
+ public DefaultMutableTreeNode getNode(String pathIndex) {
+ return nodes.get(pathIndex);
+ }
+
+ public List<String> getPathIndexList() {
+ return Collections.unmodifiableList(keys);
+ }
+
+ public String getParentPathIndex(String pathIndex) {
+ int lastUnderscore = pathIndex.lastIndexOf('_');
+ switch (lastUnderscore) {
+ case -1:
+ throw new IllegalArgumentException();
+ case 0:
+ return null;
+ default:
+ return pathIndex.substring(0, lastUnderscore);
+ }
+ }
+}
Propchange: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/TreeModel.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java?view=diff&rev=481012&r1=481011&r2=481012
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java Thu Nov 30 09:48:56 2006
@@ -20,7 +20,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.model.TreeModel;
+import org.apache.myfaces.tobago.component.TreeModel;
import org.apache.myfaces.tobago.renderkit.RenderUtil;
import javax.faces.component.NamingContainer;