Search in sources :

Example 56 with SLDDataInterface

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

the class SLDEditorMenusTest method testSLDEditorMenus.

/**
 * Test method for {@link com.sldeditor.ui.menu.SLDEditorMenus#SLDEditorMenus(com.sldeditor.common.SLDEditorInterface)}.
 */
@Test
public void testSLDEditorMenus() {
    SLDEditorMenus.createMenus(null, null);
    SLDEditorMenus.destroyInstance();
    SLDEditorInterface application = new SLDEditorInterface() {

        @Override
        public JPanel getAppPanel() {
            return null;
        }

        @Override
        public void updateWindowTitle(boolean dataEditedFlag) {
        }

        @Override
        public void chooseNewSLD() {
        }

        @Override
        public void exitApplication() {
        }

        @Override
        public void saveFile(URL url) {
        }

        @Override
        public void saveSLDData(SLDDataInterface sldData) {
        }

        @Override
        public LoadSLDInterface getLoadSLDInterface() {
            return null;
        }

        @Override
        public JFrame getApplicationFrame() {
            return null;
        }

        @Override
        public void openFile(URL selectedURL) {
        }

        @Override
        public String getAppName() {
            return null;
        }

        @Override
        public void refreshPanel(Class<?> parent, Class<?> panelClass) {
        }
    };
    SLDEditorMenus.createMenus(application, null);
    SLDEditorMenus.destroyInstance();
    SLDEditorMenus.createMenus(application, new ArrayList<ExtensionInterface>());
    SLDEditorMenus.destroyInstance();
    EnvironmentVariableManager.destroyInstance();
    SLDEditorFile.destroyInstance();
    VendorOptionManager.destroyInstance();
    UndoManager.destroyInstance();
}
Also used : SLDEditorInterface(com.sldeditor.common.SLDEditorInterface) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ExtensionInterface(com.sldeditor.extension.ExtensionInterface) URL(java.net.URL) Test(org.junit.Test)

Example 57 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface 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 58 with SLDDataInterface

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

the class DataFlavourManager method copy.

/**
 * Copy.
 *
 * @param destinationTreeNode the destination tree node
 * @param transferredData the transferred data
 * @return true, if successful
 */
public static boolean copy(NodeInterface destinationTreeNode, TransferredData transferredData) {
    if ((destinationTreeNode == null) || (transferredData == null)) {
        return false;
    }
    Map<NodeInterface, List<SLDDataInterface>> map = new LinkedHashMap<NodeInterface, List<SLDDataInterface>>();
    for (int index = 0; index < transferredData.getDataListSize(); index++) {
        NodeInterface nodeToTransfer = (NodeInterface) transferredData.getTreePath(index).getLastPathComponent();
        SelectedFiles selectedFiles = nodeToTransfer.getHandler().getSLDContents(nodeToTransfer);
        map.put(nodeToTransfer, selectedFiles.getSldData());
    }
    return destinationTreeNode.getHandler().copyNodes(destinationTreeNode, map);
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) ArrayList(java.util.ArrayList) List(java.util.List) NodeInterface(com.sldeditor.common.NodeInterface) LinkedHashMap(java.util.LinkedHashMap)

Example 59 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface 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 60 with SLDDataInterface

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

the class SaveSLDTool method saveAllSLDToFolder.

/**
 * Save all to folder.
 *
 * @param destinationFolder the destination folder
 * @param saveExternalResources the save external resources
 */
private void saveAllSLDToFolder(File destinationFolder, boolean saveExternalResources) {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    if (!destinationFolder.exists()) {
        destinationFolder.mkdirs();
    }
    logger.info(Localisation.getString(SaveSLDTool.class, "SaveSLDTool.saveAllSLD"));
    boolean yesToAll = false;
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerName();
        if (sld != null) {
            String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String sldFilename = layerName + ExternalFilenames.addFileExtensionSeparator(SLDEditorFile.getSLDFileExtension());
            File fileToSave = new File(destinationFolder, sldFilename);
            ConsoleManager.getInstance().information(this, Localisation.getField(SaveSLDTool.class, "SaveSLDTool.savingSLDr") + " " + layerName);
            BufferedWriter out;
            try {
                out = new BufferedWriter(new FileWriter(fileToSave));
                out.write(sldString);
                out.close();
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }
            // Save external images if requested
            if (saveExternalResources) {
                List<String> externalImageList = SLDExternalImages.getExternalImages(sldData.getResourceLocator(), sld);
                for (String externalImage : externalImageList) {
                    File output = new File(destinationFolder, externalImage);
                    File parentFolder = output.getParentFile();
                    // Check to see if the destination folder exists
                    if (!parentFolder.exists()) {
                        if (output.getParentFile().mkdirs()) {
                            ConsoleManager.getInstance().error(this, Localisation.getField(SaveSLDTool.class, "SaveSLDTool.error1") + output.getAbsolutePath());
                        }
                    }
                    if (parentFolder.exists()) {
                        boolean writeOutputFile = true;
                        if (output.exists()) {
                            if (!yesToAll) {
                                Object[] options = { "Yes to All", "Yes", "No" };
                                int n = JOptionPane.showOptionDialog(Controller.getInstance().getFrame(), "Overwrite destination file?\n" + output.getAbsolutePath(), "Desintation file exists", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
                                switch(n) {
                                    case 0:
                                        yesToAll = true;
                                        break;
                                    case 1:
                                        break;
                                    case 2:
                                    default:
                                        writeOutputFile = false;
                                        break;
                                }
                            }
                        }
                        if (writeOutputFile) {
                            try {
                                URL input = DataUtilities.extendURL(sldData.getResourceLocator(), externalImage);
                                URLConnection connection = input.openConnection();
                                InputStream inputStream = connection.getInputStream();
                                BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
                                byte[] buffer = new byte[BUFFER_SIZE];
                                int n = -1;
                                FileOutputStream outputStream = new FileOutputStream(output);
                                while ((n = inputStream.read(buffer)) != -1) {
                                    outputStream.write(buffer, 0, n);
                                }
                                in.close();
                                outputStream.close();
                                ConsoleManager.getInstance().information(this, Localisation.getField(SaveSLDTool.class, "SaveSLDTool.savingExternalImage") + " " + externalImage);
                            } catch (MalformedURLException e) {
                                ConsoleManager.getInstance().exception(this, e);
                            } catch (IOException e) {
                                ConsoleManager.getInstance().exception(this, e);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) BufferedWriter(java.io.BufferedWriter) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

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