Search in sources :

Example 41 with GeoServerConnection

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

the class GeoServerConnectionTool method updateButtonState.

/**
 * Update button state.
 */
private void updateButtonState() {
    int connected = 0;
    int disconnected = 0;
    if (geoServerConnectState != null) {
        for (GeoServerConnection connection : connectionList) {
            if (geoServerConnectState.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 : GeoServerConnection(com.sldeditor.common.data.GeoServerConnection)

Example 42 with GeoServerConnection

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

the class GeoServerConnectionTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    panel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) panel.getLayout();
    flowLayout.setVgap(0);
    flowLayout.setHgap(0);
    panel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.title")));
    // 
    // Connect button
    // 
    connectButton = new ToolButton(Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.connect"), "tool/connect.png");
    connectButton.setEnabled(true);
    connectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (geoServerConnectState != null) {
                connectButton.setEnabled(false);
                disconnectButton.setEnabled(false);
                geoServerConnectState.connect(connectionList);
                for (GeoServerConnection connection : connectionList) {
                    if (!geoServerConnectState.isConnected(connection)) {
                        connectButton.setEnabled(true);
                    }
                }
            }
        }
    });
    panel.add(connectButton);
    // 
    // Disconnect button
    // 
    disconnectButton = new ToolButton(Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.disconnect"), "tool/disconnect.png");
    disconnectButton.setEnabled(false);
    disconnectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (geoServerConnectState != null) {
                connectButton.setEnabled(false);
                disconnectButton.setEnabled(false);
                geoServerConnectState.disconnect(connectionList);
            }
        }
    });
    panel.add(disconnectButton);
    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) Dimension(java.awt.Dimension) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection)

Example 43 with GeoServerConnection

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

the class GeoServerConnectionListTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(GeoServerConnectionListTool.class, "GeoServerConnectionListTool.title")));
    FlowLayout flowLayout = (FlowLayout) panel.getLayout();
    flowLayout.setVgap(0);
    flowLayout.setHgap(0);
    btnNew = new ToolButton(Localisation.getString(GeoServerConnectionListTool.class, "GeoServerConnectionListTool.new"), "tool/newconnection.png");
    btnNew.setEnabled(true);
    btnNew.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (geoServerConnectUpdate != null) {
                GeoServerConnection connectionDetails = new GeoServerConnection();
                GeoServerConnection newConnectionDetails = ConnectorDetailsPanel.showDialog(null, connectionDetails);
                if (newConnectionDetails != null) {
                    geoServerConnectUpdate.addNewConnection(newConnectionDetails);
                }
            }
        }
    });
    panel.add(btnNew);
    btnDuplicate = new ToolButton(Localisation.getString(GeoServerConnectionListTool.class, "GeoServerConnectionListTool.duplicate"), "tool/duplicateconnection.png");
    btnDuplicate.setEnabled(false);
    btnDuplicate.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (geoServerConnectUpdate != null) {
                if (!connectionList.isEmpty()) {
                    GeoServerConnection selectedConnectionDetails = connectionList.get(0);
                    GeoServerConnection duplicateItem = selectedConnectionDetails.duplicate();
                    geoServerConnectUpdate.addNewConnection(duplicateItem);
                }
            }
        }
    });
    panel.add(btnDuplicate);
    btnEdit = new ToolButton(Localisation.getString(GeoServerConnectionListTool.class, "GeoServerConnectionListTool.edit"), "tool/editconnection.png");
    btnEdit.setEnabled(false);
    btnEdit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (geoServerConnectUpdate != null) {
                if (!connectionList.isEmpty()) {
                    GeoServerConnection selectedConnectionDetails = connectionList.get(0);
                    GeoServerConnection newConnectionDetails = ConnectorDetailsPanel.showDialog(null, selectedConnectionDetails);
                    if (newConnectionDetails != null) {
                        geoServerConnectUpdate.updateConnectionDetails(selectedConnectionDetails, newConnectionDetails);
                    }
                }
            }
        }
    });
    panel.add(btnEdit);
    btnDelete = new ToolButton(Localisation.getString(GeoServerConnectionListTool.class, "GeoServerConnectionListTool.delete"), "tool/deleteconnection.png");
    btnDelete.setEnabled(false);
    btnDelete.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (geoServerConnectUpdate != null) {
                geoServerConnectUpdate.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) Dimension(java.awt.Dimension) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection)

Example 44 with GeoServerConnection

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

the class FileSystemExtensionTest method testSetArguments.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.FileSystemExtension#setArguments(java.util.List)}.
 */
@Test
public void testSetArguments() {
    File configPropertiesFile = new File("./FileSystemExtensionTest.properties");
    PropertyManagerFactory.getInstance().setPropertyFile(configPropertiesFile);
    FileSystemExtension fsExt = new FileSystemExtension();
    FileSystemExtensionFactory.override(null);
    fsExt.initialise(null, new DummyToolMgr());
    // Handle null argument
    fsExt.setArguments(null);
    List<String> extensionArgList = new ArrayList<String>();
    extensionArgList.add("invalid1");
    extensionArgList.add("in.val.id2");
    extensionArgList.add("in.va.li.d3.");
    extensionArgList.add("invalid4=abc");
    String actual = fsExt.setArguments(extensionArgList);
    assertNull(actual);
    // File does not exist
    extensionArgList.clear();
    String expectedFile = "folder=X:\\asdef";
    extensionArgList.add(expectedFile);
    actual = fsExt.setArguments(extensionArgList);
    assertNull(actual);
    // Valid file
    extensionArgList.clear();
    File f = null;
    try {
        f = File.createTempFile(getClass().getSimpleName(), ".tmp");
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
    expectedFile = "folder=" + f.getParent();
    extensionArgList.add(expectedFile);
    actual = fsExt.setArguments(extensionArgList);
    assertEquals(expectedFile, actual);
    f.delete();
    // Invalid GeoServer
    extensionArgList.clear();
    String expectedGeoServer = "geoserver=unknown";
    extensionArgList.add(expectedGeoServer);
    actual = fsExt.setArguments(extensionArgList);
    assertNull(actual);
    // Valid GeoServer
    GeoServerConnection geoServerConnection = new GeoServerConnection();
    geoServerConnection.setConnectionName("GeoServer connection");
    try {
        geoServerConnection.setUrl(new URL("http://localhost/geoserver"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail();
    }
    geoServerConnection.setUserName("username");
    geoServerConnection.setPassword("password");
    GeoServerConnectionManager.getInstance().addNewConnection(null, geoServerConnection);
    GeoServerConnectionManager.getInstance().updateList();
    extensionArgList.clear();
    expectedGeoServer = "geoserver=" + geoServerConnection.getConnectionName();
    extensionArgList.add(expectedGeoServer);
    actual = fsExt.setArguments(extensionArgList);
    assertEquals(expectedGeoServer, actual);
    configPropertiesFile.delete();
}
Also used : FileSystemExtension(com.sldeditor.extension.filesystem.FileSystemExtension) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) Test(org.junit.Test)

Example 45 with GeoServerConnection

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

the class GeoServerInputTest method testUpdateConnectionDetails.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#updateConnectionDetails(com.sldeditor.common.data.GeoServerConnection, com.sldeditor.common.data.GeoServerConnection)}.
 */
@Test
public void testUpdateConnectionDetails() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    // Add some GeoServer connections
    GeoServerConnection connection1 = new GeoServerConnection();
    connection1.setConnectionName("test connection 1");
    input.addNewConnection(connection1);
    GeoServerConnection connection2 = new GeoServerConnection();
    connection2.setConnectionName("test connection 2");
    input.addNewConnection(connection2);
    // Try null parameters
    input.updateConnectionDetails(null, null);
    // Delete connection details
    List<GeoServerConnection> listToDelete = new ArrayList<GeoServerConnection>();
    listToDelete.add(connection1);
    input.deleteConnections(listToDelete);
    GeoServerConnection connection1Updated = new GeoServerConnection();
    connection1Updated.setConnectionName("update test connection 1");
    input.addNewConnection(connection1Updated);
    // Update the connection details
    input.updateConnectionDetails(connection1, connection1Updated);
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
    SLDData sldData = new SLDData(styleWrapper, "sld contents");
    sldData.setConnectionData(connection1);
    // Try and save with the old GeoServer connection details
    assertFalse(input.save(sldData));
    // Try and save with the new GeoServer connection details
    sldData.setConnectionData(connection1Updated);
    assertTrue(input.save(sldData));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ArrayList(java.util.ArrayList) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Aggregations

GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)50 Test (org.junit.Test)31 URL (java.net.URL)12 ArrayList (java.util.ArrayList)11 StyleWrapper (com.sldeditor.common.data.StyleWrapper)10 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)9 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 MalformedURLException (java.net.MalformedURLException)9 GeoServerNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode)8 SLDData (com.sldeditor.common.data.SLDData)7 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)5 GeoServerOverallNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerOverallNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 GeoServerReadProgress (com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgress)5 GeoServerClientInterface (com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface)5 HashMap (java.util.HashMap)5 List (java.util.List)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4