Example #1
0
 /**
  * Recursive method to include a tree of groups.
  *
  * @param cursor The current GroupTreeNode in the GroupsTree
  * @param parentID The integer ID associated with the cursors's parent node
  * @param currentID The integer value to associate with the cursor
  * @param out The output (PrintStream or Connection) object to which the DML should be written.
  * @param database_id Id of jabref database to which the group is part of
  */
 private int populateEntryGroupsTable(
     GroupTreeNode cursor, int parentID, int currentID, Object out, int database_id)
     throws SQLException {
   // if this group contains entries...
   if (cursor.getGroup() instanceof ExplicitGroup) {
     ExplicitGroup grp = (ExplicitGroup) cursor.getGroup();
     for (BibtexEntry be : grp.getEntries()) {
       SQLUtil.processQuery(
           out,
           "INSERT INTO entry_group (entries_id, groups_id) "
               + "VALUES ("
               + "(SELECT entries_id FROM entries WHERE jabref_eid="
               + '\''
               + be.getId()
               + "' AND database_id = "
               + database_id
               + "), "
               + "(SELECT groups_id FROM groups WHERE database_id="
               + '\''
               + database_id
               + "' AND parent_id="
               + '\''
               + parentID
               + "' AND label="
               + '\''
               + grp.getName()
               + "')"
               + ");");
     }
   }
   // recurse on child nodes (depth-first traversal)
   Object response =
       SQLUtil.processQueryWithResults(
           out,
           "SELECT groups_id FROM groups WHERE label='"
               + cursor.getGroup().getName()
               + "' AND database_id='"
               + database_id
               + "' AND parent_id='"
               + parentID
               + "';");
   // setting values to ID and myID to be used in case of textual SQL
   // export
   ++currentID;
   int myID = currentID;
   if (response instanceof Statement) {
     ResultSet rs = ((Statement) response).getResultSet();
     rs.next();
     myID = rs.getInt("groups_id");
   }
   for (Enumeration<GroupTreeNode> e = cursor.children(); e.hasMoreElements(); ) {
     currentID = populateEntryGroupsTable(e.nextElement(), myID, currentID, out, database_id);
   }
   return currentID;
 }
Example #2
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 #3
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;
 }
Example #4
0
  /**
   * Recursive worker method for the populateGroupsTable methods.
   *
   * @param cursor The current GroupTreeNode in the GroupsTree
   * @param parentID The integer ID associated with the cursors's parent node
   * @param currentID The integer value to associate with the cursor
   * @param out The output (PrintStream or Connection) object to which the DML should be written.
   * @param database_id Id of jabref database to which the groups/entries are part of
   */
  private int populateGroupsTable(
      GroupTreeNode cursor, int parentID, int currentID, Object out, int database_id)
      throws SQLException {

    AbstractGroup group = cursor.getGroup();
    String searchField = null;
    String searchExpr = null;
    String caseSens = null;
    String reg_exp = null;
    GroupHierarchyType hierContext = group.getHierarchicalContext();
    if (group instanceof KeywordGroup) {
      searchField = ((KeywordGroup) group).getSearchField();
      searchExpr = ((KeywordGroup) group).getSearchExpression();
      caseSens = ((KeywordGroup) group).isCaseSensitive() ? "1" : "0";
      reg_exp = ((KeywordGroup) group).isRegExp() ? "1" : "0";
    } else if (group instanceof SearchGroup) {
      searchExpr = ((SearchGroup) group).getSearchExpression();
      caseSens = ((SearchGroup) group).isCaseSensitive() ? "1" : "0";
      reg_exp = ((SearchGroup) group).isRegExp() ? "1" : "0";
    }
    // Protect all quotes in the group descriptions:
    if (searchField != null) {
      searchField = StringUtil.quote(searchField, "'", '\\');
    }
    if (searchExpr != null) {
      searchExpr = StringUtil.quote(searchExpr, "'", '\\');
    }

    SQLUtil.processQuery(
        out,
        "INSERT INTO groups (label, parent_id, group_types_id, search_field, "
            + "search_expression, case_sensitive, reg_exp, hierarchical_context, database_id) "
            + "VALUES ('"
            + group.getName()
            + "', "
            + parentID
            + ", (SELECT group_types_id FROM group_types where label='"
            + group.getTypeId()
            + "')"
            + ", "
            + (searchField != null ? '\'' + searchField + '\'' : "NULL")
            + ", "
            + (searchExpr != null ? '\'' + searchExpr + '\'' : "NULL")
            + ", "
            + (caseSens != null ? '\'' + caseSens + '\'' : "NULL")
            + ", "
            + (reg_exp != null ? '\'' + reg_exp + '\'' : "NULL")
            + ", "
            + hierContext.ordinal()
            + ", '"
            + database_id
            + "');");
    // recurse on child nodes (depth-first traversal)
    Object response =
        SQLUtil.processQueryWithResults(
            out,
            "SELECT groups_id FROM groups WHERE label='"
                + cursor.getGroup().getName()
                + "' AND database_id='"
                + database_id
                + "' AND parent_id='"
                + parentID
                + "';");
    // setting values to ID and myID to be used in case of textual SQL
    // export
    int myID = currentID;
    if (response instanceof Statement) {
      ResultSet rs = ((Statement) response).getResultSet();
      rs.next();
      myID = rs.getInt("groups_id");
    }
    for (Enumeration<GroupTreeNode> e = cursor.children(); e.hasMoreElements(); ) {
      ++currentID;
      currentID = populateGroupsTable(e.nextElement(), myID, currentID, out, database_id);
    }
    return currentID;
  }