1 56 package org.objectstyle.cayenne.modeler.editor.datanode; 57 58 import java.awt.Component ; 59 60 import org.objectstyle.cayenne.modeler.CayenneModelerController; 61 import org.objectstyle.cayenne.modeler.ProjectController; 62 import org.objectstyle.cayenne.modeler.pref.DBConnectionInfo; 63 import org.objectstyle.cayenne.project.ProjectDataSource; 64 import org.objectstyle.cayenne.swing.BindingBuilder; 65 import org.objectstyle.cayenne.swing.BindingDelegate; 66 import org.objectstyle.cayenne.swing.ObjectBinding; 67 68 71 public class JDBCDataSourceEditor extends DataSourceEditor { 72 73 protected JDBCDataSourceView view; 74 75 public JDBCDataSourceEditor(ProjectController parent, 76 BindingDelegate nodeChangeProcessor) { 77 super(parent, nodeChangeProcessor); 78 } 79 80 public Component getView() { 81 return view; 82 } 83 84 protected void prepareBindings(BindingBuilder builder) { 85 this.view = new JDBCDataSourceView(); 86 87 fieldAdapters = new ObjectBinding[6]; 88 fieldAdapters[0] = builder.bindToTextField( 89 view.getUserName(), 90 "node.dataSource.dataSourceInfo.userName"); 91 fieldAdapters[1] = builder.bindToTextField( 92 view.getPassword(), 93 "node.dataSource.dataSourceInfo.password"); 94 fieldAdapters[2] = builder.bindToTextField( 95 view.getUrl(), 96 "node.dataSource.dataSourceInfo.dataSourceUrl"); 97 fieldAdapters[3] = builder.bindToTextField( 98 view.getDriver(), 99 "node.dataSource.dataSourceInfo.jdbcDriver"); 100 fieldAdapters[4] = builder.bindToTextField( 101 view.getMaxConnections(), 102 "node.dataSource.dataSourceInfo.maxConnections"); 103 fieldAdapters[5] = builder.bindToTextField( 104 view.getMinConnections(), 105 "node.dataSource.dataSourceInfo.minConnections"); 106 107 builder.bindToAction(view.getSyncWithLocal(), "syncDataSourceAction()"); 109 110 } 111 112 public void syncDataSourceAction() { 113 CayenneModelerController mainController = getApplication().getFrameController(); 114 115 if (getNode() == null || getNode().getDataSource() == null) { 116 return; 117 } 118 119 ProjectDataSource projectDS = (ProjectDataSource) getNode().getDataSource(); 120 121 ProjectController parent = (ProjectController) getParent(); 122 String key = parent.getDataNodePreferences().getLocalDataSource(); 123 if (key == null) { 124 mainController.updateStatus("No Local DataSource selected for node..."); 125 return; 126 } 127 128 DBConnectionInfo dataSource = (DBConnectionInfo) parent 129 .getApplicationPreferenceDomain() 130 .getDetail(key, DBConnectionInfo.class, false); 131 132 if (dataSource != null) { 133 if (dataSource.copyTo(projectDS.getDataSourceInfo())) { 134 refreshView(); 135 super.nodeChangeProcessor.modelUpdated(null, null, null); 136 mainController.updateStatus(null); 137 } 138 else { 139 mainController.updateStatus("DataNode is up to date..."); 140 } 141 } 142 else { 143 mainController.updateStatus("Invalid Local DataSource selected for node..."); 144 } 145 } 146 } | Popular Tags |