This is what I ended up with:
TreeViewFileExplorer.mp4
In the ‘Choose Folder’ button ‘ActionPerformed’ event I have:
from javax.swing import JFileChooser
chooser = JFileChooser(event.source.parent.getComponent('txtPot').text)
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
chooser.setAcceptAllFileFilterUsed(False)
chooser.setDialogTitle("Select Folder")
if chooser.showOpenDialog(None) == JFileChooser.APPROVE_OPTION:
event.source.parent.getComponent('txtPot').text = str(chooser.getSelectedFile())
In the ‘txtFolder’ propertyChange event I have:
if event.propertyName == 'text':
treeView = event.source.parent.getComponent('Tree View')
headers = system.dataset.getColumnHeaders(treeView.data)
rows = []
treeView.data = system.dataset.toDataSet(headers, rows) #Emptying treeView
rootPath = event.source.parent.getComponent('txtPot').text
lblLoading = event.source.parent.getComponent('lblLoading')
lblLoading.visible = True
def longProcess(treeView=treeView, headers=headers, rows=rows, rootPath=rootPath, lblLoading=lblLoading):
import os
for path, dirs, files in os.walk(rootPath,topdown=True):
for f in files:
my_suffixes = (".docx",".doc",".xlsx",".xls",".pdf",".txt")
if f.endswith(my_suffixes):
filename, file_extension = os.path.splitext(f)
#print filename, file_extension
ikona = {
'.docx' : 'Icons/docx.png',
'.doc' : 'Icons/docx.png',
'.xlsx' : 'Icons/xlsx.png',
'.xls' : 'Icons/xlsx.png',
'.pdf' : 'Icons/pdf.png',
'.txt' : 'Icons/txt.png'}[file_extension]
newRow = [
path.upper(),
f,
ikona,
"color(255,255,255,255)",
"color(0,0,0,255)",
"",
"",
"",
ikona,
"color(250,214,138,255)",
"color(0,0,0,255)",
"",
""
]
rows.append(newRow)
data = system.dataset.toDataSet(headers, rows)
treeView.data = data
lblLoading.visible = False
system.util.invokeAsynchronous(longProcess) #Note that this is 'longProcess' instead of 'longProcess()'
In the ‘Refresh’ button actionPerformed event I have:
izbranapot = event.source.parent.getComponent('txtPot').text
event.source.parent.getComponent('txtPot').text = ""
event.source.parent.getComponent('txtPot').text = izbranapot
And in the ‘Tree View’ mouseClicked event I have:
if event.clickCount == 2:
fileName = event.source.selectedPath
if event.source.selectedItem > -1:
system.net.openURL("file:///" + fileName)
In the end, it turned out just fine…
Of course, any suggestions are more than welcome.