Search in sources :

Example 6 with DataSourceConnectorInterface

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

the class DataSourcePropertiesTest method testEncodeDecodeXML.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#encodeXML(org.w3c.dom.Document, org.w3c.dom.Element, java.lang.String)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#decodeXML(org.w3c.dom.Document, java.lang.String)}.
 */
@Test
public void testEncodeDecodeXML() {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    propertyMap.put("field1", "value1");
    propertyMap.put("field2", "value2");
    propertyMap.put("field3", "value3");
    DataSourceConnectorInterface dsc = new DataSourceConnector();
    DataSourceProperties dsp = new DataSourceProperties(dsc);
    dsp.setPropertyMap(propertyMap);
    dsp.setFilename("testfilename.shp");
    dsp.setPassword("top secret password");
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = null;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Document doc = documentBuilder.newDocument();
    String elementName = "test_data_source_properties";
    Element root = doc.createElement("test");
    doc.appendChild(root);
    dsp.encodeXML(doc, root, elementName);
    // Try null parameters
    dsp.encodeXML(null, null, null);
    assertNull(DataSourceProperties.decodeXML(null, null));
    // Now decode XML
    DataSourcePropertiesInterface decodeDSP = DataSourceProperties.decodeXML(doc, elementName);
    assertEquals(dsp.getConnectionProperties(), decodeDSP.getConnectionProperties());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Document(org.w3c.dom.Document) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 7 with DataSourceConnectorInterface

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

the class DataSourcePropertiesTest method testDataSourcePropertiesWithConnector.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#DataSourceProperties(com.sldeditor.DataSourceConnectorInterface)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#setPropertyMap(java.util.Map)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#getDataSourceConnector()}.
 */
@Test
public void testDataSourcePropertiesWithConnector() {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    propertyMap.put("field1", "value1");
    propertyMap.put("field2", "value2");
    propertyMap.put("field3", "value3");
    DataSourceConnectorInterface dsc = new DataSourceConnector();
    DataSourceProperties dsp = new DataSourceProperties(dsc);
    dsp.setPropertyMap(propertyMap);
    Map<String, Object> actualPropertyMap = dsp.getConnectionProperties();
    assertEquals(propertyMap, actualPropertyMap);
    assertEquals(propertyMap, dsp.getAllConnectionProperties());
    // Is empty
    assertFalse(dsp.isEmpty());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) HashMap(java.util.HashMap) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Test(org.junit.Test)

Example 8 with DataSourceConnectorInterface

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

use of com.sldeditor.common.DataSourceConnectorInterface 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)

Example 10 with DataSourceConnectorInterface

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

the class DataSourcePropertiesTest method testPopulate.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#populate()}.
 */
@Test
public void testPopulate() {
    DataSourceProperties dsp = new DataSourceProperties(null);
    dsp.populate();
    // Does nothing
    DataSourceConnectorInterface dsc = new DataSourceConnector();
    dsp = new DataSourceProperties(dsc);
    dsp.populate();
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Test(org.junit.Test)

Aggregations

DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)10 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)7 DataSourceConnector (com.sldeditor.datasource.connector.instance.DataSourceConnector)4 SLDDataInterface (com.sldeditor.common.SLDDataInterface)3 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)3 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)3 DataSourceProperties (com.sldeditor.datasource.impl.DataSourceProperties)3 File (java.io.File)3 MalformedURLException (java.net.MalformedURLException)3 Test (org.junit.Test)3 DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)2 FlowLayout (java.awt.FlowLayout)2 HashMap (java.util.HashMap)2 JPanel (javax.swing.JPanel)2 LoadSLDInterface (com.sldeditor.common.LoadSLDInterface)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 DataSourceAttributeList (com.sldeditor.datasource.attribute.DataSourceAttributeList)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1 ToolButton (com.sldeditor.tool.ToolButton)1 BorderLayout (java.awt.BorderLayout)1