Using the local history

In this section, you will use the local history feature to switch to a previously saved version of an individual Java element.

  1. Open junit.samples/VectorTest.java file in the Java editor and select the method testCapacity() in the Outline view.
  2. Change the content of the method so that the 'for' statements reads as:

    for (int i= 0; i < 99; i++)

    Save the file by pressing Ctrl+S.
  3. In the Outline view, select the method testCapacity(), and from its context menu, select Replace With > Element from Local History.
  4. In the Replace Java Element from Local History dialog, the Local History list shows the various saved states of the method. The Java Source Compare pane shows details of the differences between the selected history resource and the existing workbench resource.

    Replace from local history

  5. In the top pane, select the previous version, and click the Replace button. In the Java editor, the method is replaced with the selected history version.
  6. Save the file.
  7. Beside replacing a method's version with a previous one you can also restore Java elements that were deleted. Again, select the method testCapacity() in the Outline view, and from its context menu, select Delete. Confirm the resulting dialog with Yes and save the file.
  8. Now select the type VectorTest in the Outline view, and from its context menu, select Restore from Local History.... Select and check the method testCapacity() in the Available Java Elements pane. As before, the Local History pane shows the versions saved in the local history.

    Restore from local history

  9. In the Local History pane, select the earlier working version and then click Restore.
Java editor Using the local history