Working with Projects

While Eclipse and Poseidon work closely to maintain a single project, each has its own component within that project. It is important to remember that each component must be made aware of changes to the other, so that any time you modify the source code, you must update the model to see the changes and vice versa. This synchronization process is very simple, and most times will require only one click of a button.

Importing Source Code

A note about importing using Java 5: At a command prompt, type 'java -version'. If you see 'build 1.5', then you are running Java 5. The file chooser has changed between Java 1.4 and 5; in 1.4 it was possible to select single files or subfolders of the current folder. In Java 5, when you select a subfolder and press "open", the chooser enters that folder, rendering it impossible to import the folder using only the mouse. Instead, you must type the name of the folder into the text field and then press 'open'.

Roundtrip Import - Roundtrip is enabled

Roundtrip import can be accomplished with one mouse click of the 'Roundtrip Import' button. If all classifiers have been mapped to source directories so that Poseidon knows in which folder to generate the code, import will proceed automatically. If some classifiers have not been mapped, a dialog will appear, allowing you to either map the classifier or exclude it from roundtrip altogether. More information on how to map classifiers can be found in the Section called Classifier Mapping in Chapter 7. After the import is complete, the imported items will be available from the model navigator pane and can be added to any diagrams as usual.

Normal Import - Roundtrip is disabled

When roundtrip engineering is turned off, source code can be imported into the UML model from 'UML | File | Import Files...', then select the appropriate files from the file chooser. Click 'Open'. From here you will be presented with a dialog where you can choose to generate diagrams for packages if you like.

Generating Source Code

Add Additional Source Directories

The source directories available to Poseidon within are not set in the roundtrip settings, as is standard in the standalone Professional Edition. Instead, the source directories are determined by Eclipse. You can specify these directories from 'Project | Properties | Java Build Path'.

Generate Source Code with Roundtrip

When roundtrip is enabled, simply click the 'Generate Code' button on the Eclipse toolbar. Source code will be generated to the directories specified in 'UML | Open Roundtrip Settings Dialog | Project | Roundtrip | Classifier Mappings'. If classifiers have been added to the model, they will not have a mapping yet, and a dialog will open allowing you to set the source folders for those classifiers. For more information about this dialog, see the Section called Classifier Mapping in Chapter 7.

Generate Source Code without Roundtrip.

This method of source generation works just as it does in standalone Poseidon, which is outlined in the Section called Code Generation in Chapter 14. Start code generation from 'UML | Generation | <language>'.

To generate the code into Eclipse, you must select the output folder to be the source directory of your Eclipse project. If you created a simple Java project, this will be under your Eclipse workspace as the name of the project, which could look something like C:\Programme\Eclipse\workspace\myProject. The recommended way to create a project is with the 'Create Separate Source and Output Folders' option. In this case, your source path might be similar to C:\Programme\Eclipse\workspace\myProject\src. Refresh the Package Explorer or Navigator in Eclipse to see the changes.

This method of generation does not allow you to specify different source folders for each classifier, and as a result if more than one source directory is used for this project in Eclipse, is is likely that you will end up with duplicates - one version from Poseidon and one from Eclipse.

You can also choose to generate the source code to a completely different directory, which will not affect the Eclipse version in any way.

General

Drag and Drop

Drag and Drop functions within each component of the Eclipse integration, but does not function between components. For instance, you can drag a class from the Eclipse navigator to the Eclipse Java editor, or from the Poseidon navigator to a diagram, but you cannot drag a class from Eclipse to a diagram, nor can you drag a class from Poseidon into the Eclipse Java editor.

Remember that while these two tools function closely, you must still import and export changes made from one tool to see the alterations in the other tool. The inability to drag and drop between the two is a reminder to generate the code or model in order to transfer data between the two components.

Working with the UML Model outside of Eclipse

Incorporated into the Eclipse project is a standard .zuml file, which can be edited in standalone Poseidon if you like. These revisions can then be incorporated into the Eclipse project by generating the source as usual.

Saving the UML Model

Two options exist to save your UML model. For an interim save while working, you can save your model from 'UML | Save Project'. This will save only your Poseidon project, not the entire Eclipse project. For a final save when shutting down Eclipse, Eclipse will automatically save your UML project information while saving the workspace.

Summary

Edit Projects with Roundtrip Engineering

The roundtrip engineering function is a convenient way to keep your source code and model synchronized, therefore this is the recommended way to work with UML models in Eclipse.

Edit code in Eclipse, see changes in the UML model

  1. Edit code as usual in Eclipse

  2. Save your code in Eclipse

  3. Press the 'Import Code' button from the Eclipse toolbar

  4. Changes to existing elements will be automatically updated, new elements will be available from the Poseidon navigator.

Edit the UML model, see changes in Eclipse

  1. Edit the model from the Poseidon integration

  2. Press the 'Generate Code' button from the Eclipse toolbar

  3. Make the Eclipse navigator the active frame and press F5 to refresh the navigator and see the new code

Edit Projects with Roundtrip Disabled

You may have occasion to use Poseidon in Eclipse with Roundtrip disabled. Although this is not the recommended way to edit your code and model, it is certainly possible to do so.

Edit code in Eclipse, see changes in the UML model

  1. Edit code as usual in Eclipse

  2. Save your code in Eclipse

  3. Import changes into Poseidon from 'UML | File | Import Files'

Edit the UML model, see changes in Eclipse

  1. Edit the model from the Poseidon integration

  2. Generate the source code from 'UML | Generation | Java'. As the output folder, use the source directory for the Eclipse project.

  3. Refresh the Eclipse navigator to see the changes.