Search in sources :

Example 11 with SelectedFiles

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

the class DataFlavourManager method deleteNodes.

/**
 * Delete nodes.
 *
 * @param model the model
 * @param transferredData the transferred data
 */
public static void deleteNodes(DefaultTreeModel model, TransferredData transferredData) {
    if ((model == null) || (transferredData == null)) {
        return;
    }
    for (int index = 0; index < transferredData.getDataListSize(); index++) {
        NodeInterface nodeToTransfer = (NodeInterface) transferredData.getTreePath(index).getLastPathComponent();
        SelectedFiles selectedFiles = nodeToTransfer.getHandler().getSLDContents(nodeToTransfer);
        nodeToTransfer.getHandler().deleteNodes(nodeToTransfer, selectedFiles.getSldData());
    }
}
Also used : SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) NodeInterface(com.sldeditor.common.NodeInterface)

Example 12 with SelectedFiles

use of com.sldeditor.common.filesystem.SelectedFiles 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 13 with SelectedFiles

use of com.sldeditor.common.filesystem.SelectedFiles 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 14 with SelectedFiles

use of com.sldeditor.common.filesystem.SelectedFiles 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

SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)7 NodeInterface (com.sldeditor.common.NodeInterface)4 List (java.util.List)3 Test (org.junit.Test)3 LoadSLDInterface (com.sldeditor.common.LoadSLDInterface)2 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)2 SLDData (com.sldeditor.common.data.SLDData)2 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 File (java.io.File)2 HashMap (java.util.HashMap)2 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)1 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 FileSystemInterface (com.sldeditor.common.filesystem.FileSystemInterface)1 PrefData (com.sldeditor.common.preferences.PrefData)1 NewSLDPanel (com.sldeditor.create.NewSLDPanel)1