use of org.jabref.model.groups.AbstractGroup 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>";
}
use of org.jabref.model.groups.AbstractGroup in project jabref by JabRef.
the class GroupTreeNodeViewModel method changeEntriesTo.
public void changeEntriesTo(List<BibEntry> entries, UndoManager undoManager) {
AbstractGroup group = node.getGroup();
List<FieldChange> changesRemove = new ArrayList<>();
List<FieldChange> changesAdd = new ArrayList<>();
// Sort entries into current members and non-members of the group
// Current members will be removed
// Current non-members will be added
List<BibEntry> toRemove = new ArrayList<>(entries.size());
List<BibEntry> toAdd = new ArrayList<>(entries.size());
for (BibEntry entry : entries) {
// Sort according to current state of the entries
if (group.contains(entry)) {
toRemove.add(entry);
} else {
toAdd.add(entry);
}
}
// If there are entries to remove
if (!toRemove.isEmpty()) {
changesRemove = removeEntriesFromGroup(toRemove);
}
// If there are entries to add
if (!toAdd.isEmpty()) {
changesAdd = addEntriesToGroup(toAdd);
}
// Remember undo information
if (!changesRemove.isEmpty()) {
AbstractUndoableEdit undoRemove = UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesRemove);
if (!changesAdd.isEmpty() && (undoRemove != null)) {
// we removed and added entries
undoRemove.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesAdd));
}
undoManager.addEdit(undoRemove);
} else if (!changesAdd.isEmpty()) {
undoManager.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesAdd));
}
}
use of org.jabref.model.groups.AbstractGroup 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
}
use of org.jabref.model.groups.AbstractGroup in project jabref by JabRef.
the class GroupsParserTest method testImportSubGroups.
@Test
public void testImportSubGroups() throws ParseException {
List<String> orderedData = Arrays.asList("0 AllEntriesGroup:", "1 ExplicitGroup:1;0;", "2 ExplicitGroup:2;0;", "0 ExplicitGroup:3;0;");
//Create group hierarchy:
// Level 0 Name: All entries
// Level 1 Name: 1
// Level 2 Name: 2
// Level 1 Name: 3
GroupTreeNode rootNode = new GroupTreeNode(new ExplicitGroup("All entries", GroupHierarchyType.INDEPENDENT, ','));
AbstractGroup firstSubGrpLvl1 = new ExplicitGroup("1", GroupHierarchyType.INDEPENDENT, ',');
rootNode.addSubgroup(firstSubGrpLvl1);
AbstractGroup subLvl2 = new ExplicitGroup("2", GroupHierarchyType.INDEPENDENT, ',');
rootNode.getFirstChild().ifPresent(c -> c.addSubgroup(subLvl2));
AbstractGroup thirdSubGrpLvl1 = new ExplicitGroup("3", GroupHierarchyType.INDEPENDENT, ',');
rootNode.addSubgroup(thirdSubGrpLvl1);
GroupTreeNode parsedNode = GroupsParser.importGroups(orderedData, ',');
assertEquals(rootNode.getChildren(), parsedNode.getChildren());
}
use of org.jabref.model.groups.AbstractGroup in project jabref by JabRef.
the class GroupsParserTest method fromStringParsesAutomaticPersonGroup.
@Test
public void fromStringParsesAutomaticPersonGroup() throws Exception {
AutomaticPersonsGroup expected = new AutomaticPersonsGroup("myAutomaticGroup", GroupHierarchyType.INDEPENDENT, "authors");
AbstractGroup parsed = GroupsParser.fromString("AutomaticPersonsGroup:myAutomaticGroup;0;authors;1;;;;", ',');
assertEquals(expected, parsed);
}
Aggregations