Exemple #1
0
  public RightClickMenu(JabRefFrame frame, BasePanel panel) {
    this.panel = panel;
    JMenu typeMenu = new ChangeEntryTypeMenu().getChangeEntryTypeMenu(panel);
    // Are multiple entries selected?
    boolean multiple = areMultipleEntriesSelected();

    // If only one entry is selected, get a reference to it for adapting the menu.
    BibEntry be = null;
    if (panel.getMainTable().getSelectedRowCount() == 1) {
      be = panel.getMainTable().getSelected().get(0);
    }

    addPopupMenuListener(this);

    JMenu copySpecialMenu = new JMenu(Localization.lang("Copy") + "...");
    copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key")));
    copySpecialMenu.add(
        new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}")));
    copySpecialMenu.add(
        new GeneralAction(
            Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title")));
    copySpecialMenu.add(
        new GeneralAction(
            Actions.EXPORT_TO_CLIPBOARD,
            Localization.lang("Export to clipboard"),
            IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getSmallIcon()));

    add(
        new GeneralAction(
            Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon()));
    add(copySpecialMenu);
    add(
        new GeneralAction(
            Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcon.PASTE.getSmallIcon()));
    add(
        new GeneralAction(
            Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon()));
    add(
        new GeneralAction(
            Actions.DELETE,
            Localization.lang("Delete"),
            IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon()));
    add(
        new GeneralAction(
            Actions.PRINT_PREVIEW,
            Localization.lang("Print entry preview"),
            IconTheme.JabRefIcon.PRINTED.getSmallIcon()));
    addSeparator();

    add(
        new GeneralAction(
            Actions.SEND_AS_EMAIL,
            Localization.lang("Send as email"),
            IconTheme.JabRefIcon.EMAIL.getSmallIcon()));
    addSeparator();

    JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color"));
    for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) {
      markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem());
    }

    if (multiple) {
      add(
          new GeneralAction(
              Actions.MARK_ENTRIES,
              Localization.lang("Mark entries"),
              IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon()));
      add(markSpecific);
      add(
          new GeneralAction(
              Actions.UNMARK_ENTRIES,
              Localization.lang("Unmark entries"),
              IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon()));
    } else if (be != null) {
      Optional<String> marked = be.getFieldOptional(FieldName.MARKED_INTERNAL);
      // We have to check for "" too as the marked field may be empty
      if ((!marked.isPresent()) || marked.get().isEmpty()) {
        add(
            new GeneralAction(
                Actions.MARK_ENTRIES,
                Localization.lang("Mark entry"),
                IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon()));
        add(markSpecific);
      } else {
        add(markSpecific);
        add(
            new GeneralAction(
                Actions.UNMARK_ENTRIES,
                Localization.lang("Unmark entry"),
                IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon()));
      }
    }

    if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SPECIALFIELDSENABLED)) {
      if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_RANKING)) {
        JMenu rankingMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), frame);
        add(rankingMenu);
      }

      // TODO: multiple handling for relevance and quality-assurance
      // if multiple values are selected ("if (multiple)"), two options (set / clear) should be
      // offered
      // if one value is selected either set or clear should be offered
      if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_RELEVANCE)) {
        add(Relevance.getInstance().getValues().get(0).getMenuAction(frame));
      }
      if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_QUALITY)) {
        add(Quality.getInstance().getValues().get(0).getMenuAction(frame));
      }
      if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_PRINTED)) {
        add(Printed.getInstance().getValues().get(0).getMenuAction(frame));
      }

      if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_PRIORITY)) {
        JMenu priorityMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), frame);
        add(priorityMenu);
      }

      if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_READ)) {
        JMenu readStatusMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(readStatusMenu, ReadStatus.getInstance(), frame);
        add(readStatusMenu);
      }
    }

    addSeparator();

    add(
        new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder")) {
          {
            if (!isFieldSetForSelectedEntry(FieldName.FILE)) {
              this.setEnabled(false);
            }
          }
        });

    add(
        new GeneralAction(
            Actions.OPEN_EXTERNAL_FILE,
            Localization.lang("Open file"),
            getFileIconForSelectedEntry()) {
          {
            if (!isFieldSetForSelectedEntry(FieldName.FILE)) {
              this.setEnabled(false);
            }
          }
        });

    add(
        new GeneralAction(
            Actions.OPEN_URL,
            Localization.lang("Open URL or DOI"),
            IconTheme.JabRefIcon.WWW.getSmallIcon()) {
          {
            if (!(isFieldSetForSelectedEntry(FieldName.URL)
                || isFieldSetForSelectedEntry(FieldName.DOI))) {
              this.setEnabled(false);
            }
          }
        });

    addSeparator();

    add(typeMenu);

    add(
        new GeneralAction(
            Actions.MERGE_WITH_FETCHED_ENTRY,
            Localization.lang(
                "Get BibTeX data from %0", FetchAndMergeEntry.getDisplayNameOfSupportedFields())) {
          {
            if (!(isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_FIELDS))) {
              this.setEnabled(false);
            }
          }
        });
    add(frame.getMassSetField());
    add(
        new GeneralAction(
            Actions.ADD_FILE_LINK,
            Localization.lang("Attach file"),
            IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon()));
    add(frame.getManageKeywords());
    add(
        new GeneralAction(
            Actions.MERGE_ENTRIES,
            Localization.lang("Merge entries") + "...",
            IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()) {

          {
            if (!(areExactlyTwoEntriesSelected())) {
              this.setEnabled(false);
            }
          }
        });

    addSeparator(); // for "add/move/remove to/from group" entries (appended here)

    groupAdd =
        new JMenuItem(new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group")));
    add(groupAdd);
    groupRemove =
        new JMenuItem(
            new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group")));
    add(groupRemove);

    groupMoveTo = add(new GeneralAction(Actions.MOVE_TO_GROUP, Localization.lang("Move to group")));
    add(groupMoveTo);

    // create disabledIcons for all menu entries
    frame.createDisabledIconsForMenuEntries(this);
  }
Exemple #2
0
  public RightClickMenu(BasePanel panel_, MetaData metaData_) {
    panel = panel_;
    metaData = metaData_;

    // Are multiple entries selected?
    boolean multiple = panel.mainTable.getSelectedRowCount() > 1;

    // If only one entry is selected, get a reference to it for adapting the menu.
    BibtexEntry be = null;
    if (panel.mainTable.getSelectedRowCount() == 1) {
      be = panel.mainTable.getSelected().get(0);
    }

    addPopupMenuListener(this);

    add(
        new AbstractAction(Globals.lang("Copy"), GUIGlobals.getImage("copy")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("copy");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute copy", ex);
            }
          }
        });
    add(
        new AbstractAction(Globals.lang("Paste"), GUIGlobals.getImage("paste")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("paste");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute paste", ex);
            }
          }
        });
    add(
        new AbstractAction(Globals.lang("Cut"), GUIGlobals.getImage("cut")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("cut");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute cut", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Delete"), GUIGlobals.getImage("delete")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            /*SwingUtilities.invokeLater(new Runnable () {
            public void run() {*/
            try {
              panel.runCommand("delete");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute delete", ex);
            }
            /*}
            }); */
          }
        });
    addSeparator();

    add(
        new AbstractAction(Globals.lang("Export to clipboard")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("exportToClipboard");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute exportToClipboard", ex);
            }
          }
        });
    add(
        new AbstractAction(Globals.lang("Send as email")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("sendAsEmail");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute sendAsEmail", ex);
            }
          }
        });
    addSeparator();

    JMenu markSpecific = JabRefFrame.subMenu("Mark specific color");
    JabRefFrame frame = panel.frame;
    for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) {
      markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem());
    }

    if (multiple) {
      add(
          new AbstractAction(Globals.lang("Mark entries"), GUIGlobals.getImage("markEntries")) {

            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                panel.runCommand("markEntries");
              } catch (Throwable ex) {
                LOGGER.warn("Could not execute markEntries", ex);
              }
            }
          });

      add(markSpecific);

      add(
          new AbstractAction(Globals.lang("Unmark entries"), GUIGlobals.getImage("unmarkEntries")) {

            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                panel.runCommand("unmarkEntries");
              } catch (Throwable ex) {
                LOGGER.warn("Could not execute unmarkEntries", ex);
              }
            }
          });
      addSeparator();
    } else if (be != null) {
      String marked = be.getField(BibtexFields.MARKED);
      // We have to check for "" too as the marked field may be empty
      if (marked == null || marked.isEmpty()) {
        add(
            new AbstractAction(Globals.lang("Mark entry"), GUIGlobals.getImage("markEntries")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("markEntries");
                } catch (Throwable ex) {
                  LOGGER.warn("Could not execute markEntries", ex);
                }
              }
            });

        add(markSpecific);
      } else {
        add(markSpecific);
        add(
            new AbstractAction(Globals.lang("Unmark entry"), GUIGlobals.getImage("unmarkEntries")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("unmarkEntries");
                } catch (Throwable ex) {
                  LOGGER.warn("Could not execute unmarkEntries", ex);
                }
              }
            });
      }
      addSeparator();
    }

    if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) {
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) {
        JMenu rankingMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), panel.frame);
        add(rankingMenu);
      }

      // TODO: multiple handling for relevance and quality-assurance
      // if multiple values are selected ("if (multiple)"), two options (set / clear) should be
      // offered
      // if one value is selected either set or clear should be offered
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) {
        add(Relevance.getInstance().getValues().get(0).getMenuAction(panel.frame));
      }
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) {
        add(Quality.getInstance().getValues().get(0).getMenuAction(panel.frame));
      }
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) {
        add(Printed.getInstance().getValues().get(0).getMenuAction(panel.frame));
      }

      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) {
        JMenu priorityMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), panel.frame);
        add(priorityMenu);
      }

      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) {
        JMenu readStatusMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(
            readStatusMenu, ReadStatus.getInstance(), panel.frame);
        add(readStatusMenu);
      }

      addSeparator();
    }

    add(
        new AbstractAction(Globals.lang("Open folder"), GUIGlobals.getImage("openFolder")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("openFolder");
            } catch (Throwable ex) {
              LOGGER.warn("Could not open folder", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Open file"), GUIGlobals.getImage("openExternalFile")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("openExternalFile");
            } catch (Throwable ex) {
              LOGGER.warn("Could not open external file", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Attach file"), GUIGlobals.getImage("open")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("addFileLink");
            } catch (Throwable ex) {
              LOGGER.warn("Could not attach file", ex);
            }
          }
        });
    /*add(new AbstractAction(Globals.lang("Open PDF or PS"), GUIGlobals.getImage("openFile")) {
        public void actionPerformed(ActionEvent e) {
            try {
                panel.runCommand("openFile");
            } catch (Throwable ex) {}
        }
    });*/

    add(
        new AbstractAction(Globals.lang("Open URL or DOI"), GUIGlobals.getImage("www")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("openUrl");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute open URL", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Copy BibTeX key")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("copyKey");
            } catch (Throwable ex) {
              LOGGER.warn("Could not copy BibTex key", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Copy") + " \\cite{" + Globals.lang("BibTeX key") + '}') {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("copyCiteKey");
            } catch (Throwable ex) {
              LOGGER.warn("Could not copy cite key", ex);
            }
          }
        });

    addSeparator();
    populateTypeMenu();

    add(typeMenu);
    add(
        new AbstractAction(Globals.lang("Plain text import")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("importPlainText");
            } catch (Throwable ex) {
              LOGGER.debug("Could not import plain text", ex);
            }
          }
        });

    add(JabRef.jrf.massSetField);
    add(JabRef.jrf.manageKeywords);

    addSeparator(); // for "add/move/remove to/from group" entries (appended here)

    groupAdd =
        new JMenuItem(
            new AbstractAction(Globals.lang("Add to group")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("addToGroup");

                  // BibtexEntry[] bes = panel.getSelectedEntries();
                  // JMenu groupMenu = buildGroupMenu(bes, true, false);

                } catch (Throwable ex) {
                  LOGGER.debug("Could not add to group", ex);
                }
              }
            });
    add(groupAdd);
    groupRemove =
        new JMenuItem(
            new AbstractAction(Globals.lang("Remove from group")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("removeFromGroup");
                } catch (Throwable ex) {
                  LOGGER.debug("Could not remove from group", ex);
                }
              }
            });
    add(groupRemove);

    JMenuItem groupMoveTo =
        add(
            new AbstractAction(Globals.lang("Move to group")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("moveToGroup");
                } catch (Throwable ex) {
                  LOGGER.debug("Could not execute move to group", ex);
                }
              }
            });
    add(groupMoveTo);

    floatMarked.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            Globals.prefs.putBoolean(
                JabRefPreferences.FLOAT_MARKED_ENTRIES, floatMarked.isSelected());
            panel.mainTable.refreshSorting(); // Bad remote access
          }
        });
  }