Search in sources :

Example 1 with GroupTreeNode

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) JTree(javax.swing.JTree) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 2 with GroupTreeNode

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();
}
Also used : MatcherSet(org.jabref.model.search.matchers.MatcherSet) GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 3 with GroupTreeNode

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);
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 4 with GroupTreeNode

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()));
    }
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 5 with GroupTreeNode

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);
    }
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Aggregations

GroupTreeNode (org.jabref.model.groups.GroupTreeNode)22 Test (org.junit.Test)8 AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)5 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)4 AbstractGroup (org.jabref.model.groups.AbstractGroup)3 AbstractAction (javax.swing.AbstractAction)2 ParserResult (org.jabref.logic.importer.ParserResult)2 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)2 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 ActionEvent (java.awt.event.ActionEvent)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JButton (javax.swing.JButton)1 JDialog (javax.swing.JDialog)1 JMenu (javax.swing.JMenu)1 JPopupMenu (javax.swing.JPopupMenu)1 JScrollPane (javax.swing.JScrollPane)1