use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupAddRemoveDialog method action.
@Override
public void action() throws Exception {
Optional<GroupTreeNode> groups = panel.getBibDatabaseContext().getMetaData().getGroups();
if (!groups.isPresent()) {
return;
}
selection = panel.getSelectedEntries();
final JDialog diag = new JDialog(panel.frame(), (add ? (move ? Localization.lang("Move to group") : Localization.lang("Add to group")) : Localization.lang("Remove from group")), true);
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
tree = new JTree(new GroupTreeNodeViewModel(groups.get()));
tree.setCellRenderer(new AddRemoveGroupTreeCellRenderer());
tree.setVisibleRowCount(22);
// tree.setPreferredSize(new Dimension(200, tree.getPreferredSize().height));
// The scrollbar appears when the preferred size of a component is greater than the size of the viewport. If one hard coded the preferred size, it will never change according to the expansion/collapse. Thus the scrollbar cannot appear accordingly.
//tree.setSelectionModel(new VetoableTreeSelectionModel());
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(e -> {
GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) e.getNewLeadSelectionPath().getLastPathComponent();
ok.setEnabled(checkGroupEnable(node));
});
//STA add expand and collapse all buttons
JButton jbExpandAll = new JButton("Expand All");
jbExpandAll.addActionListener(e -> expandAll(tree, true));
JButton jbCollapseAll = new JButton("Collapse All");
jbCollapseAll.addActionListener(e -> expandAll(tree, false));
//END add expand and collapse all buttons
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addButton(jbExpandAll);
bb.addButton(jbCollapseAll);
bb.addGlue();
bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
ok.addActionListener(actionEvent -> {
if (doAddOrRemove()) {
diag.dispose();
}
});
cancel.addActionListener(actionEvent -> diag.dispose());
ok.setEnabled(false);
JScrollPane sp = new JScrollPane(tree);
// Key bindings:
ActionMap am = sp.getActionMap();
InputMap im = sp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
diag.dispose();
}
});
diag.getContentPane().add(sp, BorderLayout.CENTER);
diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
diag.pack();
diag.setLocationRelativeTo(panel.frame());
diag.setVisible(true);
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupSidePane method updateShownEntriesAccordingToSelectedGroups.
private void updateShownEntriesAccordingToSelectedGroups(List<GroupTreeNode> selectedGroups) {
if (selectedGroups == null || selectedGroups.isEmpty()) {
// No selected group, nothing to do
return;
}
final MatcherSet searchRules = MatcherSets.build(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS) ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR);
for (GroupTreeNode node : selectedGroups) {
searchRules.addRule(node.getSearchMatcher());
}
GroupingWorker worker = new GroupingWorker(frame, panel);
worker.run(searchRules);
worker.update();
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupTreeNodeViewModel method addNewGroup.
public void addNewGroup(AbstractGroup newGroup, CountingUndoManager undoManager) {
GroupTreeNode newNode = GroupTreeNode.fromGroup(newGroup);
this.getNode().addChild(newNode);
UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(this, new GroupTreeNodeViewModel(newNode), UndoableAddOrRemoveGroup.ADD_NODE);
undoManager.addEdit(undo);
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupTreeViewModel method removeGroupKeepSubgroups.
public void removeGroupKeepSubgroups(GroupNodeViewModel group) {
boolean confirmation = dialogService.showConfirmationDialogAndWait(Localization.lang("Remove group"), Localization.lang("Remove group \"%0\"?", group.getDisplayName()));
if (confirmation) {
// TODO: Add undo
//final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_KEEP_CHILDREN);
//panel.getUndoManager().addEdit(undo);
GroupTreeNode groupNode = group.getGroupNode();
groupNode.getParent().ifPresent(parent -> groupNode.moveAllChildrenTo(parent, parent.getIndexOfChild(groupNode).get()));
groupNode.removeFromParent();
dialogService.notify(Localization.lang("Removed group \"%0\".", group.getDisplayName()));
}
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class UndoableModifySubtree method redo.
@Override
public void redo() {
super.redo();
//TODO: NULL
final GroupTreeNode subtreeRoot = m_groupRoot.getDescendant(m_subtreeRootPath).get();
subtreeRoot.removeAllChildren();
for (GroupTreeNode modifiedNode : m_modifiedSubtree) {
modifiedNode.moveTo(subtreeRoot);
}
}
Aggregations