Exemple #1
0
 /** Sets the font and icon to be used, depending on the group */
 private void setGroupFontAndIcon(JMenuItem menuItem, AbstractGroup group) {
   if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) {
     menuItem.setFont(menuItem.getFont().deriveFont(group.isDynamic() ? Font.ITALIC : Font.PLAIN));
   }
   if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_ICONS)) {
     switch (group.getHierarchicalContext()) {
       case INCLUDING:
         menuItem.setIcon(GUIGlobals.getImage("groupIncluding"));
         break;
       case REFINING:
         menuItem.setIcon(GUIGlobals.getImage("groupRefining"));
         break;
       default:
         menuItem.setIcon(GUIGlobals.getImage("groupRegular"));
         break;
     }
   }
 }
Exemple #2
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;
  }