Skip to content

Commit

Permalink
More List<BibEntry> instead of BibEntry[]
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Feb 11, 2016
1 parent 5b70e9c commit 23321eb
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void run() {
if (panel == null) {
return;
}
if (panel.getSelectedEntries().size() == 0) {
if (panel.getSelectedEntries().isEmpty()) {
message = Localization.lang("No entries selected.");
getCallBack().update();
return;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void run() {
tmp = File.createTempFile("jabrefCb", ".tmp");
tmp.deleteOnExit();
List<BibEntry> bes = panel.getSelectedEntries();
HashSet<String> entries = new HashSet<>(bes.size());
Set<String> entries = new HashSet<>(bes.size());
for (BibEntry be : bes) {
entries.add(be.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class TransferableFileLinkSelection implements Transferable {
private final List<File> fileList = new ArrayList<>();


public TransferableFileLinkSelection(BasePanel panel, BibEntry[] selection) {
public TransferableFileLinkSelection(BasePanel panel, List<BibEntry> selection) {
FileListTableModel tm = new FileListTableModel();
selection[0].getFieldOptional(Globals.FILE_FIELD).ifPresent(file -> tm.setContent(file));
selection.get(0).getFieldOptional(Globals.FILE_FIELD).ifPresent(file -> tm.setContent(file));
if (tm.getRowCount() > 0) {
// Find the default directory for this field type, if any:
List<String> dirs = panel.getBibDatabaseContext().getMetaData().getFileDirectory(Globals.FILE_FIELD);
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/net/sf/jabref/groups/GroupSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
Expand Down Expand Up @@ -680,8 +678,8 @@ private void updateGroupContent(GroupTreeNode node) {
// Sort entries into current members and non-members of the group
// Current members will be removed
// Current non-members will be added
ArrayList<BibEntry> toRemove = new ArrayList<>(entries.size());
ArrayList<BibEntry> toAdd = new ArrayList<>(entries.size());
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
Expand Down Expand Up @@ -1447,39 +1445,40 @@ public void setActiveBasePanel(BasePanel panel) {
* Highlight all groups that contain any/all of the specified entries. If entries is null or has zero length,
* highlight is cleared.
*/
public void showMatchingGroups(BibEntry[] entries, boolean requireAll) {
if ((entries == null) || (entries.length == 0)) { // nothing selected
public void showMatchingGroups(List<BibEntry> list, boolean requireAll) {
if ((list == null) || (list.isEmpty())) { // nothing selected
groupsTree.setHighlight3Cells(null);
groupsTree.revalidate();
return;
}
Vector<GroupTreeNode> vec = new Vector<>();
List<GroupTreeNode> nodeList = new ArrayList<>();
for (Enumeration<GroupTreeNode> e = groupsRoot.preorderEnumeration(); e.hasMoreElements();) {
GroupTreeNode node = e.nextElement();
AbstractGroup group = node.getGroup();
int i;
for (i = 0; i < entries.length; ++i) {
boolean breakFromLoop = false;
for (BibEntry entry : list) {
if (requireAll) {
if (!group.contains(entries[i])) {
if (!group.contains(entry)) {
breakFromLoop = true;
break;
}
} else {
if (group.contains(entries[i])) {
vec.add(node);
if (group.contains(entry)) {
nodeList.add(node);
}
}
}
if (requireAll && (i >= entries.length)) // did not break from loop
if (requireAll && (!breakFromLoop)) // did not break from loop
{
vec.add(node);
nodeList.add(node);
}
}
groupsTree.setHighlight3Cells(vec.toArray());
groupsTree.setHighlight3Cells(nodeList.toArray());
// ensure that all highlighted nodes are visible
for (int i = 0; i < vec.size(); ++i) {
GroupTreeNode node = (GroupTreeNode) vec.elementAt(i).getParent();
if (node != null) {
groupsTree.expandPath(new TreePath(node.getPath()));
for (GroupTreeNode node : nodeList) {
GroupTreeNode parentNode = (GroupTreeNode) node.getParent();
if (parentNode != null) {
groupsTree.expandPath(new TreePath(parentNode.getPath()));
}
}
groupsTree.revalidate();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/groups/GroupsTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import javax.swing.JTree;
Expand Down Expand Up @@ -278,7 +279,7 @@ public void drop(DropTargetDropEvent dtde) {
}
final TransferableEntrySelection selection = (TransferableEntrySelection) transferable
.getTransferData(TransferableEntrySelection.FLAVOR_INTERNAL);
final BibEntry[] entries = selection.getSelection();
final List<BibEntry> entries = selection.getSelection();
int assignedEntries = 0;
for (BibEntry entry : entries) {
if (!target.getGroup().contains(entry)) {
Expand All @@ -298,7 +299,7 @@ public void drop(DropTargetDropEvent dtde) {
// edit has to be stored:
groupSelector.getActiveBasePanel().storeCurrentEdit();

AbstractUndoableEdit undo = group.add(Arrays.asList(selection.getSelection()));
AbstractUndoableEdit undo = group.add(selection.getSelection());
if (undo instanceof UndoableChangeAssignment) {
((UndoableChangeAssignment) undo).setEditedNode(target);
}
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/net/sf/jabref/groups/TransferableEntrySelection.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2003-2011 JabRef contributors.
/* Copyright (C) 2003-2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
Expand All @@ -20,6 +20,8 @@
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import net.sf.jabref.model.entry.BibEntry;

Expand All @@ -28,7 +30,7 @@ class TransferableEntrySelection implements Transferable {
public static final DataFlavor FLAVOR_INTERNAL;
private static final DataFlavor FLAVOR_EXTERNAL;
private static final DataFlavor[] FLAVORS;
private final BibEntry[] selectedEntries;
private final List<BibEntry> selectedEntries;
private final String selectedEntriesCiteKeys;

private boolean includeCiteKeyword;
Expand All @@ -49,16 +51,10 @@ class TransferableEntrySelection implements Transferable {
}


public TransferableEntrySelection(BibEntry[] selectedEntries) {
this.selectedEntries = selectedEntries;
StringBuilder keys = new StringBuilder();
for (int i = 0; i < selectedEntries.length; ++i) {
keys.append(selectedEntries[i].getCiteKey());
if ((i + 1) < selectedEntries.length) {
keys.append(',');
}
}
selectedEntriesCiteKeys = keys.toString();
public TransferableEntrySelection(List<BibEntry> list) {
this.selectedEntries = list;
selectedEntriesCiteKeys = String.join(",",
this.selectedEntries.stream().map(entry -> entry.getCiteKey()).collect(Collectors.toList()));
}

@Override
Expand Down Expand Up @@ -91,7 +87,7 @@ public Object getTransferData(DataFlavor someFlavor)
return new ByteArrayInputStream(s.getBytes(charset.trim()));
}

public BibEntry[] getSelection() {
public List<BibEntry> getSelection() {
return selectedEntries;
}

Expand Down
Loading

0 comments on commit 23321eb

Please sign in to comment.