Search in sources :

Example 16 with DataSourcePropertiesInterface

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

the class SLDEditor method populate.

/**
 * Populate the application with the SLD.
 *
 * @param sldData the sld data
 */
protected void populate(SLDDataInterface sldData) {
    String layerName = sldData.getLayerName();
    File sldEditorFile = sldData.getSldEditorFile();
    if (sldEditorFile != null) {
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDEditorFile"), sldEditorFile.getAbsolutePath()));
    }
    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDFile"), layerName));
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol selectedSymbolInstance = SelectedSymbol.getInstance();
    selectedSymbolInstance.setSld(sld);
    selectedSymbolInstance.setFilename(layerName);
    selectedSymbolInstance.setName(layerName);
    SLDEditorFile.getInstance().setSLDData(sldData);
    // Reload data source if sticky flag is set
    boolean isDataSourceSticky = SLDEditorFile.getInstance().isStickyDataSource();
    DataSourcePropertiesInterface previousDataSource = dataSource.getDataConnectorProperties();
    dataSource.reset();
    if (isDataSourceSticky) {
        SLDEditorFile.getInstance().setDataSource(previousDataSource);
    }
    dataSource.connect(ExternalFilenames.removeSuffix(layerName), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
    VendorOptionManager.getInstance().loadSLDFile(uiMgr, sld, sldData);
    LegendManager.getInstance().SLDLoaded(sldData.getLegendOptions());
    SLDEditorFile.getInstance().fileOpenedSaved();
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 17 with DataSourcePropertiesInterface

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

the class CreateExternalDataSource method connect.

/**
 * Connect.
 *
 * @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) {
        SLDDataInterface sldData = editorFile.getSLDData();
        DataSourcePropertiesInterface dataSourceProperties = sldData.getDataSourceProperties();
        Map<String, Object> map = dataSourceProperties.getConnectionProperties();
        if (dataSourceProperties.hasPassword()) {
            String password = dataSourceProperties.getPassword();
            if (password == null) {
                password = "dummy password";
                dataSourceProperties.setPassword(password);
                map = dataSourceProperties.getConnectionProperties();
            }
        }
        DataStore dataStore = null;
        try {
            dataStore = DataStoreFinder.getDataStore(map);
            if (dataStore != null) {
                // Try connecting to a vector data source
                dsInfo.setTypeName(typeName);
                SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
                SimpleFeatureType schema = source.getSchema();
                if (schema.getCoordinateReferenceSystem() == null) {
                    // No crs found to set a default and reload
                    if (dataStore instanceof ShapefileDataStore) {
                        ShapefileDataStore shapeFileDatastore = (ShapefileDataStore) dataStore;
                        CoordinateReferenceSystem crs = JCRSChooser.showDialog(Localisation.getString(CreateExternalDataSource.class, "CRSPanel.title"), defaultCRS.getIdentifiers().iterator().next().toString());
                        if (crs != null) {
                            shapeFileDatastore.forceSchemaCRS(crs);
                        }
                        source = dataStore.getFeatureSource(typeName);
                        schema = source.getSchema();
                    }
                }
                dsInfo.setSchema(schema);
                determineGeometryType(schema.getGeometryDescriptor().getType());
            } else {
                // Try connecting to a raster data source
                Object rasterFilename = map.get(DataSourceConnectorInterface.FILE_MAP_KEY);
                if (rasterFilename != null) {
                    File rasterFile = new File(ExternalFilenames.convertURLToFile((String) rasterFilename));
                    ChooseRasterFormatInterface panel = new ChooseRasterFormatPanel(Controller.getInstance().getFrame());
                    AbstractGridFormat format = DetermineRasterFormat.choose(rasterFile, panel);
                    AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
                    dsInfo.setGridCoverageReader(reader);
                } else {
                    logger.error("No matching datastore");
                }
            }
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        dsInfo.setDataStore(dataStore);
        if (!dsInfo.hasData()) {
            ConsoleManager.getInstance().error(this, Localisation.getField(CreateExternalDataSource.class, "CreateExternalDataSource.failedToConnect") + dataSourceProperties.getDebugConnectionString());
        }
    }
    return dataSourceInfoList;
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) ArrayList(java.util.ArrayList) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) IOException(java.io.IOException) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ChooseRasterFormatPanel(com.sldeditor.datasource.chooseraster.ChooseRasterFormatPanel) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) DataStore(org.geotools.data.DataStore) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) ChooseRasterFormatInterface(com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) File(java.io.File)

Example 18 with DataSourcePropertiesInterface

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

the class SLDEditorFile method setSLDData.

/**
 * Sets the SLD data.
 *
 * @param sldData the new SLD data
 */
public void setSLDData(SLDDataInterface sldData) {
    this.sldData = sldData;
    DataSourcePropertiesInterface dataSourceProperties = null;
    if (sldData != null) {
        dataSourceProperties = sldData.getDataSourceProperties();
    }
    setDataSource(dataSourceProperties);
    dataEditedFlag = false;
    // Update the environment variables, will update the predefined flag
    if (this.sldData != null) {
        EnvironmentVariableManager.getInstance().update(this.sldData.getEnvVarList());
    }
    notifySLDEditorFileHasUpdated();
}
Also used : DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface)

Example 19 with DataSourcePropertiesInterface

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

the class RasterTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    rasterPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) rasterPanel.getLayout();
    flowLayout.setVgap(0);
    flowLayout.setHgap(0);
    rasterPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(RasterTool.class, "RasterTool.title")));
    // 
    // Import raster
    // 
    importRasterButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.import"), "tool/importraster.png");
    rasterPanel.add(importRasterButton);
    importRasterButton.setEnabled(false);
    importRasterButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
                if (sldEditorInterface != null) {
                    FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
                    File rasterFile = fileTreeNode.getFile();
                    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.createSymbol"), rasterFile.getAbsolutePath()));
                    SLDDataInterface sldData = rasterReader.createRasterSLDData(rasterFile);
                    // Raster file
                    DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
                    DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
                    dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFile.getAbsolutePath()));
                    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(rasterFile.getParent());
                    LoadSLDInterface loadSLD = sldEditorInterface.getLoadSLDInterface();
                    loadSLD.loadSLDString(selectedFiles);
                }
            }
        }
    });
    // 
    // Set data source
    // 
    dataSourceButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.dataSource"), "tool/setdatasource.png");
    rasterPanel.add(dataSourceButton);
    dataSourceButton.setEnabled(false);
    dataSourceButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
                if (sldEditorInterface != null) {
                    FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
                    File rasterFile = fileTreeNode.getFile();
                    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.setDataSource"), rasterFile.getAbsolutePath()));
                    // Raster file
                    DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
                    String rasterFilename = null;
                    try {
                        rasterFilename = rasterFile.toURI().toURL().toString();
                    } catch (MalformedURLException exceptionObj) {
                        ConsoleManager.getInstance().exception(RasterTool.class, exceptionObj);
                        return;
                    }
                    DataSourcePropertiesInterface dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFilename));
                    SLDEditorFile.getInstance().setDataSource(dsProperties);
                    DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
                    if (dataSource != null) {
                        dataSource.connect(rasterFilename, SLDEditorFile.getInstance(), null);
                    }
                }
            }
        }
    });
    rasterPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) JPanel(javax.swing.JPanel) MalformedURLException(java.net.MalformedURLException) FlowLayout(java.awt.FlowLayout) LoadSLDInterface(com.sldeditor.common.LoadSLDInterface) ToolButton(com.sldeditor.tool.ToolButton) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) ActionListener(java.awt.event.ActionListener) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) ArrayList(java.util.ArrayList) List(java.util.List) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 20 with DataSourcePropertiesInterface

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

the class VectorTool method setDataSource.

/**
 * Sets the data source.
 *
 * @param fileTreeNode the new data source
 */
protected void setDataSource(FileTreeNode fileTreeNode) {
    File vectorFile = fileTreeNode.getFile();
    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.setDataSource"), vectorFile.getAbsolutePath()));
    // Vector file
    DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
    DataSourcePropertiesInterface dsProperties = null;
    try {
        dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(vectorFile.toURI().toURL().toString()));
    } catch (MalformedURLException exceptionObj) {
        ConsoleManager.getInstance().exception(VectorTool.class, exceptionObj);
        return;
    }
    SLDEditorFile sldEditorFile = SLDEditorFile.getInstance();
    sldEditorFile.setDataSource(dsProperties);
    DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
    if (dataSource != null) {
        String dataSourceName = ExternalFilenames.removeSuffix(vectorFile.getName());
        dataSource.connect(dataSourceName, sldEditorFile, CheckAttributeFactory.getCheckList());
    }
}
Also used : DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) MalformedURLException(java.net.MalformedURLException) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Aggregations

DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)21 Test (org.junit.Test)9 File (java.io.File)8 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)7 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)7 SLDDataInterface (com.sldeditor.common.SLDDataInterface)5 DataSourceConnector (com.sldeditor.datasource.connector.instance.DataSourceConnector)4 DataSourceProperties (com.sldeditor.datasource.impl.DataSourceProperties)4 HashMap (java.util.HashMap)4 SLDData (com.sldeditor.common.data.SLDData)3 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)2 VersionData (com.sldeditor.common.vendoroption.VersionData)2 DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)2 EnvVar (com.sldeditor.filter.v2.envvar.EnvVar)2 LegendOptionData (com.sldeditor.ui.legend.option.LegendOptionData)2