Skip to content

Commit

Permalink
Made saving configs more robust, fixed multiplex text index issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalBeetle committed Mar 25, 2011
1 parent 939878b commit 8a2b9df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/com/metalbeetle/fruitbat/Fruitbat.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public boolean run() {
// Meh.
}
try {
SavedStoreConfigs.setOpenStores(configToMainframe);
SavedStoreConfigs.setOpenStores(configToMainframe, pm);
} catch (Exception e) {
// Meh.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.metalbeetle.fruitbat.storage.EnhancedStore;
import com.metalbeetle.fruitbat.storage.FatalStorageException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class MultiplexFullTextIndex implements FullTextIndex {
Expand All @@ -32,7 +31,7 @@ public List<Document> query(List<List<String>> phrases, List<Document> within) t
for (Document d : ds) {
multiplexDs.add(s.get(d.getID()));
}
return Collections.unmodifiableList(multiplexDs);
return multiplexDs;
} catch (FatalStorageException e) {
s.handleStorageException(s.fastest(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;

public class MultiplexedStoresFieldComponent extends JPanel implements
FieldJComponent<List<StoreConfig>>, ConfigPanel.ConfigChangedListener
{
ValueListener vl;
MultiplexedStoresField f;


final ArrayList<ConfigPanel> configPanels = new ArrayList<ConfigPanel>();
final JTabbedPane tabs;
final JPanel buttonP;
final JButton addB;
Expand Down Expand Up @@ -60,6 +58,7 @@ void addStore() {
if (ss != null) {
ConfigPanel cp = new ConfigPanel(ss);
cp.setConfigChangedListener(this);
configPanels.add(cp);
tabs.addTab(getTabName(tabs.getTabCount(), ss), cp);
tabs.setSelectedComponent(cp);
}
Expand All @@ -69,6 +68,7 @@ void addStore() {

void removeStore() {
if (tabs.getSelectedIndex() != -1) {
configPanels.remove(tabs.getSelectedIndex());
tabs.removeTabAt(tabs.getSelectedIndex());
}
updateButtons();
Expand All @@ -77,9 +77,7 @@ void removeStore() {

public List<StoreConfig> getValue() {
ArrayList<StoreConfig> l = new ArrayList<StoreConfig>();
for (int i = 0; i < tabs.getTabCount(); i++) {
l.add(((ConfigPanel) tabs.getComponent(i)).getConfig());
}
for (ConfigPanel cp : configPanels) { l.add(cp.getConfig()); }
return l;
}

Expand All @@ -91,6 +89,7 @@ public void setValue(List<StoreConfig> value) {
cp.setConfig(sc);
cp.setConfigChangedListener(this);
tabs.addTab(getTabName(i, sc.system), cp);
configPanels.add(cp);
}
updateButtons();
}
Expand Down
13 changes: 9 additions & 4 deletions src/com/metalbeetle/fruitbat/prefs/SavedStoreConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static List<Pair<StoreConfig, Preferences>> getOpenStores() throws Backin
return l;
}

public static void setOpenStores(HashMap<StoreConfig, StoreFrame> openStores) throws BackingStoreException, StoreConfigInvalidException, FatalStorageException {
public static void setOpenStores(HashMap<StoreConfig, StoreFrame> openStores, ProgressMonitor pm) throws BackingStoreException, StoreConfigInvalidException, FatalStorageException {
Preferences p = Preferences.userNodeForPackage(SavedStoreConfigs.class).
node("openStores");
p.clear();
Expand All @@ -64,9 +64,14 @@ public static void setOpenStores(HashMap<StoreConfig, StoreFrame> openStores) th
}
int i = 0;
for (Entry<StoreConfig, StoreFrame> e : openStores.entrySet()) {
Preferences n = p.node(string(i++));
n.put("config", e.getKey().toStringRepresentation());
e.getValue().writePrefs(n.node("prefs"));
try {
Preferences n = p.node(string(i++));
n.put("config", e.getKey().toStringRepresentation());
e.getValue().writePrefs(n.node("prefs"));
} catch (Exception ex) {
i--;
pm.handleException(new Exception("Could not save configuration.", ex), null);
}
}
p.flush();
}
Expand Down

0 comments on commit 8a2b9df

Please sign in to comment.