KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > querybuilder > CondNode


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.db.sql.visualeditor.querybuilder;
20
21 import java.sql.SQLException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23
24 import java.beans.PropertyEditorSupport JavaDoc;
25 import java.beans.PropertyEditor JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.openide.ErrorManager;
29
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.Sheet;
32 import org.openide.nodes.Children;
33 import org.openide.nodes.PropertySupport;
34 import org.openide.nodes.PropertySupport.Reflection;
35
36 import org.openide.util.NbBundle;
37
38 import org.netbeans.modules.db.sql.visualeditor.querymodel.Expression;
39 import org.netbeans.modules.db.sql.visualeditor.querymodel.Predicate;
40
41 // A class for providing properties to arcs (joins)
42

43 public class CondNode extends AbstractNode
44 {
45     // Private variable
46

47     private String JavaDoc _table1=""; // NOI18N
48
private String JavaDoc _column1=""; // NOI18N
49
private String JavaDoc _table2=""; // NOI18N
50
private String JavaDoc _column2=""; // NOI18N
51
private QueryBuilder _queryBuilder;
52
53
54     // Constructors
55

56     CondNode(String JavaDoc table1, String JavaDoc column1, String JavaDoc table2, String JavaDoc column2, QueryBuilder queryBuilder)
57     {
58         super(Children.LEAF);
59         _table1 = table1;
60         _column1 = column1;
61         _table2 = table2;
62         _column2 = column2;
63         _queryBuilder = queryBuilder;
64     }
65
66
67     // Accessors/mutators
68

69     public String JavaDoc getTable1() {
70         return _table1;
71     }
72
73     public String JavaDoc getColumn1() {
74         return _column1;
75     }
76
77     public void setColumn1(String JavaDoc column1) {
78         Expression cond = findCond(_table1, _column1, _table2, _column2);
79         _column1 = column1;
80         updateModel(cond);
81     }
82
83     public String JavaDoc getTable2() {
84         return _table2;
85     }
86
87     public String JavaDoc getColumn2() {
88         return _column2;
89     }
90
91     public void setColumn2(String JavaDoc column2) {
92         Expression cond = findCond(_table1, _column1, _table2, _column2);
93         _column2 = column2;
94         updateModel(cond);
95     }
96
97
98     // Create minimal property sheet
99
// Column names are editable, nothing else is
100

101     protected Sheet createSheet() {
102         Sheet s = Sheet.createDefault();
103         Sheet.Set ss = s.get(Sheet.PROPERTIES);
104         try {
105             PropertySupport.Reflection p;
106             p = new Reflection(this, String JavaDoc.class, "getTable1", null); // NOI18N
107
p.setName("table1"); // NOI18N
108
// p.setDisplayName("Table 1"); // NOI18N
109
// p.setShortDescription("first table for join"); // NOI18N
110

111             String JavaDoc table1 = NbBundle.getMessage(CondNode.class, "TABLE_1"); // NOI18N
112
p.setDisplayName(table1);
113
114             String JavaDoc table1ShortDescription = NbBundle.getMessage(CondNode.class, "TABLE_1_SHORT_DESCRIPTION"); // NOI18N
115
p.setShortDescription(table1ShortDescription);
116             ss.put(p);
117             p = new Reflection(this, String JavaDoc.class, "getColumn1", "setColumn1") {
118                     public PropertyEditor JavaDoc getPropertyEditor () {
119                         return new ColumnPropertyEditor1 ();
120                     }}; // NOI18N
121
p.setName("column1"); // NOI18N
122
// p.setDisplayName("Column 1"); // NOI18N
123
// p.setShortDescription("First column for join"); // NOI18N
124

125             String JavaDoc column1 = NbBundle.getMessage(CondNode.class, "COLUMN_1"); // NOI18N
126
p.setDisplayName(column1);
127
128             String JavaDoc column1ShortDescription = NbBundle.getMessage(CondNode.class, "COLUMN_1_SHORT_DESCRIPTION"); // NOI18N
129
p.setShortDescription(column1ShortDescription);
130 // p.setPropertyEditorClass(ColumnPropertyEditor.class);
131
ss.put(p);
132             p = new Reflection(this, String JavaDoc.class, "getTable2", null); // NOI18N
133
p.setName("table2"); // NOI18N
134
// p.setDisplayName("Table 2"); // NOI18N
135
// p.setShortDescription("second table for join"); // NOI18N
136

137             String JavaDoc table2 = NbBundle.getMessage(CondNode.class, "TABLE_2"); // NOI18N
138
p.setDisplayName(table2);
139
140             String JavaDoc table2ShortDescription = NbBundle.getMessage(CondNode.class, "TABLE_2_SHORT_DESCRIPTION"); // NOI18N
141
p.setShortDescription(table2ShortDescription);
142
143             ss.put(p);
144             p = new Reflection(this, String JavaDoc.class, "getColumn2", "setColumn2") {
145                     public PropertyEditor JavaDoc getPropertyEditor () {
146                         return new ColumnPropertyEditor2 ();
147                     }}; // NOI18N
148
p.setName("column2"); // NOI18N
149
// p.setDisplayName("Column 2"); // NOI18N
150
// p.setShortDescription("Second column for join"); // NOI18N
151

152             String JavaDoc column2 = NbBundle.getMessage(CondNode.class, "COLUMN_2"); // NOI18N
153
p.setDisplayName(column2);
154
155             String JavaDoc column2ShortDescription = NbBundle.getMessage(CondNode.class, "COLUMN_2_SHORT_DESCRIPTION"); // NOI18N
156
p.setShortDescription(column2ShortDescription);
157 // p.setPropertyEditorClass(ColumnPropertyEditor.class);
158
ss.put(p);
159         } catch (NoSuchMethodException JavaDoc nsme) {
160             ErrorManager.getDefault().notify(nsme);
161         }
162         return s;
163     }
164
165
166     // Suppress label printing in graph
167

168     public String JavaDoc toString() {
169         return ""; // NOI18N
170
}
171
172     
173     // Find the JoinTable object behind this edge
174
// We may eventually add links from graph to model to simplify operations like this
175
Expression findCond(String JavaDoc _table1, String JavaDoc _column1, String JavaDoc _table2, String JavaDoc _column2) {
176         return _queryBuilder._queryModel.findCond(_table1, _column1, _table2, _column2);
177     }
178
179
180     private void updateModel(Expression cond) {
181
182         // Set the appropriate fields in this Expression
183
if (cond instanceof Predicate) {
184             Predicate pred = (Predicate) cond;
185             pred.setFields(_table1, _column1, _table2, _column2);
186         }
187
188         // And rebuild the text query
189
_queryBuilder.generateText();
190     }
191
192
193     // Property Editors
194

195     public class JoinTypePropertyEditor extends PropertyEditorSupport JavaDoc {
196
197         private String JavaDoc[] tags =
198             new String JavaDoc[] { "INNER", // NOI18N
199
"LEFT OUTER", // NOI18N
200
"RIGHT OUTER" // NOI18N
201
/*, "FULL OUTER" */ // Dropped b/c Pointbase doesn't support it
202
/*, "CROSS" */ };
203         public String JavaDoc[] getTags() {
204             return tags;
205         }
206     }
207
208     public class ColumnPropertyEditor1 extends PropertyEditorSupport JavaDoc {
209
210         public String JavaDoc[] getTags() {
211             List JavaDoc columnNames ;
212             try {
213                 columnNames = _queryBuilder.getColumnNames(_table1);
214             } catch(SQLException JavaDoc sqle) {
215                 return new String JavaDoc[0] ;
216             }
217             return (String JavaDoc[])columnNames.toArray(new String JavaDoc[columnNames.size()]);
218             // return new String[] {"PERSONID", "NAME" };
219
}
220     }
221
222     public class ColumnPropertyEditor2 extends PropertyEditorSupport JavaDoc {
223
224         public String JavaDoc[] getTags() {
225
226            List JavaDoc columnNames ;
227             try {
228                 columnNames = _queryBuilder.getColumnNames(_table2);
229             } catch (SQLException JavaDoc sqle) {
230                 return new String JavaDoc[0] ;
231             }
232             return (String JavaDoc[])columnNames.toArray(new String JavaDoc[columnNames.size()]);
233         }
234     }
235 }
236
Popular Tags