Search in sources :

Example 61 with SLDDataInterface

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

the class VectorTool method loadSymbol.

/**
 * Load symbol.
 *
 * @param dsProperties the ds properties
 * @param sldData the sld data
 * @param vectorFilename the vector filename
 * @param folder the folder
 */
private void loadSymbol(DataSourcePropertiesInterface dsProperties, SLDDataInterface sldData, String vectorFilename, String folder) {
    // Vector file
    SLDEditorFile.getInstance().setSLDData(sldData);
    SLDEditorFile.getInstance().setDataSource(dsProperties);
    // Clear the data change flag
    SLDEditorFile.getInstance().fileOpenedSaved();
    // Load sld
    List<SLDDataInterface> sldFilesToLoad = new ArrayList<SLDDataInterface>();
    sldFilesToLoad.add(sldData);
    SelectedFiles selectedFiles = new SelectedFiles();
    selectedFiles.setSldData(sldFilesToLoad);
    selectedFiles.setFolderName(folder);
    LoadSLDInterface loadSLD = sldEditorInterface.getLoadSLDInterface();
    loadSLD.loadSLDString(selectedFiles);
}
Also used : LoadSLDInterface(com.sldeditor.common.LoadSLDInterface) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) ArrayList(java.util.ArrayList)

Example 62 with SLDDataInterface

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

the class YSLDTool method exportToYSLD.

/**
 * Export to YSLD.
 */
private void exportToYSLD() {
    SLDWriterInterface ysldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.YSLD);
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerNameWithOutSuffix();
        if (sld != null) {
            String sldString = ysldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String destinationFolder = sldData.getSLDFile().getParent();
            File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, YSLDTool.YSLD_FILE_EXTENSION);
            String ysldFilename = fileToSave.getName();
            if (fileToSave.exists()) {
                ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + ysldFilename);
            } else {
                ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToYSLDMsg") + " " + ysldFilename);
                BufferedWriter out;
                try {
                    out = new BufferedWriter(new FileWriter(fileToSave));
                    out.write(sldString);
                    out.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                }
            }
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileWriter(java.io.FileWriter) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 63 with SLDDataInterface

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

the class MapBoxTool method exportToSLD.

/**
 * Export to SLD.
 */
private void exportToSLD() {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerNameWithOutSuffix();
        if (sld != null) {
            String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String destinationFolder = sldData.getSLDFile().getParent();
            File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
            String sldFilename = fileToSave.getName();
            if (fileToSave.exists()) {
                ConsoleManager.getInstance().error(this, Localisation.getField(MapBoxTool.class, "MapBoxTool.destinationAlreadyExists") + " " + sldFilename);
            } else {
                ConsoleManager.getInstance().information(this, Localisation.getField(MapBoxTool.class, "MapBoxTool.exportToSLDMsg") + " " + sldFilename);
                BufferedWriter out;
                try {
                    out = new BufferedWriter(new FileWriter(fileToSave));
                    out.write(sldString);
                    out.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                }
            }
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileWriter(java.io.FileWriter) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 64 with SLDDataInterface

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

the class BatchUpdateFontPanel method populate.

/**
 * Populate the dialog.
 *
 * @param sldDataList the sld data list
 */
public void populate(List<SLDDataInterface> sldDataList) {
    List<BatchUpdateFontData> fontDataList = new ArrayList<BatchUpdateFontData>();
    for (SLDDataInterface sldData : sldDataList) {
        List<BatchUpdateFontData> fontSLDDataList = BatchUpdateFontUtils.containsFonts(sldData);
        if ((fontSLDDataList != null) && !fontSLDDataList.isEmpty()) {
            fontDataList.addAll(fontSLDDataList);
        }
    }
    dataModel.loadData(fontDataList);
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList)

Example 65 with SLDDataInterface

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

the class DatabaseInputTest method testDatabaseInput.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.database.DatabaseInput#DatabaseInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testDatabaseInput() {
    DatabaseInput input = new DatabaseInput(ToolManager.getInstance());
    input.readPropertyFile();
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        List<SLDDataInterface> sldDataList = input.open(null);
        assertNull(sldDataList);
        DatabaseConnection connection1 = DatabaseConnectionFactory.createGeoPackage();
        String featureClassName = "test feature class";
        DatabaseFeatureClassNode fcTreeNode = new DatabaseFeatureClassNode(input, connection1, featureClassName);
        Map<String, String> connectionDataMap = new HashMap<String, String>();
        connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test.gpkg");
        connection1.setConnectionDataMap(connectionDataMap);
        // Try with no known database connections
        SelectedFiles actualSLDContents = input.getSLDContents(fcTreeNode);
        assertNotNull(actualSLDContents);
        assertTrue(actualSLDContents.isDataSource());
        // Add some database connections
        input.addNewConnection(connection1);
        DatabaseConnection connection2 = DatabaseConnectionFactory.createGeoPackage();
        Map<String, String> connectionDataMap2 = new HashMap<String, String>();
        connectionDataMap2.put(GeoPkgDataStoreFactory.DATABASE.key, "test2.gpkg");
        connection2.setConnectionDataMap(connectionDataMap2);
        input.addNewConnection(connection2);
        input.addNewConnection(null);
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(fcTreeNode).getSldData();
        assertEquals(0, sldDataContentsList.size());
        // Try saving a null object
        assertFalse(input.save(null));
        // Check how many connections we have
        assertEquals(2, input.getConnectionDetails().size());
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Test(org.junit.Test)

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