Search in sources :

Example 16 with NodeInterface

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

the class TreeTransferHandler method exportDone.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
     */
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
    if (!(source instanceof JTree) || (data == null)) {
        return;
    }
    JTree tree = (JTree) source;
    NodeInterface destinationTreeNode = (NodeInterface) tree.getLastSelectedPathComponent();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
    TransferredData transferredData = null;
    try {
        transferredData = (TransferredData) data.getTransferData(destDataFlavour);
    } catch (UnsupportedFlavorException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    if (action == MOVE) {
        DataFlavourManager.deleteNodes(model, transferredData);
    }
    if (action != NONE) {
        DataFlavourManager.displayMessages(destinationTreeNode, transferredData, action);
    }
    setDragging(false);
}
Also used : JTree(javax.swing.JTree) TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) NodeInterface(com.sldeditor.common.NodeInterface) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 17 with NodeInterface

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

the class TreeTransferHandler method createTransferable.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.TransferHandler#createTransferable(javax.swing.JComponent)
     */
@Override
protected Transferable createTransferable(JComponent c) {
    transferredDataItem = null;
    if (!(c instanceof JTree)) {
        return null;
    }
    JTree tree = (JTree) c;
    if (tree.isEditing()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
        TreePath editPath = tree.getEditingPath();
        DefaultMutableTreeNode editNode = (DefaultMutableTreeNode) editPath.getLastPathComponent();
        if (node == editNode) {
            tree.stopEditing();
        }
    }
    TreePath[] paths = tree.getSelectionPaths();
    if (paths == null) {
        return null;
    } else {
        Map<NodeInterface, TreePath> map = new LinkedHashMap<NodeInterface, TreePath>();
        for (TreePath path : paths) {
            if (path.getLastPathComponent() instanceof NodeInterface) {
                NodeInterface selection = (NodeInterface) path.getLastPathComponent();
                map.put(selection, path);
            }
        }
        if (map.isEmpty()) {
            return null;
        }
        transferredDataItem = new TransferableDataItem(map);
        setDragging(true);
        return transferredDataItem;
    }
}
Also used : JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) NodeInterface(com.sldeditor.common.NodeInterface) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with NodeInterface

use of com.sldeditor.common.NodeInterface 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 19 with NodeInterface

use of com.sldeditor.common.NodeInterface 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 20 with NodeInterface

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

NodeInterface (com.sldeditor.common.NodeInterface)26 SLDDataInterface (com.sldeditor.common.SLDDataInterface)9 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)9 ArrayList (java.util.ArrayList)8 File (java.io.File)7 IOException (java.io.IOException)7 Test (org.junit.Test)7 TransferredData (com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData)5 FileNotFoundException (java.io.FileNotFoundException)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 TreePath (javax.swing.tree.TreePath)5 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)4 JTree (javax.swing.JTree)4 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)3 DatabaseNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode)3 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)3 DataFlavor (java.awt.datatransfer.DataFlavor)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 HashMap (java.util.HashMap)3 List (java.util.List)3