Example #1
0
  /** @param move For add: if true, remove from previous groups */
  private void insertNodes(
      JMenu menu, GroupTreeNode node, BibtexEntry[] selection, boolean add, boolean move) {
    final AbstractAction action = getAction(node, selection, add, move);

    if (node.getChildCount() == 0) {
      JMenuItem menuItem = new JMenuItem(action);
      setGroupFontAndIcon(menuItem, node.getGroup());
      menu.add(menuItem);
      if (action.isEnabled()) {
        menu.setEnabled(true);
      }
      return;
    }

    JMenu submenu;
    if (node.getGroup() instanceof AllEntriesGroup) {
      for (int i = 0; i < node.getChildCount(); ++i) {
        insertNodes(menu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
      }
    } else {
      submenu = new JMenu('[' + node.getGroup().getName() + ']');
      setGroupFontAndIcon(submenu, node.getGroup());
      // setEnabled(true) is done above/below if at least one menu
      // entry (item or submenu) is enabled
      submenu.setEnabled(action.isEnabled());
      JMenuItem menuItem = new JMenuItem(action);
      setGroupFontAndIcon(menuItem, node.getGroup());
      submenu.add(menuItem);
      submenu.add(new Separator());
      for (int i = 0; i < node.getChildCount(); ++i) {
        insertNodes(submenu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
      }
      menu.add(submenu);
      if (submenu.isEnabled()) {
        menu.setEnabled(true);
      }
    }
  }
Example #2
0
 /** @param move For add: if true, remove from all previous groups */
 private AbstractAction getAction(
     GroupTreeNode node, BibtexEntry[] selection, boolean add, boolean move) {
   AbstractAction action =
       add ? new AddToGroupAction(node, move, panel) : new RemoveFromGroupAction(node, panel);
   AbstractGroup group = node.getGroup();
   if (!move) {
     action.setEnabled(
         add
             ? group.supportsAdd() && !group.containsAll(selection)
             : group.supportsRemove() && group.containsAny(selection));
   } else {
     action.setEnabled(group.supportsAdd());
   }
   return action;
 }