Search in sources :

Example 1 with FSTree

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

the class FileSystemExtension method initialise.

/**
 * Initialise.
 *
 * @param parent the parent
 * @param toolMgr the tool manager
 */
@Override
public void initialise(LoadSLDInterface parent, ToolSelectionInterface toolMgr) {
    this.toolMgr = toolMgr;
    this.parentObj = parent;
    if (toolMgr != null) {
        toolMgr.addRecursiveListener(this);
    }
    // Add extensions
    extensionList = FileSystemExtensionFactory.getFileExtensionList(toolMgr);
    extensionPanel = new JPanel();
    extensionPanel.setLayout(new BorderLayout());
    extensionPanel.setPreferredSize(new Dimension(450, 400));
    JPanel toolPanel = null;
    if (toolMgr != null) {
        toolPanel = toolMgr.getPanel();
    }
    if (toolPanel != null) {
        extensionPanel.add(toolPanel, BorderLayout.NORTH);
    }
    tree = new FSTree();
    tree.setRootVisible(true);
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode(ROOT_NODE);
        model = new DefaultTreeModel(rootNode);
        FileSystemNodeManager.create(tree, model);
        for (FileSystemInterface extension : extensionList) {
            extension.populate(tree, model, rootNode);
        }
    } catch (SecurityException e1) {
        ConsoleManager.getInstance().exception(this, e1);
    }
    tree.setModel(model);
    tree.setDragEnabled(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                int row = tree.getClosestRowForLocation(e.getX(), e.getY());
                tree.setSelectionRow(row);
                Object selectedItem = tree.getLastSelectedPathComponent();
                Thread t1 = new Thread(new Runnable() {

                    public void run() {
                        JPopupMenu popupMenu = new JPopupMenu();
                        for (FileSystemInterface extension : extensionList) {
                            extension.rightMouseButton(popupMenu, selectedItem, e);
                        }
                        if ((popupMenu.getComponentCount() > 0) && (e != null)) {
                            popupMenu.show(e.getComponent(), e.getX(), e.getY());
                        }
                    }
                });
                t1.start();
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    // Listen for Tree Selection Events
    tree.addTreeExpansionListener(new TreeExpansionListener() {

        /*
             * (non-Javadoc)
             * 
             * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
             */
        public void treeExpanded(TreeExpansionEvent evt) {
            TreePath path = evt.getPath();
            Object selectedItem = path.getLastPathComponent();
            for (FileSystemInterface extension : extensionList) {
                if (extension.treeExpanded(selectedItem)) {
                    ((DefaultTreeModel) tree.getModel()).nodeStructureChanged((TreeNode) selectedItem);
                }
            }
        }

        /*
             * (non-Javadoc)
             * 
             * @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
             */
        public void treeCollapsed(TreeExpansionEvent evt) {
        // Nothing to do
        }
    });
    // Tree selection listener
    tree.setTreeSelection(this);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.add(new JScrollPane(tree));
    extensionPanel.add(panel, BorderLayout.CENTER);
    logger.debug("FileSystem initialise finished");
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TreeExpansionListener(javax.swing.event.TreeExpansionListener) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JPopupMenu(javax.swing.JPopupMenu) FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 2 with FSTree

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

the class GeoServerInputTest method testDeleteNodes.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#deleteNodes(com.sldeditor.common.NodeInterface, java.util.List)}.
 */
@Test
public void testDeleteNodes() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    rootNode = new DefaultMutableTreeNode("Root");
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    input.populate(tree, model, rootNode);
    URL url = SLDFileHandlerTest.class.getResource("/sld/point_attribute.sld");
    List<SLDDataInterface> sldDataList = input.open(url);
    assertNull(sldDataList);
    GeoServerConnection connection1 = new GeoServerConnection();
    connection1.setConnectionName("test connection 1");
    // Add some GeoServer connections
    input.addNewConnection(connection1);
    // Try null parameters
    assertFalse(input.copyNodes(null, null));
    // Try with valid parameters
    // CHECKSTYLE:OFF
    GeoServerWorkspaceNode workspaceTreeNode = new GeoServerWorkspaceNode(input, connection1, "test workspace", false);
    // CHECKSTYLE:ON
    // Create test data
    List<SLDDataInterface> sldToDeleteList = new ArrayList<SLDDataInterface>();
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
    SLDData sldData = new SLDData(styleWrapper, "sld contents");
    sldData.setConnectionData(connection1);
    sldToDeleteList.add(sldData);
    input.deleteNodes(null, null);
    input.deleteNodes(workspaceTreeNode, null);
    input.deleteNodes(null, sldToDeleteList);
    // Try with valid parameters
    input.deleteNodes(workspaceTreeNode, sldToDeleteList);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) ArrayList(java.util.ArrayList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 3 with FSTree

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

the class GeoServerInputTest method testGeoServerInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#GeoServerInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testGeoServerInput() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertNull(sldDataList);
        GeoServerConnection connection1 = new GeoServerConnection();
        connection1.setConnectionName("test connection 1");
        StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
        GeoServerStyleNode styleTreeNode = new GeoServerStyleNode(input, connection1, styleWrapper);
        // Try with no known GeoServer connections
        assertNull(input.getSLDContents(styleTreeNode));
        // Add some GeoServer connections
        input.addNewConnection(connection1);
        GeoServerConnection connection2 = new GeoServerConnection();
        connection2.setConnectionName("test connection 2");
        input.addNewConnection(connection2);
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(styleTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        // Try saving a null object
        assertFalse(input.save(null));
        // Save valid sld data
        assertTrue(input.save(sldData));
        // Try and save to a connection that doe snot exists
        GeoServerConnection connection3 = new GeoServerConnection();
        connection2.setConnectionName("test connection 3");
        sldData.setConnectionData(connection3);
        assertFalse(input.save(sldData));
        // Check how many connections we have
        assertEquals(2, input.getConnectionDetails().size());
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 4 with FSTree

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

the class FileSystemInputTest method testFileSystemInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#FileSystemInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testFileSystemInput() {
    FileSystemInput input = new FileSystemInput(null);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertEquals(1, sldDataList.size());
        File parent = null;
        try {
            parent = new File(url.toURI());
            parent = parent.getParentFile();
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(fileTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        sldData.setSLDFile(saveFile);
        assertFalse(input.save(null));
        assertTrue(input.save(sldData));
        saveFile.delete();
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) FileNotFoundException(java.io.FileNotFoundException) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) File(java.io.File) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 5 with FSTree

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

the class FSTreeTest method testFSTree.

/**
 * Test method for {@link com.sldeditor.datasource.extension.filesystem.node.FSTree#FSTree()}.
 */
@Test
public void testFSTree() {
    FSTree tree = new FSTree();
    assertFalse(tree.isDragging());
}
Also used : FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) Test(org.junit.Test)

Aggregations

FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)6 Test (org.junit.Test)6 SLDDataInterface (com.sldeditor.common.SLDDataInterface)5 SLDData (com.sldeditor.common.data.SLDData)4 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)4 URL (java.net.URL)4 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)3 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)3 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NodeInterface (com.sldeditor.common.NodeInterface)1 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 FileSystemInterface (com.sldeditor.common.filesystem.FileSystemInterface)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1