001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.contrib.tree.model; 016 017 import java.util.Iterator; 018 019 /** 020 * The interface that defines a suitable data model for a 021 * <code>TreeView component</code>. 022 * 023 * @author ceco 024 */ 025 public interface ITreeDataModel 026 { 027 028 /** 029 * Returns the root node of the tree. 030 */ 031 Object getRoot(); 032 033 /** 034 * Returns the number of children of parent node. 035 * 036 * @param objParent 037 * is the parent object whose nr of children are sought 038 */ 039 int getChildCount(Object objParent); 040 041 /** 042 * Get an iterator to the Collection of children belonging to the parent 043 * node object. 044 * 045 * @param objParent 046 * is the parent object whose children are requested 047 */ 048 Iterator getChildren(Object objParent); 049 050 /** 051 * Get the actual node object based on some identifier (for example an UUID). 052 * 053 * @param objUniqueKey 054 * is the unique identifier of the node object being retrieved 055 * @return the instance of the node object identified by the key 056 */ 057 Object getObject(Object objUniqueKey); 058 059 /** 060 * Get the unique identifier (UUID) of the node object with a certain parent 061 * node. 062 * 063 * @param objTarget 064 * is the Object whose identifier is required 065 * @param objParentUniqueKey 066 * is the unique id of the parent of objTarget 067 * @return the unique identifier of objTarget 068 */ 069 Object getUniqueKey(Object objTarget, Object objParentUniqueKey); 070 071 /** 072 * Get the unique identifier of the parent of an object. 073 * 074 * @param objChildUniqueKey 075 * is the identifier of the Object for which the parent 076 * identifier is sought 077 * @return the identifier (possibly UUID) of the parent of objChildUniqueKey 078 */ 079 Object getParentUniqueKey(Object objChildUniqueKey); 080 081 /** 082 * Check to see (on the basis of some node object identifier) whether the 083 * parent node is indeed the parent of the object. 084 * 085 * @param objChildUniqueKey 086 * is the identifier of the object whose parent is being checked 087 * @param objParentUniqueKey 088 * is the identifier of the parent which is to be checked against 089 */ 090 boolean isAncestorOf(Object objChildUniqueKey, Object objParentUniqueKey); 091 092 }