mirror of https://github.com/zlatinb/muwire
Cache the tree once it's fully built. GitHub issue #88
parent
7df7faaea8
commit
b5228f4a41
|
@ -90,11 +90,16 @@ class BrowseController {
|
|||
}
|
||||
for(BrowseStatusEvent event : statusCopy) {
|
||||
model.status = event.status
|
||||
model.filterEnabled = (event.status == BrowseStatus.FINISHED || event.status == BrowseStatus.FAILED) &&
|
||||
model.resultCount > 0
|
||||
if (event.status == BrowseStatus.FETCHING)
|
||||
model.totalResults = event.totalResults
|
||||
}
|
||||
if (!statusCopy.isEmpty()) {
|
||||
if ((model.status == BrowseStatus.FINISHED || model.status == BrowseStatus.FAILED) &&
|
||||
model.resultCount > 0) {
|
||||
model.filterEnabled = true
|
||||
model.cacheTopTreeLevel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.muwire.core.search.BrowseStatus
|
|||
import javax.annotation.Nonnull
|
||||
import javax.swing.SwingWorker
|
||||
import javax.swing.tree.DefaultMutableTreeNode
|
||||
import javax.swing.tree.TreeNode
|
||||
|
||||
@ArtifactProviderFor(GriffonModel)
|
||||
class BrowseModel {
|
||||
|
@ -47,12 +48,18 @@ class BrowseModel {
|
|||
|
||||
volatile String[] filter
|
||||
volatile Filterer filterer
|
||||
private final List<TreeNode> topLevelNodes = new ArrayList<>()
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
root = new DefaultMutableTreeNode()
|
||||
resultsTreeModel = new ResultTreeModel(root)
|
||||
}
|
||||
|
||||
void cacheTopTreeLevel() {
|
||||
for(int i = 0; i < root.getChildCount(); i ++)
|
||||
topLevelNodes.add(root.getChildAt(i))
|
||||
}
|
||||
|
||||
private boolean filter(UIResultEvent result) {
|
||||
if (filter == null)
|
||||
return true
|
||||
|
@ -77,8 +84,9 @@ class BrowseModel {
|
|||
} else {
|
||||
synchronized (allResults) {
|
||||
results.addAll(allResults)
|
||||
for(UIResultEvent result : allResults)
|
||||
resultsTreeModel.addToTree(result)
|
||||
}
|
||||
for(TreeNode topLevel : topLevelNodes) {
|
||||
root.add(topLevel)
|
||||
}
|
||||
view.refreshResults()
|
||||
view.expandUnconditionally()
|
||||
|
|
Loading…
Reference in New Issue