站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Eclipse Rich Client Platform: Designing, Coding, and Packaging Java Applications

Section 3.6.  Sample Code - Eclipse Rich Client Platform: Designing, Coding, and Packaging Java Applications

Previous Page
Next Page

3.6. Sample Code

As mentioned earlier, the code and resources added in each chapter are available on a companion CD to this book. They are also available from the book's Web site, http://eclipsercp.org/book. The samples directory includes a directory of projects for each chapter that has code. These projects contain the final state of Hyperbola after all steps outlined in the corresponding chapter have been completed. So, to get the starting state for Chapter N, you should load the final state for Chapter N-1 into your workspace. To make it easy to load the projects for each chapter, we've written a "Samples Manager" tool as described in 3.6.1.

3.6.1. Moving from Chapter to Chapter

It turns out that managing a dozen different versions of the same plug-ins is quite complicated. Ideally, we would have just named the projects differently and allowed you to load them all at once. Unfortunately, all of the variations on that approach proved to be problematic in one way or another. In the end, we wrote a Samples Manager tool to help you both manage the chapter code and move from chapter to chapter.

Start by installing the tool in your Eclipse IDE, use Help > Software Updates > Find and Install..., then select Search for new features to install. Use New Local Site and the CD's updates directory to access the tool's feature. Click Finish and you should see an org.eclipsercp.book.tools.feature feature in the Search Results dialog. Check that feature and go through the following pages in the wizard then carefully read and accept the licenses and warnings. After the feature is installed, a restart dialog appears. You can either Apply Changes or Restart.

With the Samples Manager installed, there should be an RCP Book menu on the main menu bar. Run the tool by selecting RCP Book > Samples Manager. You should see samples manager view as shown in Figure 3-4.

Figure 3-4. Samples Manager


The list shows all chapters of the book that have associated sample code. Select a chapter and click Import to load all related projects into the workspace. It is important that you not try to load two copies of the same project into the workspace at the same time. That is the point of the tool. Before importing new projects, it deletes the old ones.

After importing a chapter, the view highlights the chapter to remind you what is in the workspace. The tool's help content includes the most up-to-date instructions and tips for using the tool.

Note

Some of the chapters include steps that update the target platform by adding new plug-ins. The Samples Manager does not update your target platform for you so you have to carry out those steps by hand. Generally speaking, it is OK to have too many plug-ins in your target. So, if you are moving back to an earlier chapter, you do not have to remove the additional plug-ins from the target.


3.6.2. Comparing

The Samples Manager also supports comparing the current workspace to the set of projects for a chapter. For example, if your workspace contains the projects for Chapter 5, you can see all the changes required for Chapter 6 by selecting "Chapter 6" in the list and clicking Compare. This gives you a standard Eclipse compare editor that you can use to browse the changes or load them into the workspace.

This is extremely useful when following the tutorial steps. For example, while doing Chapter 6, you may find that something is not working or the steps are unclear. Comparing the current workspace to the Chapter 6 projects tells you what is left to do or where your setup is different from the expected outcome.

Several chapters require sets of resources or large chunks of code that you are not expected to create on your own. The Samples Manager's comparison tool has a Copy into Workspace action, as shown in Figure 3-5, that allows you to select files and folders in the comparison and copy them into the workspace.

Figure 3-5. Comparing Chapter 4 to Chapter 9


To distinguish between files that are changes and those that only exist in one location, the compare editor shows a minus sign (-) if a file does not exist in the workspace but does exist in the comparison chapter. Conversely, if a file exists only in the workspace, a plus sign (+) is shown.


Previous Page
Next Page