Difference between revisions of "Inserting Choice Controls in Edit Table Cells"

(Review of choice function)
(Continuing)
Line 37: Line 37:
 
7. Next, create an index named Boolean having the values [False, True].  In this case, instead of using a list-of-labels, we are going to use a "List".  This means that cells in the list contains the identifiers False and True, rather than the string "False" and "True".  These evaluate to 0 and 1 respectively.  This will allow the text "False" and "True" to display in the pulldown, but when the Choice expression is evaluated, it will evaluate to the numeric values of 0 or 1.  If we were to define as a list of labels, they would evaluate to the text "False" or "True".  Drag an index node to the diagram, title it "Boolean", and select "List" for the definition type.  Enter False, press downarrow, and enter True.
 
7. Next, create an index named Boolean having the values [False, True].  In this case, instead of using a list-of-labels, we are going to use a "List".  This means that cells in the list contains the identifiers False and True, rather than the string "False" and "True".  These evaluate to 0 and 1 respectively.  This will allow the text "False" and "True" to display in the pulldown, but when the Choice expression is evaluated, it will evaluate to the numeric values of 0 or 1.  If we were to define as a list of labels, they would evaluate to the text "False" or "True".  Drag an index node to the diagram, title it "Boolean", and select "List" for the definition type.  Enter False, press downarrow, and enter True.
  
[[Boolean_index.JPG]]
+
[[image:Boolean_index.JPG]]
  
 
At this point, we have specified the possible values for each [[Choice|choice]] control.
 
At this point, we have specified the possible values for each [[Choice|choice]] control.
Line 60: Line 60:
  
 
Notice that the second parameter has changed from 1 to 4 as a result of selecting "Nuclear".  Analytica automatically re-writes the definition of a [[Choice]] function when the user selects a new option.
 
Notice that the second parameter has changed from 1 to 4 as a result of selecting "Nuclear".  Analytica automatically re-writes the definition of a [[Choice]] function when the user selects a new option.
 +
 +
12. Click on the "Select Plant Type" and press Delete.  Answer yes, that this is what you intend.  We won't be needing this variable any more.
 +
 +
= Creating the Edit Table =
 +
 +
13. Create another index and title it "Plant ID".  Make it a list-of-labels, and fill in the IDs for our power plants as follows:
 +
 +
[[image:Plant_ID.JPG]]
 +
 +
14. Create an index titled ''Plant Fields'', which will serve as the columns of our edit table, another list-of-labels, and fill in as follows:
 +
 +
[[image:Plant_fields.JPG]]
 +
 +
15. Create a variable node, name it ''Power Plant Data''.  Use the definition type pulldown to select "Table":
 +
 +
[[image:Power_plant_data.JPG]]
 +
 +
16. The index chooser appears. In the left-hand column, find ''Plant ID'' and ''Plant Fields'' and move these to the right to select.
 +
 +
[[image:Power plant indexes.JPG]]
 +
 +
17. Press OK, and then close the edit table window. 
 +
 +
18. With ''Power Plant Data'' selected, select "Make Input Node" from the Object menu.
 +
 +
[[image:Power_plant_data_input_node.JPG]]
 +
 +
What we have done with this step is to create an input node for our edit table.  The input node means that our table can be edited from browse mode.  Whenever you are using choice controls in an edit table, you will want this to be possible, since the controls actually appear when the table is edited from browse mode, so this is a critical step.
 +
 +
= Define Choice Cells =
 +
 +
19. Bring up the edit table for ''Power Plant Data''.
 +
 +
20. In the top cell in the ''Plant Type'' column, type:
 +
 +
  Choice(Plant_Type,1,false)
 +
 +
and press enter to accept typing.
 +
 +
21. With the cell just typed selected, select '''Edit → Copy'''
 +
 +
22. Click on the ''Plant Type'' column header to select the entire row and select '''Edit → Paste'''.  Now every cell in that column is defined as a choice.
 +
 +
[[image:Pasted_plant_type.JPG]]

Revision as of 22:24, 16 July 2007

Mini-tutorial: Choice controls in edit table cells

A new feature in Analytica 4.0 is the ability to present pulldown controls in the cells of an edit table. Using pulldowns in this fashion can provide a convenience to the users of your model, and ensure that they select only valid values for cell values. The following screenshot demonstrates the use of pulldowns in an edit table:

Power plant table with pulldowns.JPG

This short mini-tutorial takes you step-by-step through a simple example to produce the table shown.

How it is done

The edit table displayed above actually contains the following cell contents:

Edit table with choice in edit mode.JPG

When the edit table is viewed from edit mode (i.e., by a model builder), we see this. When the same table is viewed from browse mode (i.e., by the user of the model), the controls display. For the table to be changeable when viewed in browse mode, the table must have an input node. So, the basic steps are to create the indexes containing the list of valid choices for each pulldown, create the edit table, make an input node for the table, and finally populate the edit table with calls to the choice function, where appropriate. Later in the tutorial, we'll also learn how to configure the table so that if new rows are added, the default cell contents for the new row (with choice controls) are automatically inserted.

Identifying Possible Selections

1. Start Analytica 4.0 and fill in the object window:

ECTut object window.JPG

2. Close the object window

3. We'll begin by defining the possible Plant types. Drag an index to the diagram and title it: Plant Type

4. Press Expr.jpg to edit the definition, and in the definition type pulldown, select "List of labels".

5. Fill in the possible plant types as shown (pressing down-arrow from the last cell to append a new cell each time):

Plant types.JPG

6. Repeat steps 3-5 to define an index County:

County.JPG

7. Next, create an index named Boolean having the values [False, True]. In this case, instead of using a list-of-labels, we are going to use a "List". This means that cells in the list contains the identifiers False and True, rather than the string "False" and "True". These evaluate to 0 and 1 respectively. This will allow the text "False" and "True" to display in the pulldown, but when the Choice expression is evaluated, it will evaluate to the numeric values of 0 or 1. If we were to define as a list of labels, they would evaluate to the text "False" or "True". Drag an index node to the diagram, title it "Boolean", and select "List" for the definition type. Enter False, press downarrow, and enter True.

Boolean index.JPG

At this point, we have specified the possible values for each choice control.

Understanding the Choice function

You may have previously used the Choice function to create pulldowns. Here, we'll review this briefly before we actually insert these into the edit table cells.

8. Drag a variable node to the diagram, name it "Select Plant Type". In the definition type pulldown, select "Choice".

9. Fill in the parameters as shown:

Choice function finder.JPG

For the I parameter, we've specifies the Plant_type index that we defined in Steps 3-5. These are the possible choices. We've tentatively set n=1 to select the first item in the list (which is valid until the user actually selects something different in the control). And finally we've set inclAll to false. This third parameter turns off the "All" option so the user does not have the option of selecting every plant type. When placing pull-down controls inside edit tables, you will probably not want "All" to be an option.

10. Press OK. In the attribute dialog, a choice pulldown appears.

11. Click on the pop-up (which currently displays "Natural Gas") and select "Nuclear". Then, change the definition-type pulldown to expr (Expression). Notice that the following definition appears:

Choice(Plant_type,4,False)

Notice that the second parameter has changed from 1 to 4 as a result of selecting "Nuclear". Analytica automatically re-writes the definition of a Choice function when the user selects a new option.

12. Click on the "Select Plant Type" and press Delete. Answer yes, that this is what you intend. We won't be needing this variable any more.

Creating the Edit Table

13. Create another index and title it "Plant ID". Make it a list-of-labels, and fill in the IDs for our power plants as follows:

Plant ID.JPG

14. Create an index titled Plant Fields, which will serve as the columns of our edit table, another list-of-labels, and fill in as follows:

Plant fields.JPG

15. Create a variable node, name it Power Plant Data. Use the definition type pulldown to select "Table":

Power plant data.JPG

16. The index chooser appears. In the left-hand column, find Plant ID and Plant Fields and move these to the right to select.

Power plant indexes.JPG

17. Press OK, and then close the edit table window.

18. With Power Plant Data selected, select "Make Input Node" from the Object menu.

Power plant data input node.JPG

What we have done with this step is to create an input node for our edit table. The input node means that our table can be edited from browse mode. Whenever you are using choice controls in an edit table, you will want this to be possible, since the controls actually appear when the table is edited from browse mode, so this is a critical step.

Define Choice Cells

19. Bring up the edit table for Power Plant Data.

20. In the top cell in the Plant Type column, type:

 Choice(Plant_Type,1,false)

and press enter to accept typing.

21. With the cell just typed selected, select Edit → Copy

22. Click on the Plant Type column header to select the entire row and select Edit → Paste. Now every cell in that column is defined as a choice.

Pasted plant type.JPG

Comments


You are not allowed to post comments.