private DelayWorker bookCoverUpdater;
private String filter = "";
+ private Object[] lastLoad = new Object[4];
+
public BooksPanel(boolean listMode) {
setLayout(new BorderLayout());
// null or empty -> all sources
// sources hierarchy supported ("source/" will includes all "source" and
// "source/*")
- public void load(final List<String> sources, final List<String> authors,
+ public void loadData(final List<String> sources, final List<String> authors,
final List<String> tags) {
+ synchronized (lastLoad) {
+ lastLoad[0] = "sources, authors, tags";
+ lastLoad[1] = sources;
+ lastLoad[2] = authors;
+ lastLoad[3] = tags;
+ }
+
new SwingWorker<List<BookInfo>, Void>() {
@Override
protected List<BookInfo> doInBackground() throws Exception {
@Override
protected void done() {
try {
- load(get());
+ loadData(get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
}.execute();
}
- public void load(List<BookInfo> bookInfos) {
+ public void loadData(final BookInfo.Type type, final String value) {
+ synchronized (lastLoad) {
+ lastLoad[0] = "type";
+ lastLoad[1] = type;
+ lastLoad[2] = value;
+ }
+
+ // TODO todo todo
+ }
+
+ public void loadData(List<BookInfo> bookInfos) {
+ synchronized (lastLoad) {
+ lastLoad[0] = "bookinfos";
+ lastLoad[1] = bookInfos;
+ }
+
data.clearItems();
data.addAllItems(bookInfos);
bookCoverUpdater.clear();
filter();
}
+ public void reloadData() {
+ Object[] lastLoad;
+ synchronized (this.lastLoad) {
+ lastLoad = this.lastLoad.clone();
+ }
+
+ if (lastLoad[0] == null) {
+ return; // nothing was loaded yet
+ }
+
+ if (lastLoad[0].toString().equals("sources, authors, tags")) {
+ loadData((List<String>) lastLoad[1], (List<String>) lastLoad[2],
+ (List<String>) lastLoad[3]);
+ } else if (lastLoad[0].toString().equals("type")) {
+ loadData((BookInfo.Type) lastLoad[1], (String) lastLoad[2]);
+ } else if (lastLoad[0].toString().equals("bookInfos")) {
+ loadData((List<BookInfo>) lastLoad[1]);
+ } else {
+ Instance.getInstance().getTraceHandler()
+ .error("Unknown last load type: " + lastLoad[0]);
+ }
+ }
+
+ // is UI!
private void filter() {
data.filter(new Predicate<BookInfo>() {
@Override
browser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- books.load(browser.getSelectedSources(),
+ books.loadData(browser.getSelectedSources(),
browser.getSelectedAuthors(),
browser.getSelectedTags());
details.setBook(browser.getHighlight());
@Override
public void run() {
browser.reloadData();
- books.load(browser.getSelectedSources(),
- browser.getSelectedAuthors(),
- browser.getSelectedTags());
+ books.reloadData();
details.setBook(browser.getHighlight());
}
});
@Override
public void run() {
browser.reloadData();
- books.load(browser.getSelectedSources(),
- browser.getSelectedAuthors(),
- browser.getSelectedTags());
+ books.reloadData();
details.setBook(browser.getHighlight());
}
});
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
searchBar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- reloadData();
+ reloadData(true);
}
});
- reloadData();
+ reloadData(true);
}
+ // does NOT send a change event
public void reloadData() {
+ reloadData(false);
+ }
+
+ private void reloadData(final boolean fireActionPerformed) {
final TreeSnapshot snapshot = new TreeSnapshot(tree) {
@Override
protected boolean isSamePath(TreePath oldPath, TreePath newPath) {
snapshot.apply();
- fireActionPerformed(listenerCommand);
+ if (fireActionPerformed) {
+ fireActionPerformed(listenerCommand);
+ }
}
};
worker.execute();
import javax.swing.JPanel;
-import be.nikiroo.fanfix_swing.gui.SearchBar;
-
/**
* A {@link JPanel} with the default {@link ActionListener} add/remove/fire
* methods.
/**
* Adds the specified action listener to receive action events from this
- * {@link SearchBar}.
+ * {@link ListenerPanel}.
*
* @param listener
* the action listener to be added
/**
* Removes the specified action listener so that it no longer receives
- * action events from this {@link SearchBar}.
+ * action events from this {@link ListenerPanel}.
*
* @param listener
* the action listener to be removed