KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > gui > SchemaTreeModel


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/gui/SchemaTreeModel.java#13 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2007 Julian Hyde and others
7 // Copyright (C) 2006-2007 CINCOM SYSTEMS, INC.
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 */

11 package mondrian.gui;
12
13 import javax.swing.tree.TreePath JavaDoc;
14
15 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
16 import javax.swing.tree.DefaultTreeModel JavaDoc;
17 import java.util.Vector JavaDoc;
18
19 /**
20  *
21  * @author sean
22  * @version $Id: //open/mondrian/src/main/mondrian/gui/SchemaTreeModel.java#13 $
23  */

24 public class SchemaTreeModel extends DefaultTreeModel JavaDoc {
25     public SchemaTreeModel() {
26         super(null);
27         // TODO Auto-generated constructor stub
28
}
29
30     MondrianGuiDef.Schema schema;
31     private Vector JavaDoc treeModelListeners = new Vector JavaDoc();
32
33     /** Creates a new instance of SchemaTreeModel */
34     public SchemaTreeModel(MondrianGuiDef.Schema s) {
35         super(new DefaultMutableTreeNode JavaDoc(s.name));
36         this.schema = s;
37     }
38
39
40     /** Returns the child of <code>parent</code> at index <code>index</code>
41      * in the parent's
42      * child array. <code>parent</code> must be a node previously obtained
43      * from this data source. This should not return <code>null</code>
44      * if <code>index</code>
45      * is a valid index for <code>parent</code> (that is <code>index >= 0 &&
46      * index < getChildCount(parent</code>)).
47      *
48      * @param parent a node in the tree, obtained from this data source
49      * @return the child of <code>parent</code> at index <code>index</code>
50      *
51      */

52     public Object JavaDoc getChild(Object JavaDoc parent, int index) {
53         if (parent instanceof MondrianGuiDef.Column) {
54             MondrianGuiDef.Column c = (MondrianGuiDef.Column)parent;
55         } else if (parent instanceof MondrianGuiDef.Cube) {
56             MondrianGuiDef.Cube c = (MondrianGuiDef.Cube)parent;
57             //return children in this order: fact table, dimensions, measures, calculatedMembers, namedSets
58
if (1>index) {
59                 return c.fact;
60             } else if (1+ c.dimensions.length > index) {
61                 return c.dimensions[index -1 ];
62             } else if (1+ c.measures.length + c.dimensions.length > index) {
63                 return c.measures[index - c.dimensions.length -1];
64             } else if (1+ c.calculatedMembers.length + c.measures.length + c.dimensions.length > index) {
65                 return c.calculatedMembers[index - c.dimensions.length - c.measures.length -1];
66             } else if (1+ c.namedSets.length + c.calculatedMembers.length + c.measures.length + c.dimensions.length > index) {
67                 return c.namedSets[index - c.dimensions.length - c.measures.length - c.calculatedMembers.length -1];
68             }
69         } else if (parent instanceof MondrianGuiDef.Dimension) {
70             MondrianGuiDef.Dimension d = (MondrianGuiDef.Dimension)parent;
71             if (d.hierarchies.length > index) {
72                 return d.hierarchies[index];
73             }
74         } else if (parent instanceof MondrianGuiDef.DimensionUsage) {
75             MondrianGuiDef.DimensionUsage c = (MondrianGuiDef.DimensionUsage)parent;
76
77         } else if (parent instanceof MondrianGuiDef.ExpressionView) {
78             MondrianGuiDef.ExpressionView ev = (MondrianGuiDef.ExpressionView)parent;
79             if (ev.expressions.length > index) {
80                 return ev.expressions[index];
81             }
82         } else if (parent instanceof MondrianGuiDef.Hierarchy) {
83             MondrianGuiDef.Hierarchy h = (MondrianGuiDef.Hierarchy)parent;
84             //return children in this order: levels, memberReaderParameters, relation
85
if (h.levels.length > index) {
86                 return h.levels[index];
87             } else if (h.memberReaderParameters.length + h.levels.length > index) {
88                 return h.memberReaderParameters[index - h.levels.length];
89             } else if (1 + h.memberReaderParameters.length + h.levels.length > index) {
90                 return h.relation;
91             }
92         } else if (parent instanceof MondrianGuiDef.Join) {
93             MondrianGuiDef.Join j = (MondrianGuiDef.Join)parent;
94             if (index==0) {
95                 return j.left;
96             } else if (index==1) {
97                 return j.right;
98             }
99         } else if (parent instanceof MondrianGuiDef.Level) {
100             MondrianGuiDef.Level l = (MondrianGuiDef.Level)parent;
101             if (l.properties != null && l.properties.length > index) {
102                 return l.properties[index];
103             }
104             int otherIndex = 0;
105             if (l.properties != null) {
106                 otherIndex = index - l.properties.length;
107             }
108             if (otherIndex >= 0) {
109                 int counter = 0;
110                 if (l.keyExp != null) {
111                     if (counter == otherIndex) {
112                         return l.keyExp;
113                     }
114                     counter += 1;
115                 }
116                 if (l.nameExp != null) {
117                     if (counter == otherIndex) {
118                         return l.nameExp;
119                     }
120                     counter += 1;
121                 }
122                 if (l.ordinalExp != null) {
123                     if (counter == otherIndex) {
124                         return l.ordinalExp;
125                     }
126                     counter += 1;
127                 }
128                 if (l.parentExp != null) {
129                     if (counter == otherIndex) {
130                         return l.parentExp;
131                     }
132                 }
133                 if (l.closure != null) {
134                     return l.closure;
135                 }
136             }
137         } else if (parent instanceof MondrianGuiDef.CalculatedMember) {
138             MondrianGuiDef.CalculatedMember l = (MondrianGuiDef.CalculatedMember)parent;
139             if (l.memberProperties.length > index) {
140                 return l.memberProperties[index];
141             }
142         } else if (parent instanceof MondrianGuiDef.Measure) {
143             MondrianGuiDef.Measure m = (MondrianGuiDef.Measure)parent;
144             if (m.measureExp != null) {
145                 return m.measureExp;
146             }
147         /*
148         } else if (parent instanceof MondrianGuiDef.MemberReaderParameter) {
149             MondrianGuiDef.MemberReaderParameter p = (MondrianGuiDef.MemberReaderParameter)parent;
150         } else if (parent instanceof MondrianGuiDef.Property) {
151             MondrianGuiDef.Property p = (MondrianGuiDef.Property)parent;
152         }
153         */

154         } else if (parent instanceof MondrianGuiDef.Schema) {
155             MondrianGuiDef.Schema s = (MondrianGuiDef.Schema)parent;
156             //return children in this order: cubes, dimensions, namedSets, userDefinedFunctions, virtual cubes, roles
157
if (s.cubes.length > index) {
158                 return s.cubes[index];
159             } else if (s.dimensions.length + s.cubes.length > index) {
160                 return s.dimensions[index - s.cubes.length ];
161             } else if (s.namedSets.length + s.dimensions.length + s.cubes.length > index) {
162                 return s.namedSets[index - s.cubes.length - s.dimensions.length];
163             } else if (s.userDefinedFunctions.length + s.namedSets.length + s.dimensions.length + s.cubes.length > index) {
164                 return s.userDefinedFunctions[index - s.cubes.length - s.dimensions.length - s.namedSets.length];
165             } else if (s.virtualCubes.length + s.userDefinedFunctions.length + s.namedSets.length + s.dimensions.length + s.cubes.length > index) {
166                 return s.virtualCubes[index - s.cubes.length - s.dimensions.length - s.namedSets.length - s.userDefinedFunctions.length];
167             } else if (s.roles.length + s.virtualCubes.length + s.userDefinedFunctions.length + s.namedSets.length + s.dimensions.length + s.cubes.length > index) {
168                 return s.roles[index - s.cubes.length - s.dimensions.length - s.namedSets.length - s.userDefinedFunctions.length - s.virtualCubes.length];
169             }
170         } else if (parent instanceof MondrianGuiDef.SQL) {
171             MondrianGuiDef.SQL s = (MondrianGuiDef.SQL)parent;
172         } else if (parent instanceof MondrianGuiDef.Table) {
173             MondrianGuiDef.Table t = (MondrianGuiDef.Table)parent;
174             if (t.aggTables.length > index) {
175                 return t.aggTables[index];
176             } else if (t.aggExcludes.length + t.aggTables.length > index) {
177                 return t.aggExcludes[index - t.aggTables.length ];
178             }
179         } else if (parent instanceof MondrianGuiDef.AggTable) {
180             MondrianGuiDef.AggTable t = (MondrianGuiDef.AggTable)parent;
181             int fc = 0;
182             if (t.factcount != null) {
183                 fc = 1;
184             }
185             if (1 > index && fc == 1) {
186                 return t.factcount;
187             } else if (fc + t.ignoreColumns.length > index) {
188                 return t.ignoreColumns[index - fc];
189             } else if (fc + t.foreignKeys.length + t.ignoreColumns.length > index) {
190                 return t.foreignKeys[index - t.ignoreColumns.length - fc];
191             } else if (fc + t.measures.length + t.foreignKeys.length + t.ignoreColumns.length > index) {
192                 return t.measures[index - t.ignoreColumns.length - t.foreignKeys.length - fc];
193             } else if (fc + t.levels.length + t.measures.length + t.foreignKeys.length + t.ignoreColumns.length > index) {
194                 return t.levels[index - t.ignoreColumns.length - t.foreignKeys.length - t.measures.length - fc];
195             } else if (t instanceof MondrianGuiDef.AggPattern) {
196                 if ( ((MondrianGuiDef.AggPattern) t).excludes.length + t.levels.length + t.measures.length + t.foreignKeys.length + t.ignoreColumns.length + fc > index) {
197                     return ((MondrianGuiDef.AggPattern) t).excludes[index - t.ignoreColumns.length - t.foreignKeys.length - t.measures.length - t.levels.length - fc];
198                 }
199             }
200         } else if (parent instanceof MondrianGuiDef.View) {
201             MondrianGuiDef.View v = (MondrianGuiDef.View)parent;
202             if (v.selects.length > index) {
203                 return v.selects[index];
204             }
205         } else if (parent instanceof MondrianGuiDef.VirtualCube) {
206             MondrianGuiDef.VirtualCube c = (MondrianGuiDef.VirtualCube)parent;
207             //return children in this order: dimensions, measures
208
if (c.dimensions.length > index) {
209                 return c.dimensions[index];
210             } else if (c.measures.length + c.dimensions.length > index) {
211                 return c.measures[index - c.dimensions.length];
212             } else if (c.calculatedMembers.length + c.measures.length + c.dimensions.length > index) {
213                 return c.calculatedMembers[index - c.dimensions.length - c.measures.length];
214             }
215         } else if (parent instanceof MondrianGuiDef.VirtualCubeDimension) {
216             MondrianGuiDef.VirtualCubeDimension vcd = (MondrianGuiDef.VirtualCubeDimension)parent;
217         } else if (parent instanceof MondrianGuiDef.VirtualCubeMeasure) {
218             MondrianGuiDef.VirtualCubeMeasure vcd = (MondrianGuiDef.VirtualCubeMeasure)parent;
219         } else if (parent instanceof MondrianGuiDef.Role) {
220             MondrianGuiDef.Role c = (MondrianGuiDef.Role)parent;
221             //return children in this order: schemagrant
222
if (c.schemaGrants.length > index) {
223                 return c.schemaGrants[index];
224             }
225         } else if (parent instanceof MondrianGuiDef.SchemaGrant) {
226             MondrianGuiDef.SchemaGrant c = (MondrianGuiDef.SchemaGrant)parent;
227             //return children in this order: cubegrant
228
if (c.cubeGrants.length > index) {
229                 return c.cubeGrants[index];
230             }
231         } else if (parent instanceof MondrianGuiDef.CubeGrant) {
232             MondrianGuiDef.CubeGrant c = (MondrianGuiDef.CubeGrant)parent;
233             //return children in this order: dimensiongrant, hierarchygrant
234
if (c.dimensionGrants.length > index) {
235                 return c.dimensionGrants[index];
236             } else if (c.hierarchyGrants.length + c.dimensionGrants.length > index) {
237                 return c.hierarchyGrants[index - c.dimensionGrants.length];
238             }
239         } else if (parent instanceof MondrianGuiDef.HierarchyGrant) {
240             MondrianGuiDef.HierarchyGrant c = (MondrianGuiDef.HierarchyGrant)parent;
241             //return children in this order: membergrant
242
if (c.memberGrants.length > index) {
243                 return c.memberGrants[index];
244             }
245         } else if (parent instanceof MondrianGuiDef.Closure) {
246             MondrianGuiDef.Closure c = (MondrianGuiDef.Closure)parent;
247             if (c.table != null) {
248                 return c.table;
249             }
250         }
251         return null;
252     }
253
254     /** Returns the number of children of <code>parent</code>.
255      * Returns 0 if the node
256      * is a leaf or if it has no children. <code>parent</code> must be a node
257      * previously obtained from this data source.
258      *
259      * @param parent a node in the tree, obtained from this data source
260      * @return the number of children of the node <code>parent</code>
261      *
262      */

263     public int getChildCount(Object JavaDoc parent) {
264         int childCount = 0;
265         if (parent instanceof MondrianGuiDef.Cube) {
266             MondrianGuiDef.Cube c = (MondrianGuiDef.Cube)parent;
267             if( c.fact != null) {childCount += 1; }
268             if( c.dimensions != null ) {childCount += c.dimensions.length;}
269             if( c.measures != null ) { childCount += c.measures.length;}
270             if( c.calculatedMembers != null ) {childCount += c.calculatedMembers.length;}
271             if( c.namedSets != null ) {childCount += c.namedSets.length;}
272         } else if (parent instanceof MondrianGuiDef.Dimension) {
273             MondrianGuiDef.Dimension d = (MondrianGuiDef.Dimension)parent;
274             if( d.hierarchies != null ) {childCount += d.hierarchies.length;}
275         } else if (parent instanceof MondrianGuiDef.ExpressionView) {
276             MondrianGuiDef.ExpressionView ev = (MondrianGuiDef.ExpressionView)parent;
277             if( ev.expressions != null ) {childCount = ev.expressions.length;}
278
279         } else if (parent instanceof MondrianGuiDef.Hierarchy) {
280             MondrianGuiDef.Hierarchy h = (MondrianGuiDef.Hierarchy)parent;
281             if( h.memberReaderParameters != null ) {childCount += h.memberReaderParameters.length;}
282             if( h.levels != null ) {childCount += h.levels.length;}
283             if(h.relation != null) {childCount += 1;}
284         } else if (parent instanceof MondrianGuiDef.Join) {
285             //MondrianGuiDef.Join j = (MondrianGuiDef.Join)parent;
286
childCount += 2;
287         } else if (parent instanceof MondrianGuiDef.Table) {
288             MondrianGuiDef.Table h = (MondrianGuiDef.Table)parent;
289             if( h.aggTables != null ) {childCount += h.aggTables.length;}
290             if( h.aggExcludes != null ) {childCount += h.aggExcludes.length;}
291         } else if (parent instanceof MondrianGuiDef.AggTable) {
292             MondrianGuiDef.AggTable h = (MondrianGuiDef.AggTable)parent;
293             if( h.factcount != null ) {childCount += 1;}
294             if( h.ignoreColumns != null ) {childCount += h.ignoreColumns.length;}
295             if( h.foreignKeys != null ) {childCount += h.foreignKeys.length;}
296             if( h.measures != null ) {childCount += h.measures.length;}
297             if( h.levels != null ) {childCount += h.levels.length;}
298             if (parent instanceof MondrianGuiDef.AggPattern) {
299                 if( ((MondrianGuiDef.AggPattern)h).excludes != null ) {childCount += ((MondrianGuiDef.AggPattern)h).excludes.length;}
300             }
301         } else if (parent instanceof MondrianGuiDef.Level) {
302             MondrianGuiDef.Level l = (MondrianGuiDef.Level)parent;
303             if( l.properties != null ) {childCount = l.properties.length;}
304             if(l.keyExp != null) {childCount += 1;}
305             if(l.nameExp != null) {childCount += 1;}
306             if(l.ordinalExp != null) {childCount += 1;}
307             if(l.parentExp != null) {childCount += 1;}
308             if(l.closure != null) {childCount += 1;}
309         } else if (parent instanceof MondrianGuiDef.CalculatedMember) {
310             MondrianGuiDef.CalculatedMember l = (MondrianGuiDef.CalculatedMember)parent;
311             if( l.memberProperties != null ) {childCount = l.memberProperties.length;}
312         } else if (parent instanceof MondrianGuiDef.Schema) {
313             //return children in this order: cubes, dimensions, namedSets, userDefinedFunctions, virtual cubes, roles
314
MondrianGuiDef.Schema s = (MondrianGuiDef.Schema)parent;
315             if( s.cubes != null ) {childCount += s.cubes.length;}
316             if( s.dimensions != null ) {childCount += s.dimensions.length;}
317             if( s.namedSets != null ) {childCount += s.namedSets.length;}
318             if( s.userDefinedFunctions != null ) {childCount += s.userDefinedFunctions.length;}
319             if( s.virtualCubes != null ) {childCount += s.virtualCubes.length;}
320             if( s.roles != null ) {childCount += s.roles.length;}
321         } else if (parent instanceof MondrianGuiDef.View) {
322             MondrianGuiDef.View v = (MondrianGuiDef.View)parent;
323             if( v.selects != null ) {childCount += v.selects.length;}
324         } else if (parent instanceof MondrianGuiDef.VirtualCube) {
325             MondrianGuiDef.VirtualCube c = (MondrianGuiDef.VirtualCube)parent;
326             if( c.dimensions != null ) {childCount += c.dimensions.length;}
327             if( c.measures != null ) {childCount += c.measures.length;}
328             if( c.calculatedMembers != null ) {childCount += c.calculatedMembers.length;}
329         } else if (parent instanceof MondrianGuiDef.Role) {
330             MondrianGuiDef.Role c = (MondrianGuiDef.Role)parent;
331             if( c.schemaGrants != null ) {childCount += c.schemaGrants.length;}
332         } else if (parent instanceof MondrianGuiDef.SchemaGrant) {
333             MondrianGuiDef.SchemaGrant c = (MondrianGuiDef.SchemaGrant)parent;
334             if( c.cubeGrants != null ) {childCount += c.cubeGrants.length;}
335         } else if (parent instanceof MondrianGuiDef.CubeGrant) {
336             MondrianGuiDef.CubeGrant c = (MondrianGuiDef.CubeGrant)parent;
337             if( c.dimensionGrants != null ) {childCount += c.dimensionGrants.length;}
338             if( c.hierarchyGrants != null ) {childCount += c.hierarchyGrants.length;}
339         } else if (parent instanceof MondrianGuiDef.HierarchyGrant) {
340             MondrianGuiDef.HierarchyGrant c = (MondrianGuiDef.HierarchyGrant)parent;
341             if( c.memberGrants != null ) {childCount += c.memberGrants.length;}
342         } else if (parent instanceof MondrianGuiDef.Closure) {
343             MondrianGuiDef.Closure c = (MondrianGuiDef.Closure)parent;
344             if( c.table != null ) {childCount += 1;}
345         } else if (parent instanceof MondrianGuiDef.Measure) {
346             MondrianGuiDef.Measure m = (MondrianGuiDef.Measure)parent;
347             if(m.measureExp != null) {childCount += 1;}
348         }
349         return childCount;
350     }
351
352     /** Returns the index of child in parent. If <code>parent</code>
353      * is <code>null</code> or <code>child</code> is <code>null</code>,
354      * returns -1.
355      *
356      * @param parent a note in the tree, obtained from this data source
357      * @param child the node we are interested in
358      * @return the index of the child in the parent, or -1 if either
359      * <code>child</code> or <code>parent</code> are <code>null</code>
360      *
361      */

362     public int getIndexOfChild(Object JavaDoc parent, Object JavaDoc child) {
363         if (parent instanceof MondrianGuiDef.Column) {
364             return -1;
365         } else if (parent instanceof MondrianGuiDef.Cube) {
366             MondrianGuiDef.Cube c = (MondrianGuiDef.Cube)parent;
367             if (child instanceof MondrianGuiDef.Relation) {
368                 if (c.fact.equals(child)) {
369                     return 0;
370                 }
371                 return -1;
372             } else if (child instanceof MondrianGuiDef.CubeDimension) {
373                 for (int i=0; i<c.dimensions.length; i++) {
374                     if (c.dimensions[i].equals(child) && (c.dimensions[i]==child) ) {
375                         // check equality of parent class attributes
376
MondrianGuiDef.CubeDimension match = (MondrianGuiDef.CubeDimension) c.dimensions[i];
377                         MondrianGuiDef.CubeDimension d = (MondrianGuiDef.CubeDimension) child;
378                         if ( ((match.name== null && d.name==null) || ( match.name != null && match.name.equals(d.name) )) &&
379                                 ((match.caption== null && d.caption==null) || ( match.caption != null && match.caption.equals(d.name) )) &&
380                                 ((match.foreignKey== null && d.foreignKey==null) || ( match.foreignKey != null && match.name.equals(d.foreignKey) )) ) {
381                             return i +1;
382                         }
383                     }
384                 }
385                 return -1;
386             } else if (child instanceof MondrianGuiDef.Measure) {
387                 for (int i=0; i<c.measures.length; i++) {
388                     if (c.measures[i].equals(child)) {
389                         return i + c.dimensions.length +1;}
390                 }
391                 return -1;
392             } else if (child instanceof MondrianGuiDef.CalculatedMember) {
393                 for (int i=0; i<c.calculatedMembers.length; i++) {
394                     if (c.calculatedMembers[i].equals(child)) {
395                         return i + c.measures.length + c.dimensions.length +1;}
396                 }
397                 return -1;
398             } else if (child instanceof MondrianGuiDef.NamedSet) {
399                 for (int i=0; i<c.namedSets.length; i++) {
400                     if (c.namedSets[i].equals(child)) {
401                         return i + c.calculatedMembers.length + c.measures.length + c.dimensions.length +1;}
402                 }
403                 return -1;
404             } else {
405                 return -1;
406             }
407         } else if (parent instanceof MondrianGuiDef.Dimension) {
408             MondrianGuiDef.Dimension d = (MondrianGuiDef.Dimension)parent;
409             if (child instanceof MondrianGuiDef.Hierarchy) {
410                 for (int i=0; i<d.hierarchies.length; i++) {
411                     if (d.hierarchies[i].equals(child) && (d.hierarchies[i]==child)) {
412                         return i;}
413                 }
414                 return -1;
415             } else {
416                 return -1;
417             }
418         } else if (parent instanceof MondrianGuiDef.ExpressionView) {
419             MondrianGuiDef.ExpressionView ev = (MondrianGuiDef.ExpressionView)parent;
420             if (child instanceof MondrianGuiDef.SQL) {
421                 for (int i=0; i<ev.expressions.length; i++) {
422                     // if (ev.expressions[i].equals(child)) {
423
if (ev.expressions[i] == child) { // object reference is equal
424
return i;}
425                 }
426                 return -1;
427             } else {
428                 return -1;
429             }
430         } else if (parent instanceof MondrianGuiDef.Hierarchy) {
431             MondrianGuiDef.Hierarchy h = (MondrianGuiDef.Hierarchy)parent;
432             if (child instanceof MondrianGuiDef.Level) {
433                 for (int i=0; i<h.levels.length; i++) {
434                     if (h.levels[i].equals(child)) {
435                         return i;}
436                 }
437                 return -1;
438             } else if (child instanceof MondrianGuiDef.MemberReaderParameter) {
439                 for (int i=0; i<h.memberReaderParameters.length; i++) {
440                     if (h.memberReaderParameters[i].equals(child)) {
441                         return i + h.levels.length;}
442                 }
443                 return -1;
444             } else if (child instanceof MondrianGuiDef.Relation) {
445                 if (h.relation.equals(child) && (h.relation == child) ) {
446                     return h.levels.length + h.memberReaderParameters.length; }
447                 return -1;
448             } else {
449                 return -1;
450             }
451         } else if (parent instanceof MondrianGuiDef.Level) {
452             MondrianGuiDef.Level l = (MondrianGuiDef.Level)parent;
453             int counter = 0;
454             if (l.properties != null) {
455                 counter = l.properties.length;
456             }
457             if (child instanceof MondrianGuiDef.Property) {
458                 for (int i=0; i<l.properties.length; i++) {
459                     if (l.properties[i].equals(child)) {
460                         return i;
461                     }
462                 }
463                 return -1;
464             }
465             if (child instanceof MondrianGuiDef.KeyExpression) {
466                 if (child.equals(l.keyExp)) {
467                     return counter;
468                 }
469                 return -1;
470             }
471             if (l.keyExp != null) { counter += 1; }
472             if (child instanceof MondrianGuiDef.NameExpression) {
473                 if (child.equals(l.nameExp)) {
474                     return counter;
475                 }
476                 return -1;
477             }
478             if (l.nameExp != null) { counter += 1; }
479             if (child instanceof MondrianGuiDef.OrdinalExpression) {
480                 if (child.equals(l.ordinalExp)) {
481                     return counter;
482                 }
483                 return -1;
484             }
485             if (l.ordinalExp != null) { counter += 1; }
486             if (child instanceof MondrianGuiDef.ParentExpression) {
487                 if (child.equals(l.parentExp)) {
488                     return counter;
489                 }
490                 return -1;
491             }
492             if (l.parentExp != null) { counter += 1; }
493             if (child instanceof MondrianGuiDef.Closure) {
494                 if (child.equals(l.closure)) {
495                     return counter;
496                 }
497                 return -1;
498             }
499             return -1;
500         } else if (parent instanceof MondrianGuiDef.Join) {
501             MondrianGuiDef.Join j = (MondrianGuiDef.Join)parent;
502             if (child instanceof MondrianGuiDef.Relation) {
503                 if (j.left.equals(child)) {
504                     return 0;
505                 } else if (j.right.equals(child)) {
506                     return 1;
507                 } else {
508                     return -1;
509                 }
510             } else {
511                 return -1;
512             }
513         } else if (parent instanceof MondrianGuiDef.Table) {
514             MondrianGuiDef.Table l = (MondrianGuiDef.Table)parent;
515             if (child instanceof MondrianGuiDef.AggTable) {
516                 for (int i=0; i<l.aggTables.length; i++) {
517                     if (l.aggTables[i].equals(child)) {
518                         return i;}
519                 }
520                 return -1;
521             } else if (child instanceof MondrianGuiDef.AggExclude) {
522                 for (int i=0; i<l.aggExcludes.length; i++) {
523                     if (l.aggExcludes[i].equals(child)) {
524                         return i + l.aggTables.length;}
525                 }
526                 return -1;
527             } else {
528                 return -1;
529             }
530         } else if (parent instanceof MondrianGuiDef.AggTable) {
531             MondrianGuiDef.AggTable l = (MondrianGuiDef.AggTable)parent;
532             if (child instanceof MondrianGuiDef.AggFactCount) {
533                 if (l.factcount.equals(child)) {
534                     return 0;
535                 }
536                 return -1;
537             } else if (child instanceof MondrianGuiDef.AggIgnoreColumn) {
538                 for (int i=0; i<l.ignoreColumns.length; i++) {
539                     if (l.ignoreColumns[i].equals(child)) {
540                         return i;}
541                 }
542                 return -1;
543             } else if (child instanceof MondrianGuiDef.AggForeignKey) {
544                 for (int i=0; i<l.foreignKeys.length; i++) {
545                     if (l.foreignKeys[i].equals(child)) {
546                         return i + l.ignoreColumns.length;}
547                 }
548                 return -1;
549             } else if (child instanceof MondrianGuiDef.AggMeasure) {
550                 for (int i=0; i<l.measures.length; i++) {
551                     if (l.measures[i].equals(child)) {
552                         return i + l.ignoreColumns.length + l.foreignKeys.length;}
553                 }
554                 return -1;
555             } else if (child instanceof MondrianGuiDef.AggLevel) {
556                 for (int i=0; i<l.levels.length; i++) {
557                     if (l.levels[i].equals(child)) {
558                         return i + l.ignoreColumns.length + l.foreignKeys.length + l.measures.length;}
559                 }
560                 return -1;
561             } else if (parent instanceof MondrianGuiDef.AggPattern &&
562                     child instanceof MondrianGuiDef.AggExclude) {
563                 for (int i=0; i<((MondrianGuiDef.AggPattern)l).excludes.length; i++) {
564                     if (((MondrianGuiDef.AggPattern)l).excludes[i].equals(child)) {
565                         return i + l.ignoreColumns.length + l.foreignKeys.length + l.measures.length + l.levels.length;}
566                 }
567                 return -1;
568             } else {
569                 return -1;
570             }
571         } else if (parent instanceof MondrianGuiDef.CalculatedMember) {
572             MondrianGuiDef.CalculatedMember l = (MondrianGuiDef.CalculatedMember)parent;
573             if (child instanceof MondrianGuiDef.CalculatedMemberProperty) {
574                 for (int i=0; i<l.memberProperties.length; i++) {
575                     if (l.memberProperties[i].equals(child)) {
576                         return i;}
577                 }
578                 return -1;
579             } else {
580                 return -1;
581             }
582         } else if (parent instanceof MondrianGuiDef.Measure) {
583             MondrianGuiDef.Measure m = (MondrianGuiDef.Measure)parent;
584             if (child instanceof MondrianGuiDef.MeasureExpression) {
585                 if (child.equals(m.measureExp)) {
586                     return 0;
587                 }
588                 return -1;
589             }
590             return -1;
591         } else if (parent instanceof MondrianGuiDef.Schema) {
592             //return children in this order: cubes, dimensions, namedSets, userDefinedFunctions, virtual cubes, roles
593
MondrianGuiDef.Schema s = (MondrianGuiDef.Schema)parent;
594             //return children in this order: cubes, virtual cubes, dimensions
595
if (child instanceof MondrianGuiDef.Cube) {
596                 for (int i=0; i<s.cubes.length; i++) {
597                     if (s.cubes[i].equals(child)) {
598                         return i;}
599                 }
600                 return -1;
601             } else if (child instanceof MondrianGuiDef.Dimension) {
602                 for (int i=0; i<s.dimensions.length; i++) {
603                     if (s.dimensions[i].equals(child)) {
604                         return i + s.cubes.length ;}
605                 }
606                 return -1;
607             } else if (child instanceof MondrianGuiDef.NamedSet) {
608                 for (int i=0; i<s.namedSets.length; i++) {
609                     if (s.namedSets[i].equals(child)) {
610                         return i + s.cubes.length + s.dimensions.length;}
611                 }
612                 return -1;
613             } else if (child instanceof MondrianGuiDef.UserDefinedFunction) {
614                 for (int i=0; i<s.userDefinedFunctions.length; i++) {
615                     if (s.userDefinedFunctions[i].equals(child)) {
616                         return i + s.cubes.length + s.dimensions.length + s.namedSets.length;}
617                 }
618                 return -1;
619             } else if (child instanceof MondrianGuiDef.VirtualCube) {
620                 for (int i=0; i<s.virtualCubes.length; i++) {
621                     if (s.virtualCubes[i].equals(child)) {
622                         return i + s.cubes.length + s.dimensions.length + s.namedSets.length + s.userDefinedFunctions.length;}
623                 }
624                 return -1;
625             } else if (child instanceof MondrianGuiDef.Role) {
626                 for (int i=0; i<s.roles.length; i++) {
627                     if (s.roles[i].equals(child)) {
628                         return i + s.cubes.length + s.dimensions.length + s.namedSets.length + s.userDefinedFunctions.length + s.virtualCubes.length;}
629                 }
630                 return -1;
631             } else {
632                 return -1;
633             }
634         } else if (parent instanceof MondrianGuiDef.View) {
635             MondrianGuiDef.View v = (MondrianGuiDef.View)parent;
636             if (child instanceof MondrianGuiDef.SQL) {
637                 for (int i=0; i<v.selects.length; i++) {
638                     if (v.selects[i].equals(child)) {
639                         return i;
640                     }
641                 }
642                 return -1;
643             }
644             return -1;
645         } else if (parent instanceof MondrianGuiDef.VirtualCube) {
646             MondrianGuiDef.VirtualCube c = (MondrianGuiDef.VirtualCube)parent;
647             if (child instanceof MondrianGuiDef.VirtualCubeDimension) {
648                 for (int i=0; i<c.dimensions.length; i++) {
649                     if (c.dimensions[i].equals(child)) {
650                         return i;}
651                 }
652                 return -1;
653             } else if (child instanceof MondrianGuiDef.VirtualCubeMeasure) {
654                 for (int i=0; i<c.measures.length; i++) {
655                     if (c.measures[i].equals(child)) {
656                         return i + c.dimensions.length;}
657                 }
658                 return -1;
659             } else if (child instanceof MondrianGuiDef.CalculatedMember) {
660                 for (int i=0; i<c.calculatedMembers.length; i++) {
661                     if (c.calculatedMembers[i].equals(child)) {
662                         return i + c.dimensions.length + c.measures.length;}
663                 }
664                 return -1;
665             } else {
666                 return -1;
667             }
668         } else if (parent instanceof MondrianGuiDef.VirtualCubeDimension) {
669             MondrianGuiDef.VirtualCubeDimension d = (MondrianGuiDef.VirtualCubeDimension)parent;
670             return -1;
671         } else if (parent instanceof MondrianGuiDef.VirtualCubeMeasure) {
672             MondrianGuiDef.VirtualCubeMeasure d = (MondrianGuiDef.VirtualCubeMeasure)parent;
673             return -1;
674         } else if (parent instanceof MondrianGuiDef.Role) {
675             MondrianGuiDef.Role c = (MondrianGuiDef.Role)parent;
676             if (child instanceof MondrianGuiDef.SchemaGrant) {
677                 for (int i=0; i<c.schemaGrants.length; i++) {
678                     if (c.schemaGrants[i].equals(child)) {
679                         return i;}
680                 }
681                 return -1;
682             } else {
683                 return -1;
684             }
685         } else if (parent instanceof MondrianGuiDef.SchemaGrant) {
686             MondrianGuiDef.SchemaGrant c = (MondrianGuiDef.SchemaGrant)parent;
687             if (child instanceof MondrianGuiDef.CubeGrant) {
688                 for (int i=0; i<c.cubeGrants.length; i++) {
689                     if (c.cubeGrants[i].equals(child)) {
690                         return i;}
691                 }
692                 return -1;
693             } else {
694                 return -1;
695             }
696         } else if (parent instanceof MondrianGuiDef.CubeGrant) {
697             MondrianGuiDef.CubeGrant c = (MondrianGuiDef.CubeGrant)parent;
698             if (child instanceof MondrianGuiDef.DimensionGrant) {
699                 for (int i=0; i<c.dimensionGrants.length; i++) {
700                     if (c.dimensionGrants[i].equals(child)) {
701                         return i;}
702                 }
703                 return -1;
704             } else if (child instanceof MondrianGuiDef.HierarchyGrant) {
705                 for (int i=0; i<c.hierarchyGrants.length; i++) {
706                     if (c.hierarchyGrants[i].equals(child)) {
707                         return i + c.dimensionGrants.length ;}
708                 }
709                 return -1;
710             } else {
711                 return -1;
712             }
713         } else if (parent instanceof MondrianGuiDef.HierarchyGrant) {
714             MondrianGuiDef.HierarchyGrant c = (MondrianGuiDef.HierarchyGrant)parent;
715             if (child instanceof MondrianGuiDef.MemberGrant) {
716                 for (int i=0; i<c.memberGrants.length; i++) {
717                     if (c.memberGrants[i].equals(child)) {
718                         return i;}
719                 }
720                 return -1;
721             } else {
722                 return -1;
723             }
724         } else if (parent instanceof MondrianGuiDef.Closure) {
725             MondrianGuiDef.Closure c = (MondrianGuiDef.Closure)parent;
726             if (child instanceof MondrianGuiDef.Table) {
727                 return 0;
728             } else {
729                 return -1;
730             }
731         } else {
732             return -1;
733         }
734     }
735
736     /** Returns the root of the tree. Returns <code>null</code>
737      * only if the tree has no nodes.
738      *
739      * @return the root of the tree
740      *
741      */

742     public Object JavaDoc getRoot() {
743         return schema;
744     }
745
746     /** Returns <code>true</code> if <code>node</code> is a leaf.
747      * It is possible for this method to return <code>false</code>
748      * even if <code>node</code> has no children.
749      * A directory in a filesystem, for example,
750      * may contain no files; the node representing
751      * the directory is not a leaf, but it also has no children.
752      *
753      * @param node a node in the tree, obtained from this data source
754      * @return true if <code>node</code> is a leaf
755      *
756      */

757     public boolean isLeaf(Object JavaDoc node) {
758         return getChildCount(node) == 0;
759     }
760
761     public void valueForPathChanged(TreePath JavaDoc path, Object JavaDoc newValue) {
762         //super.valueForPathChanged(path, newValue);
763
}
764
765 }
766
767 // End SchemaTreeModel.java
768
Popular Tags