1 19 20 package org.netbeans.modules.dbschema.nodes; 21 22 import org.openide.actions.*; 23 import org.openide.nodes.*; 24 25 import org.openide.util.HelpCtx; 26 import org.openide.util.NbBundle; 27 import org.openide.util.actions.SystemAction; 28 29 import org.netbeans.modules.dbschema.*; 30 31 34 public class DefaultDBFactory implements DBElementNodeFactory, IconStrings { 35 public static final String WAIT = 36 "org/openide/src/resources/wait"; 38 public static final String ERROR = 39 "org/openide/src/resources/error"; 41 42 public static final DefaultDBFactory READ_WRITE = new DefaultDBFactory(true); 43 44 45 public static final DefaultDBFactory READ_ONLY = new DefaultDBFactory(false); 46 47 50 private boolean _writeable; 51 52 57 public DefaultDBFactory (boolean writeable) { 58 _writeable = writeable; 59 } 60 61 64 public boolean isWriteable() { 65 return _writeable; 66 } 67 68 71 public Node createSchemaNode (final SchemaElement element) { 72 return new SchemaElementNode(element, createSchemaChildren(element), isWriteable()); 73 } 74 75 81 protected Children createSchemaChildren (SchemaElement element) { 82 return createSchemaChildren(element, (isWriteable() ? READ_WRITE : READ_ONLY)); 83 } 84 85 91 final protected Children createSchemaChildren (SchemaElement element, DBElementNodeFactory factory) { 92 SchemaChildren children = new SchemaChildren(factory, element); 93 boolean writeable = isWriteable(); 94 95 return children; 96 } 97 98 101 public Node createColumnNode (final ColumnElement element) { 102 return new ColumnElementNode(element, isWriteable()); 103 } 104 105 108 public Node createColumnPairNode (final ColumnPairElement element) { 109 return new ColumnPairElementNode(element, isWriteable()); 110 } 111 112 116 public Node createIndexNode (final IndexElement element) { 117 return new IndexElementNode(element, (TableChildren) createIndexChildren(element), isWriteable()); 118 } 119 120 126 protected Children createIndexChildren (IndexElement element) { 127 return createIndexChildren(element, (isWriteable() ? READ_WRITE : READ_ONLY)); 128 } 129 130 136 final protected Children createIndexChildren (IndexElement element, DBElementNodeFactory factory) { 137 TableChildren children = new TableChildren(factory, element); 138 boolean writeable = isWriteable(); 139 140 return children; 141 } 142 143 144 148 public Node createForeignKeyNode (final ForeignKeyElement element) { 149 return new ForeignKeyElementNode(element, (TableChildren) createForeignKeyChildren(element), isWriteable()); 150 } 151 152 158 protected Children createForeignKeyChildren(ForeignKeyElement element) { 159 return createForeignKeyChildren(element, (isWriteable() ? READ_WRITE : READ_ONLY)); 160 } 161 162 168 final protected Children createForeignKeyChildren (ForeignKeyElement element, DBElementNodeFactory factory) { 169 TableChildren children = new TableChildren(factory, element); 170 boolean writeable = isWriteable(); 171 172 return children; 173 } 174 175 178 public Node createTableNode (TableElement element) { 179 return new TableElementNode(element, createTableChildren(element), isWriteable()); 180 } 181 182 188 protected Children createTableChildren (TableElement element) { 189 return createTableChildren(element, (isWriteable() ? READ_WRITE : READ_ONLY)); 190 } 191 192 198 final protected Children createTableChildren (TableElement element, DBElementNodeFactory factory) { 199 TableChildren children = new TableChildren(factory, element); 200 TableElementFilter filter = new TableElementFilter(); 201 boolean writeable = isWriteable(); 202 203 filter.setOrder(new int[] {TableElementFilter.TABLE, TableElementFilter.VIEW}); 204 children.setFilter(filter); 205 String db = element.getDeclaringSchema().getDatabaseProductName(); 206 boolean viewSupport =false; 207 if (db!=null){ 208 db = db.toLowerCase(); 209 viewSupport = (db.indexOf("oracle") != -1 || db.indexOf("microsoft sql server") != -1) ? true : false; 210 } 211 212 if (((TableElement) element).isTableOrView() || viewSupport) 213 children.add(new Node[] { 215 new ElementCategoryNode(0, factory, element, writeable), 216 new ElementCategoryNode(1, factory, element, writeable), 217 new ElementCategoryNode(2, factory, element, writeable), 218 }); 219 else 220 children.add(new Node[] { 221 new ElementCategoryNode(0, factory, element, writeable), 222 }); 223 224 return children; 225 } 226 227 228 233 public Node createWaitNode() { 234 AbstractNode n = new AbstractNode(Children.LEAF); 235 n.setName(NbBundle.getMessage(DefaultDBFactory.class,"Wait")); 236 n.setIconBase(WAIT); 237 return n; 238 } 239 240 244 public Node createErrorNode() { 245 AbstractNode n = new AbstractNode(Children.LEAF); 246 n.setName(NbBundle.getMessage(DefaultDBFactory.class,"Error")); n.setIconBase(ERROR); 248 return n; 249 } 250 251 private static final SystemAction[] CATEGORY_ACTIONS = new SystemAction[] { 252 SystemAction.get(ToolsAction.class), 253 }; 254 255 256 static final String [] NAMES = new String [] { 257 NbBundle.getMessage(DefaultDBFactory.class, "Columns"), NbBundle.getMessage(DefaultDBFactory.class, "Indexes"), NbBundle.getMessage(DefaultDBFactory.class, "FKs"), NbBundle.getMessage(DefaultDBFactory.class, "Tables") }; 262 263 264 static final int[][] FILTERS = new int[][] { 265 { TableElementFilter.COLUMN }, 266 { TableElementFilter.INDEX }, 267 { TableElementFilter.FK }, 268 { SchemaElementFilter.TABLE }, 269 }; 270 271 272 static final String [] CATEGORY_ICONS = new String [] { 273 COLUMNS_CATEGORY, INDEXES_CATEGORY, FKS_CATEGORY, TABLE 274 }; 275 276 280 static class ElementCategoryNode extends AbstractNode { 281 282 DBElement element; 283 284 285 int newTypeIndex; 286 287 293 ElementCategoryNode (int index, DBElementNodeFactory factory, TableElement element, boolean writeable) { 294 this(index, new TableChildren(factory, element)); 295 this.element = element; 296 newTypeIndex = writeable ? index : -1; 297 switch (index) { 298 case 0: setName(NbBundle.getMessage(DefaultDBFactory.class, "Columns")); break; case 1: setName(NbBundle.getMessage(DefaultDBFactory.class, "Indexes")); break; case 2: setName(NbBundle.getMessage(DefaultDBFactory.class, "FKs")); break; } 302 } 303 304 ElementCategoryNode (int index, DBElementNodeFactory factory, SchemaElement element, boolean writeable) { 305 this(index, new SchemaChildren(factory, element)); 306 this.element = element; 307 newTypeIndex = writeable ? index : -1; 308 setName(NbBundle.getMessage(DefaultDBFactory.class, "Tables")); } 310 311 315 private ElementCategoryNode (int index, TableChildren children) { 316 super(children); 317 setDisplayName(NAMES[index]); 318 systemActions = CATEGORY_ACTIONS; 319 TableElementFilter filter = new TableElementFilter(); 320 filter.setOrder(FILTERS[index]); 321 children.setFilter(filter); 322 setIconBase(CATEGORY_ICONS[index]); 323 } 324 325 private ElementCategoryNode (int index, SchemaChildren children) { 326 super(children); 327 setDisplayName(NAMES[index]); 328 systemActions = CATEGORY_ACTIONS; 329 setIconBase(CATEGORY_ICONS[index]); 330 } 331 332 public HelpCtx getHelpCtx () { 333 return new HelpCtx("dbschema_ctxhelp_wizard"); } 335 } 336 } 337 | Popular Tags |