// toolBarPanel.add(m_toolBars, BorderLayout.CENTER);
// add(m_toolBars, BorderLayout.NORTH);
add(toolBarPanel, BorderLayout.NORTH);
DefaultTreeModel model = new DefaultTreeModel(jtreeRoot);
// subclass JTree so that tool tips can be displayed for leaves (if necessary)
m_componentTree = new JTree(model) {
public String getToolTipText(MouseEvent e) {
if ((getRowForLocation(e.getX(), e.getY())) == -1) {
return null;
}
TreePath currPath = getPathForLocation(e.getX(), e.getY());
if (currPath.getLastPathComponent() instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)currPath.getLastPathComponent();
if (node.isLeaf()) {
JTreeLeafDetails leaf = (JTreeLeafDetails)node.getUserObject();
return leaf.getToolTipText();
}
}
return null;
}
};
m_componentTree.setEnabled(true);
m_componentTree.setToolTipText("");
m_componentTree.setRootVisible(false);
m_componentTree.setShowsRootHandles(true);
m_componentTree.setCellRenderer(new BeanIconRenderer());
DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
m_componentTree.setSelectionModel(selectionModel);
m_componentTree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (((e.getModifiers() & InputEvent.BUTTON1_MASK)
!= InputEvent.BUTTON1_MASK) || e.isAltDown()) {
boolean clearSelection = true;
/*TreePath path =
m_componentTree.getPathForLocation(e.getX(), e.getY());
if (path != null) {
DefaultMutableTreeNode tNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
if (tNode.isLeaf()) {
System.out.println("Rick click selection");
// m_componentTree.setSelectionPath(path);
}
}*/
if (clearSelection) {
// right click cancels selected component
m_toolBarBean = null;
m_mode = NONE;
KnowledgeFlowApp.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
m_componentTree.clearSelection();
}
}
TreePath p = m_componentTree.getSelectionPath();
if (p != null) {
if (p.getLastPathComponent() instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode tNode = (DefaultMutableTreeNode)p.getLastPathComponent();
if (tNode.isLeaf()) {
// System.err.println("Selected : " + tNode.getUserObject().toString());
Object userObject = tNode.getUserObject();
if (userObject instanceof JTreeLeafDetails) {
if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0 &&
((JTreeLeafDetails)userObject).isMetaBean()) {
if (m_firstUserComponentOpp) {
installWindowListenerForSavingUserStuff();
m_firstUserComponentOpp = false;
}
Vector toRemove = ((JTreeLeafDetails)userObject).getMetaBean();
DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel();
MutableTreeNode userRoot = (MutableTreeNode)tNode.getParent(); // The "User" folder
model.removeNodeFromParent(tNode);
m_userComponents.remove(toRemove);
if (m_userComponents.size() == 0) {
model.removeNodeFromParent(userRoot);
m_userCompNode = null;
}
} else {
((JTreeLeafDetails)userObject).instantiateBean();