Search in sources :

Example 1 with DatabaseFeatureClassNode

use of com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode in project sldeditor by robward-scisys.

the class VectorToolTest method testSupports.

/**
 * Test method for {@link com.sldeditor.tool.vector.VectorTool#supports(java.util.List, java.util.List, java.util.List)}.
 */
@Test
public void testSupports() {
    try {
        FileTreeNode vectorTreeNode = new FileTreeNode(new File("/test"), "sld_cookbook_polygon.shp");
        vectorTreeNode.setFileCategory(FileTreeNodeTypeEnum.VECTOR);
        FileTreeNode rasterTreeNode = new FileTreeNode(new File("/test"), "sld_cookbook_polygon.tif");
        rasterTreeNode.setFileCategory(FileTreeNodeTypeEnum.RASTER);
        List<Class<?>> uniqueNodeTypeList = new ArrayList<Class<?>>();
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        // Try vector file
        nodeTypeList.add(vectorTreeNode);
        VectorTool vectorTool = new VectorTool(null);
        assertTrue(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try raster file
        nodeTypeList.clear();
        nodeTypeList.add(rasterTreeNode);
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try database feature class
        nodeTypeList.clear();
        DatabaseFeatureClassNode databaseFeatureClassNode = new DatabaseFeatureClassNode(null, null, "db fc");
        nodeTypeList.add(databaseFeatureClassNode);
        assertTrue(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try invalid node class
        nodeTypeList.clear();
        nodeTypeList.add(new GeoServerStyleHeadingNode(null, null, "test"));
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try with no nodes
        nodeTypeList.clear();
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try with null
        assertFalse(vectorTool.supports(uniqueNodeTypeList, null, sldDataList));
    } catch (SecurityException e) {
        e.printStackTrace();
        fail();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) VectorTool(com.sldeditor.tool.vector.VectorTool) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) GeoServerStyleHeadingNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test)

Example 2 with DatabaseFeatureClassNode

use of com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode in project sldeditor by robward-scisys.

the class DatabaseInput method getSLDContents.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#getSLDContents(com.sldeditor.extension.input.NodeInterface)
     */
@Override
public SelectedFiles getSLDContents(NodeInterface node) {
    SelectedFiles selectedFiles = new SelectedFiles();
    if (node instanceof DatabaseFeatureClassNode) {
        List<SLDDataInterface> sldContentList = new ArrayList<SLDDataInterface>();
        selectedFiles.setSldData(sldContentList);
        selectedFiles.setDataSource(true);
    }
    return selectedFiles;
}
Also used : DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) ArrayList(java.util.ArrayList)

Example 3 with DatabaseFeatureClassNode

use of com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode in project sldeditor by robward-scisys.

the class DatabaseReadProgress method populateFeatureClasses.

/**
 * Populate feature classes.
 *
 * @param connection the connection
 * @param databaseNode the database node
 */
private void populateFeatureClasses(DatabaseConnection connection, DatabaseNode databaseNode) {
    List<String> featureClassList = databaseFeatureClassMap.get(connection);
    for (String featureClass : featureClassList) {
        DatabaseFeatureClassNode fcNode = new DatabaseFeatureClassNode(this.handler, connection, featureClass);
        // It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
        treeModel.insertNodeInto(fcNode, databaseNode, databaseNode.getChildCount());
    }
}
Also used : DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)

Example 4 with DatabaseFeatureClassNode

use of com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode in project sldeditor by robward-scisys.

the class VectorFileHandler method getSLDContents.

/**
 * Gets the SLD contents.
 *
 * @param node the node
 * @return the SLD contents
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileHandlerInterface#getSLDContents(com.sldeditor.extension.input.NodeInterface)
     */
@Override
public List<SLDDataInterface> getSLDContents(NodeInterface node) {
    if (node instanceof FileTreeNode) {
        FileTreeNode fileTreeNode = (FileTreeNode) node;
        File f = fileTreeNode.getFile();
        String fileExtension = ExternalFilenames.getFileExtension(f.getAbsolutePath());
        if (getFileExtensionList().contains(fileExtension)) {
            return open(f);
        }
    } else if (node instanceof DatabaseFeatureClassNode) {
        return open(null);
    }
    return null;
}
Also used : DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 5 with DatabaseFeatureClassNode

use of com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode in project sldeditor by robward-scisys.

the class VectorTool method createUI.

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

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
                if (sldEditorInterface != null) {
                    NodeInterface nodeInterface = nodeTypeList.get(0);
                    if (nodeInterface instanceof FileTreeNode) {
                        FileTreeNode fileTreeNode = (FileTreeNode) nodeInterface;
                        if (!importFile(fileTreeNode)) {
                            return;
                        }
                    } else if (nodeInterface instanceof DatabaseFeatureClassNode) {
                        DatabaseFeatureClassNode featureClassNode = (DatabaseFeatureClassNode) nodeInterface;
                        if (!importFeatureClass(featureClassNode)) {
                            return;
                        }
                    }
                }
            }
        }
    });
    // 
    // Set data source
    // 
    dataSourceButton = new ToolButton(Localisation.getString(VectorTool.class, "VectorTool.dataSource"), "tool/setdatasource.png");
    vectorPanel.add(dataSourceButton);
    dataSourceButton.setEnabled(false);
    dataSourceButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
                if (sldEditorInterface != null) {
                    NodeInterface nodeInterface = nodeTypeList.get(0);
                    if (nodeInterface instanceof FileTreeNode) {
                        FileTreeNode fileTreeNode = (FileTreeNode) nodeInterface;
                        setDataSource(fileTreeNode);
                    } else if (nodeInterface instanceof DatabaseFeatureClassNode) {
                        DatabaseFeatureClassNode featureClassNode = (DatabaseFeatureClassNode) nodeInterface;
                        setDataSource(featureClassNode);
                    }
                }
            }
        }
    });
    vectorPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) ActionListener(java.awt.event.ActionListener) ToolButton(com.sldeditor.tool.ToolButton) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Aggregations

DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)7 SLDDataInterface (com.sldeditor.common.SLDDataInterface)3 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)3 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 NodeInterface (com.sldeditor.common.NodeInterface)2 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)2 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1 CheckAttributeInterface (com.sldeditor.datasource.checks.CheckAttributeInterface)1 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)1 GeoServerStyleHeadingNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode)1 DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)1 ToolButton (com.sldeditor.tool.ToolButton)1 VectorTool (com.sldeditor.tool.vector.VectorTool)1 Dimension (java.awt.Dimension)1