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);
}
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;
}
}
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);
}
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());
}
}
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));
}
Aggregations