Force configure cell update in power table

I have setup a couple of dropdowns in a power table. The data is fed through an SQL query.

The first time I ran the query after writing the code for the dropdowns, everything was as it should have been. All of the dropdown options were visible.

However, the nature of the app required that users be able to edit these dropdown lists. The dropdown lists are derived from datasets, which users edit in a popup window.

When an item is added or deleted from one of these datasets, the drop down in the power table does not update for a long time. The table does eventually update, but I need it to happen immediately.

Is there perhaps a different approach to this problem?

Is there a way I can force the configureCell method to run?

Hacky Solution Found in A Previous Post: Power Table Drop Down List with ability to enter new text?

As the person who came up this solution mentioned, this is not good solution. It puts a lot of strain on the userā€™s computer when they are making many edits.

That is a horrible solution, no offense. The only way I can see, to update the editors, is to ā€œupdateā€ the extension functions at run time. Try this, where c is a reference to the table:

c.setExtensionFunctions(c.getExtensionFunctions())

This should work.

6 Likes

Maybe Iā€™m misunderstanding the problem but it seems like you could create 2 datasets as custom properties on your root container.

Whenever the user changes the items in the popup, you just refresh the datasets.

Then in you configureEditor event, you could read the values in the appropriate dataset and return those items as options.

1 Like

I currently store the datasets in tags
The user edits the datasets in the tags.
The table feeds off those datasets to create the dropdowns.
Unfortunately, the table lazily updates the dropdowns in the table.

By default, the columns only update when the columns themselves change, or on component start up. If you use my code posted in my last comment, it should re-fire the configureEditor function.

The much more efficient solution is to embed a custom editor, which will lookup the datasets dynamically whenever itā€™s appropriate. Iā€™ve got a very simple example of this below; the project has an editable ā€˜Optionsā€™ dataset, and the available options in column B in the editable table will be dynamic based on the value in column A.

The relevant code is here:

		root = self
		from javax.swing import JComboBox, DefaultCellEditor, DefaultComboBoxModel
		
		class CustomCellEditor(DefaultCellEditor):
			def getTableCellEditorComponent(self, table, value, isSelected, row, column):
				comp = DefaultCellEditor.getTableCellEditorComponent(self, table, value, isSelected, row, column)
				data = []
				target = root.parent.getComponent("Options")
				for r in range(target.data.rowCount):
					if target.data.getValueAt(r, 0) == root.data.getValueAt(row, 0):
						data = target.data.getValueAt(r, 1).split(",")
				comp.setModel(DefaultComboBoxModel(data))
				return comp
		return {'editor': CustomCellEditor(JComboBox())}

Specifically, comp.setModel(DefaultComboBoxModel(data)) - every time the table asks the editor what renderer it should use, the CustomCellEditor will fire getTableCellEditorComponent and refresh the data in the dropdown.

Custom Editor.proj (9.2 KB)

11 Likes

This would work, but the problem is that it is inefficient. Creating a combobox everytime a cell loads makes everything slug along. It is more efficient to create the combobox once and then reuse it.

1 Like

Awesome Paul, Thanks.
Let me ask you this though.
How about changing the font size of the combo box drop down list items?
Would be easier to select on touch screens.

Within getTableCellEditorComponent, comp is a standard JComboBox; to change the item rendering you would need to subclass JComboBox's getListCellRendererComponent in a similar manner, and use that modified combobox in the CustomCellEditor constructor.

Awesome Paul.

You wouldnā€™t happen to have an example of that would you?

Paul, would you happen to have an example or know of one.

Thank you for your response. I was unable to import the linked .proj but I have been attempting variations of your example above.
I made a Custom property for my Power Table labeled roleList.
Property type is Dataset.
It is running a SELECT Query.

SELECT '%' AS Value, ""
UNION
FROM brewshift
WHERE role != ""
ORDER BY Value ASC

Here is my Dataset from Query -
Power%20Table%20Drop%20Down%20List2

I feel like I came closest to achieving my goal by placing the script below in the Component Scripting configureEditor

if colName == 'role':
return {'options': [self.roleList)]}

Power%20Table%20Drop%20Down%20List3

I tried and tried to get results using Custom Method script and had no luck.
Please advise.

A bit late, but for posterity, see this post, specifically this line:
component.setFont(component.getFont() if itemEnabled else component.getFont().deriveFont(Font.ITALIC))

1 Like

Fantastic Nick. Iā€™ll give it a go

This article helped me accomplish our goal using Power Table Drop Down List.

http://forum.inductiveautomation.com/t/power-table-drop-down-list-with-ability-to-enter-new-text/12876