Created
December 19, 2012 15:47
-
-
Save davidecavestro/4337705 to your computer and use it in GitHub Desktop.
Trying to set up a TreeTable with glazedlists on a griffon app, as discussed on http://griffon-user.3225736.n2.nabble.com/Problem-expanding-TreeTable-nodes-td7578033.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ca.odell.glazedlists.BasicEventList | |
import ca.odell.glazedlists.DisposableMap | |
import ca.odell.glazedlists.FunctionList | |
import ca.odell.glazedlists.GlazedLists | |
import ca.odell.glazedlists.SortedList | |
import ca.odell.glazedlists.TreeList | |
... | |
BasicEventList taskList = new BasicEventList () | |
//fake data | |
Map data = [1:[id:1, name: 'elem 1', parentId: null], 2:[id:2, name: 'elem 1.1', parentId: 1], 3:[id:3, name: 'elem 1.2', parentId: 1], 4:[id:4, name: 'elem 1.1.1', parentId: 2]] | |
//holds path to the tree root for fake data | |
Map paths = [1:[data[1]], 2:[data[1], data[2]], 3:[data[1], data[3]], 4:[data[1], data[2], data[4]]] | |
TreeList taskTreeList = new TreeList(new SortedList (taskList, {a,b-> a.key <=> b.key} as Comparator), new TaskTreeFormat(), TreeList.NODES_START_EXPANDED) | |
public TreeTableTestModel () { | |
taskList.addAll(data.values()) | |
} | |
private class TaskTreeFormat implements TreeList.Format { | |
public void getPath(List path, Object element) { | |
def taskPath = getTaskPath (element.id) | |
path.addAll (taskPath) | |
} | |
public boolean allowsChildren(Object element) { | |
return true; | |
} | |
@Override | |
public Comparator getComparator(int arg0) { | |
return null | |
} | |
} | |
def getTaskPath (def id) { | |
return paths[id] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ca.odell.glazedlists.swing.TreeTableSupport | |
... | |
scrollPane { | |
table(id:'taskTree') { | |
tableFormat = defaultAdvancedTableFormat(columns: [ | |
[name: 'title', title: 'Name'], | |
[name: 'id', title: 'ID']]) | |
eventTableModel(source:model.taskList, format:tableFormat) | |
TreeTableSupport treeTableSupport = installTreeTableSupport(source:model.taskTreeList, index:0i) | |
treeTableSupport.arrowKeyExpansionEnabled = true | |
treeTableSupport.showExpanderForEmptyParent = true | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment