001 /* 002 // $Id: //open/mondrian/src/main/mondrian/gui/SchemaTreeModel.java#16 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2002-2008 Julian Hyde and others 007 // Copyright (C) 2006-2007 CINCOM SYSTEMS, INC. 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 */ 011 package mondrian.gui; 012 013 import javax.swing.tree.TreePath; 014 015 import javax.swing.tree.DefaultMutableTreeNode; 016 import javax.swing.tree.DefaultTreeModel; 017 import java.util.Vector; 018 019 /** 020 * 021 * @author sean 022 * @version $Id: //open/mondrian/src/main/mondrian/gui/SchemaTreeModel.java#16 $ 023 */ 024 public class SchemaTreeModel extends DefaultTreeModel { 025 public SchemaTreeModel() { 026 super(null); 027 // TODO Auto-generated constructor stub 028 } 029 030 MondrianGuiDef.Schema schema; 031 private Vector treeModelListeners = new Vector(); 032 033 /** Creates a new instance of SchemaTreeModel */ 034 public SchemaTreeModel(MondrianGuiDef.Schema s) { 035 super(new DefaultMutableTreeNode(s.name)); 036 this.schema = s; 037 } 038 039 040 /** Returns the child of <code>parent</code> at index <code>index</code> 041 * in the parent's 042 * child array. <code>parent</code> must be a node previously obtained 043 * from this data source. This should not return <code>null</code> 044 * if <code>index</code> 045 * is a valid index for <code>parent</code> (that is <code>index >= 0 && 046 * index < getChildCount(parent</code>)). 047 * 048 * @param parent a node in the tree, obtained from this data source 049 * @return the child of <code>parent</code> at index <code>index</code> 050 * 051 */ 052 public Object getChild(Object parent, int index) { 053 if (parent instanceof MondrianGuiDef.Column) { 054 MondrianGuiDef.Column c = (MondrianGuiDef.Column)parent; 055 } else if (parent instanceof MondrianGuiDef.Cube) { 056 MondrianGuiDef.Cube c = (MondrianGuiDef.Cube)parent; 057 //return children in this order: fact table, dimensions, measures, calculatedMembers, namedSets 058 if (1 > index) { 059 return c.fact; 060 } else if (1 + c.dimensions.length > index) { 061 return c.dimensions[index - 1]; 062 } else if (1 + c.measures.length + c.dimensions.length > index) { 063 return c.measures[index - c.dimensions.length - 1]; 064 } else if (1 + c.calculatedMembers.length + c.measures.length + c.dimensions.length > index) { 065 return c.calculatedMembers[index - c.dimensions.length - c.measures.length - 1]; 066 } else if (1 + c.namedSets.length + c.calculatedMembers.length + c.measures.length + c.dimensions.length > index) { 067 return c.namedSets[index - c.dimensions.length - c.measures.length - c.calculatedMembers.length - 1]; 068 } 069 } else if (parent instanceof MondrianGuiDef.Dimension) { 070 MondrianGuiDef.Dimension d = (MondrianGuiDef.Dimension)parent; 071 if (d.hierarchies.length > index) { 072 return d.hierarchies[index]; 073 } 074 } else if (parent instanceof MondrianGuiDef.DimensionUsage) { 075 MondrianGuiDef.DimensionUsage c = (MondrianGuiDef.DimensionUsage)parent; 076 077 } else if (parent instanceof MondrianGuiDef.ExpressionView) { 078 MondrianGuiDef.ExpressionView ev = (MondrianGuiDef.ExpressionView)parent; 079 if (ev.expressions.length > index) { 080 return ev.expressions[index]; 081 } 082 } else if (parent instanceof MondrianGuiDef.Hierarchy) { 083 MondrianGuiDef.Hierarchy h = (MondrianGuiDef.Hierarchy)parent; 084 //return children in this order: levels, memberReaderParameters, relation 085 if (h.levels.length > index) { 086 return h.levels[index]; 087 } else if (h.memberReaderParameters.length + h.levels.length > index) { 088 return h.memberReaderParameters[index - h.levels.length]; 089 } else if (1 + h.memberReaderParameters.length + h.levels.length > index) { 090 return h.relation; 091 } 092 } else if (parent instanceof MondrianGuiDef.Join) { 093 MondrianGuiDef.Join j = (MondrianGuiDef.Join)parent; 094 if (index == 0) { 095 return j.left; 096 } else if (index == 1) { 097 return j.right; 098 } 099 } 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 parent) { 264 int childCount = 0; 265 if (parent instanceof MondrianGuiDef.Cube) { 266 MondrianGuiDef.Cube c = (MondrianGuiDef.Cube)parent; 267 if (c.fact != null) { 268 childCount += 1; 269 } 270 if (c.dimensions != null) { 271 childCount += c.dimensions.length; 272 } 273 if (c.measures != null) { 274 childCount += c.measures.length; 275 } 276 if (c.calculatedMembers != null) { 277 childCount += c.calculatedMembers.length; 278 } 279 if (c.namedSets != null) { 280 childCount += c.namedSets.length; 281 } 282 } else if (parent instanceof MondrianGuiDef.Dimension) { 283 MondrianGuiDef.Dimension d = (MondrianGuiDef.Dimension)parent; 284 if (d.hierarchies != null) { 285 childCount += d.hierarchies.length; 286 } 287 } else if (parent instanceof MondrianGuiDef.ExpressionView) { 288 MondrianGuiDef.ExpressionView ev = (MondrianGuiDef.ExpressionView)parent; 289 if (ev.expressions != null) { 290 childCount = ev.expressions.length; 291 } 292 } else if (parent instanceof MondrianGuiDef.Hierarchy) { 293 MondrianGuiDef.Hierarchy h = (MondrianGuiDef.Hierarchy)parent; 294 if (h.memberReaderParameters != null) { 295 childCount += h.memberReaderParameters.length; 296 } 297 if (h.levels != null) { 298 childCount += h.levels.length; 299 } 300 if (h.relation != null) { 301 childCount += 1; 302 } 303 } else if (parent instanceof MondrianGuiDef.Join) { 304 //MondrianGuiDef.Join j = (MondrianGuiDef.Join)parent; 305 childCount += 2; 306 } else if (parent instanceof MondrianGuiDef.Table) { 307 MondrianGuiDef.Table h = (MondrianGuiDef.Table)parent; 308 if (h.aggTables != null) { 309 childCount += h.aggTables.length; 310 } 311 if (h.aggExcludes != null) { 312 childCount += h.aggExcludes.length; 313 } 314 } else if (parent instanceof MondrianGuiDef.AggTable) { 315 MondrianGuiDef.AggTable h = (MondrianGuiDef.AggTable)parent; 316 if (h.factcount != null) { 317 childCount += 1; 318 } 319 if (h.ignoreColumns != null) { 320 childCount += h.ignoreColumns.length; 321 } 322 if (h.foreignKeys != null) { 323 childCount += h.foreignKeys.length; 324 } 325 if (h.measures != null) { 326 childCount += h.measures.length; 327 } 328 if (h.levels != null) { 329 childCount += h.levels.length; 330 } 331 if (parent instanceof MondrianGuiDef.AggPattern) { 332 if (((MondrianGuiDef.AggPattern)h).excludes != null) { 333 childCount += ((MondrianGuiDef.AggPattern)h).excludes.length; 334 } 335 } 336 } else if (parent instanceof MondrianGuiDef.Level) { 337 MondrianGuiDef.Level l = (MondrianGuiDef.Level)parent; 338 if (l.properties != null) { 339 childCount = l.properties.length; 340 } 341 if (l.keyExp != null) { 342 childCount += 1; 343 } 344 if (l.nameExp != null) { 345 childCount += 1; 346 } 347 if (l.ordinalExp != null) { 348 childCount += 1; 349 } 350 if (l.parentExp != null) { 351 childCount += 1; 352 } 353 if (l.closure != null) { 354 childCount += 1; 355 } 356 } else if (parent instanceof MondrianGuiDef.CalculatedMember) { 357 MondrianGuiDef.CalculatedMember l = (MondrianGuiDef.CalculatedMember)parent; 358 if (l.memberProperties != null) { 359 childCount = l.memberProperties.length; 360 } 361 } else if (parent instanceof MondrianGuiDef.Schema) { 362 //return children in this order: cubes, dimensions, namedSets, userDefinedFunctions, virtual cubes, roles 363 MondrianGuiDef.Schema s = (MondrianGuiDef.Schema)parent; 364 if (s.cubes != null) { 365 childCount += s.cubes.length; 366 } 367 if (s.dimensions != null) { 368 childCount += s.dimensions.length; 369 } 370 if (s.namedSets != null) { 371 childCount += s.namedSets.length; 372 } 373 if (s.userDefinedFunctions != null) { 374 childCount += s.userDefinedFunctions.length; 375 } 376 if (s.virtualCubes != null) { 377 childCount += s.virtualCubes.length; 378 } 379 if (s.roles != null) { 380 childCount += s.roles.length; 381 } 382 } else if (parent instanceof MondrianGuiDef.View) { 383 MondrianGuiDef.View v = (MondrianGuiDef.View)parent; 384 if (v.selects != null) { 385 childCount += v.selects.length; 386 } 387 } else if (parent instanceof MondrianGuiDef.VirtualCube) { 388 MondrianGuiDef.VirtualCube c = (MondrianGuiDef.VirtualCube)parent; 389 if (c.dimensions != null) { 390 childCount += c.dimensions.length; 391 } 392 if (c.measures != null) { 393 childCount += c.measures.length; 394 } 395 if (c.calculatedMembers != null) { 396 childCount += c.calculatedMembers.length; 397 } 398 } else if (parent instanceof MondrianGuiDef.Role) { 399 MondrianGuiDef.Role c = (MondrianGuiDef.Role)parent; 400 if (c.schemaGrants != null) { 401 childCount += c.schemaGrants.length; 402 } 403 } else if (parent instanceof MondrianGuiDef.SchemaGrant) { 404 MondrianGuiDef.SchemaGrant c = (MondrianGuiDef.SchemaGrant)parent; 405 if (c.cubeGrants != null) { 406 childCount += c.cubeGrants.length; 407 } 408 } else if (parent instanceof MondrianGuiDef.CubeGrant) { 409 MondrianGuiDef.CubeGrant c = (MondrianGuiDef.CubeGrant)parent; 410 if (c.dimensionGrants != null) { 411 childCount += c.dimensionGrants.length; 412 } 413 if (c.hierarchyGrants != null) { 414 childCount += c.hierarchyGrants.length; 415 } 416 } else if (parent instanceof MondrianGuiDef.HierarchyGrant) { 417 MondrianGuiDef.HierarchyGrant c = (MondrianGuiDef.HierarchyGrant)parent; 418 if (c.memberGrants != null) { 419 childCount += c.memberGrants.length; 420 } 421 } else if (parent instanceof MondrianGuiDef.Closure) { 422 MondrianGuiDef.Closure c = (MondrianGuiDef.Closure)parent; 423 if (c.table != null) { 424 childCount += 1; 425 } 426 } else if (parent instanceof MondrianGuiDef.Measure) { 427 MondrianGuiDef.Measure m = (MondrianGuiDef.Measure)parent; 428 if (m.measureExp != null) { 429 childCount += 1; 430 } 431 } 432 return childCount; 433 } 434 435 /** Returns the index of child in parent. If <code>parent</code> 436 * is <code>null</code> or <code>child</code> is <code>null</code>, 437 * returns -1. 438 * 439 * @param parent a note in the tree, obtained from this data source 440 * @param child the node we are interested in 441 * @return the index of the child in the parent, or -1 if either 442 * <code>child</code> or <code>parent</code> are <code>null</code> 443 * 444 */ 445 public int getIndexOfChild(Object parent, Object child) { 446 if (parent instanceof MondrianGuiDef.Column) { 447 return -1; 448 } else if (parent instanceof MondrianGuiDef.Cube) { 449 MondrianGuiDef.Cube c = (MondrianGuiDef.Cube)parent; 450 if (child instanceof MondrianGuiDef.RelationOrJoin) { 451 if (c.fact.equals(child)) { 452 return 0; 453 } 454 return -1; 455 } else if (child instanceof MondrianGuiDef.CubeDimension) { 456 for (int i = 0; i < c.dimensions.length; i++) { 457 if (c.dimensions[i].equals(child) && (c.dimensions[i] == child)) { 458 // check equality of parent class attributes 459 MondrianGuiDef.CubeDimension match = (MondrianGuiDef.CubeDimension) c.dimensions[i]; 460 MondrianGuiDef.CubeDimension d = (MondrianGuiDef.CubeDimension) child; 461 if (((match.name == null && d.name == null) || (match.name != null && match.name.equals(d.name))) && 462 ((match.caption == null && d.caption == null) || (match.caption != null && match.caption.equals(d.name))) && 463 ((match.foreignKey == null && d.foreignKey == null) || (match.foreignKey != null && match.name.equals(d.foreignKey)))) { 464 return i + 1; 465 } 466 } 467 } 468 return -1; 469 } else if (child instanceof MondrianGuiDef.Measure) { 470 for (int i = 0; i < c.measures.length; i++) { 471 if (c.measures[i].equals(child)) { 472 return i + c.dimensions.length + 1;} 473 } 474 return -1; 475 } else if (child instanceof MondrianGuiDef.CalculatedMember) { 476 for (int i = 0; i < c.calculatedMembers.length; i++) { 477 if (c.calculatedMembers[i].equals(child)) { 478 return i + c.measures.length + c.dimensions.length + 1;} 479 } 480 return -1; 481 } else if (child instanceof MondrianGuiDef.NamedSet) { 482 for (int i = 0; i < c.namedSets.length; i++) { 483 if (c.namedSets[i].equals(child)) { 484 return i + c.calculatedMembers.length + c.measures.length + c.dimensions.length + 1;} 485 } 486 return -1; 487 } else { 488 return -1; 489 } 490 } else if (parent instanceof MondrianGuiDef.Dimension) { 491 MondrianGuiDef.Dimension d = (MondrianGuiDef.Dimension)parent; 492 if (child instanceof MondrianGuiDef.Hierarchy) { 493 for (int i = 0; i < d.hierarchies.length; i++) { 494 if (d.hierarchies[i].equals(child) && (d.hierarchies[i] == child)) { 495 return i; 496 } 497 } 498 return -1; 499 } else { 500 return -1; 501 } 502 } else if (parent instanceof MondrianGuiDef.ExpressionView) { 503 MondrianGuiDef.ExpressionView ev = (MondrianGuiDef.ExpressionView)parent; 504 if (child instanceof MondrianGuiDef.SQL) { 505 for (int i = 0; i < ev.expressions.length; i++) { 506 // if (ev.expressions[i].equals(child)) { 507 if (ev.expressions[i] == child) { // object reference is equal 508 return i; 509 } 510 } 511 return -1; 512 } else { 513 return -1; 514 } 515 } else if (parent instanceof MondrianGuiDef.Hierarchy) { 516 MondrianGuiDef.Hierarchy h = (MondrianGuiDef.Hierarchy)parent; 517 if (child instanceof MondrianGuiDef.Level) { 518 for (int i = 0; i < h.levels.length; i++) { 519 if (h.levels[i].equals(child)) { 520 return i; 521 } 522 } 523 return -1; 524 } else if (child instanceof MondrianGuiDef.MemberReaderParameter) { 525 for (int i = 0; i < h.memberReaderParameters.length; i++) { 526 if (h.memberReaderParameters[i].equals(child)) { 527 return i + h.levels.length; 528 } 529 } 530 return -1; 531 } else if (child instanceof MondrianGuiDef.RelationOrJoin) { 532 if (h.relation.equals(child) && (h.relation == child)) { 533 return h.levels.length + h.memberReaderParameters.length; } 534 return -1; 535 } else { 536 return -1; 537 } 538 } else if (parent instanceof MondrianGuiDef.Level) { 539 MondrianGuiDef.Level l = (MondrianGuiDef.Level)parent; 540 int counter = 0; 541 if (l.properties != null) { 542 counter = l.properties.length; 543 } 544 if (child instanceof MondrianGuiDef.Property) { 545 for (int i = 0; i < l.properties.length; i++) { 546 if (l.properties[i].equals(child)) { 547 return i; 548 } 549 } 550 return -1; 551 } 552 if (child instanceof MondrianGuiDef.KeyExpression) { 553 if (child.equals(l.keyExp)) { 554 return counter; 555 } 556 return -1; 557 } 558 if (l.keyExp != null) { 559 counter += 1; 560 } 561 if (child instanceof MondrianGuiDef.NameExpression) { 562 if (child.equals(l.nameExp)) { 563 return counter; 564 } 565 return -1; 566 } 567 if (l.nameExp != null) { 568 counter += 1; 569 } 570 if (child instanceof MondrianGuiDef.OrdinalExpression) { 571 if (child.equals(l.ordinalExp)) { 572 return counter; 573 } 574 return -1; 575 } 576 if (l.ordinalExp != null) { 577 counter += 1; 578 } 579 if (child instanceof MondrianGuiDef.ParentExpression) { 580 if (child.equals(l.parentExp)) { 581 return counter; 582 } 583 return -1; 584 } 585 if (l.parentExp != null) { 586 counter += 1; 587 } 588 if (child instanceof MondrianGuiDef.Closure) { 589 if (child.equals(l.closure)) { 590 return counter; 591 } 592 return -1; 593 } 594 return -1; 595 } else if (parent instanceof MondrianGuiDef.Join) { 596 MondrianGuiDef.Join j = (MondrianGuiDef.Join)parent; 597 if (child instanceof MondrianGuiDef.RelationOrJoin) { 598 if (j.left.equals(child)) { 599 return 0; 600 } else if (j.right.equals(child)) { 601 return 1; 602 } else { 603 return -1; 604 } 605 } else { 606 return -1; 607 } 608 } else if (parent instanceof MondrianGuiDef.Table) { 609 MondrianGuiDef.Table l = (MondrianGuiDef.Table)parent; 610 if (child instanceof MondrianGuiDef.AggTable) { 611 for (int i = 0; i < l.aggTables.length; i++) { 612 if (l.aggTables[i].equals(child)) { 613 return i; 614 } 615 } 616 return -1; 617 } else if (child instanceof MondrianGuiDef.AggExclude) { 618 for (int i = 0; i < l.aggExcludes.length; i++) { 619 if (l.aggExcludes[i].equals(child)) { 620 return i + l.aggTables.length; 621 } 622 } 623 return -1; 624 } else { 625 return -1; 626 } 627 } else if (parent instanceof MondrianGuiDef.AggTable) { 628 MondrianGuiDef.AggTable l = (MondrianGuiDef.AggTable)parent; 629 if (child instanceof MondrianGuiDef.AggFactCount) { 630 if (l.factcount.equals(child)) { 631 return 0; 632 } 633 return -1; 634 } else if (child instanceof MondrianGuiDef.AggIgnoreColumn) { 635 for (int i = 0; i < l.ignoreColumns.length; i++) { 636 if (l.ignoreColumns[i].equals(child)) { 637 return i; 638 } 639 } 640 return -1; 641 } else if (child instanceof MondrianGuiDef.AggForeignKey) { 642 for (int i = 0; i < l.foreignKeys.length; i++) { 643 if (l.foreignKeys[i].equals(child)) { 644 return i + l.ignoreColumns.length; 645 } 646 } 647 return -1; 648 } else if (child instanceof MondrianGuiDef.AggMeasure) { 649 for (int i = 0; i < l.measures.length; i++) { 650 if (l.measures[i].equals(child)) { 651 return i + l.ignoreColumns.length + l.foreignKeys.length; 652 } 653 } 654 return -1; 655 } else if (child instanceof MondrianGuiDef.AggLevel) { 656 for (int i = 0; i < l.levels.length; i++) { 657 if (l.levels[i].equals(child)) { 658 return i + l.ignoreColumns.length + l.foreignKeys.length + l.measures.length; 659 } 660 } 661 return -1; 662 } else if (parent instanceof MondrianGuiDef.AggPattern && 663 child instanceof MondrianGuiDef.AggExclude) { 664 for (int i = 0; i < ((MondrianGuiDef.AggPattern)l).excludes.length; i++) { 665 if (((MondrianGuiDef.AggPattern)l).excludes[i].equals(child)) { 666 return i + l.ignoreColumns.length + l.foreignKeys.length + l.measures.length + l.levels.length; 667 } 668 } 669 return -1; 670 } else { 671 return -1; 672 } 673 } else if (parent instanceof MondrianGuiDef.CalculatedMember) { 674 MondrianGuiDef.CalculatedMember l = (MondrianGuiDef.CalculatedMember)parent; 675 if (child instanceof MondrianGuiDef.CalculatedMemberProperty) { 676 for (int i = 0; i < l.memberProperties.length; i++) { 677 if (l.memberProperties[i].equals(child)) { 678 return i; 679 } 680 } 681 return -1; 682 } else { 683 return -1; 684 } 685 } else if (parent instanceof MondrianGuiDef.Measure) { 686 MondrianGuiDef.Measure m = (MondrianGuiDef.Measure)parent; 687 if (child instanceof MondrianGuiDef.MeasureExpression) { 688 if (child.equals(m.measureExp)) { 689 return 0; 690 } 691 return -1; 692 } 693 return -1; 694 } else if (parent instanceof MondrianGuiDef.Schema) { 695 //return children in this order: cubes, dimensions, namedSets, userDefinedFunctions, virtual cubes, roles 696 MondrianGuiDef.Schema s = (MondrianGuiDef.Schema)parent; 697 //return children in this order: cubes, virtual cubes, dimensions 698 if (child instanceof MondrianGuiDef.Cube) { 699 for (int i = 0; i < s.cubes.length; i++) { 700 if (s.cubes[i].equals(child)) { 701 return i; 702 } 703 } 704 return -1; 705 } else if (child instanceof MondrianGuiDef.Dimension) { 706 for (int i = 0; i < s.dimensions.length; i++) { 707 if (s.dimensions[i].equals(child)) { 708 return i + s.cubes.length; 709 } 710 } 711 return -1; 712 } else if (child instanceof MondrianGuiDef.NamedSet) { 713 for (int i = 0; i < s.namedSets.length; i++) { 714 if (s.namedSets[i].equals(child)) { 715 return i + s.cubes.length + s.dimensions.length; 716 } 717 } 718 return -1; 719 } else if (child instanceof MondrianGuiDef.UserDefinedFunction) { 720 for (int i = 0; i < s.userDefinedFunctions.length; i++) { 721 if (s.userDefinedFunctions[i].equals(child)) { 722 return i + s.cubes.length + s.dimensions.length + s.namedSets.length; 723 } 724 } 725 return -1; 726 } else if (child instanceof MondrianGuiDef.VirtualCube) { 727 for (int i = 0; i < s.virtualCubes.length; i++) { 728 if (s.virtualCubes[i].equals(child)) { 729 return i + s.cubes.length + s.dimensions.length + s.namedSets.length + s.userDefinedFunctions.length; 730 } 731 } 732 return -1; 733 } else if (child instanceof MondrianGuiDef.Role) { 734 for (int i = 0; i < s.roles.length; i++) { 735 if (s.roles[i].equals(child)) { 736 return i + s.cubes.length + s.dimensions.length + s.namedSets.length + s.userDefinedFunctions.length + s.virtualCubes.length; 737 } 738 } 739 return -1; 740 } else { 741 return -1; 742 } 743 } else if (parent instanceof MondrianGuiDef.View) { 744 MondrianGuiDef.View v = (MondrianGuiDef.View)parent; 745 if (child instanceof MondrianGuiDef.SQL) { 746 for (int i = 0; i < v.selects.length; i++) { 747 if (v.selects[i].equals(child)) { 748 return i; 749 } 750 } 751 return -1; 752 } 753 return -1; 754 } else if (parent instanceof MondrianGuiDef.VirtualCube) { 755 MondrianGuiDef.VirtualCube c = (MondrianGuiDef.VirtualCube)parent; 756 if (child instanceof MondrianGuiDef.VirtualCubeDimension) { 757 for (int i = 0; i < c.dimensions.length; i++) { 758 if (c.dimensions[i].equals(child)) { 759 return i; 760 } 761 } 762 return -1; 763 } else if (child instanceof MondrianGuiDef.VirtualCubeMeasure) { 764 for (int i = 0; i < c.measures.length; i++) { 765 if (c.measures[i].equals(child)) { 766 return i + c.dimensions.length; 767 } 768 } 769 return -1; 770 } else if (child instanceof MondrianGuiDef.CalculatedMember) { 771 for (int i = 0; i < c.calculatedMembers.length; i++) { 772 if (c.calculatedMembers[i].equals(child)) { 773 return i + c.dimensions.length + c.measures.length; 774 } 775 } 776 return -1; 777 } else { 778 return -1; 779 } 780 } else if (parent instanceof MondrianGuiDef.VirtualCubeDimension) { 781 MondrianGuiDef.VirtualCubeDimension d = (MondrianGuiDef.VirtualCubeDimension)parent; 782 return -1; 783 } else if (parent instanceof MondrianGuiDef.VirtualCubeMeasure) { 784 MondrianGuiDef.VirtualCubeMeasure d = (MondrianGuiDef.VirtualCubeMeasure)parent; 785 return -1; 786 } else if (parent instanceof MondrianGuiDef.Role) { 787 MondrianGuiDef.Role c = (MondrianGuiDef.Role)parent; 788 if (child instanceof MondrianGuiDef.SchemaGrant) { 789 for (int i = 0; i < c.schemaGrants.length; i++) { 790 if (c.schemaGrants[i].equals(child)) { 791 return i; 792 } 793 } 794 return -1; 795 } else { 796 return -1; 797 } 798 } else if (parent instanceof MondrianGuiDef.SchemaGrant) { 799 MondrianGuiDef.SchemaGrant c = (MondrianGuiDef.SchemaGrant)parent; 800 if (child instanceof MondrianGuiDef.CubeGrant) { 801 for (int i = 0; i < c.cubeGrants.length; i++) { 802 if (c.cubeGrants[i].equals(child)) { 803 return i; 804 } 805 } 806 return -1; 807 } else { 808 return -1; 809 } 810 } else if (parent instanceof MondrianGuiDef.CubeGrant) { 811 MondrianGuiDef.CubeGrant c = (MondrianGuiDef.CubeGrant)parent; 812 if (child instanceof MondrianGuiDef.DimensionGrant) { 813 for (int i = 0; i < c.dimensionGrants.length; i++) { 814 if (c.dimensionGrants[i].equals(child)) { 815 return i; 816 } 817 } 818 return -1; 819 } else if (child instanceof MondrianGuiDef.HierarchyGrant) { 820 for (int i = 0; i < c.hierarchyGrants.length; i++) { 821 if (c.hierarchyGrants[i].equals(child)) { 822 return i + c.dimensionGrants.length ; 823 } 824 } 825 return -1; 826 } else { 827 return -1; 828 } 829 } else if (parent instanceof MondrianGuiDef.HierarchyGrant) { 830 MondrianGuiDef.HierarchyGrant c = (MondrianGuiDef.HierarchyGrant)parent; 831 if (child instanceof MondrianGuiDef.MemberGrant) { 832 for (int i = 0; i < c.memberGrants.length; i++) { 833 if (c.memberGrants[i].equals(child)) { 834 return i; 835 } 836 } 837 return -1; 838 } else { 839 return -1; 840 } 841 } else if (parent instanceof MondrianGuiDef.Closure) { 842 MondrianGuiDef.Closure c = (MondrianGuiDef.Closure)parent; 843 if (child instanceof MondrianGuiDef.Table) { 844 return 0; 845 } else { 846 return -1; 847 } 848 } else { 849 return -1; 850 } 851 } 852 853 /** Returns the root of the tree. Returns <code>null</code> 854 * only if the tree has no nodes. 855 * 856 * @return the root of the tree 857 * 858 */ 859 public Object getRoot() { 860 return schema; 861 } 862 863 /** Returns <code>true</code> if <code>node</code> is a leaf. 864 * It is possible for this method to return <code>false</code> 865 * even if <code>node</code> has no children. 866 * A directory in a filesystem, for example, 867 * may contain no files; the node representing 868 * the directory is not a leaf, but it also has no children. 869 * 870 * @param node a node in the tree, obtained from this data source 871 * @return true if <code>node</code> is a leaf 872 * 873 */ 874 public boolean isLeaf(Object node) { 875 return getChildCount(node) == 0; 876 } 877 878 public void valueForPathChanged(TreePath path, Object newValue) { 879 //super.valueForPathChanged(path, newValue); 880 } 881 882 } 883 884 // End SchemaTreeModel.java