Skip to content

Commit

Permalink
Merge pull request #748 from oscargus/basepanellist
Browse files Browse the repository at this point in the history
Added method getBasePanelList() and used it
  • Loading branch information
simonharrer committed Jan 30, 2016
2 parents 49d156e + c6d9f17 commit 0ed73b2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
15 changes: 2 additions & 13 deletions src/main/java/net/sf/jabref/exporter/AutoSaveManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;
import java.util.ArrayList;
import java.io.File;

/**
Expand Down Expand Up @@ -70,12 +68,7 @@ public void run() {
// Since this method is running in the background, we must be prepared that
// there could be changes done by the user while this method is running.

List<BasePanel> panels = new ArrayList<>();
for (int i = 0; i < frame.getBasePanelCount(); i++) {
panels.add(frame.getBasePanelAt(i));
}

for (BasePanel panel : panels) {
for (BasePanel panel : frame.getBasePanelList()) {
if (panel.isModified() && (panel.getDatabaseFile() != null)) {
AutoSaveManager.autoSave(panel);
}
Expand Down Expand Up @@ -135,11 +128,7 @@ public static boolean deleteAutoSaveFile(BasePanel panel) {
* if they exist.
*/
public void clearAutoSaves() {
List<BasePanel> panels = new ArrayList<>();
for (int i = 0; i < frame.getBasePanelCount(); i++) {
panels.add(frame.getBasePanelAt(i));
}
for (BasePanel panel : panels) {
for (BasePanel panel : frame.getBasePanelList()) {
AutoSaveManager.deleteAutoSaveFile(panel);
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/net/sf/jabref/gui/EntryCustomizationDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ public void actionPerformed(ActionEvent e) {
* the right-click menus' change type menu is up-to-date.
*/
private void updateTypesForEntries(String typeName) {
for (int i = 0; i < frame.getBasePanelCount(); i++) {
BasePanel bp = frame.getBasePanelAt(i);
for (BasePanel bp : frame.getBasePanelList()) {

// Invalidate associated cached entry editor
bp.entryEditors.remove(typeName);
Expand All @@ -382,9 +381,8 @@ private void updateTypesForEntries(String typeName) {
}

private void updateTables() {
for (int i = 0; i < frame.getBasePanelCount(); i++) {
((javax.swing.table.AbstractTableModel) frame.getBasePanelAt(i).mainTable.getModel())
.fireTableDataChanged();
for (BasePanel basePanel : frame.getBasePanelList()) {
((javax.swing.table.AbstractTableModel) basePanel.mainTable.getModel()).fireTableDataChanged();
}
}

Expand Down
27 changes: 20 additions & 7 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,19 @@ public BasePanel getBasePanelAt(int i) {
return (BasePanel) tabbedPane.getComponentAt(i);
}

/**
* Returns a list of BasePanel.
*
* @param i Index of base
*/
public List<BasePanel> getBasePanelList() {
List<BasePanel> returnList = new ArrayList<>(getBasePanelCount());
for (int i=0; i< getBasePanelCount(); i++) {
returnList.add((BasePanel) tabbedPane.getComponentAt(i));
}
return returnList;
}

public void showBasePanelAt(int i) {
tabbedPane.setSelectedIndex(i);
}
Expand Down Expand Up @@ -1562,13 +1575,13 @@ public BasePanel addTab(BibDatabase db, File file, MetaData metaData, Charset en
private List<String> collectDatabaseFilePaths() {
List<String> dbPaths = new ArrayList<>(getBasePanelCount());

for (int i = 0; i < getBasePanelCount(); i++) {
for (BasePanel basePanel : getBasePanelList()) {
try {
// db file exists
if (getBasePanelAt(i).getDatabaseFile() == null) {
if (basePanel.getDatabaseFile() == null) {
dbPaths.add("");
} else {
dbPaths.add(getBasePanelAt(i).getDatabaseFile().getCanonicalPath());
dbPaths.add(basePanel.getDatabaseFile().getCanonicalPath());
}
} catch (IOException ex) {
LOGGER.error("Invalid database file path: " + ex.getMessage());
Expand Down Expand Up @@ -2003,8 +2016,8 @@ public void actionPerformed(ActionEvent event) {
GUIGlobals.CURRENTFONT = new Font(GUIGlobals.CURRENTFONT.getFamily(), GUIGlobals.CURRENTFONT.getStyle(),
currentSize + 1);
Globals.prefs.putInt(JabRefPreferences.FONT_SIZE, currentSize + 1);
for (int i = 0; i < getBasePanelCount(); i++) {
getBasePanelAt(i).updateTableFont();
for (BasePanel basePanel : getBasePanelList()) {
basePanel.updateTableFont();
}
}
}
Expand All @@ -2025,8 +2038,8 @@ public void actionPerformed(ActionEvent event) {
GUIGlobals.CURRENTFONT = new Font(GUIGlobals.CURRENTFONT.getFamily(), GUIGlobals.CURRENTFONT.getStyle(),
currentSize - 1);
Globals.prefs.putInt(JabRefPreferences.FONT_SIZE, currentSize - 1);
for (int i = 0; i < getBasePanelCount(); i++) {
getBasePanelAt(i).updateTableFont();
for (BasePanel basePanel : getBasePanelList()) {
basePanel.updateTableFont();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/WaitForSaveOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public boolean cancelled() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
boolean anySaving = false;
for (int i = 0; i < frame.getBasePanelCount(); i++) {
if (frame.getBasePanelAt(i).isSaving()) {
for (BasePanel basePanel : frame.getBasePanelList()) {
if (basePanel.isSaving()) {
anySaving = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.logic.journals.Abbreviation;
Expand Down Expand Up @@ -408,8 +409,8 @@ private void storeSettings() throws FileNotFoundException {

// Update the autocompleter for the "journal" field in all base panels,
// so added journal names are available:
for (int i = 0; i < frame.getBasePanelCount(); i++) {
frame.getBasePanelAt(i).getAutoCompleters().addJournalListToAutoCompleter();
for (BasePanel basePanel : frame.getBasePanelList()) {
basePanel.getAutoCompleters().addJournalListToAutoCompleter();
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ public void actionPerformed(ActionEvent event) {
private java.util.List<BibDatabase> getBaseList() {
java.util.List<BibDatabase> databases = new ArrayList<>();
if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) {
for (int i = 0; i < frame.getBasePanelCount(); i++) {
databases.add(frame.getBasePanelAt(i).database());
for (BasePanel basePanel : frame.getBasePanelList()) {
databases.add(basePanel.database());
}
} else {
databases.add(frame.getCurrentBasePanel().database());
Expand Down

0 comments on commit 0ed73b2

Please sign in to comment.