model.insertNodeInto(node, selectedNode, selectedNode.getChildCount());
CommunityTreeObject selectedObject = (CommunityTreeObject)selectedNode.getUserObject();  if (selectedObject.isCommunity()) model.insertNodeInto(node, selectedNode, selectedNode.getChildCount()); else {  DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot(); model.insertNodeInto(node, root, root.getChildCount()); }
  private void createCommunity() {    String communityName = JOptionPane.showInputDialog("New community name: ");    if (communityName == null || communityName.length() == 0)      return;    // TODO: check that name is unique    String[] communityTypes = new String[] { "Domain", "Robustness" };    JComboBox cb = new JComboBox(communityTypes);    cb.setEditable(false);    JPanel panel = new JPanel();    panel.add(new JLabel("Community Type:"));    panel.add(cb);    int result =       JOptionPane.showConfirmDialog(null, panel, "Community Type",                                    JOptionPane.OK_CANCEL_OPTION,                                    JOptionPane.PLAIN_MESSAGE);    if (result != JOptionPane.OK_OPTION)      return;    String communityType = (String)cb.getSelectedItem();    DefaultTreeModel model = (DefaultTreeModel)communityTree.getModel();    CommunityTreeObject cto =       new CommunityTreeObject(communityName, "Community");    DefaultMutableTreeNode node = new DefaultMutableTreeNode(cto, true);    TreePath selectedPath = communityTree.getSelectionPath();    if (selectedPath == null) {      DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();      model.insertNodeInto(node, root, root.getChildCount());    } else {      DefaultMutableTreeNode selectedNode =         (DefaultMutableTreeNode)selectedPath.getLastPathComponent();      model.insertNodeInto(node, selectedNode, selectedNode.getChildCount());    }    communityTree.scrollPathToVisible(new TreePath(node.getPath()));    // add community info to database    CommunityDBUtils.insertCommunityInfo(communityName, communityType);    // populate table by retrieving new info from database    communityTableUtils.getCommunityInfo(communityName);  }