1 56 package org.objectstyle.cayenne.modeler.dialog.pref; 57 58 import java.awt.Component ; 59 60 import javax.swing.DefaultComboBoxModel ; 61 62 import org.objectstyle.cayenne.modeler.pref.DBConnectionInfo; 63 import org.objectstyle.cayenne.modeler.util.CayenneController; 64 import org.objectstyle.cayenne.modeler.util.DbAdapterInfo; 65 import org.objectstyle.cayenne.swing.BindingBuilder; 66 import org.objectstyle.cayenne.swing.ObjectBinding; 67 68 73 public class DBConnectionInfoEditor extends CayenneController { 74 75 private static final DBConnectionInfo emptyInfo = new DBConnectionInfo(); 77 78 protected DBConnectionInfoEditorView view; 79 protected DBConnectionInfo connectionInfo; 80 protected ObjectBinding[] bindings; 81 82 public DBConnectionInfoEditor(CayenneController parent) { 83 super(parent); 84 85 this.view = new DBConnectionInfoEditorView(); 86 initBindings(); 87 } 88 89 public Component getView() { 90 return view; 91 } 92 93 protected void initBindings() { 94 this.view.setEnabled(false); 95 96 DefaultComboBoxModel adapterModel = new DefaultComboBoxModel (DbAdapterInfo 97 .getStandardAdapters()); 98 adapterModel.insertElementAt("", 0); 99 view.getAdapters().setModel(adapterModel); 100 view.getAdapters().setSelectedIndex(0); 101 102 BindingBuilder builder = new BindingBuilder( 103 getApplication().getBindingFactory(), 104 this); 105 106 bindings = new ObjectBinding[5]; 107 bindings[0] = builder.bindToComboSelection( 108 view.getAdapters(), 109 "connectionInfo.dbAdapter"); 110 bindings[1] = builder.bindToTextField( 111 view.getUserName(), 112 "connectionInfo.userName"); 113 bindings[2] = builder.bindToTextField( 114 view.getPassword(), 115 "connectionInfo.password"); 116 bindings[3] = builder.bindToTextField( 117 view.getDriver(), 118 "connectionInfo.jdbcDriver"); 119 bindings[4] = builder.bindToTextField(view.getUrl(), "connectionInfo.url"); 120 } 121 122 public DBConnectionInfo getConnectionInfo() { 123 return connectionInfo != null ? connectionInfo : emptyInfo; 124 } 125 126 public void setConnectionInfo(DBConnectionInfo connectionInfo) { 127 this.connectionInfo = connectionInfo; 128 refreshView(); 129 } 130 131 protected void refreshView() { 132 getView().setEnabled(connectionInfo != null); 133 134 for (int i = 0; i < bindings.length; i++) { 135 bindings[i].updateView(); 136 } 137 } 138 } | Popular Tags |