Search in sources :

Example 6 with StyleWrapper

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

the class YSLDFileHandler method internalOpenFile.

/**
 * Internal open file.
 *
 * @param f the file
 * @param list the list
 */
private void internalOpenFile(File f, List<SLDDataInterface> list) {
    if (f.isFile() && FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
        try {
            String contents = readFile(f, Charset.defaultCharset());
            StyledLayerDescriptor sld = Ysld.parse(contents);
            // Convert YSLD to SLD string
            if (sldWriter == null) {
                sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
            }
            String sldContents = sldWriter.encodeSLD(null, sld);
            SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            sldData.setReadOnly(false);
            sldData.setOriginalFormat(SLDOutputFormatEnum.YSLD);
            list.add(sldData);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) IOException(java.io.IOException)

Example 7 with StyleWrapper

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

the class GeoServerInput method populateWorkspaceList.

/**
 * Populate workspace list.
 *
 * @param client the client
 * @param parentMenu the parent menu
 */
private void populateWorkspaceList(GeoServerClientInterface client, JMenu parentMenu) {
    for (String workspaceName : client.getWorkspaceList()) {
        JMenuItem workspaceMenuItem = new JMenuItem(workspaceName);
        workspaceMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
                StyleWrapper styleWrapper = sldData.getStyle();
                removeStyleFileExtension(styleWrapper);
                styleWrapper.setWorkspace(workspaceName);
                client.uploadSLD(styleWrapper, sldData.getSld());
                client.refreshWorkspace(workspaceName);
            }
        });
        parentMenu.add(workspaceMenuItem);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem)

Example 8 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper 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 9 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper 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 10 with StyleWrapper

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

the class GeoServerClient method parseLayerList.

/**
 * Parses the layer list.
 *
 * @param reader the reader
 * @param existingWorkspaceList the existing workspace list
 * @param workspaceName the workspace name
 */
private void parseLayerList(GeoServerRESTReader reader, List<String> existingWorkspaceList, String workspaceName) {
    Thread t1 = new Thread(new Runnable() {

        public void run() {
            List<String> workspaceList = null;
            if (workspaceName == null) {
                workspaceList = existingWorkspaceList;
                // Add the default workspace last
                workspaceList.add(null);
            }
            Map<String, List<GeoServerLayer>> layerMap = new LinkedHashMap<String, List<GeoServerLayer>>();
            RESTLayerList layers = reader.getLayers();
            int count = 1;
            int total = layers.size();
            for (NameLinkElem featureTypeName : layers) {
                @SuppressWarnings("deprecation") RESTLayer layer = reader.getLayer(featureTypeName.getName());
                if (layer != null) {
                    String layerName = layer.getName();
                    String workspace = null;
                    for (String workspaceNameToTest : workspaceList) {
                        if (reader.existsLayer(workspaceNameToTest, layerName, true)) {
                            if (workspaceNameToTest == null) {
                                workspace = DEFAULT_WORKSPACE_NAME;
                            } else {
                                workspace = workspaceNameToTest;
                            }
                            break;
                        }
                    }
                    GeoServerLayer geoServerlayer = new GeoServerLayer();
                    geoServerlayer.setLayerWorkspace(workspace);
                    geoServerlayer.setLayerName(layerName);
                    geoServerlayer.setConnection(connection);
                    StyleWrapper styleWrapper = new StyleWrapper();
                    styleWrapper.setStyle(layer.getDefaultStyle());
                    String styleWorkspace = layer.getDefaultStyleWorkspace();
                    styleWrapper.setWorkspace((styleWorkspace == null) ? DEFAULT_WORKSPACE_NAME : styleWorkspace);
                    geoServerlayer.setStyle(styleWrapper);
                    List<GeoServerLayer> layerList = layerMap.get(workspace);
                    if (layerList == null) {
                        layerList = new ArrayList<GeoServerLayer>();
                        layerMap.put(workspace, layerList);
                    }
                    layerList.add(geoServerlayer);
                    if (parentObj != null) {
                        parentObj.readLayersProgress(connection, count, total);
                    }
                }
                count++;
            }
            if (parentObj != null) {
                parentObj.readLayersComplete(connection, layerMap);
            }
        }
    });
    t1.start();
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) RESTLayer(it.geosolutions.geoserver.rest.decoder.RESTLayer) ArrayList(java.util.ArrayList) RESTStyleList(it.geosolutions.geoserver.rest.decoder.RESTStyleList) ArrayList(java.util.ArrayList) List(java.util.List) RESTLayerList(it.geosolutions.geoserver.rest.decoder.RESTLayerList) RESTLayerList(it.geosolutions.geoserver.rest.decoder.RESTLayerList) NameLinkElem(it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)59 SLDData (com.sldeditor.common.data.SLDData)35 Test (org.junit.Test)31 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)15 File (java.io.File)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)12 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)10 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 List (java.util.List)9 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)8 IOException (java.io.IOException)8 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)7 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 HashMap (java.util.HashMap)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)4 NamedLayer (org.geotools.styling.NamedLayer)4