Example #1
0
 @Override
 public void update() {
   if (cancelled) {
     frame.unblock();
     return;
   }
   if (unsuccessfulRenames > 0) { // Rename failed for at least one entry
     JOptionPane.showMessageDialog(
         frame,
         Localization.lang(
             "File rename failed for %0 entries.", Integer.toString(unsuccessfulRenames)),
         Localization.lang("Autogenerate PDF Names"),
         JOptionPane.INFORMATION_MESSAGE);
   }
   if (modifiedEntriesCount > 0) {
     panel.updateEntryEditorIfShowing();
     panel.markBaseChanged();
   }
   String message;
   switch (modifiedEntriesCount) {
     case 0:
       message = Localization.lang("No entry needed a clean up");
       break;
     case 1:
       message = Localization.lang("One entry needed a clean up");
       break;
     default:
       message =
           Localization.lang(
               "%0 entries needed a clean up", Integer.toString(modifiedEntriesCount));
       break;
   }
   panel.output(message);
   frame.unblock();
 }
 private void updateTables() {
   if (frame.getTabbedPane().getTabCount() == 0) {
     return;
   }
   for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
     frame.getTabbedPane().getComponentAt(i);
   }
 }
Example #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   databases = frame.getTabbedPane().getTabCount();
   saved = 0;
   frame.output(Localization.lang("Saving all databases..."));
   Spin.off(this);
   run();
   frame.output(Localization.lang("Save all finished."));
 }
Example #4
0
 @Override
 public void run() {
   for (int i = 0; i < databases; i++) {
     if (i < frame.getTabbedPane().getTabCount()) {
       // System.out.println("Base "+i);
       BasePanel panel = frame.baseAt(i);
       if (panel.getFile() == null) {
         frame.showBaseAt(i);
       }
       panel.runCommand("save");
       // TODO: can we find out whether the save was actually done or not?
       saved++;
     }
   }
 }
  /**
   * 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();
      }
    }
  }
Example #6
0
  @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);
    }
  }
Example #7
0
 // run third, on EDT:
 @Override
 public void update() {
   if (databases == null) {
     return;
   }
   for (DBImporterResult res : databases) {
     database = res.getDatabase();
     metaData = res.getMetaData();
     if (database != null) {
       BasePanel pan =
           frame.addTab(database, null, metaData, Globals.prefs.getDefaultEncoding(), true);
       pan.getBibDatabaseContext().getMetaData().setDBStrings(dbs);
       frame.setTabTitle(pan, res.getName() + "(Imported)", "Imported DB");
       pan.markBaseChanged();
     }
   }
   frame.output(
       Localization.lang(
           "Imported %0 databases successfully", Integer.toString(databases.size())));
 }
Example #8
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();
  }
Example #9
0
 @Override
 public void init() {
   cancelled = false;
   modifiedEntriesCount = 0;
   int numSelected = panel.getSelectedEntries().length;
   if (numSelected == 0) { // None selected. Inform the user to select entries first.
     JOptionPane.showMessageDialog(
         frame,
         Localization.lang("First select entries to clean up."),
         Localization.lang("Cleanup entry"),
         JOptionPane.INFORMATION_MESSAGE);
     cancelled = true;
     return;
   }
   frame.block();
   panel.output(
       Localization.lang("Doing a cleanup for %0 entries...", Integer.toString(numSelected)));
 }
Example #10
0
  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);
    }
  }
Example #11
0
  private void performImport() {
    if (connectedToDB) {
      try {
        frame.output(Localization.lang("Attempting SQL import..."));
        DBExporterAndImporterFactory factory = new DBExporterAndImporterFactory();
        DBImporter importer = factory.getImporter(dbs.getServerType());
        try (Connection conn = importer.connectToDB(dbs);
            Statement statement = SQLUtil.queryAllFromTable(conn, "jabref_database");
            ResultSet rs = statement.getResultSet()) {

          Vector<String> v;
          Vector<Vector<String>> matrix = new Vector<>();

          while (rs.next()) {
            v = new Vector<>();
            v.add(rs.getString("database_name"));
            matrix.add(v);
          }

          if (matrix.isEmpty()) {
            JOptionPane.showMessageDialog(
                frame,
                Localization.lang("There are no available databases to be imported"),
                Localization.lang("Import from SQL database"),
                JOptionPane.INFORMATION_MESSAGE);
          } else {
            DBImportExportDialog dialogo =
                new DBImportExportDialog(frame, matrix, DBImportExportDialog.DialogType.IMPORTER);
            if (dialogo.removeAction) {
              String dbName = dialogo.selectedDB;
              importer.removeDB(dialogo, dbName, conn, metaData);
              performImport();
            } else if (dialogo.moreThanOne) {
              databases =
                  importer.performImport(
                      dbs,
                      dialogo.listOfDBs,
                      frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
              for (DBImporterResult res : databases) {
                database = res.getDatabase();
                metaData = res.getMetaData();
                dbs.isConfigValid(true);
              }
              frame.output(
                  Localization.lang(
                      "%0 databases will be imported", Integer.toString(databases.size())));
            } else {
              frame.output(Localization.lang("Importing cancelled"));
            }
          }
        }
      } catch (Exception ex) {
        String preamble =
            Localization.lang("Could not import from SQL database for the following reason:");
        String errorMessage = SQLUtil.getExceptionMessage(ex);
        dbs.isConfigValid(false);
        JOptionPane.showMessageDialog(
            frame,
            preamble + '\n' + errorMessage,
            Localization.lang("Import from SQL database"),
            JOptionPane.ERROR_MESSAGE);
        frame.output(Localization.lang("Error importing from database"));
        LOGGER.error("Error importing from databae", ex);
      }
    }
  }
Example #12
0
  @Override
  public void drop(DropTargetDropEvent dtde) {
    Transferable tsf = dtde.getTransferable();
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    // try with an URL
    DataFlavor dtURL = null;
    try {
      dtURL = new DataFlavor("application/x-java-url; class=java.net.URL");
    } catch (ClassNotFoundException e) {
      LOGGER.warn("Could not find DropTargetDropEvent class.", e);
    }
    try {
      URL url = (URL) tsf.getTransferData(dtURL);
      JOptionChoice res =
          (JOptionChoice)
              JOptionPane.showInputDialog(
                  editor,
                  "",
                  Localization.lang("Select action"),
                  JOptionPane.QUESTION_MESSAGE,
                  null,
                  new JOptionChoice[] {
                    new JOptionChoice(Localization.lang("Insert URL"), 0),
                    new JOptionChoice(Localization.lang("Download file"), 1)
                  },
                  new JOptionChoice(Localization.lang("Insert URL"), 0));
      if (res != null) {
        switch (res.getId()) {
            // insert URL
          case 0:
            feditor.setText(url.toString());
            editor.updateField(feditor);
            break;
            // download file
          case 1:
            try {
              // auto filename:
              File file =
                  new File(
                      new File(Globals.prefs.get("pdfDirectory")),
                      editor.getEntry().getCiteKey() + ".pdf");
              frame.output(Localization.lang("Downloading..."));
              MonitoredURLDownload.buildMonitoredDownload(editor, url).downloadToFile(file);
              frame.output(Localization.lang("Download completed"));
              feditor.setText(file.toURI().toURL().toString());
              editor.updateField(feditor);

            } catch (IOException ioex) {
              LOGGER.error("Error while downloading file.", ioex);
              JOptionPane.showMessageDialog(
                  editor,
                  Localization.lang("File download"),
                  Localization.lang("Error while downloading file:" + ioex.getMessage()),
                  JOptionPane.ERROR_MESSAGE);
            }
            break;
          default:
            LOGGER.warn("Unknown selection (should not happen)");
            break;
        }
      }
      return;
    } catch (UnsupportedFlavorException nfe) {
      // not an URL then...
      LOGGER.warn("Could not parse URL.", nfe);
    } catch (IOException ioex) {
      LOGGER.warn("Could not perform drag and drop.", ioex);
    }

    try {
      // try with a File List
      @SuppressWarnings("unchecked")
      List<File> filelist = (List<File>) tsf.getTransferData(DataFlavor.javaFileListFlavor);
      if (filelist.size() > 1) {
        JOptionPane.showMessageDialog(
            editor,
            Localization.lang("Only one item is supported"),
            Localization.lang("Drag and Drop Error"),
            JOptionPane.ERROR_MESSAGE);
        return;
      }
      File fl = filelist.get(0);
      feditor.setText(fl.toURI().toURL().toString());
      editor.updateField(feditor);

    } catch (UnsupportedFlavorException nfe) {
      JOptionPane.showMessageDialog(
          editor,
          Localization.lang("Operation not supported"),
          Localization.lang("Drag and Drop Error"),
          JOptionPane.ERROR_MESSAGE);
      LOGGER.warn("Could not perform drag and drop.", nfe);
    } catch (IOException ioex) {
      LOGGER.warn("Could not perform drag and drop.", ioex);
    }
  }
Example #13
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
          }
        });
  }
Example #14
0
  void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) {

    InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = panel.getActionMap();

    im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", parent.prevEntryAction);
    im.put(Globals.prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", parent.nextEntryAction);

    im.put(Globals.prefs.getKey("Entry editor, store field"), "store");
    am.put("store", parent.storeFieldAction);
    im.put(Globals.prefs.getKey("Entry editor, next panel"), "right");
    im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("left", parent.switchLeftAction);
    im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left");
    im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("right", parent.switchRightAction);
    im.put(Globals.prefs.getKey("Help"), "help");
    am.put("help", parent.helpAction);
    im.put(Globals.prefs.getKey("Save database"), "save");
    am.put("save", parent.saveDatabaseAction);
    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", parent.frame.nextTab);
    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", parent.frame.prevTab);

    panel.setName(title);
    // String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref";
    String colSpec = "fill:pref, 1dlu, fill:pref:grow, 1dlu, fill:pref";
    StringBuffer sb = new StringBuffer();
    for (String field : fields) {
      sb.append("fill:pref:grow, ");
    }
    if (addKeyField) sb.append("4dlu, fill:pref");
    else sb.delete(sb.length() - 2, sb.length());
    String rowSpec = sb.toString();

    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel);

    for (int i = 0; i < fields.length; i++) {
      // Create the text area:
      int editorType = BibtexFields.getEditorType(fields[i]);

      final FieldEditor ta;
      int defaultHeight;
      int wHeight = (int) (50.0 * BibtexFields.getFieldWeight(fields[i]));
      if (editorType == GUIGlobals.FILE_LIST_EDITOR) {
        ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
        fileListEditor = (FileListEditor) ta;
        defaultHeight = 0;
      } else {
        ta = new FieldTextArea(fields[i], null);
        frame.getSearchManager().addSearchListener((FieldTextArea) ta);
        defaultHeight = ta.getPane().getPreferredSize().height;
      }
      // ta.addUndoableEditListener(bPanel.undoListener);

      JComponent ex = parent.getExtra(fields[i], ta);

      // Add autocompleter listener, if required for this field:
      AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]);
      AutoCompleteListener acl = null;
      if (autoComp != null) {
        acl = new AutoCompleteListener(autoComp);
      }
      setupJTextComponent(ta.getTextComponent(), acl);
      ta.setAutoCompleteListener(acl);

      // Store the editor for later reference:
      editors.put(fields[i], ta);
      if (i == 0) activeField = ta;
      // System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i]));
      ta.getPane().setPreferredSize(new Dimension(100, Math.max(defaultHeight, wHeight)));
      builder.append(ta.getLabel());
      if (ex == null) builder.append(ta.getPane(), 3);
      else {
        builder.append(ta.getPane());
        JPanel pan = new JPanel();
        pan.setLayout(new BorderLayout());
        pan.add(ex, BorderLayout.NORTH);
        builder.append(pan);
      }
      builder.nextLine();
    }

    // Add the edit field for Bibtex-key.
    if (addKeyField) {
      final FieldTextField tf =
          new FieldTextField(
              BibtexFields.KEY_FIELD, parent.getEntry().getField(BibtexFields.KEY_FIELD), true);
      // tf.addUndoableEditListener(bPanel.undoListener);
      setupJTextComponent(tf, null);

      editors.put("bibtexkey", tf);
      /*
       * If the key field is the only field, we should have only one
       * editor, and this one should be set as active initially:
       */
      if (editors.size() == 1) activeField = tf;
      builder.nextLine();
      builder.append(tf.getLabel());
      builder.append(tf, 3);
    }
  }