64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
'''
|
|
Created on Sep 11, 2013
|
|
@author: Wesley Ray
|
|
'''
|
|
|
|
from java.lang import Boolean, String
|
|
from javax.swing.table import AbstractTableModel
|
|
|
|
class FileTableModel(AbstractTableModel):
|
|
'''
|
|
Implementation of AbstractTableModel for displaying a list of file names with a check box for each of them.
|
|
'''
|
|
headers = ['File', 'Process?']
|
|
cache = []
|
|
|
|
#@Override
|
|
def getColumnName(self, i):
|
|
return self.headers[i]
|
|
|
|
#@Override
|
|
def getRowCount(self):
|
|
if (self.cache == None):
|
|
return 0
|
|
return len(self.cache)
|
|
|
|
#@Override
|
|
def getColumnCount(self):
|
|
return len(self.headers) #Never changes, could just be: return 2
|
|
|
|
#@Override
|
|
def getValueAt(self, rowIndex, columnIndex):
|
|
row = self.cache[rowIndex]
|
|
return row[columnIndex]
|
|
|
|
#@Override
|
|
def isCellEditable(self, rowIndex, columnIndex):
|
|
#We have to do this to allow the state of the check boxes to be changed by the user
|
|
if(columnIndex == 1):
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
#@Override
|
|
def setValueAt(self, aValue, rowIndex, columnIndex):
|
|
#This toggles the state of the check box in the given rowIndex
|
|
if(columnIndex == 1):
|
|
self.cache[rowIndex][columnIndex] = not(self.cache[rowIndex][columnIndex])
|
|
|
|
#@Override
|
|
def getColumnClass(self, column):
|
|
if(column == 1):
|
|
return Boolean #This causes the second column to be rendered as check boxes
|
|
else:
|
|
return String
|
|
|
|
def loadTable(self, files):
|
|
self.cache = []
|
|
for x in files:
|
|
s = x.split('\\')
|
|
row = [s[4], Boolean.FALSE]
|
|
self.cache.append(row)
|
|
|
|
self.fireTableChanged(None)
|
|
self.fireTableStructureChanged() |