|CPSC 329||Software Development||Fall 2017|
Papyrus is a free plugin for Eclipse which allows the creation of a number of types of diagrams. We will be using it for class diagrams because, while it is a bit more cumbersome than PlantUML to use, it is capable of generating Java class skeletons from the class diagram.
Successful completion of this lab means that you:
Work in pairs (and one group of three) to complete this lab. Other than the code generator installation, only one person needs to carry out the steps in the lab but everyone in the group should make sure they understand what is going on. There is no limit on collaboration with others, but you need to make sure that you understand for yourself how (and why) to do things.
One handin per group.
To hand in the lab, create a handin tag as directed and include the names of everyone in your group in the commit comment.
It is assumed that you have the Papyrus plugin installed in Eclipse - lab 1 contains the instructions if you need to install it.
You will also need to install the code generator: (everyone in the group should do this)
In Eclipse, go to Help->Install New Software...
Add a new software site with the name "papyrus codegen" and location http://download.eclipse.org/modeling/mdt/papyrus/components/designer/.
Choose "Papyrus base elements for code generation" and "Papyrus Java profile, library and code generation" under "Papyrus Designer Category" as the items to install.
Repeatedly click "Next>" to complete the wizard, accepting the licenses as needed. Restart Eclipse when prompted to do so.
Create a project for this lab: (only one person should do this)
Create a new Eclipse project called lab5.
Create a new folder called classdiagram within the project. (This should be at the same level as the src directory, not inside it.)
Share your project into the repository. (Name the folder lab5.) Remember to choose the correct repository layout, and to check the structure in the repository after sharing.
There isn't anything special about the name of this folder; it just is a way to organize the various files within the project.
Only one person in the group needs to carry out the steps in the rest of this lab.
The first step in creating a class diagram is to create a model:
In the Package Explorer, right-click on the folder where you want the files associated with the model to go (in this case, the classdiagram folder), choose New->Other..., and select "Papyrus Model" under "Papyrus". Click "Next>".
Check "UML" in the "Architecture Contexts" box and "Software Analysis" and "Software Design" in the "Architecture Viewpoints" box. Click "Next>".
Select the folder where the model files should go (classdiagram in lab5) and enter lab5.di for the filename. (There isn't anything special about this filename; it doesn't have to match the project name.) Click "Next>".
Check "Class Diagram" in the "Select a Representation Kind" box. Click "Finish".
The result should be the creation of three files lab5.di, lab5.notation, and lab5.uml in the classdiagram directory.
Navigate to the .di file (lab5.di in this case) in the Package Explorer, click on it to select it, then go to the Model Explorer tab below the editor view.
Right-click on the top-level element (lab5 in this case) in the Model Explorer tab and choose Import->Import Registered Profile. Select "Papyrus Code Generation Profile" and click OK. Select all (Codegen) in the dialog box that appears and click OK. Note that a Codegen element appears in the Model Explorer view.
Repeat the previous step, choosing "Papyrus Java Profile" (and selecting PapyrusJava) instead.
Right-click on the top-level element (lab5 in this case) in the Model Explorer tab and choose Import->Import Registered Package. Select "JavaLibrary" and click OK. Select all (Java Library) in the dialog box that appears and click OK. Note that a JavaLibrary element appears in the Model Explorer view.
Finally, open the editor:
In the Package Explorer, double-click on lab5.di to open the class diagram editor.
Switch to the Properties tab (below the editor view) if it is not the current tab.
Use the Palette tab on the right side of the editor window to select the type of component to create, then click in the editor window to create an instance of the desired component.
Use the Properties tab below the editor window to edit properties of the currently-selected component (if any).
Information on specific components can be found in the sections below.
Classes are created using the "Class" item in the Nodes section of the Palette. Edit the class name by typing the desired name immediately after creating the class (the class name should be editable) or by selecting the class, going to the UML tab within the Properties view, and entering the desired name in the Name box.
Properties are used for instance variables. Note: if the type of the variable is a class type, create that class first.
Add a property to a class by selecting and then mousing over the desired class, then choosing the 7th icon from the left (mousing over the icon should show "Add Property Class Attribute Label"). A new property is created with some placeholder text. Edit the placeholder text by clicking on the desired property twice (note that this is two separate clicks, not a double-click) and typing the new contents or by clicking on the desired property once (to select it) and then going to the UML tab within the Properties view. (Use the Properties view unless you are sure of the format to type directly.) In the Properties editor, fill in the "Name", "Visibility" (private), "Multiplicity" (1 for a single value with null not an option, 0..1 for a single value with null as an option, 0..* for a possibly empty collection, and 1..* for a non-empty collection), and "Type" boxes (click on the ... icon to choose). Browse through the available options to choose the appropriate type; if the desired type isn't listed, cancel out and create a class for that type first.
Operations correspond to methods. Note: if the type of any of the method's parameters or return value is a class type, create that class first.
Add an operation by selecting and then mousing over the desired class, then choosing the 5th icon from the left (mousing over the icon should show "Add Operation Class Operation Label"). A new operation is created with some placeholder text for the name of the operation. Type in the name (and just the name, without any visibility modifiers, parameters, return values, or even parens).
To edit the name later or to set/change any of the other properties, click on the desired operation to select it, then go to the UML tab within the Properties view below the editor view. Fill in the "Name" and "Visibility" values. For parameters and the return value (if any), click on the + button for "Owned parameter". Fill in the "Name", "Direction" ("in" for parameters, "return" for return values), "Type" (click on the ... icon to choose), and "Multiplicity" (1 for a single value with null not an option, 0..1 for a single value with null as an option, 0..* for a possibly empty collection, and 1..* for a non-empty collection) boxes. Browse through the available options to choose the appropriate type; if the desired type isn't listed, cancel out and create a class for that type first.
To show aggregation and composition relationships between classes, choose either "Shared Association (Directed)" or "Composite Assocation (Directed)", respectively. (Find these under "Association (Directed)" in the Edges section of the Palette.) In the editor view, click first on the "whole" class and second on the "part" class to create the association line. Once created, verify that the diamond icon appears on the "whole" class end, then click on the line to select it and go to the UML tab within the Properties view below the editor view. On the Member End associated with the "part" class, change the Owner to "Assocation" (this will make the arrowhead on the line go away) and update "Multiplicity" as needed (1 for a single value with null not an option, 0..1 for a single value with null as an option, 0..* for a possibly empty collection, and 1..* for a non-empty collection).
You can drag the ends of the line around as needed to clean up the diagram.
For a plain association (an association other than aggregation or composition), use the "Association (Directed)" element. In the editor view, click first on the referencing class and second on the referenced class to create the association line; verify that the line points in the correct direction (in the direction of the reference). To edit multiplicity, click on the line to select it, and go to the UML tab within the Properties view below the editor view.
There is an auto-layout feature - right-click on the background in the editor view and choose Arrange All.
Specifications are entered by clicking on the element in question (class, property, or operation) so that it is selected, going to the Comments tab in the Properties view below the editor view, and adding an Owned comment. (Enter the comment in the "Body" box in the "Create a new Comment" dialog.) For parameter and return value descriptions, select the parameter/return value in the "Owned parameter" section of the operation's properties, click on the edit icon, then add an Owned comment on the Comments tab of the "Edit Parameter" dialog box that appears.
Enter specifications for the classes and methods in your class diagram.
Commit your changes to the repository.
Generate skeleton code by right-clicking in the background of the editor view and choosing Designer->Generate java code. You will be prompted about creating a new project; say "Yes". Accept the defaults in the new project wizard.
When the class diagram and specifications are complete, generate code. Copy the generated skeleton classes into your lab5 project. (You can then delete the auto-generated project - be sure to check the checkbox to delete the contents on disk.)
Commit your changes to the repository.
Hand in your lab by creating a tag called handin. Important: Put the names of your group in the commit comment.