Search in sources :

Example 1 with GeoServerStyleNode

use of com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode in project sldeditor by robward-scisys.

the class GeoServerInput method getSLDContents.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#getSLDContents(com.sldeditor.extension.input.NodeInterface)
     */
@Override
public SelectedFiles getSLDContents(NodeInterface node) {
    if (node instanceof GeoServerStyleNode) {
        GeoServerStyleNode styleNode = (GeoServerStyleNode) node;
        GeoServerConnection connectionData = styleNode.getConnectionData();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
        if (client != null) {
            String sldContent = client.getStyle(styleNode.getStyle());
            SLDDataInterface sldData = new SLDData(styleNode.getStyle(), sldContent);
            sldData.setConnectionData(connectionData);
            sldData.setReadOnly(false);
            List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
            sldDataList.add(sldData);
            SelectedFiles selectedFiles = new SelectedFiles();
            selectedFiles.setSldData(sldDataList);
            selectedFiles.setDataSource(false);
            selectedFiles.setConnectionData(connectionData);
            return selectedFiles;
        }
    } else if (node instanceof GeoServerWorkspaceNode) {
        GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) node;
        GeoServerConnection connectionData = workspaceNode.getConnection();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        if (workspaceNode.isStyle()) {
            Map<String, List<StyleWrapper>> styleMap = getStyleMap(connectionData);
            if ((client != null) && (styleMap != null)) {
                for (StyleWrapper style : styleMap.get(workspaceNode.getWorkspaceName())) {
                    String sldContent = client.getStyle(style);
                    SLDDataInterface sldData = new SLDData(style, sldContent);
                    sldData.setConnectionData(connectionData);
                    sldData.setReadOnly(false);
                    sldDataList.add(sldData);
                }
            }
        }
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setSldData(sldDataList);
        selectedFiles.setDataSource(false);
        selectedFiles.setConnectionData(connectionData);
        return selectedFiles;
    } else if (node instanceof GeoServerStyleHeadingNode) {
        GeoServerStyleHeadingNode styleHeadingNode = (GeoServerStyleHeadingNode) node;
        GeoServerConnection connectionData = styleHeadingNode.getConnection();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        Map<String, List<StyleWrapper>> styleMap = getStyleMap(connectionData);
        if ((client != null) && (styleMap != null)) {
            for (String workspaceName : styleMap.keySet()) {
                for (StyleWrapper style : styleMap.get(workspaceName)) {
                    String sldContent = client.getStyle(style);
                    SLDDataInterface sldData = new SLDData(style, sldContent);
                    sldData.setConnectionData(connectionData);
                    sldData.setReadOnly(false);
                    sldDataList.add(sldData);
                }
            }
        }
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setSldData(sldDataList);
        selectedFiles.setDataSource(false);
        selectedFiles.setConnectionData(connectionData);
        return selectedFiles;
    } else if (node instanceof GeoServerNode) {
        GeoServerNode geoServerNode = (GeoServerNode) node;
        GeoServerConnection connectionData = geoServerNode.getConnection();
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setDataSource(false);
        selectedFiles.setConnectionData(connectionData);
        return selectedFiles;
    }
    return null;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode) ArrayList(java.util.ArrayList) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) GeoServerClientInterface(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerStyleHeadingNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with GeoServerStyleNode

use of com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode in project sldeditor by robward-scisys.

the class GeoServerReadProgress method populateStyles.

/**
 * Populate styles.
 *
 * @param connection the connection
 * @param geoServerNode the geo server node
 */
private void populateStyles(GeoServerConnection connection, GeoServerNode geoServerNode) {
    removeNode(geoServerNode, STYLES_NODE_TITLE);
    GeoServerStyleHeadingNode styleNode = new GeoServerStyleHeadingNode(this.handler, connection, STYLES_NODE_TITLE);
    geoServerNode.add(styleNode);
    Map<String, List<StyleWrapper>> styleMap = geoServerStyleMap.get(connection);
    for (String workspaceName : styleMap.keySet()) {
        List<StyleWrapper> styleList = styleMap.get(workspaceName);
        GeoServerWorkspaceNode workspaceNode = new GeoServerWorkspaceNode(this.handler, connection, workspaceName, true);
        // It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
        treeModel.insertNodeInto(workspaceNode, styleNode, styleNode.getChildCount());
        for (StyleWrapper styleWrapper : styleList) {
            GeoServerStyleNode childNode = new GeoServerStyleNode(this.handler, connection, styleWrapper);
            // It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
            treeModel.insertNodeInto(childNode, workspaceNode, workspaceNode.getChildCount());
        }
    }
}
Also used : GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerStyleHeadingNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode) List(java.util.List) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)

Example 3 with GeoServerStyleNode

use of com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode in project sldeditor by robward-scisys.

the class GeoServerInputTest method testGeoServerInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#GeoServerInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testGeoServerInput() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertNull(sldDataList);
        GeoServerConnection connection1 = new GeoServerConnection();
        connection1.setConnectionName("test connection 1");
        StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
        GeoServerStyleNode styleTreeNode = new GeoServerStyleNode(input, connection1, styleWrapper);
        // Try with no known GeoServer connections
        assertNull(input.getSLDContents(styleTreeNode));
        // Add some GeoServer connections
        input.addNewConnection(connection1);
        GeoServerConnection connection2 = new GeoServerConnection();
        connection2.setConnectionName("test connection 2");
        input.addNewConnection(connection2);
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(styleTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        // Try saving a null object
        assertFalse(input.save(null));
        // Save valid sld data
        assertTrue(input.save(sldData));
        // Try and save to a connection that doe snot exists
        GeoServerConnection connection3 = new GeoServerConnection();
        connection2.setConnectionName("test connection 3");
        sldData.setConnectionData(connection3);
        assertFalse(input.save(sldData));
        // Check how many connections we have
        assertEquals(2, input.getConnectionDetails().size());
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 4 with GeoServerStyleNode

use of com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode in project sldeditor by robward-scisys.

the class GeoServerReadProgress method refreshWorkspace.

/**
 * Refresh workspace.
 *
 * @param connection the connection
 * @param workspaceNode the workspace node
 */
private void refreshWorkspace(GeoServerConnection connection, GeoServerWorkspaceNode workspaceNode) {
    workspaceNode.removeAllChildren();
    Map<String, List<StyleWrapper>> styleMap = geoServerStyleMap.get(connection);
    List<StyleWrapper> styleList = styleMap.get(workspaceNode.getWorkspaceName());
    for (StyleWrapper styleWrapper : styleList) {
        GeoServerStyleNode childNode = new GeoServerStyleNode(this.handler, connection, styleWrapper);
        // It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
        treeModel.insertNodeInto(childNode, workspaceNode, workspaceNode.getChildCount());
    }
    treeModel.reload(workspaceNode);
}
Also used : StyleWrapper(com.sldeditor.common.data.StyleWrapper) List(java.util.List) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)

Example 5 with GeoServerStyleNode

use of com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode in project sldeditor by robward-scisys.

the class GeoServerStyleNodeTest method testGeoServerLayerNode.

/**
 * Test method for {@link com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode#GeoServerStyleNode(com.sldeditor.common.filesystem.FileSystemInterface)}.
 */
@Test
public void testGeoServerLayerNode() {
    FileSystemInterface fileHandler = new DummyFileSystemInput();
    GeoServerConnection connection = new GeoServerConnection();
    connection.setConnectionName("test connection");
    connection.setUserName("test user name");
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer");
    GeoServerStyleNode node = new GeoServerStyleNode(fileHandler, connection, styleWrapper);
    assertEquals(fileHandler, node.getHandler());
    assertEquals(connection, node.getConnectionData());
    assertEquals(styleWrapper, node.getStyle());
    assertEquals(BuiltInDataFlavour.GEOSERVER_STYLE_DATAITEM_FLAVOUR, node.getDataFlavour());
    assertNull(node.getDestinationText());
}
Also used : FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) Test(org.junit.Test)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)3 List (java.util.List)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 SLDData (com.sldeditor.common.data.SLDData)2 GeoServerStyleHeadingNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode)2 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)2 Test (org.junit.Test)2 FileSystemInterface (com.sldeditor.common.filesystem.FileSystemInterface)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)1 GeoServerNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode)1 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)1 GeoServerClientInterface (com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface)1 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1