use of javax.swing.tree.TreeNode 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");
}
use of javax.swing.tree.TreeNode in project sldeditor by robward-scisys.
the class FileSystemInput method deleteNodes.
/*
* (non-Javadoc)
*
* @see
* com.sldeditor.extension.input.FileSystemInterface#deleteNodes(com.sldeditor.extension.input.
* NodeInterface, java.util.List)
*/
@Override
public void deleteNodes(NodeInterface nodeToTransfer, List<SLDDataInterface> sldDataList) {
if (sldDataList == null) {
return;
}
if (nodeToTransfer instanceof FileTreeNode) {
for (SLDDataInterface sldData : sldDataList) {
String sldFilename = sldData.getSLDFile().getAbsolutePath();
File file = new File(sldFilename);
file.delete();
}
DefaultMutableTreeNode destinationNode = (DefaultMutableTreeNode) nodeToTransfer;
TreeNode parent = destinationNode.getParent();
destinationNode.removeFromParent();
if (treeModel != null) {
treeModel.reload(parent);
}
}
}
use of javax.swing.tree.TreeNode in project sldeditor by robward-scisys.
the class GeoServerLayerUpdateTool method extractWorkspaceLayers.
private void extractWorkspaceLayers(GeoServerWorkspaceNode workspaceNode) {
for (int layerIndex = 0; layerIndex < workspaceNode.getChildCount(); layerIndex++) {
TreeNode childTreeNode = workspaceNode.getChildAt(layerIndex);
if (childTreeNode instanceof GeoServerLayerNode) {
GeoServerLayerNode layerNode = (GeoServerLayerNode) childTreeNode;
GeoServerLayer layer = layerNode.getLayer();
layerList.add(layer);
}
}
}
use of javax.swing.tree.TreeNode in project Spark by igniterealtime.
the class BroadcastDialog method hideOfflineUsers.
private void hideOfflineUsers() {
int i;
if (OfflineUsers.isSelected()) {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
i = 0;
for (CheckNode node : nodes) {
if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType() == Presence.Type.unavailable) {
if (node.getParent() != null) {
TreeNode parent = node.getParent();
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node);
checkTree.getTree().setSelectionPath(new TreePath(path));
NodesGroups.add(new ArrayList<>());
NodesGroups.get(i).add(parent);
NodesGroups.get(i).add(node);
i++;
}
}
}
for (int x = 0; x < groupNodes.size(); x++) {
if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) {
OfflineGroup = x;
TreeNode parent = groupNodes.get(x).getParent();
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(groupNodes.get(x));
checkTree.getTree().setSelectionPath(new TreePath(path));
}
}
} else {
i = 0;
DefaultMutableTreeNode child = groupNodes.get(OfflineGroup);
((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, rosterNode, rosterNode.getChildCount());
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode);
checkTree.getTree().expandPath(new TreePath(path));
checkTree.expandTree();
for (CheckNode node : nodes) {
if (node.getParent() == null) {
child = (CheckNode) NodesGroups.get(i).get(1);
((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, ((CheckNode) NodesGroups.get(i).get(0)), ((CheckNode) NodesGroups.get(i).get(0)).getChildCount());
path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node);
checkTree.getTree().expandPath(new TreePath(path));
checkTree.expandTree();
i++;
}
}
}
}
use of javax.swing.tree.TreeNode in project MtgDesktopCompanion by nicho92.
the class JDeckChooserDialog method expandAll.
private void expandAll(TreePath parent) {
TreeNode node = (TreeNode) parent.getLastPathComponent();
if (node.getChildCount() >= 0) {
for (Enumeration e = node.children(); e.hasMoreElements(); ) {
TreeNode n = (TreeNode) e.nextElement();
TreePath path = parent.pathByAddingChild(n);
expandAll(path);
}
}
tree.expandPath(parent);
}
Aggregations