Search in sources :

Example 1 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionManager method getConnectionList.

/**
 * Gets the connection list.
 *
 * @return the connection list
 */
@Override
public List<DatabaseConnection> getConnectionList() {
    List<DatabaseConnection> connectionList = new ArrayList<DatabaseConnection>();
    List<String> valueList = PropertyManagerFactory.getInstance().getMultipleValues(DATABASE_CONNECTION_FIELD);
    for (String connectionString : valueList) {
        DatabaseConnection connection = DatabaseConnection.decodeString(connectionString);
        if (connection != null) {
            connectionList.add(connection);
        }
    }
    return connectionList;
}
Also used : ArrayList(java.util.ArrayList) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 2 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseInput method connectToDatabase.

/**
 * Connect to database.
 *
 * @param connection the connection
 * @return true, if successful
 */
private boolean connectToDatabase(DatabaseConnection connection) {
    boolean isConnected = false;
    DatabaseConnection dbConnection = DatabaseConnectionManager.getInstance().getMatchingConnection(connection);
    if (dbConnection == null) {
        addNewConnection(connection);
        dbConnection = connection;
    }
    DatabaseClientInterface client = DatabaseConnectionManager.getInstance().getConnectionMap().get(dbConnection);
    if (client != null) {
        client.connect();
        if (client.isConnected()) {
            String message = String.format("%s : %s", Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.connected"), dbConnection.getConnectionName());
            ConsoleManager.getInstance().information(GeoServerConnectionTool.class, message);
            client.retrieveData();
            isConnected = true;
        } else {
            String errorMessage = String.format("%s : %s", Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.failedToConnect"), dbConnection.getConnectionName());
            ConsoleManager.getInstance().error(GeoServerConnectionTool.class, errorMessage);
        }
    }
    return isConnected;
}
Also used : GeoServerConnectionTool(com.sldeditor.tool.geoserverconnection.GeoServerConnectionTool) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 3 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseInput method deleteConnections.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.datasource.extension.filesystem.DatabaseConnectUpdateInterface#deleteConnections(java.util.List)
     */
@Override
public void deleteConnections(List<DatabaseConnection> connectionList) {
    if (connectionList == null) {
        return;
    }
    List<DefaultMutableTreeNode> overallNodesToRefresh = new ArrayList<DefaultMutableTreeNode>();
    String overallNodeName = null;
    for (DatabaseConnection connection : connectionList) {
        logger.debug("Deleting connection : " + connection.getConnectionName());
        DatabaseClientInterface client = DatabaseConnectionManager.getInstance().getConnectionMap().get(connection);
        if (client != null) {
            disconnectFromDatabase(client);
            featureClassMap.remove(connection);
            DatabaseConnectionManager.getInstance().removeConnection(connection);
            progress.deleteConnection(connection);
            DefaultMutableTreeNode overallNode = getRootDatabaseNode(connection);
            if (!overallNodesToRefresh.contains(overallNode)) {
                overallNodesToRefresh.add(overallNode);
            }
            overallNodeName = connection.getDatabaseTypeLabel();
        }
    }
    updatePropertyFile();
    for (DefaultMutableTreeNode overallNode : overallNodesToRefresh) {
        progress.refreshNode(overallNode);
    }
    progress.setFolder(overallNodeName, null, false);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 4 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseInput method populate.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.filesystem.FileSystemInterface#populate(com.sldeditor.datasource.extension.filesystem.node.FSTree,
     * javax.swing.tree.DefaultTreeModel, javax.swing.tree.DefaultMutableTreeNode)
     */
@Override
public void populate(FSTree tree, DefaultTreeModel model, DefaultMutableTreeNode rootNode) {
    progress.setTreeModel(tree, model);
    if (rootNode != null) {
        for (String key : getRootDatabaseNodes().keySet()) {
            DatabaseOverallNode node = getRootDatabaseNodes().get(key);
            rootNode.add(node);
        }
    }
    for (DatabaseConnection connection : DatabaseConnectionManager.getInstance().getConnectionMap().keySet()) {
        addConnectionNode(connection);
    }
}
Also used : DatabaseOverallNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseOverallNode) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 5 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionTool method updateButtonState.

/**
 * Update button state.
 */
private void updateButtonState() {
    int connected = 0;
    int disconnected = 0;
    if (databaseConnectState != null) {
        for (DatabaseConnection connection : connectionList) {
            if (databaseConnectState.isConnected(connection)) {
                connected++;
            } else {
                disconnected++;
            }
        }
    }
    boolean connectedEnabled = false;
    boolean disconnectedEnabled = false;
    if ((connected == 0) || (disconnected == 0)) {
        if (connected > 0) {
            disconnectedEnabled = true;
        } else if (disconnected > 0) {
            connectedEnabled = true;
        }
    }
    connectButton.setEnabled(connectedEnabled);
    disconnectButton.setEnabled(disconnectedEnabled);
}
Also used : DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

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