hook up downloads to the table

This commit is contained in:
Zlatin Balevsky
2019-05-31 05:26:04 +01:00
parent 7e4bf5d85d
commit deae9a3977
3 changed files with 23 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ import javax.annotation.Nonnull
import javax.inject.Inject
import com.muwire.core.Core
import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.download.UIDownloadEvent
import com.muwire.core.search.QueryEvent
import com.muwire.core.search.SearchEvent
@@ -31,7 +33,18 @@ class MainFrameController {
replyTo: core.me.destination, receivedOn: core.me.destination))
}
@ControllerAction
void download() {
def resultsTable = builder.getVariable("results-table")
int row = resultsTable.getSelectedRow()
def result = model.results[row]
def file = new File(System.getProperty("user.home"), result.name) // TODO: move elsewhere
core.eventBus.publish(new UIDownloadEvent(result : result, target : file))
}
void mvcGroupInit(Map<String, String> args) {
application.addPropertyChangeListener("core", {e-> core = e.getNewValue()})
application.addPropertyChangeListener("core", {e->
core = e.getNewValue()
})
}
}

View File

@@ -5,6 +5,7 @@ import javax.inject.Inject
import javax.swing.JTable
import com.muwire.core.Core
import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.search.UIResultEvent
import griffon.core.GriffonApplication
@@ -31,6 +32,7 @@ class MainFrameModel {
coreInitialized = (e.getNewValue() != null)
core = e.getNewValue()
core.eventBus.register(UIResultEvent.class, this)
core.eventBus.register(DownloadStartedEvent.class, this)
})
Timer timer = new Timer("download-pumper", true)
timer.schedule({
@@ -47,4 +49,10 @@ class MainFrameModel {
table.model.fireTableDataChanged()
}
}
void onDownloadStartedEvent(DownloadStartedEvent e) {
runInsideUIAsync {
downloads << e
}
}
}

View File

@@ -73,7 +73,7 @@ class MainFrameView {
}
}
panel(constraints : BorderLayout.SOUTH) {
button(text : "Download")
button(text : "Download", downloadAction)
button(text : "Trust")
button(text : "Distrust")
}