Search in sources :

Example 1 with KeywordGroup

use of org.jabref.model.groups.KeywordGroup in project jabref by JabRef.

the class GroupTreeNodeViewModel method getDescription.

public String getDescription() {
    AbstractGroup group = node.getGroup();
    String shortDescription = "";
    boolean showDynamic = true;
    if (group instanceof ExplicitGroup) {
        shortDescription = GroupDescriptions.getShortDescriptionExplicitGroup((ExplicitGroup) group);
    } else if (group instanceof KeywordGroup) {
        shortDescription = GroupDescriptions.getShortDescriptionKeywordGroup((KeywordGroup) group, showDynamic);
    } else if (group instanceof SearchGroup) {
        shortDescription = GroupDescriptions.getShortDescription((SearchGroup) group, showDynamic);
    } else {
        shortDescription = GroupDescriptions.getShortDescriptionAllEntriesGroup();
    }
    return "<html>" + shortDescription + "</html>";
}
Also used : KeywordGroup(org.jabref.model.groups.KeywordGroup) AbstractGroup(org.jabref.model.groups.AbstractGroup) SearchGroup(org.jabref.model.groups.SearchGroup) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Example 2 with KeywordGroup

use of org.jabref.model.groups.KeywordGroup in project jabref by JabRef.

the class WarnAssignmentSideEffects method warnAssignmentSideEffects.

/**
     * Warns the user of undesired side effects of an explicit assignment/removal of entries to/from this group.
     * Currently there are four types of groups: AllEntriesGroup, SearchGroup - do not support explicit assignment.
     * ExplicitGroup and KeywordGroup - this modifies entries upon assignment/removal.
     * Modifications are acceptable unless they affect a standard field (such as "author") besides the "keywords" or "groups' field.
     *
     * @param parent The Component used as a parent when displaying a confirmation dialog.
     * @return true if the assignment has no undesired side effects, or the user chose to perform it anyway. false
     * otherwise (this indicates that the user has aborted the assignment).
     */
public static boolean warnAssignmentSideEffects(List<AbstractGroup> groups, Component parent) {
    List<String> affectedFields = new ArrayList<>();
    for (AbstractGroup group : groups) {
        if (group instanceof KeywordGroup) {
            KeywordGroup keywordGroup = (KeywordGroup) group;
            String field = keywordGroup.getSearchField().toLowerCase(Locale.ROOT);
            if (FieldName.KEYWORDS.equals(field) || FieldName.GROUPS.equals(field)) {
                // this is not undesired
                continue;
            }
            for (String fieldName : InternalBibtexFields.getAllPublicFieldNames()) {
                if (field.equals(fieldName)) {
                    affectedFields.add(field);
                    break;
                }
            }
        }
    }
    if (affectedFields.isEmpty()) {
        // no side effects
        return true;
    }
    // show a warning, then return
    StringBuilder message = new StringBuilder(Localization.lang("This action will modify the following field(s) in at least one entry each:")).append('\n');
    for (String affectedField : affectedFields) {
        message.append(affectedField).append('\n');
    }
    message.append(Localization.lang("This could cause undesired changes to your entries.")).append('\n').append("It is recommended that you change the grouping field in your group definition to \"keywords\" or a non-standard name.").append("\n\n").append(Localization.lang("Do you still want to continue?"));
    int choice = JOptionPane.showConfirmDialog(parent, message, Localization.lang("Warning"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
    return choice != JOptionPane.NO_OPTION;
// if (groups instanceof KeywordGroup) {
// KeywordGroup kg = (KeywordGroup) groups;
// String field = kg.getSearchField().toLowerCase(Locale.ROOT);
// if (field.equals("keywords"))
// return true; // this is not undesired
// for (int i = 0; i < GUIGlobals.ALL_FIELDS.length; ++i) {
// if (field.equals(GUIGlobals.ALL_FIELDS[i])) {
// // show a warning, then return
// String message = Globals ...
// .lang(
// "This action will modify the \"%0\" field "
// + "of your entries.\nThis could cause undesired changes to "
// + "your entries, so it is\nrecommended that you change the grouping
// field "
// + "in your group\ndefinition to \"keywords\" or a non-standard name."
// + "\n\nDo you still want to continue?",
// field);
// int choice = JOptionPane.showConfirmDialog(parent, message,
// Globals.lang("Warning"), JOptionPane.YES_NO_OPTION,
// JOptionPane.WARNING_MESSAGE);
// return choice != JOptionPane.NO_OPTION;
// }
// }
// }
// return true; // found no side effects
}
Also used : KeywordGroup(org.jabref.model.groups.KeywordGroup) AbstractGroup(org.jabref.model.groups.AbstractGroup) ArrayList(java.util.ArrayList)

Example 3 with KeywordGroup

use of org.jabref.model.groups.KeywordGroup in project jabref by JabRef.

the class GroupSerializerTest method serializeSingleRegexKeywordGroup.

@Test
public void serializeSingleRegexKeywordGroup() {
    KeywordGroup group = new RegexKeywordGroup("myExplicitGroup", GroupHierarchyType.REFINING, "author", "asdf", false);
    List<String> serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
    assertEquals(Collections.singletonList("0 KeywordGroup:myExplicitGroup;1;author;asdf;0;1;1;;;;"), serialization);
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) KeywordGroup(org.jabref.model.groups.KeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Example 4 with KeywordGroup

use of org.jabref.model.groups.KeywordGroup in project jabref by JabRef.

the class GroupsParser method keywordGroupFromString.

/**
     * Parses s and recreates the KeywordGroup from it.
     *
     * @param s The String representation obtained from
     *          KeywordGroup.toString()
     */
private static KeywordGroup keywordGroupFromString(String s, Character keywordSeparator) throws ParseException {
    if (!s.startsWith(MetadataSerializationConfiguration.KEYWORD_GROUP_ID)) {
        throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(s.substring(MetadataSerializationConfiguration.KEYWORD_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
    String field = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String expression = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    boolean caseSensitive = Integer.parseInt(tok.nextToken()) == 1;
    boolean regExp = Integer.parseInt(tok.nextToken()) == 1;
    KeywordGroup newGroup;
    if (regExp) {
        newGroup = new RegexKeywordGroup(name, context, field, expression, caseSensitive);
    } else {
        newGroup = new WordKeywordGroup(name, context, field, expression, caseSensitive, keywordSeparator, false);
    }
    addGroupDetails(tok, newGroup);
    return newGroup;
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) KeywordGroup(org.jabref.model.groups.KeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) GroupHierarchyType(org.jabref.model.groups.GroupHierarchyType) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup)

Aggregations

KeywordGroup (org.jabref.model.groups.KeywordGroup)4 AbstractGroup (org.jabref.model.groups.AbstractGroup)2 AutomaticKeywordGroup (org.jabref.model.groups.AutomaticKeywordGroup)2 RegexKeywordGroup (org.jabref.model.groups.RegexKeywordGroup)2 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)2 ArrayList (java.util.ArrayList)1 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)1 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)1 GroupHierarchyType (org.jabref.model.groups.GroupHierarchyType)1 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)1 SearchGroup (org.jabref.model.groups.SearchGroup)1 Test (org.junit.Test)1