Search in sources :

Example 46 with SLDDataInterface

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

the class GeoServerInput method deleteNodes.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#deleteNodes(com.sldeditor.extension.input.NodeInterface, java.util.List)
     */
@Override
public void deleteNodes(NodeInterface nodeToTransfer, List<SLDDataInterface> sldDataList) {
    if ((nodeToTransfer == null) || (sldDataList == null)) {
        return;
    }
    if (nodeToTransfer instanceof GeoServerWorkspaceNode) {
        Map<GeoServerClientInterface, String> connectionsToRefreshMap = new HashMap<GeoServerClientInterface, String>();
        for (SLDDataInterface sldData : sldDataList) {
            GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(sldData.getConnectionData());
            if (client != null) {
                connectionsToRefreshMap.put(client, sldData.getStyle().getWorkspace());
                client.deleteStyle(sldData.getStyle());
            }
        }
        // Refreshing the workspace re-populates the user interface
        for (GeoServerClientInterface client : connectionsToRefreshMap.keySet()) {
            client.refreshWorkspace(connectionsToRefreshMap.get(client));
        }
    }
}
Also used : GeoServerClientInterface(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) HashMap(java.util.HashMap) SLDDataInterface(com.sldeditor.common.SLDDataInterface)

Example 47 with SLDDataInterface

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

the class GeoServerInput method copyNodes.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#drop(com.sldeditor.extension.input.NodeInterface, java.util.Map)
     */
@Override
public boolean copyNodes(NodeInterface destinationTreeNode, Map<NodeInterface, List<SLDDataInterface>> droppedDataMap) {
    if (droppedDataMap == null) {
        return false;
    }
    if (destinationTreeNode instanceof GeoServerWorkspaceNode) {
        GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) destinationTreeNode;
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(workspaceNode.getConnection());
        if (client == null) {
            return false;
        } else {
            for (NodeInterface key : droppedDataMap.keySet()) {
                for (SLDDataInterface sldData : droppedDataMap.get(key)) {
                    StyleWrapper styleWrapper = sldData.getStyle();
                    removeStyleFileExtension(styleWrapper);
                    styleWrapper.setWorkspace(workspaceNode.getWorkspaceName());
                    client.uploadSLD(styleWrapper, sldData.getSld());
                }
            }
            client.refreshWorkspace(workspaceNode.getWorkspaceName());
        }
        return true;
    }
    return false;
}
Also used : 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) NodeInterface(com.sldeditor.common.NodeInterface)

Example 48 with SLDDataInterface

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

the class FileSystemExtension method treeItemSelected.

/**
 * Called to determine the selected items from the tree nodes selected.
 *
 * @return the selected files
 */
private SelectedFiles treeItemSelected() {
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    List<NodeInterface> nodeList = new ArrayList<NodeInterface>();
    SelectedFiles combinedFiles = new SelectedFiles();
    TreePath[] selectedPaths = tree.getSelectionPaths();
    if (selectedPaths != null) {
        for (TreePath selectedPath : selectedPaths) {
            Object o = selectedPath.getLastPathComponent();
            if (o instanceof NodeInterface) {
                NodeInterface handler = (NodeInterface) o;
                FileSystemInterface input = handler.getHandler();
                SelectedFiles selectedFiles = input.getSLDContents(handler);
                if (selectedFiles != null) {
                    combinedFiles.setDataSource(selectedFiles.isDataSource());
                    combinedFiles.setFolderName(selectedFiles.getFolderName());
                    combinedFiles.setConnectionData(selectedFiles.getConnectionData());
                    combinedFiles.setIsFolder(combinedFiles.isFolder() | selectedFiles.isFolder());
                    List<SLDDataInterface> handlerDataList = selectedFiles.getSldData();
                    if (handlerDataList != null) {
                        combinedFiles.appendSLDData(handlerDataList);
                        sldDataList.addAll(handlerDataList);
                    }
                }
                nodeList.add(handler);
            }
        }
    }
    if (toolMgr != null) {
        toolMgr.setSelectedItems(nodeList, sldDataList);
    }
    return combinedFiles;
}
Also used : FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) TreePath(javax.swing.tree.TreePath) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) ArrayList(java.util.ArrayList) NodeInterface(com.sldeditor.common.NodeInterface)

Example 49 with SLDDataInterface

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

the class MXDParser method readLayers.

/**
 * Read layers from intermediate mxd files.
 *
 * @param mxdJSON the mxd JSON
 * @param outputFormat the output format
 * @return the MXD info
 */
public static Map<String, SLDDataInterface> readLayers(String filename, SLDOutputFormatEnum outputFormat) {
    if (filename == null) {
        return null;
    }
    File intermediateFile = new File(filename);
    if (!intermediateFile.exists()) {
        return null;
    }
    MXDParser parser = new MXDParser();
    MXDInfo mxdInfo = new MXDInfo();
    mxdInfo.setIntermediateFile(intermediateFile);
    JsonObject mxdJSON = convertFileToJSON(filename);
    // Read mxd filename
    String mxdFilename = "";
    JsonElement mxdFilenameJson = mxdJSON.get("mxd");
    if (mxdFilenameJson != null) {
        mxdFilename = mxdFilenameJson.getAsString();
        mxdInfo.setMxdFilename(mxdFilename);
    }
    File f = new File(mxdFilename);
    String mxdName = f.getName();
    int pos = mxdName.lastIndexOf("\\");
    if (pos > 0) {
        mxdName = mxdName.substring(pos + 1);
    }
    mxdInfo.setMxdName(mxdName);
    // Read layers
    Map<String, SLDDataInterface> layerMap = new HashMap<String, SLDDataInterface>();
    // Read layers
    JsonArray layerList = mxdJSON.getAsJsonArray("layers");
    for (int index = 0; index < layerList.size(); index++) {
        JsonObject layer = (JsonObject) layerList.get(index);
        JsonElement layerNameElement = layer.get("name");
        if (layerNameElement != null) {
            String layerName = layerNameElement.getAsString();
            SLDDataInterface sldData = parser.importLayer(layer, outputFormat);
            layerMap.put(layerName, sldData);
        }
    }
    return layerMap;
}
Also used : JsonArray(com.google.gson.JsonArray) SLDDataInterface(com.sldeditor.common.SLDDataInterface) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) File(java.io.File)

Example 50 with SLDDataInterface

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

the class SLDTree method repopulateTree.

/**
 * Repopulate tree for a undo/redo operation.
 *
 * @param sldContents the sld contents
 */
private void repopulateTree(String sldContents) {
    int[] selectedRows = symbolTree.getSelectionRows();
    SLDDataInterface sldData = new SLDData(null, sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol.getInstance().setSld(sld);
    populateSLD();
    if ((selectedRows != null) && (selectedRows.length > 0)) {
        symbolTree.setSelectionRow(selectedRows[0]);
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface)

Aggregations

SLDDataInterface (com.sldeditor.common.SLDDataInterface)72 File (java.io.File)34 IOException (java.io.IOException)21 SLDData (com.sldeditor.common.data.SLDData)20 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)20 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)17 URL (java.net.URL)17 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)14 StyleWrapper (com.sldeditor.common.data.StyleWrapper)12 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)12 FileNotFoundException (java.io.FileNotFoundException)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 URISyntaxException (java.net.URISyntaxException)10 NodeInterface (com.sldeditor.common.NodeInterface)9 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)5 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5