KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > DBschemaDataObject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.dbschema.jdbcimpl;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
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 JavaDoc listener = new PropertyChangeListener JavaDoc() {
54             public void propertyChange(PropertyChangeEvent JavaDoc event) {
55                 if (event.getPropertyName().equals("valid")) //NOI18N
56
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()); //NOI18N
63
} catch (Exception JavaDoc exc) {
64                                     if (Boolean.getBoolean("netbeans.debug.exceptions")) //NOI18N
65
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()); //NOI18N
74
} catch (Exception JavaDoc exc) {
75                                 if (Boolean.getBoolean("netbeans.debug.exceptions")) //NOI18N
76
exc.printStackTrace();
77                             }
78                             schemaElement = null;
79                             return;
80                         }
81
82                 if (event.getPropertyName().equals("primaryFile")) //NOI18N
83
if (schemaElement == null)
84                         return;
85                     else {
86                         SchemaElement.removeFromCache(schemaElement.getName().getFullName());
87                         try {
88                             SchemaElement.removeFromCache(schemaElement.getName().getFullName() + "#" + getPrimaryFile().getURL().toString()); //NOI18N
89
} catch (Exception JavaDoc exc) {
90                             if (Boolean.getBoolean("netbeans.debug.exceptions")) //NOI18N
91
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 JavaDoc c) {
104         // Looks like a bug - why is it done this way? This inevitable leads to a ClassCastException
105
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"); //NOI18N
134
}
135   
136     protected Node createNodeDelegate () {
137         Node nodeDelegate = new DBschemaDataNode(this);
138         
139         return nodeDelegate;
140     }
141 }
142
Popular Tags