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/WorkspaceConfigurationPanel.java
WorkspaceConfigurationPanel.java | ||
---|---|---|
3 | 3 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
4 | 4 |
import java.awt.event.ActionEvent; |
5 | 5 |
import java.awt.event.ActionListener; |
6 |
import java.awt.event.ItemEvent; |
|
7 |
import java.awt.event.ItemListener; |
|
8 | 6 |
import javax.swing.JButton; |
9 |
import javax.swing.JComboBox; |
|
10 | 7 |
import javax.swing.JComponent; |
8 |
import javax.swing.event.ChangeEvent; |
|
9 |
import javax.swing.event.ChangeListener; |
|
11 | 10 |
import org.apache.commons.lang.StringUtils; |
12 | 11 |
import org.gvsig.featureform.swing.JFeaturesForm; |
13 | 12 |
import org.gvsig.fmap.dal.DALLocator; |
14 | 13 |
import org.gvsig.fmap.dal.DataManager; |
15 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
16 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
|
17 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
|
18 | 14 |
import org.gvsig.fmap.dal.DataStoreParameters; |
19 | 15 |
import org.gvsig.fmap.dal.StoresRepository; |
20 | 16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
... | ... | |
22 | 18 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
23 | 19 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
24 | 20 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
25 |
import org.gvsig.geodb.vectorialdb.wizard.VectorialDBConnectionParamsDialog; |
|
26 | 21 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYID; |
27 | 22 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYLABEL; |
28 | 23 |
import org.gvsig.tools.swing.api.Component; |
29 | 24 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
25 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
|
30 | 26 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
31 | 27 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
32 | 28 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
33 |
import org.gvsig.tools.util.LabeledValueImpl; |
|
34 | 29 |
import org.slf4j.Logger; |
35 | 30 |
import org.slf4j.LoggerFactory; |
36 | 31 |
|
... | ... | |
163 | 158 |
private TableController resourcesTableController; |
164 | 159 |
private TableController repositoryTableController; |
165 | 160 |
private TableController configurationTableController; |
161 |
private PickerController<JDBCServerExplorerParameters> connectionPicker; |
|
166 | 162 |
|
167 | 163 |
public WorkspaceConfigurationPanel() { |
168 | 164 |
this.initComponents(); |
169 | 165 |
} |
170 | 166 |
|
171 | 167 |
private void initComponents() { |
172 |
this.fillConnections(this.cboConnections); |
|
173 |
this.cboConnections.addItemListener(new ItemListener() { |
|
168 |
this.connectionPicker = DALSwingLocator.getSwingManager().createJDBCConnectionPickerController( |
|
169 |
this.cboConnections, |
|
170 |
this.btnAddConnection |
|
171 |
); |
|
172 |
this.connectionPicker.addChangeListener(new ChangeListener() { |
|
174 | 173 |
@Override |
175 |
public void itemStateChanged(ItemEvent e) { |
|
176 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
177 |
doUpdateEnableComponents(); |
|
178 |
doUpdateStoresRepositoryInfo(); |
|
179 |
} |
|
174 |
public void stateChanged(ChangeEvent e) { |
|
175 |
doUpdateEnableComponents(); |
|
176 |
doUpdateStoresRepositoryInfo(); |
|
180 | 177 |
} |
181 | 178 |
}); |
182 |
this.btnAddConnection.addActionListener(new ActionListener() { |
|
183 |
@Override |
|
184 |
public void actionPerformed(ActionEvent e) { |
|
185 |
doAddConnection(); |
|
186 |
} |
|
187 |
}); |
|
188 | 179 |
this.resourcesTableController = new TableController( |
189 | 180 |
DatabaseWorkspaceManager.TABLE_RESOURCES, |
190 | 181 |
btnCreateResourceTable, |
... | ... | |
230 | 221 |
} |
231 | 222 |
|
232 | 223 |
public JDBCServerExplorerParameters getConnection() { |
233 |
LabeledValueImpl<JDBCServerExplorerParameters> item = (LabeledValueImpl<JDBCServerExplorerParameters>) this.cboConnections.getSelectedItem(); |
|
234 |
if (item == null) { |
|
235 |
return null; |
|
236 |
} |
|
237 |
return item.getValue(); |
|
224 |
JDBCServerExplorerParameters conn = this.connectionPicker.get(); |
|
225 |
return conn; |
|
238 | 226 |
} |
239 | 227 |
|
240 |
private void fillConnections(JComboBox combo) { |
|
241 |
DataManager dataManager = DALLocator.getDataManager(); |
|
242 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
|
243 |
|
|
244 |
DataServerExplorerParameters params; |
|
245 |
combo.removeAllItems(); |
|
246 |
for (DataServerExplorerPoolEntry entry : pool) { |
|
247 |
if (entry.getExplorerParameters() instanceof JDBCServerExplorerParameters) { |
|
248 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) entry.getExplorerParameters(); |
|
249 |
combo.addItem( |
|
250 |
new LabeledValueImpl<>(entry.getName(), dbParams) |
|
251 |
); |
|
252 |
} |
|
253 |
} |
|
254 |
combo.setSelectedIndex(-1); |
|
255 |
} |
|
256 |
|
|
257 |
private void doAddConnection() { |
|
258 |
VectorialDBConnectionParamsDialog newco = new VectorialDBConnectionParamsDialog(); |
|
259 |
newco.showDialog(); |
|
260 |
if (newco.isCanceled()) { |
|
261 |
return; |
|
262 |
} |
|
263 |
DataManager dataManager = DALLocator.getDataManager(); |
|
264 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
|
265 |
|
|
266 |
pool.add(newco.getConnectionName(), newco.getServerExplorerParameters()); |
|
267 |
this.fillConnections(this.cboConnections); |
|
268 |
} |
|
269 |
|
|
270 | 228 |
private void doUpdateEnableComponents() { |
271 | 229 |
boolean theEnabled = this.getConnection() != null; |
272 | 230 |
this.repositoryTableController.setEnabled(theEnabled); |
Also available in: Unified diff