Firing an event for window onOpen

I have a window with a few dozen tanks, with various labels and such. The tank and its level indicators, temperature labels, etc. are grouped into a container (cntTank_1, for example) and I think copied it many times, renaming it cntTank_2, etc.

When this window opens, I am passing it a parameter that identifies the cellar number. Based on that I would like to make visible only the number of tanks in that cellar. Is the internalFrameOpened action for the window the correct way to do this? I suppose it would be a switch statement making cntTank_1.visible=0 or 1?

Related to this, I have a dataset that is populated based on that same cellarnum parameter I pass in. It will have as many rows as there are tanks, and has a dozen columns or so. Is the best approach to populating labels and such to iterate through that dataset at the same time I make visible or invisible the tank containers. I guess I would go row by row, column by column to assign data to objects? Any advice would be appreciated. TIA D. Lewis

To answer the first question, the internalFrameActivated would be the best choice to put this logic. Then you would, as you said, set the visible property to 0 or 1 based on your logic. It would be something like:event.source.rootContainer.getComponent("cntTank_1").visible=1

However, why do this in scripting at all? I would simply bind the visible property of the container do an expression involving the cellar number. This would be easier and more maintainable.

For the second question: Yes, you could iterate through the dataset and assign values to properties. (see the fpmi.db.toPyDataSet() function).

Again, though, I would simply bind your properties (label texts, tank levels, etc) to an expression involving the cellar data, and tank number. For example, suppose that we are binding for tank 6, and only cellar numbers less than #4 had 6 or more tanks. The expression for a label text would look something like this:

if ({rc.cellarNum} < 4, {rc.cellarData}[6, "SomeColumn"], // bind into the dataset at row 6 '') // blank text, cellers >= 4 don't have 6 tanks

Let me know if you need some more explaination about this,

Much easier as you propose it. Thx. D

No problem. FYI: for binding numbers using this technique, the expression would look like this:

if ({rc.cellarNum} < 4, toInt({rc.cellarData}[6, "SomeColumn"]), // bind into the dataset at row 6 -1) // use -1 for 'invalid', cellers >= 4 don't have 6 tanks

Glad to have helped,

Hi All:

On the internalFrameActivated event of my startup window, I placed the following code:

lbln_Avg_OG = event.source.parent.getComponent("lbln_Avg_OG") 
lbln_Avg_OG.text = 0

The label in question is a numeric lable. I also tried

lbln_Avg_OG.text=“0” but got the same error (see below).

How should I go about clearing out the textboxes? TIA D. Lewis

Traceback (innermost last):
File “event:internalFrameActivated”, line 1, in ?
TypeError: getComponent(): 1st arg can’t be coerced to int

at org.python.core.Py.TypeError(Py.java)
at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyMethod.__call__(PyMethod.java)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyInstance.invoke(PyInstance.java)
at org.python.pycode._pyx0.f$0(<event:internalFrameActivated>:1)
at org.python.pycode._pyx0.call_function(<event:internalFrameActivated>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.calmetrics.factoryhmi.application.script.ScriptManager.runCode(ScriptManager.java:156)
at com.calmetrics.factoryhmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:137)
at com.calmetrics.factoryhmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:277)
at com.calmetrics.factoryhmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:54)
at $Proxy1.internalFrameActivated(Unknown Source)
at javax.swing.JInternalFrame.fireInternalFrameEvent(Unknown Source)
at javax.swing.JInternalFrame.setSelected(Unknown Source)
at javax.swing.JInternalFrame.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at javax.swing.JComponent.setVisible(Unknown Source)
at com.calmetrics.factoryhmi.application.FHMIApp.openWindow(FHMIApp.java:477)
at com.calmetrics.factoryhmi.application.FHMIApp.openWindow(FHMIApp.java:426)
at com.calmetrics.factoryhmi.application.FHMIApp.startup(FHMIApp.java:386)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel.initFHMIApp(RuntimePanel.java:750)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction.doLogin(RuntimePanel.java:1106)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction.tryLoadApp(RuntimePanel.java:1140)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction.access$600(RuntimePanel.java:1011)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction$LoginLockWaiter$1.run(RuntimePanel.java:1043)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

David,

The problem is actually in the first line of this script. Since this event is an event of the window, event.source refers to the window itself. Thus, getting the parent of the window isn’t what you want to do. Rather, you want to get the root container of the window.

Also, you do need to make sure that you are assigning strings to text properties of labels. I think that the script as written below will work:

lbln_Avg_OG = event.source.rootContainer.getComponent("lbln_Avg_OG") lbln_Avg_OG.text = "0"

Another note - if your goal is to simply ‘zero out’ this text when the window starts, you can do something like bind the text to the expression "0" or the SQL query SELECT '0' with polling off. Either way (scripting vs binding) will work fine though.

Hope this helps,

Hi Carl: Thanks. I suspected it was something in the way I was addressing the control. I sent a note off list to Nathan about this very subject. I like the alternative approach as well. D

David. I didn’t get the note. Was it an email or private message?

edit - correction, got the email