[8.0 Vision Client] Power Table - saving column order/sizing

Global default table changes are handled automatically in the designer with the defaultColumnView propertyChange event, but custom default table changes on a client by client basis would have to be handled with scripting. To do this, simply get the columnModel, and then get or set whatever you want:
Take for example, this test button script:

powerTable = event.source.parent.getComponent('Power Table') 
table = powerTable.table
columnModel = table.columnModel
for index, column in enumerate(columnModel.columns):
	print column.identifier + "'s width = ", column.width
	print column.identifier + "'s displayed Index = ", columnModel.getColumnIndex(column.identifier)

On this table:

Here is the output:

Float Column's width =  166
Float Column's displayed Index =  0
Int Column's width =  125
Int Column's displayed Index =  1
String Column's width =  138
String Column's displayed Index =  2
Boolean Column's width =  138
Boolean Column's displayed Index =  3
Date Column's width =  137
Date Column's displayed Index =  4

To change the width of a specific column such as the int column, the code is this:

intColumn = columnModel.getColumn(columnModel.getColumnIndex('Int Column'))
intColumn.preferredWidth = 200

Result:
image

To move the int column to a specific position such as position 0, the code is this:

intColumnIndex = columnModel.getColumnIndex('Int Column')
columnModel.moveColumn(intColumnIndex, 0)

Result:
image

If I wanted to set a table up to where it remembered each client's changes and subsequently restored them during the next session, I would use a column model listener on the power table's initialize extension function and write any changes to the database as they happen. Alternatively, one of the window's closed or closing event handlers could be used to save the data all at once at the end of the session.

Here is what a listener script on the initialize extension function would look like:

	from javax.swing.event import TableColumnModelListener
	class ColumnModelListener(TableColumnModelListener):
		def __init__(self):
			pass
		def columnSelectionChanged(self, event):
			pass
		def columnMoved(self, event):
			for column in event.source.columns:
				print column.identifier
				print event.source.getColumnIndex(column.identifier)
				#save this information to the database
		def columnAdded(self, event):
			pass
		def columnRemoved(self, event):
			pass
		def columnMarginChanged(self, event):
			for column in event.source.columns:
				print column.identifier
				print column.width
				#save this information to the database
	table = self.table
	#Set table column properties from the database here 
	#Then add the the listener to save any subsequent changes
	listener = ColumnModelListener()
	self.table.columnModel.addColumnModelListener(listener)