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.

Creating a new 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:

  1. Select your ToDoList class in the Workbench, and type a new comment in the Source pane.
  2. 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.)

Adding a counter to the ToDoList program

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:

  1. Add labels for the counter name and the counter itself.
  2. Connect the Add, Remove, and Open To-Do File buttons to the counter label.

When modified, the running applet will look like this:

tmeupd5.gif (4791 bytes)

Adding the labels

To add the two Labels using the Visual Composition Editor:

  1. 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.
  2. To make it easier to create the new connections, hide the existing connections by selecting Hide Connections from the tool bar:
  3. Select a JLabel bean from the palette.
  4. 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.
  5. Modify the text of the JLabel bean to To-Do Counter.
  6. Add another JLabel bean to the right of the JLabel bean you just added.
  7. 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.
  8. Align the two new JLabel beans.

The visual beans have been added and aligned. The free-form surface should look like this:

tvcesta0.gif (5646 bytes)

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.

Connecting the labels

To connect the Add button to the counter:

  1. Select the Add button and click mouse button 2. From the pop-up menu select Connect and then actionPerformed.
  2. Position the mouse over the counter label and click mouse button 1.
  3. From the pop-up menu, select text. A dashed green line now appears, indicating an incomplete connection.
  4. Select the connection and click mouse button 2. Select Connect and then value from the pop-up menu that appears.
  5. Position the mouse over the DefaultListModel bean and click mouse button 1.
  6. From the pop-up menu, select Connectable Features to bring up the End connection to (DefaultListModel1) window.
  7. 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.
  8. 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:

tvcesta1.gif (6678 bytes)

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.