diff --git a/CHANGELOG.md b/CHANGELOG.md index a262139b69b..eecbaff3814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Set/clear/append/rename fields: available through Edit menu - Manage keywords: available through Edit menu - Copy linked files to folder: available through File menu + - Add/move/remove from group: removed completely (functionality still available through group interface) - We removed the option to change the column widths in the preferences dialog. [#4546](https://github.com/JabRef/jabref/issues/4546) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 812335db076..89d54058434 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -52,7 +52,6 @@ import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.filelist.FileListEntry; import org.jabref.gui.filelist.FileListTableModel; -import org.jabref.gui.groups.GroupAddRemoveDialog; import org.jabref.gui.icon.JabRefIcon; import org.jabref.gui.importer.actions.AppendDatabaseAction; import org.jabref.gui.journals.AbbreviateAction; @@ -405,10 +404,6 @@ private void setupActions() { actions.put(Actions.ABBREVIATE_MEDLINE, new AbbreviateAction(this, false)); actions.put(Actions.UNABBREVIATE, new UnabbreviateAction(this)); - actions.put(Actions.ADD_TO_GROUP, new GroupAddRemoveDialog(this, true, false)); - actions.put(Actions.REMOVE_FROM_GROUP, new GroupAddRemoveDialog(this, false, false)); - actions.put(Actions.MOVE_TO_GROUP, new GroupAddRemoveDialog(this, true, true)); - actions.put(Actions.DOWNLOAD_FULL_TEXT, new FindFullTextAction(this)::execute); } diff --git a/src/main/java/org/jabref/gui/actions/Actions.java b/src/main/java/org/jabref/gui/actions/Actions.java index c3776047608..f115eda059c 100644 --- a/src/main/java/org/jabref/gui/actions/Actions.java +++ b/src/main/java/org/jabref/gui/actions/Actions.java @@ -8,7 +8,6 @@ public enum Actions { ABBREVIATE_ISO, ABBREVIATE_MEDLINE, ADD_FILE_LINK, - ADD_TO_GROUP, CLEANUP, COPY, COPY_CITATION_ASCII_DOC, @@ -34,7 +33,6 @@ public enum Actions { MERGE_ENTRIES, MERGE_WITH_FETCHED_ENTRY, NEXT_PREVIEW_STYLE, - MOVE_TO_GROUP, OPEN_CONSOLE, OPEN_EXTERNAL_FILE, OPEN_FOLDER, @@ -43,7 +41,6 @@ public enum Actions { PREVIOUS_PREVIEW_STYLE, PULL_CHANGES_FROM_SHARED_DATABASE, REDO, - REMOVE_FROM_GROUP, REPLACE_ALL, SAVE, SAVE_AS, diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index f6e843de78d..6e7493f32d7 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -35,9 +35,6 @@ public enum StandardActions implements Action { OPEN_URL(Localization.lang("Open URL or DOI"), IconTheme.JabRefIcons.WWW, KeyBinding.OPEN_URL_OR_DOI), MERGE_WITH_FETCHED_ENTRY(Localization.lang("Get BibTeX data from %0", "DOI/ISBN/...")), ATTACH_FILE(Localization.lang("Attach file"), IconTheme.JabRefIcons.ATTACH_FILE), - ADD_TO_GROUP(Localization.lang("Add to group")), - REMOVE_FROM_GROUP(Localization.lang("Remove from group")), - MOVE_TO_GROUP(Localization.lang("Move to group")), PRIORITY(Localization.lang("Priority"), IconTheme.JabRefIcons.PRIORITY), CLEAR_PRIORITY(Localization.lang("Clear priority")), PRIORITY_HIGH(Localization.lang("Set priority to high"), IconTheme.JabRefIcons.PRIORITY_HIGH), diff --git a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java deleted file mode 100644 index 870af219e7b..00000000000 --- a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java +++ /dev/null @@ -1,227 +0,0 @@ -package org.jabref.gui.groups; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTree; -import javax.swing.SwingUtilities; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; - -import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.actions.BaseAction; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.groups.GroupTreeNode; - -import com.jgoodies.forms.builder.ButtonBarBuilder; - -public class GroupAddRemoveDialog implements BaseAction { - - private final BasePanel panel; - private final boolean add; - private final boolean move; - private List selection; - private JTree tree; - - public GroupAddRemoveDialog(BasePanel panel, boolean add, boolean move) { - this.panel = panel; - this.add = add; - this.move = move; - } - - @Override - public void action() throws Exception { - Optional groups = panel.getBibDatabaseContext().getMetaData().getGroups(); - if (!groups.isPresent()) { - return; - } - - selection = panel.getSelectedEntries(); - - final JDialog diag = new JDialog((JFrame) null, - (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(); - tree.repaint(); - } - }); - 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), "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.setVisible(true); - - } - - // If "expand" is true, all nodes in the tree area expanded - // otherwise all nodes in the tree are collapsed: - private void expandAll(final JTree subtree, final boolean expand) { - SwingUtilities.invokeLater(() -> { - TreeNode root = ((TreeNode) subtree.getModel().getRoot()); - // walk through the tree, beginning at the root: - expandAll(subtree, new TreePath(((DefaultTreeModel) subtree.getModel()).getPathToRoot(root)), expand); - tree.requestFocusInWindow(); - }); - } - - private void expandAll(final JTree subtree, final TreePath parent, final boolean expand) { - // walk through the children: - TreeNode node = (TreeNode) parent.getLastPathComponent(); - int numChildren = node.getChildCount(); - if (numChildren > 0) { - for (int i = 0; i < numChildren; i++) { - TreeNode child = node.getChildAt(i); - TreePath path = parent.pathByAddingChild(child); - expandAll(subtree, path, expand); - } - } - // "expand" / "collapse" occurs from bottom to top: - if (expand) { - tree.expandPath(parent); - } else { - if (node.getParent() != null) { - tree.collapsePath(parent); - } - } - } - - private boolean doAddOrRemove() { - TreePath path = tree.getSelectionPath(); - if (path == null) { - return false; - } else { - GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent(); - if (checkGroupEnable(node)) { - - //we need to copy the contents of the observable list here, because when removeFromEntries is called, - //probably the focus changes to the first entry in the all entries group and thus getSelectedEntries() no longer contains our entry we want to move - List entries = new ArrayList<>(Globals.stateManager.getSelectedEntries()); - - if (move) { - recuriveRemoveFromNode((GroupTreeNodeViewModel) tree.getModel().getRoot(), entries); - } - - if (add) { - node.addEntriesToGroup(entries); - } else { - node.removeEntriesFromGroup(entries); - } - - return true; - } else { - return false; - } - } - } - - private void recuriveRemoveFromNode(GroupTreeNodeViewModel node, List entries) { - node.removeEntriesFromGroup(entries); - for (GroupTreeNodeViewModel child : node.getChildren()) { - recuriveRemoveFromNode(child, entries); - } - } - - /** - * Check if we can perform the action for this group. Determines whether - * the group should be shown in an enabled state, and if selecting it should - * leave the Ok button enabled. - * @param node The group to check - * @return true if this dialog's action can be performed on the group - */ - private boolean checkGroupEnable(GroupTreeNodeViewModel node) { - return (add ? node.canAddEntries(selection) : node.canRemoveEntries(selection)); - } - - class AddRemoveGroupTreeCellRenderer extends GroupTreeCellRenderer { - - @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, - boolean leaf, int row, boolean hasFocus) { - Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); - - GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) value; - if (checkGroupEnable(node)) { - c.setForeground(Color.black); - } else { - c.setForeground(Color.gray); - } - - return c; - } - } - -} diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index f0bd9d61775..3070a50a2b7 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -21,7 +21,6 @@ import org.jabref.gui.mergeentries.FetchAndMergeEntry; import org.jabref.gui.specialfields.SpecialFieldMenuItemFactory; import org.jabref.logic.citationstyle.CitationStyle; -import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.specialfields.SpecialField; @@ -85,33 +84,9 @@ public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingReposit contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(panel, dialogService))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_ENTRIES, mergeEntries(panel))); - contextMenu.getItems().add(new SeparatorMenuItem()); - - contextMenu.getItems().add(factory.createMenuItem(StandardActions.ADD_TO_GROUP, addToGroup(panel))); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.REMOVE_FROM_GROUP, removeFromGroup(panel))); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.MOVE_TO_GROUP, moveToGroup(panel))); - return contextMenu; } - private static OldCommandWrapper moveToGroup(BasePanel panel) { - OldCommandWrapper command = new OldCommandWrapper(Actions.MOVE_TO_GROUP, panel); - command.setExecutable(areGroupsPresent(panel.getBibDatabaseContext())); - return command; - } - - private static OldCommandWrapper removeFromGroup(BasePanel panel) { - OldCommandWrapper command = new OldCommandWrapper(Actions.REMOVE_FROM_GROUP, panel); - command.setExecutable(areGroupsPresent(panel.getBibDatabaseContext())); - return command; - } - - private static OldCommandWrapper addToGroup(BasePanel panel) { - OldCommandWrapper command = new OldCommandWrapper(Actions.ADD_TO_GROUP, panel); - command.setExecutable(areGroupsPresent(panel.getBibDatabaseContext())); - return command; - } - private static OldCommandWrapper mergeEntries(BasePanel panel) { OldCommandWrapper command = new OldCommandWrapper(Actions.MERGE_ENTRIES, panel); command.setExecutable(panel.getMainTable().getSelectedEntries().size() == 2); @@ -169,10 +144,6 @@ private static Menu createCopySubMenu(BasePanel panel, ActionFactory factory, Di return copySpecialMenu; } - private static boolean areGroupsPresent(BibDatabaseContext database) { - return database.getMetaData().getGroups().isPresent(); - } - private static boolean isFieldSetForSelectedEntry(String field, BasePanel panel) { return isAnyFieldSetForSelectedEntry(Collections.singletonList(field), panel); } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index b7f8e0dd5ea..54ccec1845d 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -801,8 +801,6 @@ Remove\ selected\ entries\ from\ this\ group=Remove selected entries from this g Remove\ entry\ type=Remove entry type -Remove\ from\ group=Remove from group - Remove\ group=Remove group Remove\ group,\ keep\ subgroups=Remove group, keep subgroups @@ -1439,8 +1437,6 @@ Show\ extra\ columns=Show extra columns Parsing\ error=Parsing error illegal\ backslash\ expression=illegal backslash expression -Move\ to\ group=Move to group - Clear\ read\ status=Clear read status Convert\ to\ biblatex\ format\ (for\ example,\ move\ the\ value\ of\ the\ 'journal'\ field\ to\ 'journaltitle')=Convert to biblatex format (for example, move the value of the 'journal' field to 'journaltitle') Deprecated\ fields=Deprecated fields