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

I suppose the easiest route to achieve this would be to use something like the parent window's internalFrameClosed event handler. Then, just simply throw all of the column information into a dictionary that you save to the database.

Example:

userName = system.security.getUsername()
powerTable = system.gui.getParentWindow(event).getComponentForPath('Root Container.Power Table')
table = powerTable.table
columnModel = table.columnModel
columnProperties = {str(column.identifier): {'location': columnModel.getColumnIndex(column.identifier), 'width': column.width} 
	for column in columnModel.columns}

#INSERT or UPDATE the following information:
print userName
print columnProperties

Then, when the user first opens the table use a script similar to this to change the table:

columnProperties = system.util.jsonDecode(yourStoredDatabaseString)
powerTable = event.source.parent.getComponent('Power Table') 
columnModel = powerTable.table.columnModel
def restoreSavedColumnSettings():
	columnsChanging = False
	for column in columnModel.columns:
		column.preferredWidth = columnProperties[column.identifier]['width']
		preferredLocation = columnProperties[column.identifier]['location']
		actualLocation = columnModel.getColumnIndex(column.identifier)
		if preferredLocation != actualLocation:
			columnModel.moveColumn(actualLocation, preferredLocation)
			columnsChanging = True
	return columnsChanging
restorationAttempts = 0
while restoreSavedColumnSettings() and restorationAttempts <= 5:
	restorationAttempts += 1

Edit: I set up a test window with a power table to test the above scripts, and I discovered that with multiple column moves, more than one iteration is sometimes required to restore the table using the original script. I modified the original script to automatically reattempt [up to 5 times], if the initial column changes do not result in the preferred configuration.

In case it's helpful, here is the test window:
testWindow.zip (44.6 KB)
The save button saves the column information as a string on a custom property, and the restore button restores the column settings using the custom string property.