1 19 20 package org.netbeans.modules.dbschema.jdbcimpl; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 25 import org.openide.filesystems.FileObject; 26 import org.openide.loaders.DataObjectExistsException; 27 import org.openide.loaders.MultiDataObject; 28 import org.openide.nodes.CookieSet; 29 import org.openide.nodes.Children; 30 import org.openide.nodes.Node; 31 import org.openide.util.HelpCtx; 32 33 import org.netbeans.modules.dbschema.DBElementProvider; 34 import org.netbeans.modules.dbschema.SchemaElement; 35 import org.netbeans.modules.dbschema.SchemaElementUtil; 36 import org.netbeans.modules.dbschema.nodes.SchemaRootChildren; 37 38 public class DBschemaDataObject extends MultiDataObject { 39 40 transient protected SchemaElement schemaElement; 41 transient SchemaElementImpl schemaElementImpl; 42 43 public DBschemaDataObject (FileObject pf, DBschemaDataLoader loader) throws DataObjectExistsException { 44 super (pf, loader); 45 init (); 46 } 47 48 private void init () { 49 CookieSet cookies = getCookieSet (); 50 51 cookies.add(new DBElementProvider()); 52 53 PropertyChangeListener listener = new PropertyChangeListener () { 54 public void propertyChange(PropertyChangeEvent event) { 55 if (event.getPropertyName().equals("valid")) if (! isValid()) 57 if (schemaElement == null) { 58 schemaElement = SchemaElementUtil.forName(getPrimaryFile()); 59 if (schemaElement != null) { 60 SchemaElement.removeFromCache(schemaElement.getName().getFullName()); 61 try { 62 SchemaElement.removeFromCache(schemaElement.getName().getFullName() + "#" + getPrimaryFile().getURL().toString()); } catch (Exception exc) { 64 if (Boolean.getBoolean("netbeans.debug.exceptions")) exc.printStackTrace(); 66 } 67 schemaElement = null; 68 } 69 return; 70 } else { 71 SchemaElement.removeFromCache(schemaElement.getName().getFullName()); 72 try { 73 SchemaElement.removeFromCache(schemaElement.getName().getFullName() + "#" + getPrimaryFile().getURL().toString()); } catch (Exception exc) { 75 if (Boolean.getBoolean("netbeans.debug.exceptions")) exc.printStackTrace(); 77 } 78 schemaElement = null; 79 return; 80 } 81 82 if (event.getPropertyName().equals("primaryFile")) if (schemaElement == null) 84 return; 85 else { 86 SchemaElement.removeFromCache(schemaElement.getName().getFullName()); 87 try { 88 SchemaElement.removeFromCache(schemaElement.getName().getFullName() + "#" + getPrimaryFile().getURL().toString()); } catch (Exception exc) { 90 if (Boolean.getBoolean("netbeans.debug.exceptions")) exc.printStackTrace(); 92 } 93 schemaElement = null; 94 getSchema(); 95 return; 96 } 97 } 98 }; 99 100 addPropertyChangeListener(listener); 101 } 102 103 public Node.Cookie getCookie (Class c) { 104 if (SchemaElement.class.isAssignableFrom(c)) 106 return getCookie(DBElementProvider.class); 107 return super.getCookie(c); 108 } 109 110 public SchemaElement getSchema() { 111 if (schemaElement == null) 112 setSchema(SchemaElementUtil.forName(getPrimaryFile())); 113 114 return schemaElement; 115 } 116 117 public void setSchema(SchemaElement schema) { 118 schemaElement = schema; 119 Node n = getNodeDelegate(); 120 Children ch = n.getChildren(); 121 ((SchemaRootChildren) ch).setElement(schemaElement); 122 } 123 124 public SchemaElementImpl getSchemaElementImpl() { 125 return schemaElementImpl; 126 } 127 128 public void setSchemaElementImpl(SchemaElementImpl schemaImpl) { 129 schemaElementImpl = schemaImpl; 130 } 131 132 public HelpCtx getHelpCtx () { 133 return new HelpCtx("dbschema_ctxhelp_wizard"); } 135 136 protected Node createNodeDelegate () { 137 Node nodeDelegate = new DBschemaDataNode(this); 138 139 return nodeDelegate; 140 } 141 } 142 | Popular Tags |