1 56 package org.objectstyle.cayenne.modeler.dialog.db; 57 58 import java.awt.BorderLayout ; 59 import java.awt.FlowLayout ; 60 import java.awt.event.ActionEvent ; 61 import java.awt.event.ActionListener ; 62 import java.util.Collection ; 63 import java.util.Iterator ; 64 65 import javax.swing.DefaultComboBoxModel ; 66 import javax.swing.JButton ; 67 import javax.swing.JCheckBox ; 68 import javax.swing.JComboBox ; 69 import javax.swing.JDialog ; 70 import javax.swing.JLabel ; 71 import javax.swing.JPanel ; 72 import javax.swing.JTextField ; 73 import javax.swing.event.ChangeEvent ; 74 import javax.swing.event.ChangeListener ; 75 76 import org.objectstyle.cayenne.access.DbLoader; 77 import org.objectstyle.cayenne.modeler.Application; 78 import org.objectstyle.cayenne.modeler.util.CayenneDialog; 79 80 import com.jgoodies.forms.builder.DefaultFormBuilder; 81 import com.jgoodies.forms.layout.FormLayout; 82 83 86 public class DbLoaderOptionsDialog extends CayenneDialog { 87 88 public static final int CANCEL = 0; 89 public static final int SELECT = 1; 90 91 protected JLabel schemaLabel; 92 protected JComboBox schemaSelector; 93 protected JTextField tableNamePatternField; 94 protected JCheckBox loadProcedures; 95 protected JTextField procNamePatternField; 96 protected JLabel procedureLabel; 97 protected JButton selectButton; 98 protected JButton cancelButton; 99 protected int choice; 100 101 104 public DbLoaderOptionsDialog(Collection schemas, String dbUserName, 105 boolean loadProcedures) { 106 super(Application.getFrame(), "Reengineer DB Schema: Select Options"); 107 108 init(); 109 initController(); 110 initFromModel(schemas, dbUserName, loadProcedures); 111 112 pack(); 113 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 114 setModal(true); 115 centerWindow(); 116 } 117 118 119 protected void init() { 120 121 selectButton = new JButton ("Continue"); 123 cancelButton = new JButton ("Cancel"); 124 schemaSelector = new JComboBox (); 125 tableNamePatternField = new JTextField (); 126 procNamePatternField = new JTextField (); 127 loadProcedures = new JCheckBox (); 128 129 FormLayout layout = new FormLayout( 131 "right:pref, 3dlu, fill:max(170dlu;pref):grow", 132 ""); 133 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 134 builder.setDefaultDialogBorder(); 135 136 schemaLabel = builder.append("Select Schema:", schemaSelector); 137 builder.append("Table Name Pattern:", tableNamePatternField); 138 builder.append("Load Procedures:", loadProcedures); 139 procedureLabel = builder.append("Procedure Name Pattern:", procNamePatternField); 140 141 JPanel buttons = new JPanel (new FlowLayout (FlowLayout.RIGHT)); 142 buttons.add(cancelButton); 143 buttons.add(selectButton); 144 145 getContentPane().setLayout(new BorderLayout ()); 146 getContentPane().add(builder.getPanel(), BorderLayout.CENTER); 147 getContentPane().add(buttons, BorderLayout.SOUTH); 148 } 149 150 protected void initController() { 151 selectButton.addActionListener(new ActionListener () { 152 153 public void actionPerformed(ActionEvent e) { 154 processSelect(); 155 } 156 }); 157 158 cancelButton.addActionListener(new ActionListener () { 159 160 public void actionPerformed(ActionEvent e) { 161 processCancel(); 162 } 163 }); 164 165 loadProcedures.addChangeListener(new ChangeListener () { 166 167 public void stateChanged(ChangeEvent e) { 168 procNamePatternField.setEnabled(loadProcedures.isSelected()); 169 procedureLabel.setEnabled(loadProcedures.isSelected()); 170 } 171 }); 172 } 173 174 protected void initFromModel( 175 Collection schemas, 176 String dbUserName, 177 boolean shouldLoadProcedures) { 178 179 this.choice = CANCEL; 180 this.tableNamePatternField.setText(DbLoader.WILDCARD); 181 this.loadProcedures.setSelected(shouldLoadProcedures); 182 this.procNamePatternField.setText(DbLoader.WILDCARD); 183 this.procNamePatternField.setEnabled(shouldLoadProcedures); 184 this.procedureLabel.setEnabled(shouldLoadProcedures); 185 186 boolean showSchemaSelector = schemas != null && !schemas.isEmpty(); 187 schemaSelector.setVisible(showSchemaSelector); 188 schemaLabel.setVisible(showSchemaSelector); 189 190 if (showSchemaSelector) { 191 192 schemaSelector.setModel(new DefaultComboBoxModel (schemas.toArray())); 193 194 if (dbUserName != null) { 196 Iterator it = schemas.iterator(); 197 while (it.hasNext()) { 198 String schema = (String ) it.next(); 199 if (dbUserName.equalsIgnoreCase(schema)) { 200 schemaSelector.setSelectedItem(schema); 201 break; 202 } 203 } 204 } 205 } 206 } 207 208 public int getChoice() { 209 return choice; 210 } 211 212 private void processSelect() { 213 choice = SELECT; 214 setVisible(false); 215 } 216 217 private void processCancel() { 218 choice = CANCEL; 219 setVisible(false); 220 } 221 222 225 public String getSelectedSchema() { 226 String schema = (String ) schemaSelector.getSelectedItem(); 227 return "".equals(schema) ? null : schema; 228 } 229 230 233 public String getTableNamePattern() { 234 return "".equals(tableNamePatternField.getText()) ? null : tableNamePatternField 235 .getText(); 236 } 237 238 public boolean isLoadingProcedures() { 239 return loadProcedures.isSelected(); 240 } 241 242 245 public String getProcedureNamePattern() { 246 return "".equals(procNamePatternField.getText()) ? null : procNamePatternField 247 .getText(); 248 } 249 } | Popular Tags |