1 21 package org.jacorb.ir.gui.typesystem; 22 23 24 28 29 import java.util.*; 30 import javax.swing.tree.*; 31 import java.lang.reflect.*; 32 33 public abstract class TypeSystemNode 34 extends ModelParticipant 35 { 36 protected DefaultMutableTreeNode treeNode; 37 protected String name = ""; 38 protected String absoluteName = ""; 39 40 42 public TypeSystemNode ( ) { 43 } 44 45 49 protected TypeSystemNode ( DefaultMutableTreeNode treeNode) { 50 this(); 51 this.treeNode = treeNode; 52 } 53 54 57 58 public TypeSystemNode ( String name) { 59 this(); 60 this.name = name; 61 } 62 63 69 70 public String [] allowedToAdd ( ) 71 { 72 return null; 73 } 74 75 79 public int compareTo(ModelParticipant other) { 80 return this.toString().compareTo(other.toString()); 81 } 82 83 86 87 public String description() { 88 return getInstanceNodeTypeName() + " " + getAbsoluteName(); 89 } 90 91 94 public String getAbsoluteName() { 95 return absoluteName; 96 } 97 98 101 102 public String getInstanceNodeTypeName ( ) 103 { 104 Method nodeTypeNameMethod; 108 String nodeTypeName = ""; 109 try { 110 nodeTypeNameMethod = getClass().getMethod("nodeTypeName", new Class [0]); 111 nodeTypeName = (String ) nodeTypeNameMethod.invoke(null, new Object [0]) ; 112 } 113 catch (Exception e) { 114 e.printStackTrace(); 115 } 116 return nodeTypeName; 117 } 118 119 122 123 public String getName ( ) 124 { 125 return name; 126 } 127 128 135 136 protected void insertChild ( TypeSystemNode newChild) 137 throws IllegalChildException 138 { 139 String [] allowedTypes = allowedToAdd(); 140 int i; 141 for (i = 0; 142 i <allowedTypes.length && !allowedTypes[i].equals(newChild.nodeTypeName()); 143 i++); 144 145 if (!allowedTypes[i].equals(newChild.nodeTypeName())) { 146 throw new IllegalChildException(); 147 } 148 } 153 154 158 159 public static String nodeTypeName ( ) { 160 return null; 162 } 163 164 166 protected void setAbsoluteName(String absoluteName ) { 167 this.absoluteName = absoluteName; 168 } 169 170 174 175 protected void setName( String name) { 176 this.name = name; 177 } 178 179 184 public String toString ( ) { 185 return getInstanceNodeTypeName() + " " + getName(); 186 } 187 } 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | Popular Tags |