コード例 #1
0
 private void updateTables() {
   if (frame.getTabbedPane().getTabCount() == 0) {
     return;
   }
   for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
     frame.getTabbedPane().getComponentAt(i);
   }
 }
コード例 #2
0
  /**
   * Cycle through all databases, and make sure everything is updated with the new type
   * customization. This includes making sure all entries have a valid type, that no obsolete entry
   * editors are around, and that the right-click menus' change type menu is up-to-date.
   */
  private void updateTypesForEntries(String typeName) {
    if (frame.getTabbedPane().getTabCount() == 0) {
      return;
    }
    for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
      BasePanel bp = (BasePanel) frame.getTabbedPane().getComponentAt(i);

      // Invalidate associated cached entry editor
      bp.entryEditors.remove(typeName);

      for (BibtexEntry entry : bp.database().getEntries()) {
        entry.updateType();
      }
    }
  }
コード例 #3
0
ファイル: SearchManager2.java プロジェクト: steog88/jabref
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == escape) {
      incSearch = false;
      clearSearchLater();
    } else if (((e.getSource() == searchField) || (e.getSource() == search))
        && !increment.isSelected()
        && (panel != null)) {

      updatePrefs(); // Make sure the user's choices are recorded.
      if (searchField.getText().isEmpty()) {
        // An empty search field should cause the search to be cleared.
        clearSearchLater();
        return;
      }

      fireSearchlistenerEvent(searchField.getText());

      // Setup search parameters common to both normal and float.
      SearchRule searchRule;

      if (Globals.prefs.getBoolean(JabRefPreferences.REG_EXP_SEARCH)) {
        searchRule =
            new BasicRegexSearchRule(
                Globals.prefs.getBoolean(JabRefPreferences.CASE_SENSITIVE_SEARCH));
      } else {
        searchRule =
            new BasicSearchRule(Globals.prefs.getBoolean(JabRefPreferences.CASE_SENSITIVE_SEARCH));
      }

      try {
        // this searches specified fields if specified,
        // and all fields otherwise
        searchRule =
            new SearchExpression(
                Globals.prefs.getBoolean(JabRefPreferences.CASE_SENSITIVE_SEARCH),
                Globals.prefs.getBoolean(JabRefPreferences.REG_EXP_SEARCH));
      } catch (Exception ex) {
        // we'll do a search in all fields
      }

      if (!searchRule.validateSearchStrings(searchField.getText())) {
        panel.output(Globals.lang("Search failed: illegal search expression"));
        panel.stopShowingSearchResults();
        return;
      }
      SearchWorker worker = new SearchWorker(searchRule, searchField.getText());
      worker.getWorker().run();
      worker.getCallBack().update();
      escape.setEnabled(true);

      frame.basePanel().mainTable.setSelected(0);
    }
  }
コード例 #4
0
  @Override
  public void actionPerformed(ActionEvent e) {
    BasePanel bp = frame.basePanel();
    if (bp == null) {
      return;
    }
    BibtexEntry[] entries = bp.getSelectedEntries();
    // Lazy creation of the dialog:
    if (diag == null) {
      createDialog();
    }
    cancelled = true;
    prepareDialog(entries.length > 0);
    Util.placeDialog(diag, frame);
    diag.setVisible(true);
    if (cancelled) {
      return;
    }

    Collection<BibtexEntry> entryList;
    // If all entries should be treated, change the entries array:
    if (all.isSelected()) {
      entryList = bp.database().getEntries();
    } else {
      entryList = Arrays.asList(entries);
    }
    String toSet = text.getText();
    if (toSet.isEmpty()) {
      toSet = null;
    }
    String[] fields = getFieldNames(field.getText().trim().toLowerCase());
    NamedCompound ce = new NamedCompound(Globals.lang("Set field"));
    if (rename.isSelected()) {
      if (fields.length > 1) {
        // TODO: message: can only rename a single field
      } else {
        ce.addEdit(
            Util.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected()));
      }
    } else {
      for (String field1 : fields) {
        ce.addEdit(
            Util.massSetField(
                entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected()));
      }
    }
    ce.end();
    bp.undoManager.addEdit(ce);
    bp.markBaseChanged();
  }
コード例 #5
0
ファイル: MoveFileAction.java プロジェクト: kifetew/SWAT
  public void actionPerformed(ActionEvent event) {
    int selected = editor.getSelectedRow();
    if (selected == -1) return;
    FileListEntry flEntry = editor.getTableModel().getEntry(selected);
    // Check if the current file exists:
    String ln = flEntry.getLink();
    boolean httpLink = ln.toLowerCase().startsWith("http");
    if (httpLink) {
      // TODO: notify that this operation cannot be done on remote links

    }

    // Get an absolute path representation:
    String dir = frame.basePanel().metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
    if ((dir == null) || (dir.trim().length() == 0) || !(new File(dir)).exists()) {
      JOptionPane.showMessageDialog(
          frame,
          Globals.lang("File_directory_is_not_set_or_does_not_exist!"),
          Globals.lang("Move/Rename file"),
          JOptionPane.ERROR_MESSAGE);
      return;
    }
    File file = new File(ln);
    if (!file.isAbsolute()) {
      file = Util.expandFilename(ln, new String[] {dir});
    }
    if ((file != null) && file.exists()) {
      // Ok, we found the file. Now get a new name:
      String extension = null;
      if (flEntry.getType() != null) extension = "." + flEntry.getType().getExtension();

      File newFile = null;
      boolean repeat = true;
      while (repeat) {
        repeat = false;
        String chosenFile;
        if (toFileDir) {
          String suggName = eEditor.getEntry().getCiteKey() + extension;
          CheckBoxMessage cbm =
              new CheckBoxMessage(
                  Globals.lang("Move file to file directory?"),
                  Globals.lang("Rename to '%0'", suggName),
                  Globals.prefs.getBoolean("renameOnMoveFileToFileDir"));
          int answer;
          // Only ask about renaming file if the file doesn't have the proper name already:
          if (!suggName.equals(file.getName()))
            answer =
                JOptionPane.showConfirmDialog(
                    frame, cbm, Globals.lang("Move/Rename file"), JOptionPane.YES_NO_OPTION);
          else
            answer =
                JOptionPane.showConfirmDialog(
                    frame,
                    Globals.lang("Move file to file directory?"),
                    Globals.lang("Move/Rename file"),
                    JOptionPane.YES_NO_OPTION);
          if (answer != JOptionPane.YES_OPTION) return;
          Globals.prefs.putBoolean("renameOnMoveFileToFileDir", cbm.isSelected());
          StringBuilder sb = new StringBuilder(dir);
          if (!dir.endsWith(File.separator)) sb.append(File.separator);
          if (cbm.isSelected()) {
            // Rename:
            sb.append(suggName);
          } else {
            // Do not rename:
            sb.append(file.getName());
          }
          chosenFile = sb.toString();
        } else {
          chosenFile =
              FileDialogs.getNewFile(frame, file, extension, JFileChooser.SAVE_DIALOG, false);
        }
        if (chosenFile == null) {
          return; // cancelled
        }
        newFile = new File(chosenFile);
        // Check if the file already exists:
        if (newFile.exists()
            && (JOptionPane.showConfirmDialog(
                    frame,
                    "'" + newFile.getName() + "' " + Globals.lang("exists. Overwrite file?"),
                    Globals.lang("Move/Rename file"),
                    JOptionPane.OK_CANCEL_OPTION)
                != JOptionPane.OK_OPTION)) {
          if (!toFileDir) repeat = true;
          else return;
        }
      }

      if (!newFile.equals(file)) {
        try {
          boolean success = file.renameTo(newFile);
          if (!success) {
            success = Util.copyFile(file, newFile, true);
          }
          if (success) {
            // Remove the original file:
            file.delete();
            // Relativise path, if possible.
            String canPath = (new File(dir)).getCanonicalPath();
            if (newFile.getCanonicalPath().startsWith(canPath)) {
              if ((newFile.getCanonicalPath().length() > canPath.length())
                  && (newFile.getCanonicalPath().charAt(canPath.length()) == File.separatorChar))
                flEntry.setLink(newFile.getCanonicalPath().substring(1 + canPath.length()));
              else flEntry.setLink(newFile.getCanonicalPath().substring(canPath.length()));

            } else flEntry.setLink(newFile.getCanonicalPath());
            eEditor.updateField(editor);
            JOptionPane.showMessageDialog(
                frame,
                Globals.lang("File moved"),
                Globals.lang("Move/Rename file"),
                JOptionPane.INFORMATION_MESSAGE);
          } else {
            JOptionPane.showMessageDialog(
                frame,
                Globals.lang("Move file failed"),
                Globals.lang("Move/Rename file"),
                JOptionPane.ERROR_MESSAGE);
          }

        } catch (SecurityException ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              frame,
              Globals.lang("Could not move file") + ": " + ex.getMessage(),
              Globals.lang("Move/Rename file"),
              JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              frame,
              Globals.lang("Could not move file") + ": " + ex.getMessage(),
              Globals.lang("Move/Rename file"),
              JOptionPane.ERROR_MESSAGE);
        }
      }
    } else {

      // File doesn't exist, so we can't move it.
      JOptionPane.showMessageDialog(
          frame,
          Globals.lang("Could not find file '%0'.", flEntry.getLink()),
          Globals.lang("File not found"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #6
0
ファイル: RightClickMenu.java プロジェクト: tnoz/jabref
  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
          }
        });
  }