mirror of https://github.com/zlatinb/muwire
review step
parent
21144c532d
commit
608de1c9b3
|
@ -4,7 +4,15 @@ import griffon.core.artifact.GriffonController
|
|||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
import javax.swing.tree.DefaultMutableTreeNode
|
||||
import javax.swing.tree.MutableTreeNode
|
||||
|
||||
import com.muwire.core.SharedFile
|
||||
import com.muwire.core.collections.FileCollectionBuilder
|
||||
import com.muwire.core.collections.PathTree
|
||||
import com.muwire.core.collections.PathTree.Callback
|
||||
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class CollectionWizardController {
|
||||
|
@ -21,6 +29,49 @@ class CollectionWizardController {
|
|||
|
||||
@ControllerAction
|
||||
void review() {
|
||||
model.timestamp = System.currentTimeMillis()
|
||||
model.root = view.nameTextField.text
|
||||
model.comment = view.commentTextArea.text
|
||||
if (model.comment == null)
|
||||
model.comment = ""
|
||||
|
||||
def builder = new FileCollectionBuilder()
|
||||
builder.with {
|
||||
setAuthor(model.me)
|
||||
setComment(model.comment)
|
||||
setRoot(model.root)
|
||||
setTimestamp(model.timestamp)
|
||||
setSPK(model.spk)
|
||||
for (SharedFile sf : model.files)
|
||||
addFile(sf)
|
||||
}
|
||||
model.collection = builder.build()
|
||||
|
||||
copyTree(model.treeRoot, model.collection.tree.root)
|
||||
model.tree.nodeStructureChanged(model.treeRoot)
|
||||
|
||||
view.switchToReview()
|
||||
}
|
||||
|
||||
private static void copyTree(DefaultMutableTreeNode jtreeNode, PathTree.PathNode pathNode) {
|
||||
jtreeNode.setUserObject(pathNode.path)
|
||||
pathNode.children.each {
|
||||
MutableTreeNode newChild = new DefaultMutableTreeNode()
|
||||
jtreeNode.add(newChild)
|
||||
copyTree(newChild, it)
|
||||
}
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void previous() {
|
||||
model.treeRoot.removeAllChildren()
|
||||
model.tree.nodeStructureChanged(model.treeRoot)
|
||||
view.switchToConfiguration()
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void save() {
|
||||
// TODO: emit event
|
||||
cancel()
|
||||
}
|
||||
}
|
|
@ -530,3 +530,4 @@ COLLECTION_NAME=Collection name
|
|||
COLLECTION_DESCRIPTION=Enter description for this collection
|
||||
COLLECTION_TOTAL_FILES=Number of files
|
||||
COLLECTION_TOTAL_SIZE=Total size
|
||||
COLLECTION_REVIEW_TITLE=This is what the collection will look like
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode
|
||||
import javax.swing.tree.DefaultTreeModel
|
||||
import javax.swing.tree.MutableTreeNode
|
||||
import javax.swing.tree.TreeModel
|
||||
import javax.swing.tree.TreeNode
|
||||
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.SharedFile
|
||||
import com.muwire.core.collections.FileCollection
|
||||
|
||||
import griffon.core.artifact.GriffonModel
|
||||
import griffon.transform.Observable
|
||||
|
@ -17,7 +24,11 @@ class CollectionWizardModel {
|
|||
long timestamp
|
||||
@Observable String root
|
||||
@Observable String comment
|
||||
|
||||
|
||||
DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode()
|
||||
TreeModel tree = new DefaultTreeModel(treeRoot)
|
||||
FileCollection collection
|
||||
|
||||
long totalSize() {
|
||||
long rv = 0
|
||||
files.each {
|
||||
|
|
|
@ -12,6 +12,7 @@ import griffon.metadata.ArtifactProviderFor
|
|||
import net.i2p.data.DataHelper
|
||||
|
||||
import javax.swing.JDialog
|
||||
import javax.swing.JTree
|
||||
import javax.swing.SwingConstants
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
|
@ -27,6 +28,7 @@ class CollectionWizardView {
|
|||
def mainPanel
|
||||
|
||||
def nameTextField // TODO: disable "Review" button if empty
|
||||
def commentTextArea
|
||||
def filesTable
|
||||
|
||||
void initUI() {
|
||||
|
@ -36,45 +38,70 @@ class CollectionWizardView {
|
|||
dialog = new JDialog(mainFrame, trans("COLLECTION_WIZARD"), true)
|
||||
|
||||
mainPanel = builder.panel {
|
||||
gridLayout(rows : 2, cols : 1)
|
||||
panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
cardLayout()
|
||||
panel(constraints : "configuration") {
|
||||
gridLayout(rows : 2, cols : 1)
|
||||
panel {
|
||||
borderLayout()
|
||||
label(text : trans("COLLECTION_NAME"), constraints : BorderLayout.WEST)
|
||||
nameTextField = textField(constraints : BorderLayout.CENTER)
|
||||
}
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
borderLayout()
|
||||
label(text: trans("COLLECTION_DESCRIPTION"), constraints : BorderLayout.NORTH)
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
textArea(editable : true, columns : 100, lineWrap : true, wrapStyleWord : true)
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
borderLayout()
|
||||
label(text : trans("COLLECTION_NAME"), constraints : BorderLayout.WEST)
|
||||
nameTextField = textField(constraints : BorderLayout.CENTER)
|
||||
}
|
||||
}
|
||||
}
|
||||
panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
label(text : trans("COLLECTION_TOTAL_FILES") + ":" + model.files.size())
|
||||
label(text : trans("COLLECTION_TOTAL_SIZE") + ":" + DataHelper.formatSize2Decimal(model.totalSize(), false) + trans("BYTES_SHORT"))
|
||||
}
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
filesTable = table(id : "files-table", autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||
tableModel(list : model.files) {
|
||||
closureColumn(header : trans("NAME"), type : String, read : {it.getCachedPath()})
|
||||
closureColumn(header : trans("SIZE"), type : Long, preferredWidth: 30, read : {it.getCachedLength()})
|
||||
closureColumn(header : trans("COMMENT"), type : Boolean, preferredWidth : 20, read : {it.getComment() != null})
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
borderLayout()
|
||||
label(text: trans("COLLECTION_DESCRIPTION"), constraints : BorderLayout.NORTH)
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
commentTextArea = textArea(editable : true, columns : 100, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
}
|
||||
}
|
||||
panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
label(text : trans("COLLECTION_TOTAL_FILES") + ":" + model.files.size())
|
||||
label(text : trans("COLLECTION_TOTAL_SIZE") + ":" + DataHelper.formatSize2Decimal(model.totalSize(), false) + trans("BYTES_SHORT"))
|
||||
}
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
filesTable = table(id : "files-table", autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||
tableModel(list : model.files) {
|
||||
closureColumn(header : trans("NAME"), type : String, read : {it.getCachedPath()})
|
||||
closureColumn(header : trans("SIZE"), type : Long, preferredWidth: 30, read : {it.getCachedLength()})
|
||||
closureColumn(header : trans("COMMENT"), type : Boolean, preferredWidth : 20, read : {it.getComment() != null})
|
||||
}
|
||||
}
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
button(text : trans("CANCEL"), cancelAction)
|
||||
button(text : trans("REVIEW"), reviewAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
panel(constraints : "review") {
|
||||
borderLayout()
|
||||
label(text : trans("COLLECTION_REVIEW_TITLE"), constraints : BorderLayout.NORTH)
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
def jtree = new JTree(model.tree)
|
||||
// jtree.setCellRenderer(new SharedTreeRenderer()) // TODO: create new renderer
|
||||
tree(id : "preview-tree", rowHeight : rowHeight, rootVisible : true, expandsSelectedPaths : true, jtree)
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
button(text : trans("CANCEL"), cancelAction)
|
||||
button(text : trans("REVIEW"), reviewAction)
|
||||
button(text : trans("PREVIOUS"), previousAction)
|
||||
button(text : trans("SAVE"), saveAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void switchToReview() {
|
||||
mainPanel.getLayout().show(mainPanel, "review")
|
||||
}
|
||||
|
||||
void switchToConfiguration() {
|
||||
mainPanel.getLayout().show(mainPanel, "configuration")
|
||||
}
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
filesTable.setDefaultRenderer(Long.class, new SizeRenderer())
|
||||
|
||||
|
|
Loading…
Reference in New Issue