Search in sources :

Example 16 with DatabaseConnection

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);
        }
    }
}
Also used : DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 17 with DatabaseConnection

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));
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) DatabaseConnectionName(com.sldeditor.tool.dbconnectionlist.DatabaseConnectionName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Param(org.geotools.data.DataAccessFactory.Param) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) File(java.io.File) Test(org.junit.Test)

Example 18 with DatabaseConnection

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());
    }
}
Also used : DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 19 with DatabaseConnection

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));
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) ToolButton(com.sldeditor.tool.ToolButton) ActionEvent(java.awt.event.ActionEvent) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Dimension(java.awt.Dimension)

Example 20 with DatabaseConnection

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);
}
Also used : DatabaseNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode) DatabaseOverallNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseOverallNode) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) NodeInterface(com.sldeditor.common.NodeInterface)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)33 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)11 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)10 HashMap (java.util.HashMap)10 DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)7 File (java.io.File)6 NodeInterface (com.sldeditor.common.NodeInterface)3 DatabaseNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)2 DatabaseOverallNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseOverallNode)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)2 FileNotFoundException (java.io.FileNotFoundException)2 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Param (org.geotools.data.DataAccessFactory.Param)2 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1