Search in sources :

Example 21 with FileTreeNode

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

the class GeoServerInput method rightMouseButton.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.filesystem.FileSystemInterface#rightMouseButton(javax.swing.JPopupMenu, java.lang.Object, java.awt.event.MouseEvent)
     */
@Override
public void rightMouseButton(JPopupMenu popupMenu, Object selectedItem, MouseEvent e) {
    if (selectedItem instanceof GeoServerNode) {
        GeoServerNode geoServerNode = (GeoServerNode) selectedItem;
        GeoServerConnection connection = geoServerNode.getConnection();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connection);
        if (client != null) {
            if (client.isConnected()) {
                JMenuItem connectMenuItem = new JMenuItem(Localisation.getString(GeoServerInput.class, "GeoServerInput.disconnect"));
                connectMenuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent event) {
                        disconnectFromGeoServer(client);
                    }
                });
                popupMenu.add(connectMenuItem);
            } else {
                JMenuItem connectMenuItem = new JMenuItem(Localisation.getString(GeoServerInput.class, "GeoServerInput.connect"));
                connectMenuItem.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent event) {
                        GeoServerNode geoserver = (GeoServerNode) selectedItem;
                        GeoServerConnection connection = geoserver.getConnection();
                        connectToGeoServer(connection);
                    }
                });
                popupMenu.add(connectMenuItem);
            }
        }
    } else if (selectedItem instanceof FileTreeNode) {
        FileTreeNode fileNode = (FileTreeNode) selectedItem;
        if (ExternalFilenames.getFileExtension(fileNode.getFile().getAbsolutePath()).compareToIgnoreCase(SLD_FILE_EXTENSION) == 0) {
            JMenu uploadToGeoServerMenu = new JMenu(Localisation.getString(GeoServerInput.class, "GeoServerInput.uploadToGeoServer"));
            populateGeoServerConnections(uploadToGeoServerMenu);
            popupMenu.add(uploadToGeoServerMenu);
        }
    }
}
Also used : GeoServerClientInterface(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface) ActionListener(java.awt.event.ActionListener) GeoServerNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) JMenu(javax.swing.JMenu) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 22 with FileTreeNode

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

the class FileSystemInput method rightMouseButton.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.sldeditor.common.filesystem.FileSystemInterface#rightMouseButton(javax.swing.JPopupMenu,
     * java.lang.Object, java.awt.event.MouseEvent)
     */
@Override
public void rightMouseButton(JPopupMenu popupMenu, Object selectedItem, MouseEvent e) {
    if (selectedItem instanceof FileTreeNode) {
        FileTreeNode fileTreeNode = (FileTreeNode) selectedItem;
        File file = fileTreeNode.getFile();
        JMenuItem connectMenuItem = new JMenuItem(Localisation.getString(FileSystemInput.class, "FileSystemInput.copyPathToClipboard"));
        connectMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                StringSelection selection = new StringSelection(file.getAbsolutePath());
                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                clipboard.setContents(selection, selection);
            }
        });
        popupMenu.add(connectMenuItem);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Clipboard(java.awt.datatransfer.Clipboard) JMenuItem(javax.swing.JMenuItem) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) StringSelection(java.awt.datatransfer.StringSelection)

Example 23 with FileTreeNode

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

the class FileSystemInput method populate.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.filesystem.FileSystemInterface#populate(com.sldeditor.datasource.
     * extension.filesystem.node.FSTree, javax.swing.tree.DefaultTreeModel,
     * javax.swing.tree.DefaultMutableTreeNode)
     */
@Override
public void populate(FSTree tree, DefaultTreeModel model, DefaultMutableTreeNode rootNode) {
    this.treeModel = model;
    this.tree = tree;
    FileTreeNode.setTreeModel(model);
    FileTreeNode.setInputInterface(this);
    try {
        if (rootNode != null) {
            boolean prePopulateFirstLevelFolders = false;
            for (Path path : FileSystems.getDefault().getRootDirectories()) {
                logger.debug("Adding root folder : " + path.toString());
                FileTreeNode fileSystemRootNode = new FileTreeNode(path);
                fileSystemRootNode.populateDirectories(prePopulateFirstLevelFolders);
                rootNode.add(fileSystemRootNode);
            }
        }
    } catch (SecurityException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (FileNotFoundException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
}
Also used : Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 24 with FileTreeNode

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

the class MapBoxFileHandler method getSLDContents.

/*
     * (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;
        if (fileTreeNode.isDir()) {
            // Cater for folders
            return open(fileTreeNode.getFile());
        } else {
            // Cater for single file
            File f = fileTreeNode.getFile();
            String fileExtension = ExternalFilenames.getFileExtension(f.getAbsolutePath());
            if (getFileExtensionList().contains(fileExtension)) {
                return open(f);
            }
        }
    }
    return null;
}
Also used : File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 25 with FileTreeNode

use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode 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)

Aggregations

FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)33 File (java.io.File)28 SLDDataInterface (com.sldeditor.common.SLDDataInterface)17 FileNotFoundException (java.io.FileNotFoundException)17 Test (org.junit.Test)17 IOException (java.io.IOException)13 URL (java.net.URL)10 NodeInterface (com.sldeditor.common.NodeInterface)9 URISyntaxException (java.net.URISyntaxException)9 SLDData (com.sldeditor.common.data.SLDData)8 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)7 ArrayList (java.util.ArrayList)7 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)3 FileHandlerInterface (com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface)3 SLDFileHandler (com.sldeditor.extension.filesystem.file.sld.SLDFileHandler)3 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)3 Path (java.nio.file.Path)3