1 19 20 package org.netbeans.modules.web.project; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.JComboBox ; 25 import org.netbeans.modules.j2ee.common.DatasourceUIHelper; 26 import org.netbeans.modules.j2ee.deployment.common.api.Datasource; 27 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSource; 28 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSourcePopulator; 29 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSourceProvider; 30 31 36 public class WebJPADataSourceSupport implements JPADataSourcePopulator, JPADataSourceProvider{ 37 38 private final WebProject project; 39 40 41 public WebJPADataSourceSupport(WebProject project) { 42 this.project = project; 43 } 44 45 public void connect(JComboBox comboBox) { 46 DatasourceUIHelper.connect(project.getWebModule(), comboBox); 47 int size = comboBox.getItemCount(); 49 for (int i = 0; i < size; i++){ 50 Object item = comboBox.getItemAt(i); 51 if (item instanceof Datasource){ 52 comboBox.insertItemAt(new DatasourceWrapper((Datasource)item), i); 53 } 54 } 55 } 56 57 public List <JPADataSource> getDataSources() { 58 List <Datasource> datasources = new ArrayList <Datasource>(); 59 datasources.addAll(project.getWebModule().getModuleDatasources()); 60 datasources.addAll(project.getWebModule().getServerDatasources()); 61 62 List <JPADataSource> result = new ArrayList <JPADataSource>(datasources.size()); 63 for(Datasource each : datasources){ 64 result.add(new DatasourceWrapper(each)); 65 } 66 return result; 67 } 68 69 72 private static class DatasourceWrapper implements Datasource, JPADataSource{ 74 75 private Datasource delegate; 76 77 DatasourceWrapper(Datasource datasource){ 78 this.delegate = datasource; 79 } 80 81 public String getJndiName() { 82 return delegate.getJndiName(); 83 } 84 85 public String getUrl() { 86 return delegate.getUrl(); 87 } 88 89 public String getUsername() { 90 return delegate.getUsername(); 91 } 92 93 public String getPassword() { 94 return delegate.getPassword(); 95 } 96 97 public String getDriverClassName() { 98 return delegate.getDriverClassName(); 99 } 100 101 public String getDisplayName() { 102 return delegate.getDisplayName(); 103 } 104 105 public String toString(){ 106 return delegate.toString(); 107 } 108 } 109 110 } 111 | Popular Tags |