1 19 package org.netbeans.modules.db.sql.visualeditor.querybuilder; 20 21 import java.sql.SQLException ; 22 import java.util.ArrayList ; 23 24 import java.beans.PropertyEditorSupport ; 25 import java.beans.PropertyEditor ; 26 import java.util.List ; 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 43 public class CondNode extends AbstractNode 44 { 45 47 private String _table1=""; private String _column1=""; private String _table2=""; private String _column2=""; private QueryBuilder _queryBuilder; 52 53 54 56 CondNode(String table1, String column1, String table2, String 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 69 public String getTable1() { 70 return _table1; 71 } 72 73 public String getColumn1() { 74 return _column1; 75 } 76 77 public void setColumn1(String column1) { 78 Expression cond = findCond(_table1, _column1, _table2, _column2); 79 _column1 = column1; 80 updateModel(cond); 81 } 82 83 public String getTable2() { 84 return _table2; 85 } 86 87 public String getColumn2() { 88 return _column2; 89 } 90 91 public void setColumn2(String column2) { 92 Expression cond = findCond(_table1, _column1, _table2, _column2); 93 _column2 = column2; 94 updateModel(cond); 95 } 96 97 98 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 .class, "getTable1", null); p.setName("table1"); 111 String table1 = NbBundle.getMessage(CondNode.class, "TABLE_1"); p.setDisplayName(table1); 113 114 String table1ShortDescription = NbBundle.getMessage(CondNode.class, "TABLE_1_SHORT_DESCRIPTION"); p.setShortDescription(table1ShortDescription); 116 ss.put(p); 117 p = new Reflection(this, String .class, "getColumn1", "setColumn1") { 118 public PropertyEditor getPropertyEditor () { 119 return new ColumnPropertyEditor1 (); 120 }}; p.setName("column1"); 125 String column1 = NbBundle.getMessage(CondNode.class, "COLUMN_1"); p.setDisplayName(column1); 127 128 String column1ShortDescription = NbBundle.getMessage(CondNode.class, "COLUMN_1_SHORT_DESCRIPTION"); p.setShortDescription(column1ShortDescription); 130 ss.put(p); 132 p = new Reflection(this, String .class, "getTable2", null); p.setName("table2"); 137 String table2 = NbBundle.getMessage(CondNode.class, "TABLE_2"); p.setDisplayName(table2); 139 140 String table2ShortDescription = NbBundle.getMessage(CondNode.class, "TABLE_2_SHORT_DESCRIPTION"); p.setShortDescription(table2ShortDescription); 142 143 ss.put(p); 144 p = new Reflection(this, String .class, "getColumn2", "setColumn2") { 145 public PropertyEditor getPropertyEditor () { 146 return new ColumnPropertyEditor2 (); 147 }}; p.setName("column2"); 152 String column2 = NbBundle.getMessage(CondNode.class, "COLUMN_2"); p.setDisplayName(column2); 154 155 String column2ShortDescription = NbBundle.getMessage(CondNode.class, "COLUMN_2_SHORT_DESCRIPTION"); p.setShortDescription(column2ShortDescription); 157 ss.put(p); 159 } catch (NoSuchMethodException nsme) { 160 ErrorManager.getDefault().notify(nsme); 161 } 162 return s; 163 } 164 165 166 168 public String toString() { 169 return ""; } 171 172 173 Expression findCond(String _table1, String _column1, String _table2, String _column2) { 176 return _queryBuilder._queryModel.findCond(_table1, _column1, _table2, _column2); 177 } 178 179 180 private void updateModel(Expression cond) { 181 182 if (cond instanceof Predicate) { 184 Predicate pred = (Predicate) cond; 185 pred.setFields(_table1, _column1, _table2, _column2); 186 } 187 188 _queryBuilder.generateText(); 190 } 191 192 193 195 public class JoinTypePropertyEditor extends PropertyEditorSupport { 196 197 private String [] tags = 198 new String [] { "INNER", "LEFT OUTER", "RIGHT OUTER" }; 203 public String [] getTags() { 204 return tags; 205 } 206 } 207 208 public class ColumnPropertyEditor1 extends PropertyEditorSupport { 209 210 public String [] getTags() { 211 List columnNames ; 212 try { 213 columnNames = _queryBuilder.getColumnNames(_table1); 214 } catch(SQLException sqle) { 215 return new String [0] ; 216 } 217 return (String [])columnNames.toArray(new String [columnNames.size()]); 218 } 220 } 221 222 public class ColumnPropertyEditor2 extends PropertyEditorSupport { 223 224 public String [] getTags() { 225 226 List columnNames ; 227 try { 228 columnNames = _queryBuilder.getColumnNames(_table2); 229 } catch (SQLException sqle) { 230 return new String [0] ; 231 } 232 return (String [])columnNames.toArray(new String [columnNames.size()]); 233 } 234 } 235 } 236 | Popular Tags |