Esempio n. 1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (editor == null) {
     if (frame == null) {
       editor = new ExternalFileTypeEditor(dialog);
     } else {
       editor = new ExternalFileTypeEditor(frame);
     }
   }
   editor.setValues();
   editor.setVisible(true);
   if ((frame != null) && (frame.getCurrentBasePanel() != null)) {
     frame.getCurrentBasePanel().getMainTable().repaint();
   }
 }
Esempio n. 2
0
  public boolean openLink() {
    frame.output(Localization.lang("External viewer called") + ".");
    try {
      ExternalFileType type = fileType;
      if (this.fileType == null) {
        if (this.fieldName == null) {
          // We don't already know the file type, so we try to deduce it from the extension:
          File file = new File(link);
          // We try to check the extension for the file:
          String name = file.getName();
          int pos = name.indexOf('.');
          String extension =
              (pos >= 0) && (pos < (name.length() - 1))
                  ? name.substring(pos + 1).trim().toLowerCase()
                  : null;
          // Now we know the extension, check if it is one we know about:
          type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension);
          fileType = type;
        } else {
          JabRefDesktop.openExternalViewer(
              frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData(), link, fieldName);
          return true;
        }
      }

      if (type instanceof UnknownExternalFileType) {
        return JabRefDesktop.openExternalFileUnknown(
            frame, entry, metaData, link, (UnknownExternalFileType) type);
      } else {
        return JabRefDesktop.openExternalFileAnyFormat(metaData, link, type);
      }

    } catch (IOException e1) {
      // See if we should show an error message concerning the application to open the
      // link with. We check if the file type is set, and if the file type has a non-empty
      // application link. If that link is referred by the error message, we can assume
      // that the problem is in the open-with-application setting:
      if ((fileType != null)
          && (fileType.getOpenWith() != null)
          && !fileType.getOpenWith().isEmpty()
          && e1.getMessage().contains(fileType.getOpenWith())) {

        JOptionPane.showMessageDialog(
            frame,
            Localization.lang(
                "Unable to open link. "
                    + "The application '%0' associated with the file type '%1' could not be called.",
                fileType.getOpenWith(), fileType.getName()),
            Localization.lang("Could not open link"),
            JOptionPane.ERROR_MESSAGE);
        return false;
      }

      LOGGER.warn("Unable to open link", e1);
    }
    return false;
  }
  @Subscribe
  public void listen(SharedEntryNotPresentEvent event) {
    BasePanel panel = jabRefFrame.getCurrentBasePanel();
    EntryEditor entryEditor = panel.getCurrentEditor();

    panel
        .getUndoManager()
        .addEdit(new UndoableRemoveEntry(panel.getDatabase(), event.getBibEntry(), panel));

    if (Objects.nonNull(entryEditor) && (entryEditor.getEntry() == event.getBibEntry())) {
      JOptionPane.showMessageDialog(
          jabRefFrame,
          Localization.lang(
                  "The BibEntry you currently work on has been deleted on the shared side.")
              + "\n"
              + Localization.lang("You can restore the entry using the \"Undo\" operation."),
          Localization.lang("Shared entry is no longer present"),
          JOptionPane.INFORMATION_MESSAGE);

      SwingUtilities.invokeLater(() -> panel.hideBottomComponent());
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    panel = frame.getCurrentBasePanel();

    // Check if a BasePanel exists:
    if (panel == null) {
      return;
    }

    // Check if any entries are selected:
    entries = panel.getSelectedEntries();
    if (entries.length == 0) {
      JOptionPane.showMessageDialog(
          frame,
          Localization.lang("This operation requires one or more entries to be selected."),
          (String) getValue(Action.NAME),
          JOptionPane.ERROR_MESSAGE);
      return;
    }

    // If required, check that all entries have BibTeX keys defined:
    if (operation.requiresBibtexKeys()) {
      for (BibEntry entry : entries) {
        if ((entry.getCiteKey() == null) || entry.getCiteKey().trim().isEmpty()) {
          JOptionPane.showMessageDialog(
              frame,
              Localization.lang(
                  "This operation requires all selected entries to have BibTex keys defined."),
              (String) getValue(Action.NAME),
              JOptionPane.ERROR_MESSAGE);
          return;
        }
      }
    }

    // All set, call the operation in a new thread:
    JabRefExecutorService.INSTANCE.execute(this);
  }
Esempio n. 5
0
  public PreferencesDialog(JabRefFrame parent) {
    super(parent, Localization.lang("JabRef preferences"), false);
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    frame = parent;

    main = new JPanel();
    JPanel mainPanel = new JPanel();
    JPanel lower = new JPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(lower, BorderLayout.SOUTH);

    final CardLayout cardLayout = new CardLayout();
    main.setLayout(cardLayout);

    List<PrefsTab> tabs = new ArrayList<>();
    tabs.add(new GeneralTab(prefs));
    tabs.add(new NetworkTab(prefs));
    tabs.add(new FileTab(frame, prefs));
    tabs.add(new FileSortTab(prefs));
    tabs.add(new EntryEditorPrefsTab(frame, prefs));
    tabs.add(new GroupsPrefsTab(prefs));
    tabs.add(new AppearancePrefsTab(prefs));
    tabs.add(new ExternalTab(frame, this, prefs));
    tabs.add(new TablePrefsTab(prefs));
    tabs.add(new TableColumnsTab(prefs, parent));
    tabs.add(new BibtexKeyPatternPrefTab(prefs, parent.getCurrentBasePanel()));
    tabs.add(new PreviewPrefsTab(prefs));
    tabs.add(new NameFormatterTab(prefs));
    tabs.add(new ImportSettingsTab(prefs));
    tabs.add(new XmpPrefsTab(prefs));
    tabs.add(new AdvancedTab(prefs));

    // add all tabs
    tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new);
    JList<String> chooser = new JList<>(tabNames);
    chooser.setBorder(BorderFactory.createEtchedBorder());
    // Set a prototype value to control the width of the list:
    chooser.setPrototypeCellValue("This should be wide enough");
    chooser.setSelectedIndex(0);
    chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Add the selection listener that will show the correct panel when
    // selection changes:
    chooser.addListSelectionListener(
        e -> {
          if (e.getValueIsAdjusting()) {
            return;
          }
          String o = chooser.getSelectedValue();
          cardLayout.show(main, o);
        });

    JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout(4, 1));
    buttons.add(importPreferences, 0);
    buttons.add(exportPreferences, 1);
    buttons.add(showPreferences, 2);
    buttons.add(resetPreferences, 3);

    JPanel westPanel = new JPanel();
    westPanel.setLayout(new BorderLayout());
    westPanel.add(chooser, BorderLayout.CENTER);
    westPanel.add(buttons, BorderLayout.SOUTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(main, BorderLayout.CENTER);
    mainPanel.add(westPanel, BorderLayout.WEST);

    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(new OkAction());
    CancelAction cancelAction = new CancelAction();
    cancel.addActionListener(cancelAction);
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower);
    buttonBarBuilder.addGlue();
    buttonBarBuilder.addButton(ok);
    buttonBarBuilder.addButton(cancel);
    buttonBarBuilder.addGlue();

    // Key bindings:
    KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);

    // Import and export actions:
    exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
    exportPreferences.addActionListener(
        e -> {
          Optional<Path> path =
              new NewFileDialogs(frame, System.getProperty("user.home"))
                  .withExtension(FileExtensions.XML)
                  .saveNewFile();
          path.ifPresent(
              exportFile -> {
                try {
                  prefs.exportPreferences(exportFile.toString());
                } catch (JabRefException ex) {
                  LOGGER.warn(ex.getMessage(), ex);
                  JOptionPane.showMessageDialog(
                      PreferencesDialog.this,
                      ex.getLocalizedMessage(),
                      Localization.lang("Export preferences"),
                      JOptionPane.ERROR_MESSAGE);
                }
              });
        });

    importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
    importPreferences.addActionListener(
        e -> {
          Optional<Path> fileName =
              new NewFileDialogs(frame, System.getProperty("user.home"))
                  .withExtension(FileExtensions.XML)
                  .openDlgAndGetSelectedFile();

          if (fileName.isPresent()) {
            try {
              prefs.importPreferences(fileName.get().toString());
              updateAfterPreferenceChanges();
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  Localization.lang("You must restart JabRef for this to come into effect."),
                  Localization.lang("Import preferences"),
                  JOptionPane.WARNING_MESSAGE);
            } catch (JabRefException ex) {
              LOGGER.warn(ex.getMessage(), ex);
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  ex.getLocalizedMessage(),
                  Localization.lang("Import preferences"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    showPreferences.addActionListener(
        e ->
            new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame)
                .setVisible(true));
    resetPreferences.addActionListener(
        e -> {
          if (JOptionPane.showConfirmDialog(
                  PreferencesDialog.this,
                  Localization.lang(
                      "Are you sure you want to reset all settings to default values?"),
                  Localization.lang("Reset preferences"),
                  JOptionPane.OK_CANCEL_OPTION)
              == JOptionPane.OK_OPTION) {
            try {
              prefs.clear();
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  Localization.lang("You must restart JabRef for this to come into effect."),
                  Localization.lang("Reset preferences"),
                  JOptionPane.WARNING_MESSAGE);
            } catch (BackingStoreException ex) {
              LOGGER.warn(ex.getMessage(), ex);
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  ex.getLocalizedMessage(),
                  Localization.lang("Reset preferences"),
                  JOptionPane.ERROR_MESSAGE);
            }
            updateAfterPreferenceChanges();
          }
        });

    setValues();

    pack();
  }
 @Override
 public void actionPerformed(ActionEvent evt) {
   frame.getCurrentBasePanel().runCommand(actionName);
 }
Esempio n. 7
0
  private void performImport() {
    if (!connectedToDB) {
      return;
    }

    frame.output(Localization.lang("Attempting SQL import..."));
    DBExporterAndImporterFactory factory = new DBExporterAndImporterFactory();
    DatabaseImporter importer = factory.getImporter(dbs.getDbPreferences().getServerType());
    try {
      try (Connection conn = importer.connectToDB(dbs);
          Statement statement = conn.createStatement();
          ResultSet rs = statement.executeQuery(SQLUtil.queryAllFromTable("jabref_database"))) {

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

        while (rs.next()) {
          Vector<String> 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;
            DatabaseUtil.removeDB(dialogo, dbName, conn, databaseContext);
            performImport();
          } else if (dialogo.moreThanOne) {
            databases =
                importer.performImport(
                    dbs,
                    dialogo.listOfDBs,
                    frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
            for (DBImporterResult res : databases) {
              databaseContext = res.getDatabaseContext();
              dbs.isConfigValid(true);
            }
            frame.output(
                Localization.lang(
                    "%0 databases will be imported", Integer.toString(databases.size())));
          } else {
            frame.output(Localization.lang("Importing canceled"));
          }
        }
      }
    } 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 database", ex);
    }
  }