Updating your code again
Now that you have a versioned edition of your program in the repository, you can change
your program elements in the workspace with the assurance that you can always revert back
to the versioned edition.
Because a versioned edition cannot be modified, you will need to create a new open
edition from the versioned edition before you can continue changing the program element.
If the edition in the workspace is the versioned edition, a new edition is automatically
created for you if you make changes to the program element and then save it. For example:
- Select your ToDoList class in the Workbench, and type a new comment in the Source
pane.
- From the pop-up menu in the Source pane, select Save.
Notice that the edition name (in the hierarchy pane) changes from the versioned edition
name to a timestamp. Because the workspace can only hold one edition of a program element
at any given time, the new edition replaces the versioned edition. (Of course, a copy of
the versioned edition can always be retrieved from the repository.)
Let's add a counter to the ToDoList program, which will reflect the number of items in
the To-Do list at any given time. To add this feature, we need to change the applet as
follows:
- Add labels for the counter name and the counter itself.
- Connect the Add, Remove, and Open To-Do File
buttons to the counter label.
When modified, the running applet will look like this:

To add the two Labels using the Visual Composition Editor:
- Select the ToDoList class in the Workbench and select Open To then Visual
Composition from the Selected menu. This opens the ToDoList
class in the Visual Composition Editor.
- To make it easier to create the new connections, hide the existing connections by
selecting Hide Connections from the tool bar:
- Select a JLabel bean from the palette.
- Click mouse button 1 beneath the list to add the label. You may wish to select the
scrollpane, the text field and the labels and move them slightly up to make room for the
new label.
- Modify the text of the JLabel bean to To-Do Counter.
- Add another JLabel bean to the right of the JLabel bean you just added.
- Double-click on this new JLabel bean to open its Properties window. Select the value
field to the right of the horizontalAlignment field. From its pull-down
menu, select RIGHT, which right-justifies the value. In the text
field, change the value to 0, which is the initial value of the counter.
Close the Properties window.
- Align the two new JLabel beans.
- Select the counter name label, then the text field, and select the Align Left
tool.
- Select the counter label, then the text field, and select the Align Right
tool from the tool bar.
- Select the counter name label, then the counter label, and then select the Align
Middle tool.
The visual beans have been added and aligned. The free-form surface should look like
this:

Now you're ready to add the connections.
Note:
All the other connections you made are still there, they are just hidden now because you
selected Hide Connections from the tool bar. The new connections that you
make in the next step will not be hidden.
To connect the Add button to the counter:
- Select the Add button and click mouse button 2. From the pop-up menu
select Connect and then actionPerformed.
- Position the mouse over the counter label and click mouse button 1.
- From the pop-up menu, select text. A dashed green line now appears,
indicating an incomplete connection.
- Select the connection and click mouse button 2. Select Connect and then
value from the pop-up menu that appears.
- Position the mouse over the DefaultListModel bean and click mouse button 1.
- From the pop-up menu, select Connectable Features to bring up the End
connection to (DefaultListModel1) window.
- From the Method list, select the getSize() method and
then select OK. This provides the count of the list of items as input for
setting the counter string. The connection is now complete.
- Connect the Remove and Open To-Do File buttons in the
same manner. You're simply updating the count of items in the list whenever an action is
taken that may modify the count. In this applet, any of the top three buttons have this
potential.
Now the free-form surface should look like this:

From the Bean menu, select Save Bean. The changes
you've made are reflected in this open edition, both in the workspace and in the
repository. Select the Run tool from the tool bar to launch the applet
viewer and see the counter in action.
