Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importer now use FileExtensions enum, too, FileDialogs display extension #1737

Merged
merged 2 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import net.sf.jabref.logic.layout.Layout;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.layout.LayoutHelper;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.logic.util.io.FileBasedLock;
import net.sf.jabref.logic.util.io.FileUtil;
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/net/sf/jabref/gui/FileExtensions.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/gui/NewFileDialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import net.sf.jabref.Globals;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.preferences.JabRefPreferences;

public class NewFileDialogs {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/actions/BrowseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import javax.swing.JFrame;
import javax.swing.JTextField;

import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.NewFileDialogs;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;

/**
* Action used to produce a "Browse" button for one of the text fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.BrowseAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.logic.auxparser.AuxParser;
import net.sf.jabref.logic.auxparser.AuxParserResult;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.model.database.BibDatabase;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
import javax.swing.JTextField;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.BrowseAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import net.sf.jabref.JabRefExecutorService;
import net.sf.jabref.collab.ChangeScanner;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.NewFileDialogs;
import net.sf.jabref.gui.worker.AbstractWorker;
Expand All @@ -44,6 +43,7 @@
import net.sf.jabref.logic.exporter.SaveSession;
import net.sf.jabref.logic.l10n.Encodings;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.io.FileBasedLock;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import javax.swing.table.TableColumnModel;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.NewFileDialogs;
import net.sf.jabref.gui.help.HelpAction;
Expand All @@ -55,6 +54,7 @@
import net.sf.jabref.logic.importer.fileformat.CustomImporter;
import net.sf.jabref.logic.importer.fileformat.ImportFormat;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.xmp.XMPPreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down
31 changes: 8 additions & 23 deletions src/main/java/net/sf/jabref/gui/importer/ImportFileFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,25 @@
package net.sf.jabref.gui.importer;

import java.io.File;
import java.util.StringJoiner;

import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import net.sf.jabref.logic.importer.fileformat.ImportFormat;
import net.sf.jabref.logic.util.FileExtensions;

/**
* File filter that lets the user choose export format while choosing file to
* export to. Contains a reference to the ExportFormat in question.
*/
class ImportFileFilter extends FileFilter implements Comparable<ImportFileFilter> {

private final ImportFormat format;
private final String name;
private final FileNameExtensionFilter filextFilter;


public ImportFileFilter(ImportFormat format) {
this.format = format;

StringJoiner sj = new StringJoiner(", ", format.getFormatName() + " (", ")");
for (String ext : format.getExtensions()) {
sj.add("*" + ext);
}
this.name = sj.toString();
FileExtensions extensions = format.getExtensions();
this.name = extensions.getDescription();
filextFilter = new FileNameExtensionFilter(extensions.getDescription(), extensions.getExtensions());
}

public ImportFormat getImportFormat() {
Expand All @@ -48,17 +43,7 @@ public ImportFormat getImportFormat() {

@Override
public boolean accept(File file) {
if (format.getExtensions().isEmpty()) {
return true;
}

for (String extension : format.getExtensions()) {
if (file.getName().endsWith(extension)) {
return true;
}
}

return false;
return filextFilter.accept(file);
}

@Override
Expand All @@ -73,7 +58,7 @@ public int compareTo(ImportFileFilter o) {

@Override
public boolean equals(Object o) {
if(this == o) {
if (this == o) {
return true;
}
if (o instanceof ImportFileFilter) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/net/sf/jabref/gui/importer/ImportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkstyle will complain (I guess).

import javax.swing.filechooser.FileFilter;

import net.sf.jabref.Globals;
Expand All @@ -40,8 +41,10 @@
import org.apache.commons.logging.LogFactory;

public class ImportFormats {

private static final Log LOGGER = LogFactory.getLog(ImportFormats.class);


private static JFileChooser createImportFileChooser(String currentDir) {

SortedSet<ImportFormat> importers = Globals.IMPORT_FORMAT_READER.getImportFormats();
Expand Down Expand Up @@ -91,12 +94,14 @@ public ImportAction(JabRefFrame frame, boolean openInNew) {
putValue(Action.NAME, openInNew ? Localization.menuTitle("Import into new database") : Localization
.menuTitle("Import into current database"));
putValue(Action.ACCELERATOR_KEY,
openInNew ? Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE) : Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE));
openInNew ? Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE) : Globals
.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE));
}

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = createImportFileChooser(Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY));
JFileChooser fileChooser = createImportFileChooser(
Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY));
int result = fileChooser.showOpenDialog(frame);

if (result != JFileChooser.APPROVE_OPTION) {
Expand All @@ -118,8 +123,7 @@ public void actionPerformed(ActionEvent e) {
if (!file.exists()) {
// Warn that the file doesn't exists:
JOptionPane.showMessageDialog(frame,
Localization.lang("File not found") +
": '" + file.getName() + "'.",
Localization.lang("File not found") + ": '" + file.getName() + "'.",
Localization.lang("Import"), JOptionPane.ERROR_MESSAGE);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.sf.jabref.JabRefExecutorService;
import net.sf.jabref.MetaData;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.NewFileDialogs;
Expand All @@ -46,6 +45,7 @@
import net.sf.jabref.logic.importer.OpenDatabase;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.io.AutoSaveUtil;
import net.sf.jabref.logic.util.io.FileBasedLock;
import net.sf.jabref.logic.util.strings.StringUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import net.sf.jabref.external.ExternalFileType;
import net.sf.jabref.external.ExternalFileTypes;
import net.sf.jabref.external.UnknownExternalFileType;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.PreviewPanel;
Expand All @@ -63,6 +62,7 @@
import net.sf.jabref.logic.openoffice.OOBibStyle;
import net.sf.jabref.logic.openoffice.OpenOfficePreferences;
import net.sf.jabref.logic.openoffice.StyleLoader;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.TestEntry;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
import net.sf.jabref.Globals;
import net.sf.jabref.gui.ClipBoardManager;
import net.sf.jabref.gui.EntryMarker;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.NewFileDialogs;
Expand All @@ -127,6 +126,7 @@
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.importer.fileformat.FreeCiteImporter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.model.EntryTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefException;

import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.NewFileDialogs;
import net.sf.jabref.gui.keyboard.KeyBinder;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.logic.exporter.ExportFormats;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.preferences.JabRefPreferencesFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import javax.swing.JTextField;

import net.sf.jabref.Globals;

import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.BrowseAction;
import net.sf.jabref.gui.keyboard.KeyBinding;

import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.protectedterms.ProtectedTermsLoader;
import net.sf.jabref.logic.util.FileExtensions;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import com.jgoodies.forms.builder.FormBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
import net.sf.jabref.external.ExternalFileType;
import net.sf.jabref.external.ExternalFileTypes;
import net.sf.jabref.external.UnknownExternalFileType;

import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.BrowseAction;
Expand All @@ -65,6 +63,7 @@
import net.sf.jabref.logic.protectedterms.ProtectedTermsList;
import net.sf.jabref.logic.protectedterms.ProtectedTermsLoader;
import net.sf.jabref.logic.protectedterms.ProtectedTermsPreferences;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
Expand All @@ -28,6 +27,7 @@

import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.importer.util.BibTeXMLHandler;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.model.entry.BibEntry;

import org.apache.commons.logging.Log;
Expand All @@ -52,8 +52,8 @@ public String getFormatName() {
}

@Override
public List<String> getExtensions() {
return Collections.singletonList(".xml");
public FileExtensions getExtensions() {
return FileExtensions.BIBTEXML;
}

@Override
Expand Down
Loading