{
final TreePath selTreePath = m_tree.getLeadSelectionPath();
m_bTreePopupMenu = true;
m_tree.setSelectionPath(treePath);
m_tree.scrollPathToVisible(treePath);
JStatusPopupMenu menu = new JStatusPopupMenu(m_statusBar);
menu.addPopupMenuListener(new PopupMenuAdapter()
{
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent ev)
{
m_bTreePopupMenu = false;
}
});
JStatusMenuItem menuItem;
final DefaultTreeModel treeModel = (DefaultTreeModel)m_tree.getModel();
if (treeNode.isCustom())
{
menuItem = new JStatusMenuItem(Main.getString("menu_tree_remove"), Main.getString("statusbar_menutree_remove_help"), m_statusBar);
menu.add(menuItem);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent ev)
{
DefaultMutableTreeNode parent = (DefaultMutableTreeNode)treeNode.getParent();
parent.remove(treeNode);
treeModel.nodeStructureChanged(parent);
/*
JPathTreeNode root = (JPathTreeNode)treeModel.getRoot();
ArrayList<TreePath> treePathList = new ArrayList<TreePath>();
root.addExpandedChilds(m_tree, treePathList);
for (TreePath item : treePathList)
{
m_tree.expandPath(item);
}
*/
// if (selTreePath != null) m_tree.scrollPathToVisible(selTreePath);
}
});
}
else
{
menuItem = new JStatusMenuItem(Main.getString("menu_tree_add"), Main.getString("statusbar_menutree_add_help"), m_statusBar);
menu.add(menuItem);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent ev)
{
DefaultMutableTreeNode root = (DefaultMutableTreeNode)treeModel.getRoot();
String path = getPathFromTreePath(treePath);
JPathTreeNode newNode = new JPathTreeNode(path, !JPathTreeNode.hasChilds(new File(path)), false, true);
root.insert(newNode, 0);
treeModel.nodeStructureChanged(root);
m_tree.scrollPathToVisible(selTreePath);
m_tree.scrollPathToVisible(new TreePath(newNode.getPath()));
}
});
}
menu.addSeparator();
menuItem = new JStatusMenuItem(Main.getString("menu_tree_batch"), Main.getString("statusbar_menutree_batch_help"), m_statusBar);
menu.add(menuItem);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent ev)
{
m_batchData.m_srcFolder = getPathFromTreePath(treePath);
doBatch();
}
});
menu.addSeparator();
menuItem = new JStatusMenuItem(Main.getString("cancel"), Main.getString("statusbar_menutree_cancel_help"), m_statusBar);
menu.add(menuItem);
menu.show(ev.getComponent(), ev.getX(), ev.getY());
}
}
}
}
});