Search in sources :

Example 6 with SLDDataInterface

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

the class SLDEditor method saveFile.

/**
 * Save file.
 *
 * @param urlToSave the url to save
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.SLDEditorInterface#saveFile(java.net.URL)
     */
@Override
public void saveFile(URL urlToSave) {
    String sldContents = getSLDString();
    SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
    sldData.updateSLDContents(sldContents);
    if (RelativePath.isLocalFile(urlToSave)) {
        StyleWrapper style = null;
        try {
            File f = new File(urlToSave.toURI());
            style = new StyleWrapper(f.getName());
        } catch (URISyntaxException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        sldData.updateStyleWrapper(style);
    }
    ReloadManager.getInstance().setFileSaved();
    saveSLDData(sldData);
    SLDEditorFile.getInstance().fileOpenedSaved();
    UndoManager.getInstance().fileSaved();
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) URISyntaxException(java.net.URISyntaxException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 7 with SLDDataInterface

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

the class SLDEditor method reloadSLDFile.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.LoadSLDInterface#reloadSLDFile()
     */
@Override
public void reloadSLDFile() {
    boolean reloadFile = true;
    if (!underTestFlag) {
        reloadFile = sldEditorDlg.reload(frame);
    }
    if (reloadFile) {
        SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
        if (sldData != null) {
            URL url = sldData.getSLDURL();
            if (url != null) {
                List<SLDDataInterface> sldDataList = null;
                for (ExtensionInterface extension : extensionList) {
                    if (sldDataList == null) {
                        sldDataList = extension.open(url);
                    }
                }
                if ((sldDataList != null) && !sldDataList.isEmpty()) {
                    SLDDataInterface firstObject = sldDataList.get(0);
                    populate(firstObject);
                }
            }
        }
        // Inform UndoManager that a new SLD file has been
        // loaded and to clear undo history
        UndoManager.getInstance().fileLoaded();
        Controller.getInstance().setPopulating(true);
        uiMgr.populateUI(1);
        Controller.getInstance().setPopulating(false);
    }
    ReloadManager.getInstance().reset();
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) ExtensionInterface(com.sldeditor.extension.ExtensionInterface) URL(java.net.URL)

Example 8 with SLDDataInterface

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

the class SLDEditor method chooseNewSLD.

/**
 * Choose new sld.
 */
@Override
public void chooseNewSLD() {
    NewSLDPanel panel = new NewSLDPanel();
    List<SLDDataInterface> newSLDList = panel.showDialog(Controller.getInstance().getFrame());
    if (newSLDList != null) {
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setSldData(newSLDList);
        if (loadSLDString(selectedFiles)) {
            uiMgr.populateUI(1);
        }
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) NewSLDPanel(com.sldeditor.create.NewSLDPanel)

Example 9 with SLDDataInterface

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

the class MapBoxWriterImpl method encodeSLD.

/**
 * Encode sld to a string.
 *
 * @param resourceLocator the resource locator
 * @param sld the sld
 * @return the MppBox string
 */
@Override
public String encodeSLD(URL resourceLocator, StyledLayerDescriptor sld) {
    SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
    if (sldData.getOriginalFormat() == SLDOutputFormatEnum.MAPBOX) {
        File f = sldData.getSLDFile();
        if ((cachedFile == null) || !cachedFile.equals(f)) {
            cachedFile = f;
            try {
                StringBuilder data = new StringBuilder();
                Stream<String> lines = Files.lines(f.toPath());
                lines.forEach(line -> data.append(line).append("\n"));
                lines.close();
                cachedString = data.toString();
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }
        }
        return cachedString;
    }
    return Localisation.getString(MapBoxWriterImpl.class, "MapBoxWriterImpl.notSupported");
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 10 with SLDDataInterface

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

the class CreateInternalDataSource method connect.

/**
 * Creates the.
 *
 * @param typeName the type name
 * @param geometryFieldName the geometry field name
 * @param editorFile the editor file
 * @return the list of datastores
 */
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
    List<DataSourceInfo> dataSourceInfoList = new ArrayList<DataSourceInfo>();
    dataSourceInfoList.add(dsInfo);
    dsInfo.reset();
    if (editorFile != null) {
        StyledLayerDescriptor sld = editorFile.getSLD();
        determineGeometryType(sld);
        ExtendedSimpleFeatureTypeBuilder b = new ExtendedSimpleFeatureTypeBuilder();
        // set the name
        typeName = INTERNAL_SCHEMA_NAME;
        dsInfo.setTypeName(typeName);
        b.setName(typeName);
        String namespace = null;
        b.setNamespaceURI(namespace);
        // add a geometry property
        // set crs first
        b.setCRS(DefaultGeographicCRS.WGS84);
        SLDDataInterface sldData = editorFile.getSLDData();
        List<DataSourceAttributeData> fieldList = sldData.getFieldList();
        // Set the geometry field by default
        geometryField.reset();
        if (geometryFieldName != null) {
            geometryField.setGeometryFieldName(geometryFieldName);
        }
        List<AttributeDescriptor> attrDescList = new ArrayList<AttributeDescriptor>();
        if ((fieldList == null) || fieldList.isEmpty()) {
            // Read the fields from the SLD
            ExtractAttributes extract = new ExtractAttributes();
            extract.extractDefaultFields(sld);
            fieldList = extract.getFields();
            // Add non-geometry fields to the feature type builder
            for (DataSourceAttributeData dsAttribute : fieldList) {
                if (dsAttribute.getName() != null) {
                    b.add(dsAttribute.getName(), dsAttribute.getType());
                }
            }
            List<String> geometryFields = extract.getGeometryFields();
            for (String localGeometryFieldName : geometryFields) {
                geometryField.setGeometryFieldName(localGeometryFieldName);
            }
        } else {
            addFields(attrDescList, b, fieldList);
        }
        attrDescList.add(addGeometryField(b, geometryField.getGeometryFieldName()));
        b.addAll(attrDescList);
        // Store the fields
        sldData.setFieldList(fieldList);
        // Build the feature type
        SimpleFeatureType schema = b.buildFeatureType();
        dsInfo.setSchema(schema);
        CreateSampleData sampleData = new CreateSampleData();
        sampleData.create(schema, fieldList);
        MemoryDataStore dataStore = sampleData.getDataStore();
        dsInfo.setDataStore(dataStore);
        dsInfo.populateFieldMap();
    }
    return dataSourceInfoList;
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ArrayList(java.util.ArrayList) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) LineString(com.vividsolutions.jts.geom.LineString) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) 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