1 19 package org.netbeans.modules.db.sql.visualeditor.querybuilder; 20 21 import java.sql.SQLException ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import java.beans.PropertyEditorSupport ; 26 import java.beans.PropertyEditor ; 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.JoinTable; 39 import org.netbeans.modules.db.sql.visualeditor.querymodel.Predicate; 40 41 43 public class JoinNode extends AbstractNode 44 { 45 47 private String _table1=""; private String _column1=""; private String _table2=""; private String _column2=""; private String _type=""; private QueryBuilder _queryBuilder; 53 54 55 57 JoinNode(String table1, String column1, String table2, String column2, String type, 58 QueryBuilder queryBuilder) 59 { 60 super(Children.LEAF); 61 _table1 = table1; 62 _column1 = column1; 63 _table2 = table2; 64 _column2 = column2; 65 _type = type; 66 _queryBuilder = queryBuilder; 67 } 68 69 JoinNode(String table1, String column1, String table2, String column2, QueryBuilder queryBuilder) 70 { 71 this(table1, column1, table2, column2, "INNER", queryBuilder); } 73 74 76 public String getTable1() { 77 return _table1; 78 } 79 80 public String getColumn1() { 81 return _column1; 82 } 83 84 public void setColumn1(String column1) { 85 JoinTable jt = findJoinTable(_table1, _column1, _table2, _column2); 86 _column1 = column1; 87 updateModel(jt); 88 } 89 90 public String getTable2() { 91 return _table2; 92 } 93 94 public String getColumn2() { 95 return _column2; 96 } 97 98 public void setColumn2(String column2) { 99 JoinTable jt = findJoinTable(_table1, _column1, _table2, _column2); 100 _column2 = column2; 101 updateModel(jt); 102 } 103 104 public String getType() { 105 return _type; 106 } 107 108 public void setType(String type) { 109 JoinTable jt = findJoinTable(_table1, _column1, _table2, _column2); 110 _type = type; 111 updateModel(jt); 112 } 113 114 117 protected Sheet createSheet() { 118 Sheet s = Sheet.createDefault(); 119 Sheet.Set ss = s.get(Sheet.PROPERTIES); 120 try { 121 PropertySupport.Reflection p; 122 p = new Reflection(this, String .class, "getTable1", null); p.setName("table1"); 127 String table1 = NbBundle.getMessage(JoinNode.class, "TABLE_1"); p.setDisplayName(table1); 129 130 String table1ShortDescription = NbBundle.getMessage(JoinNode.class, "TABLE_1_SHORT_DESCRIPTION"); p.setShortDescription(table1ShortDescription); 132 ss.put(p); 133 p = new Reflection(this, String .class, "getColumn1", "setColumn1") { 134 public PropertyEditor getPropertyEditor () { 135 return new ColumnPropertyEditor1 (); 136 }}; p.setName("column1"); 141 String column1 = NbBundle.getMessage(JoinNode.class, "COLUMN_1"); p.setDisplayName(column1); 143 144 String column1ShortDescription = NbBundle.getMessage(JoinNode.class, "COLUMN_1_SHORT_DESCRIPTION"); p.setShortDescription(column1ShortDescription); 146 ss.put(p); 148 p = new Reflection(this, String .class, "getTable2", null); p.setName("table2"); String table2 = NbBundle.getMessage(JoinNode.class, "TABLE_2"); p.setDisplayName(table2); 154 155 String table2ShortDescription = NbBundle.getMessage(JoinNode.class, "TABLE_2_SHORT_DESCRIPTION"); p.setShortDescription(table2ShortDescription); 157 ss.put(p); 158 p = new Reflection(this, String .class, "getColumn2", "setColumn2") { 159 public PropertyEditor getPropertyEditor () { 160 return new ColumnPropertyEditor2 (); 161 }}; p.setName("column2"); 166 String column2 = NbBundle.getMessage(JoinNode.class, "COLUMN_2"); p.setDisplayName(column2); 168 169 String column2ShortDescription = NbBundle.getMessage(JoinNode.class, "COLUMN_2_SHORT_DESCRIPTION"); p.setShortDescription(column2ShortDescription); 171 ss.put(p); 173 p = new Reflection(this, String .class, "getType", "setType") { public PropertyEditor getPropertyEditor () { 175 return new JoinTypePropertyEditor (); 176 }}; p.setName("type"); String type = NbBundle.getMessage(JoinNode.class, "TYPE"); p.setDisplayName(type); 182 183 String typeShortDescription = NbBundle.getMessage(JoinNode.class, "TYPE_SHORT_DESCRIPTION"); p.setShortDescription(typeShortDescription); 185 186 ss.put(p); 188 } catch (NoSuchMethodException nsme) { 189 ErrorManager.getDefault().notify(nsme); 190 } 191 return s; 192 } 193 194 196 public String toString() { 197 return ""; } 199 200 201 JoinTable findJoinTable(String _table1, String _column1, String _table2, String _column2) { 204 return _queryBuilder._queryModel.findJoinTable(_table1, _column1, _table2, _column2); 205 } 206 207 208 private void updateModel(JoinTable jt) { 209 210 jt.setJoinType(_type); 213 if (_type.equals("CROSS")) jt.setExpression(null); 215 else 216 ((Predicate)jt.getExpression()).setFields(_table1, _column1, _table2, _column2); 217 218 _queryBuilder.generateText(); 220 } 221 222 223 225 public class JoinTypePropertyEditor extends PropertyEditorSupport { 226 227 private String [] tags = 228 new String [] { "INNER", "LEFT OUTER", "RIGHT OUTER" }; 233 public String [] getTags() { 234 return tags; 235 } 236 } 237 238 public class ColumnPropertyEditor1 extends PropertyEditorSupport { 239 240 public String [] getTags() { 241 List columnNames ; 242 try { 243 columnNames = _queryBuilder.getColumnNames(_table1); 244 } catch(SQLException sqle) { 245 return new String [0] ; 246 } 247 return (String [])columnNames.toArray(new String [columnNames.size()]); 248 } 249 } 250 251 public class ColumnPropertyEditor2 extends PropertyEditorSupport { 252 253 public String [] getTags() { 254 255 List columnNames ; 256 try { 257 columnNames = _queryBuilder.getColumnNames(_table2); 258 } catch(SQLException sqle) { 259 return new String [0] ; 260 } 261 return (String [])columnNames.toArray(new String [columnNames.size()]); 262 } 263 } 264 } 265 | Popular Tags |