use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseInput method disconnectFromDatabase.
/**
* Disconnect from database.
*
* @param client the connection
*/
private void disconnectFromDatabase(DatabaseClientInterface client) {
if (client != null) {
client.disconnect();
DatabaseConnection connection = client.getConnection();
if (connection != null) {
featureClassMap.remove(connection);
progress.disconnect(connection);
}
}
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionTest method testDatabaseConnection.
/**
* Test method for
* {@link com.sldeditor.common.data.DatabaseConnection#DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)}.
*/
@Test
public void testDatabaseConnection() {
Param param = GeoPkgDataStoreFactory.DBTYPE;
List<DatabaseConnectionField> expectedDetailList = new ArrayList<DatabaseConnectionField>();
expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.DATABASE));
expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.USER));
String expectedDatabaseTypeLabel = "GeoPackage";
boolean expectedSupportsDuplication = false;
DatabaseConnection test = new DatabaseConnection(param, expectedDatabaseTypeLabel, expectedSupportsDuplication, expectedDetailList, new DatabaseConnectionName() {
@Override
public String getConnectionName(String duplicatePrefix, int noOfDuplicates, Map<String, String> properties) {
String connectionName = Localisation.getString(DatabaseConnectionTest.class, "common.notSet");
String databaseName = properties.get(GeoPkgDataStoreFactory.DATABASE.key);
if (databaseName != null) {
File f = new File(databaseName);
if (f.isFile()) {
connectionName = f.getName();
}
}
for (int i = 0; i < noOfDuplicates; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
Map<String, String> connectionDataMap = new HashMap<String, String>();
connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test datatbase");
test.setConnectionDataMap(connectionDataMap);
assertEquals(test.isSupportsDuplication(), expectedSupportsDuplication);
assertNotNull(test.getConnectionName());
assertNotNull(test.getDatabaseConnectionName());
assertEquals(test.getDetailList(), expectedDetailList);
assertEquals(test.getDatabaseTypeLabel(), expectedDatabaseTypeLabel);
assertTrue(test.hashCode() != 0);
assertEquals(1, test.getExpectedKeys().size());
assertEquals(GeoPkgDataStoreFactory.DATABASE.key, test.getExpectedKeys().get(0));
assertEquals(test.getDatabaseType(), param.sample);
assertEquals(test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DATABASE.key), connectionDataMap.get(GeoPkgDataStoreFactory.DATABASE.key));
assertEquals(test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DBTYPE.key), GeoPkgDataStoreFactory.DBTYPE.sample);
String expectedUserName = "test user";
test.setUserName(expectedUserName);
assertEquals(test.getUserName(), expectedUserName);
assertNotNull(test.getDBConnectionParams());
String expectedPassword = "password123";
test.setPassword(expectedPassword);
assertEquals(test.getPassword(), expectedPassword);
// Duplicate
DatabaseConnection testCopy = test.duplicate();
assertTrue(testCopy.compareTo(test) < 0);
testCopy.update(test);
assertEquals(testCopy, test);
assertEquals(testCopy, testCopy);
testCopy.setUserName("new username");
assertFalse(testCopy.equals(test));
testCopy.update(test);
assertTrue(testCopy.equals(test));
String actualString = test.encodeAsString();
DatabaseConnection newTest = DatabaseConnection.decodeString(actualString);
assertTrue(newTest.equals(test));
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionManager method updateList.
/**
* Update connection list.
*/
@Override
public void updateList() {
Set<DatabaseConnection> keySet = connectionMap.keySet();
int count = 0;
PropertyManagerFactory.getInstance().clearValue(DATABASE_CONNECTION_FIELD, true);
for (DatabaseConnection connection : keySet) {
count++;
PropertyManagerFactory.getInstance().updateValue(DATABASE_CONNECTION_FIELD, count, connection.encodeAsString());
}
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionListTool method createUI.
/**
* Creates the ui.
*/
private void createUI() {
panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(DatabaseConnectionListTool.class, "DatabaseConnectionListTool.title")));
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
btnNew = new ToolButton(Localisation.getString(DatabaseConnectionListTool.class, "DatabaseConnectionListTool.new"), "tool/newconnection.png");
btnNew.setEnabled(true);
btnNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (databaseConnectUpdate != null) {
DatabaseConnection connectionDetails = DatabaseConnectionFactory.getNewConnection(selectedDatabaseType);
DatabaseConnection newConnectionDetails = DBConnectorDetailsPanel.showDialog(null, connectionDetails);
if (newConnectionDetails != null) {
databaseConnectUpdate.addNewConnection(newConnectionDetails);
}
}
}
});
panel.add(btnNew);
btnDuplicate = new ToolButton(Localisation.getString(DatabaseConnectionListTool.class, "DatabaseConnectionListTool.duplicate"), "tool/duplicateconnection.png");
btnDuplicate.setEnabled(false);
btnDuplicate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (databaseConnectUpdate != null) {
if (!connectionList.isEmpty()) {
DatabaseConnection selectedConnectionDetails = connectionList.get(0);
DatabaseConnection duplicateItem = selectedConnectionDetails.duplicate();
databaseConnectUpdate.addNewConnection(duplicateItem);
}
}
}
});
panel.add(btnDuplicate);
btnEdit = new ToolButton(Localisation.getString(DatabaseConnectionListTool.class, "DatabaseConnectionListTool.edit"), "tool/editconnection.png");
btnEdit.setEnabled(false);
btnEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (databaseConnectUpdate != null) {
if (!connectionList.isEmpty()) {
DatabaseConnection selectedConnectionDetails = connectionList.get(0);
DatabaseConnection newConnectionDetails = DBConnectorDetailsPanel.showDialog(null, selectedConnectionDetails);
if (newConnectionDetails != null) {
databaseConnectUpdate.updateConnectionDetails(selectedConnectionDetails, newConnectionDetails);
}
}
}
}
});
panel.add(btnEdit);
btnDelete = new ToolButton(Localisation.getString(DatabaseConnectionListTool.class, "DatabaseConnectionListTool.delete"), "tool/deleteconnection.png");
btnDelete.setEnabled(false);
btnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (databaseConnectUpdate != null) {
databaseConnectUpdate.deleteConnections(connectionList);
}
}
});
panel.add(btnDelete);
panel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionListTool method setSelectedItems.
/*
* (non-Javadoc)
*
* @see com.sldeditor.tool.ToolInterface#setSelectedItems(java.util.List, java.util.List)
*/
@Override
public void setSelectedItems(List<NodeInterface> nodeTypeList, List<SLDDataInterface> sldDataList) {
connectionList.clear();
selectedDatabaseType = null;
boolean databaseNodesSelected = false;
boolean canDuplicate = true;
for (NodeInterface nodeType : nodeTypeList) {
if (nodeType instanceof DatabaseNode) {
DatabaseNode databaseNode = (DatabaseNode) nodeType;
DatabaseConnection connection = databaseNode.getConnection();
connectionList.add(connection);
databaseNodesSelected = true;
if (!connection.isSupportsDuplication()) {
canDuplicate = false;
}
} else if (nodeType instanceof DatabaseOverallNode) {
DatabaseOverallNode databaseOverallNode = (DatabaseOverallNode) nodeType;
selectedDatabaseType = databaseOverallNode.toString();
canDuplicate = false;
}
}
btnDuplicate.setEnabled(canDuplicate && databaseNodesSelected && (connectionList.size() == 1));
btnEdit.setEnabled(databaseNodesSelected && (connectionList.size() == 1));
btnDelete.setEnabled(databaseNodesSelected);
}
Aggregations