Revision 44308 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geodb.app/org.gvsig.geodb.app.mainplugin/src/main/java/org/gvsig/geodb/databaseworkspace/ConnectToDatabaseWorkspacePanel.java
ConnectToDatabaseWorkspacePanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.geodb.databaseworkspace; |
2 | 2 |
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
5 |
import java.awt.event.ItemEvent; |
|
6 |
import java.awt.event.ItemListener; |
|
7 |
import javax.swing.JComboBox; |
|
8 | 3 |
import javax.swing.JComponent; |
4 |
import javax.swing.event.ChangeEvent; |
|
5 |
import javax.swing.event.ChangeListener; |
|
9 | 6 |
import org.apache.commons.lang.StringUtils; |
10 | 7 |
import org.gvsig.fmap.dal.DALLocator; |
11 | 8 |
import org.gvsig.fmap.dal.DataManager; |
12 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
13 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
|
14 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
|
15 | 9 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
16 | 10 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYID; |
17 | 11 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYLABEL; |
18 | 12 |
import org.gvsig.fmap.dal.StoresRepository; |
19 | 13 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
20 |
import org.gvsig.geodb.vectorialdb.wizard.VectorialDBConnectionParamsDialog;
|
|
14 |
import org.gvsig.fmap.dal.swing.DALSwingLocator;
|
|
21 | 15 |
import org.gvsig.tools.swing.api.Component; |
16 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
|
22 | 17 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
23 | 18 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
24 |
import org.gvsig.tools.util.LabeledValueImpl; |
|
25 | 19 |
|
26 | 20 |
/** |
27 | 21 |
* |
... | ... | |
33 | 27 |
{ |
34 | 28 |
|
35 | 29 |
private Dialog dialog; |
30 |
private PickerController<JDBCServerExplorerParameters> connectionPicker; |
|
36 | 31 |
|
37 | 32 |
public ConnectToDatabaseWorkspacePanel() { |
38 | 33 |
this.initComponents(); |
... | ... | |
51 | 46 |
} |
52 | 47 |
|
53 | 48 |
private void initComponents() { |
54 |
this.fillConnections(this.cboConnection); |
|
55 |
this.cboConnection.addItemListener(new ItemListener() { |
|
49 |
this.connectionPicker = DALSwingLocator.getSwingManager().createJDBCConnectionPickerController( |
|
50 |
this.cboConnection, |
|
51 |
this.btnConnection |
|
52 |
); |
|
53 |
this.connectionPicker.addChangeListener(new ChangeListener() { |
|
56 | 54 |
@Override |
57 |
public void itemStateChanged(ItemEvent e) { |
|
58 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
59 |
doUpdateStoresRepositoryInfo(); |
|
60 |
} |
|
55 |
public void stateChanged(ChangeEvent e) { |
|
56 |
doUpdateStoresRepositoryInfo(); |
|
61 | 57 |
} |
62 | 58 |
}); |
63 |
this.btnConnection.addActionListener(new ActionListener() { |
|
64 |
@Override |
|
65 |
public void actionPerformed(ActionEvent e) { |
|
66 |
doAddConnection(); |
|
67 |
} |
|
68 |
}); |
|
69 | 59 |
doUpdateStoresRepositoryInfo(); |
70 | 60 |
} |
71 | 61 |
|
... | ... | |
75 | 65 |
} |
76 | 66 |
|
77 | 67 |
public JDBCServerExplorerParameters getConnection() { |
78 |
LabeledValueImpl<JDBCServerExplorerParameters> item = (LabeledValueImpl<JDBCServerExplorerParameters>) this.cboConnection.getSelectedItem();
|
|
79 |
if (item == null) {
|
|
68 |
JDBCServerExplorerParameters conn = this.connectionPicker.get();
|
|
69 |
if (conn == null) {
|
|
80 | 70 |
return null; |
81 | 71 |
} |
82 |
JDBCServerExplorerParameters conn = item.getValue(); |
|
83 | 72 |
DataManager dataManager = DALLocator.getDataManager(); |
84 | 73 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(conn); |
85 | 74 |
if( !workspace.isValidStoresRepository() ) { |
... | ... | |
88 | 77 |
return conn; |
89 | 78 |
} |
90 | 79 |
|
91 |
private void fillConnections(JComboBox combo) { |
|
92 |
DataManager dataManager = DALLocator.getDataManager(); |
|
93 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
|
94 |
|
|
95 |
DataServerExplorerParameters params; |
|
96 |
combo.removeAllItems(); |
|
97 |
for (DataServerExplorerPoolEntry entry : pool) { |
|
98 |
if (entry.getExplorerParameters() instanceof JDBCServerExplorerParameters) { |
|
99 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) entry.getExplorerParameters(); |
|
100 |
combo.addItem( |
|
101 |
new LabeledValueImpl<>(entry.getName(), dbParams) |
|
102 |
); |
|
103 |
} |
|
104 |
} |
|
105 |
combo.setSelectedIndex(-1); |
|
106 |
} |
|
107 |
|
|
108 |
private void doAddConnection() { |
|
109 |
VectorialDBConnectionParamsDialog newco = new VectorialDBConnectionParamsDialog(); |
|
110 |
newco.showDialog(); |
|
111 |
if (newco.isCanceled()) { |
|
112 |
return; |
|
113 |
} |
|
114 |
DataManager dataManager = DALLocator.getDataManager(); |
|
115 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
|
116 |
|
|
117 |
pool.add(newco.getConnectionName(), newco.getServerExplorerParameters()); |
|
118 |
this.fillConnections(this.cboConnection); |
|
119 |
} |
|
120 |
|
|
121 | 80 |
private void doUpdateEnableComponents() { |
122 | 81 |
boolean theEnabled = this.getConnection() != null; |
123 | 82 |
if( dialog!=null ) { |
Also available in: Unified diff