Skip to content

Commit

Permalink
Some formatting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Mar 14, 2017
1 parent ff63449 commit 875678b
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 104 deletions.
15 changes: 7 additions & 8 deletions src/main/java/org/jabref/gui/groups/AddToGroupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public AddToGroupAction(GroupTreeNodeViewModel node, boolean move, BasePanel pan
}

public AddToGroupAction(boolean move) {
super(move ? Localization.lang("Assign entry selection exclusively to this group") :
Localization.lang("Add entry selection to this group"));
super(move ? Localization.lang("Assign entry selection exclusively to this group") : Localization
.lang("Add entry selection to this group"));
this.move = move;
}

Expand Down Expand Up @@ -73,19 +73,18 @@ public void actionPerformed(ActionEvent evt) {
}

private void moveToGroup(List<BibEntry> entries, NamedCompound undoAll) {
List<AbstractGroup> affectedGroups =
node.getNode().getRoot().getContainingGroups(entries, false).stream()
.map(GroupTreeNode::getGroup)
.filter(group -> group instanceof GroupEntryChanger)
.collect(Collectors.toList());
List<AbstractGroup> affectedGroups = node.getNode().getRoot().getContainingGroups(entries, false).stream()
.map(GroupTreeNode::getGroup)
.filter(group -> group instanceof GroupEntryChanger)
.collect(Collectors.toList());
affectedGroups.add(node.getNode().getGroup());
if (!WarnAssignmentSideEffects.warnAssignmentSideEffects(affectedGroups, panel.frame())) {
return; // user aborted operation
}

// first remove
for (AbstractGroup group : affectedGroups) {
GroupEntryChanger entryChanger = (GroupEntryChanger)group;
GroupEntryChanger entryChanger = (GroupEntryChanger) group;
List<FieldChange> changes = entryChanger.remove(entries);
if (!changes.isEmpty()) {
undoAll.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(node, changes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,14 @@
public class EntryTableTransferHandler extends TransferHandler {

private final MainTable entryTable;

private final JabRefFrame frame;

private final BasePanel panel;

private DataFlavor urlFlavor;

private final DataFlavor stringFlavor;

private static final boolean DROP_ALLOWED = true;

private static final Log LOGGER = LogFactory.getLog(EntryTableTransferHandler.class);

private boolean draggingFile;


/**
* Construct the transfer handler.
*
Expand Down Expand Up @@ -174,14 +166,12 @@ public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
return false;
}



@Override
public void exportAsDrag(JComponent comp, InputEvent e, int action) {
if (e instanceof MouseEvent) {
int columnIndex = entryTable.columnAtPoint(((MouseEvent) e).getPoint());
int modelIndex = entryTable.getColumnModel().getColumn(columnIndex).getModelIndex();
if(entryTable.isFileColumn(modelIndex)) {
if (entryTable.isFileColumn(modelIndex)) {
LOGGER.info("Dragging file");
draggingFile = true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class GroupAddRemoveDialog implements BaseAction {
private List<BibEntry> selection;
private JTree tree;


public GroupAddRemoveDialog(BasePanel panel, boolean add, boolean move) {
this.panel = panel;
this.add = add;
Expand Down Expand Up @@ -199,7 +198,6 @@ private boolean checkGroupEnable(GroupTreeNodeViewModel node) {
return (add ? node.canAddEntries(selection) : node.canRemoveEntries(selection));
}


class AddRemoveGroupTreeCellRenderer extends GroupTreeCellRenderer {

@Override
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/org/jabref/gui/groups/GroupDescriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
public class GroupDescriptions {

public static String getDescriptionForPreview(String field, String expr, boolean caseSensitive, boolean regExp) {
String header = regExp ? Localization.lang("This group contains entries whose <b>%0</b> field contains the regular expression <b>%1</b>",
field, StringUtil.quoteForHTML(expr))
: Localization.lang("This group contains entries whose <b>%0</b> field contains the keyword <b>%1</b>",
field, StringUtil.quoteForHTML(expr));
String caseSensitiveText = caseSensitive ? Localization.lang("case sensitive") :
Localization.lang("case insensitive");
String footer = regExp ?
Localization.lang("Entries cannot be manually assigned to or removed from this group.")
: Localization.lang(
"Additionally, entries whose <b>%0</b> field does not contain "
+ "<b>%1</b> can be assigned manually to this group by selecting them "
+ "then using either drag and drop or the context menu. "
+ "This process adds the term <b>%1</b> to "
+ "each entry's <b>%0</b> field. "
+ "Entries can be removed manually from this group by selecting them "
+ "then using the context menu. "
+ "This process removes the term <b>%1</b> from "
+ "each entry's <b>%0</b> field.",
field, StringUtil.quoteForHTML(expr));
String header = regExp ? Localization.lang(
"This group contains entries whose <b>%0</b> field contains the regular expression <b>%1</b>",
field, StringUtil.quoteForHTML(expr)) : Localization.lang(
"This group contains entries whose <b>%0</b> field contains the keyword <b>%1</b>",
field, StringUtil.quoteForHTML(expr));
String caseSensitiveText = caseSensitive ? Localization.lang("case sensitive") : Localization
.lang("case insensitive");
String footer = regExp ? Localization
.lang("Entries cannot be manually assigned to or removed from this group.") : Localization.lang(
"Additionally, entries whose <b>%0</b> field does not contain "
+ "<b>%1</b> can be assigned manually to this group by selecting them "
+ "then using either drag and drop or the context menu. "
+ "This process adds the term <b>%1</b> to "
+ "each entry's <b>%0</b> field. "
+ "Entries can be removed manually from this group by selecting them "
+ "then using the context menu. "
+ "This process removes the term <b>%1</b> from "
+ "each entry's <b>%0</b> field.",
field, StringUtil.quoteForHTML(expr));
return String.format("%s (%s). %s", header, caseSensitiveText, footer);
}

Expand Down
37 changes: 21 additions & 16 deletions src/main/java/org/jabref/gui/groups/GroupSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public class GroupSelector extends SidePaneComponent implements TreeSelectionLis
public GroupSelector(JabRefFrame frame, SidePaneManager manager) {
super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups"));

Globals.stateManager.activeGroupProperty().addListener((observable, oldValue, newValue) -> updateShownEntriesAccordingToSelectedGroups(newValue));

Globals.stateManager.activeGroupProperty()
.addListener((observable, oldValue, newValue) -> updateShownEntriesAccordingToSelectedGroups(newValue));

toggleAction = new ToggleAction(Localization.menuTitle("Toggle groups interface"),
Localization.lang("Toggle groups interface"),
Expand All @@ -142,9 +142,12 @@ public GroupSelector(JabRefFrame frame, SidePaneManager manager) {
ButtonGroup nonHits = new ButtonGroup();
nonHits.add(hideNonHits);
nonHits.add(grayOut);
floatCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected()));
andCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected()));
invCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected()));
floatCb.addChangeListener(
event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected()));
andCb.addChangeListener(
event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected()));
invCb.addChangeListener(
event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected()));
showOverlappingGroups.addChangeListener(new ChangeListener() {

@Override
Expand All @@ -156,7 +159,8 @@ public void stateChanged(ChangeEvent event) {
}
});

grayOut.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected()));
grayOut.addChangeListener(
event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected()));

JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false);
if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) {
Expand All @@ -176,7 +180,8 @@ public void stateChanged(ChangeEvent event) {
andCb.setSelected(false);
}

autoAssignGroup.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected()));
autoAssignGroup.addChangeListener(
event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected()));

invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS));
showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING));
Expand Down Expand Up @@ -258,8 +263,8 @@ public void stateChanged(ChangeEvent event) {

JScrollPane groupsTreePane = new JScrollPane(groupsTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
con.gridwidth = GridBagConstraints.REMAINDER;
con.weighty = 1;
con.gridx = 0;
Expand All @@ -284,10 +289,8 @@ public void stateChanged(ChangeEvent event) {
moveNodeRightAction.putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK));


setGroups(GroupTreeNode.fromGroup(DefaultGroupsFactory.getAllEntriesGroup()));


JFXPanel groupsPane = new JFXPanel();
add(groupsPane);
// Execute on JavaFX Application Thread
Expand Down Expand Up @@ -483,7 +486,7 @@ private void updateShownEntriesAccordingToSelectedGroups() {
final MatcherSet searchRules = MatcherSets
.build(andCb.isSelected() ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR);

for(GroupTreeNodeViewModel node : getLeafsOfSelection()) {
for (GroupTreeNodeViewModel node : getLeafsOfSelection()) {
SearchMatcher searchRule = node.getNode().getSearchMatcher();
searchRules.addRule(searchRule);
}
Expand All @@ -506,7 +509,7 @@ private void updateShownEntriesAccordingToSelectedGroups(Optional<GroupTreeNode>

private List<GroupTreeNodeViewModel> getLeafsOfSelection() {
TreePath[] selection = groupsTree.getSelectionPaths();
if((selection == null) || (selection.length == 0)) {
if ((selection == null) || (selection.length == 0)) {
return new ArrayList<>();
}

Expand Down Expand Up @@ -916,7 +919,8 @@ public void actionPerformed(ActionEvent e) {
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
boolean keepPreviousAssignments = (i == JOptionPane.YES_OPTION) &&
WarnAssignmentSideEffects.warnAssignmentSideEffects(newGroup, panel.frame());
boolean removePreviousAssignents = (oldGroup instanceof ExplicitGroup) && (newGroup instanceof ExplicitGroup);
boolean removePreviousAssignents = (oldGroup instanceof ExplicitGroup)
&& (newGroup instanceof ExplicitGroup);

AbstractUndoableEdit undoAddPreviousEntries = null;
UndoableModifyGroup undo = new UndoableModifyGroup(GroupSelector.this, groupsRoot, node, newGroup);
Expand Down Expand Up @@ -964,7 +968,8 @@ public void actionPerformed(ActionEvent e) {
if (node == null) {
groupsRoot.getNode().addChild(newNode);
} else {
((GroupTreeNodeViewModel)node.getParent()).getNode().addChild(newNode, node.getNode().getPositionInParent() + 1);
((GroupTreeNodeViewModel) node.getParent()).getNode().addChild(newNode,
node.getNode().getPositionInParent() + 1);
}
UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot,
new GroupTreeNodeViewModel(newNode), UndoableAddOrRemoveGroup.ADD_NODE);
Expand Down Expand Up @@ -1016,7 +1021,7 @@ public void actionPerformed(ActionEvent e) {
if (conf == JOptionPane.YES_OPTION) {
final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node,
UndoableAddOrRemoveGroup.REMOVE_NODE_KEEP_CHILDREN);
final GroupTreeNodeViewModel parent = (GroupTreeNodeViewModel)node.getParent();
final GroupTreeNodeViewModel parent = (GroupTreeNodeViewModel) node.getParent();
node.getNode().removeFromParent();
node.getNode().moveAllChildrenTo(parent.getNode(), parent.getIndex(node));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class GroupTreeCellRenderer extends DefaultTreeCellRenderer {
private List<GroupTreeNode> matchingGroups = new ArrayList<>();
private Object highlightBorderCell;


@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
int row, boolean tmpHasFocus) {
Expand Down Expand Up @@ -96,7 +95,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
}

private boolean printInRed(GroupTreeNodeViewModel viewModel) {
if(viewModel.isAllEntriesGroup()) {
if (viewModel.isAllEntriesGroup()) {
// Do not print all entries group in red
return false;
}
Expand All @@ -105,7 +104,7 @@ private boolean printInRed(GroupTreeNodeViewModel viewModel) {
}

private boolean printUnderlined(GroupTreeNodeViewModel viewModel) {
if(viewModel.isAllEntriesGroup()) {
if (viewModel.isAllEntriesGroup()) {
// Do not underline all entries group
return false;
}
Expand Down
34 changes: 16 additions & 18 deletions src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GroupTreeNodeViewModel implements Transferable, TreeNode {
DataFlavor df = null;
try {
df = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType
+ ";class="+GroupTreeNode.class.getCanonicalName());
+ ";class=" + GroupTreeNode.class.getCanonicalName());
} catch (ClassNotFoundException e) {
LOGGER.error("Creating DataFlavor failed. This should not happen.", e);
}
Expand Down Expand Up @@ -108,11 +108,11 @@ public TreeNode getParent() {

@Override
public int getIndex(TreeNode child) {
if(! (child instanceof GroupTreeNodeViewModel)) {
if (!(child instanceof GroupTreeNodeViewModel)) {
return -1;
}

GroupTreeNodeViewModel childViewModel = (GroupTreeNodeViewModel)child;
GroupTreeNodeViewModel childViewModel = (GroupTreeNodeViewModel) child;
return node.getIndexOfChild(childViewModel.getNode()).orElse(-1);
}

Expand All @@ -127,7 +127,7 @@ public boolean isLeaf() {
}

@Override
public Enumeration children() {
public Enumeration<GroupTreeNodeViewModel> children() {
Iterable<GroupTreeNode> children = node.getChildren();
return new Enumeration<GroupTreeNodeViewModel>() {

Expand Down Expand Up @@ -159,21 +159,21 @@ public void collapseSubtree(JTree tree) {
public void expandSubtree(JTree tree) {
tree.expandPath(this.getTreePath());

for(GroupTreeNodeViewModel child : getChildren()) {
for (GroupTreeNodeViewModel child : getChildren()) {
child.expandSubtree(tree);
}
}

public List<GroupTreeNodeViewModel> getChildren() {
List<GroupTreeNodeViewModel> children = new ArrayList<>();
for(GroupTreeNode child : node.getChildren()) {
for (GroupTreeNode child : node.getChildren()) {
children.add(new GroupTreeNodeViewModel(child));
}
return children;
}

protected boolean printInItalics() {
return Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC) && node.getGroup().isDynamic();
return Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC) && node.getGroup().isDynamic();
}

public String getDescription() {
Expand Down Expand Up @@ -213,11 +213,11 @@ public TreePath getTreePath() {
}

public boolean canAddEntries(List<BibEntry> entries) {
return getNode().getGroup() instanceof GroupEntryChanger && !getNode().getGroup().containsAll(entries);
return (getNode().getGroup() instanceof GroupEntryChanger) && !getNode().getGroup().containsAll(entries);
}

public boolean canRemoveEntries(List<BibEntry> entries) {
return getNode().getGroup() instanceof GroupEntryChanger && getNode().getGroup().containsAny(entries);
return (getNode().getGroup() instanceof GroupEntryChanger) && getNode().getGroup().containsAny(entries);
}

public void sortChildrenByName(boolean recursive) {
Expand Down Expand Up @@ -355,7 +355,7 @@ public Optional<MoveGroupChange> moveLeft() {
final Optional<GroupTreeNode> grandParent = parent.getParent();
final int index = node.getPositionInParent();

if (! grandParent.isPresent()) {
if (!grandParent.isPresent()) {
return Optional.empty();
}
final int indexOfParent = grandParent.get().getIndexOfChild(parent).get();
Expand All @@ -380,10 +380,9 @@ public Optional<MoveGroupChange> moveRight() {
* Adds the given entries to this node's group.
*/
public List<FieldChange> addEntriesToGroup(List<BibEntry> entries) {
if(node.getGroup() instanceof GroupEntryChanger) {
return ((GroupEntryChanger)node.getGroup()).add(entries);
}
else {
if (node.getGroup() instanceof GroupEntryChanger) {
return ((GroupEntryChanger) node.getGroup()).add(entries);
} else {
return Collections.emptyList();
}
}
Expand All @@ -392,10 +391,9 @@ public List<FieldChange> addEntriesToGroup(List<BibEntry> entries) {
* Removes the given entries from this node's group.
*/
public List<FieldChange> removeEntriesFromGroup(List<BibEntry> entries) {
if(node.getGroup() instanceof GroupEntryChanger) {
return ((GroupEntryChanger)node.getGroup()).remove(entries);
}
else {
if (node.getGroup() instanceof GroupEntryChanger) {
return ((GroupEntryChanger) node.getGroup()).remove(entries);
} else {
return Collections.emptyList();
}
}
Expand Down
Loading

0 comments on commit 875678b

Please sign in to comment.