wip on collections tab

pull/53/head
Zlatin Balevsky 2020-11-01 07:02:20 +00:00
parent cad3946d3e
commit df577f97e8
No known key found for this signature in database
GPG Key ID: A72832072D525E41
4 changed files with 91 additions and 7 deletions

View File

@ -173,8 +173,9 @@ class SearchTabController {
def params = [:]
params['fileName'] = event.name
params['eventBus'] = mvcGroup.parentGroup.model.core.eventBus
params['collections'] = event.collections.collect()
params['infoHashes'] = event.collections.collect()
params['uuid'] = UUID.randomUUID()
params['host'] = event.sender
mvcGroup.createMVCGroup("collection-tab", params)
}
}

View File

@ -542,3 +542,6 @@ CREATED=Created
AUTHOR=Author
COLLECTION_TOOL_HEADER=These are the collections in your repository. Deleting a collection will not affect the files included in it.
DELETE=Delete
## Collection tab
COLLECTION_SELECT=Select a collection to view it's description

View File

@ -1,37 +1,71 @@
package com.muwire.gui
import static com.muwire.gui.Translator.trans
import javax.annotation.Nonnull
import com.muwire.core.EventBus
import com.muwire.core.InfoHash
import com.muwire.core.Persona
import com.muwire.core.collections.CollectionFetchStatus
import com.muwire.core.collections.CollectionFetchStatusEvent
import com.muwire.core.collections.CollectionFetchedEvent
import com.muwire.core.collections.FileCollection
import com.muwire.core.collections.FileCollectionItem
import com.muwire.core.collections.UICollectionFetchEvent
import griffon.core.artifact.GriffonModel
import griffon.inject.MVCMember
import griffon.transform.Observable
import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonModel)
class CollectionTabModel {
@MVCMember @Nonnull
CollectionTabView view
String fileName
EventBus eventBus
List<FileCollection> collections
List<FileCollectionItem> items
@Observable String comment
Persona host
List<InfoHash> infoHashes
UUID uuid
List<FileCollection> collections = new ArrayList<>()
List<FileCollectionItem> items = new ArrayList<>()
@Observable CollectionFetchStatus status
@Observable String comment = trans("COLLECTION_SELECT")
@Observable int totalCollections
void mvcGroupInit(Map<String,String> args) {
eventBus.register(CollectionFetchedEvent.class, this)
eventBus.with {
register(CollectionFetchStatusEvent.class, this)
register(CollectionFetchedEvent.class, this)
publish(new UICollectionFetchEvent(uuid : uuid, host : host, infoHashes : infoHashes))
}
}
void mvcGroupDestroy() {
eventBus.unregister(CollectionFetchedEvent.class, this)
}
void onCollectionFetchStatusEvent(CollectionFetchStatusEvent e) {
if (uuid != e.uuid)
return
runInsideUIAsync {
status = e.status
if (status == CollectionFetchStatus.FETCHING)
totalCollections = e.count
}
}
void onCollectionFetchedEvent(CollectionFetchedEvent e) {
if (uuid != e.uuid)
return
runInsideUIAsync {
collections.add(e.collection)
// TODO: refresh tables
view.collectionsTable.model.fireTableDataChanged() // maybe preserving selection?
}
}
}

View File

@ -1,9 +1,14 @@
package com.muwire.gui
import static com.muwire.gui.Translator.trans
import griffon.core.artifact.GriffonView
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.swing.JLabel
import javax.swing.JTable
import javax.swing.SwingConstants
import javax.swing.table.DefaultTableCellRenderer
import java.awt.BorderLayout
@ -19,8 +24,38 @@ class CollectionTabView {
def parent
def p
JTable collectionsTable
def lastCollectionsTableSortEvent
void initUI() {
p = builder.panel {}
int rowHeight = application.context.get("row-height")
p = builder.panel {
gridLayout(rows : 3, cols: 1)
panel {
borderLayout()
panel(constraints : BorderLayout.NORTH) {
borderLayout()
panel(constraints : BorderLayout.NORTH) {
label(text : trans("STATUS") + ":")
label(text : bind {trans(model.status.name())})
}
scrollPane(constraints : BorderLayout.CENTER) {
collectionsTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
tableModel(list : model.collections) {
closureColumn(header: trans("NAME"), preferredWidth: 200, type : String, read : {it.name})
closureColumn(header: trans("AUTHOR"), preferredWidth: 200, type : String, read : {it.author.getHumanReadableName()})
closureColumn(header: trans("COLLECTION_TOTAL_FILES"), preferredWidth: 20, type: Integer, read : {it.numFiles()})
closureColumn(header: trans("COLLECTION_TOTAL_SIZE"), preferredWidth: 20, type: Long, read : {it.totalSize()})
closureColumn(header: trans("COMMENT"), preferredWidth: 20, type: Boolean, read: {it.comment != ""})
closureColumn(header: trans("CREATED"), preferredWidth: 50, type: Long, read: {it.timestamp})
}
}
}
}
}
panel {}
panel {}
}
}
void mvcGroupInit(Map<String, String> args) {
@ -45,6 +80,17 @@ class CollectionTabView {
}
parent.setTabComponentAt(index, tabPanel)
mainFrameGroup.view.showSearchWindow.call()
def centerRenderer = new DefaultTableCellRenderer()
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
collectionsTable.setDefaultRenderer(Integer.class, centerRenderer)
collectionsTable.columnModel.getColumn(3).setCellRenderer(new SizeRenderer())
collectionsTable.columnModel.getColumn(5).setCellRenderer(new DateRenderer())
collectionsTable.rowSorter.addRowSorterListener({evt -> lastCollectionsTableSortEvent = evt})
collectionsTable.rowSorter.setSortsOnUpdates(true)
}
def closeTab = {