Creating a model
We are now ready to start with the creation of a new UML model. Once finished, we will use ArchGenXML to turn our model into the expected content type.
Getting ready
Before going on, let's create a new models
folder inside our ArchGenXML installation folder to store the following example code:
cd ~/libexec/archgenxml mkdir ./models
And don't forget to set project properties as explained in Configuring ArgoUML.
How to do it…
After having created a new project and set its properties as above, and before starting to draw, we must define the product name:
- Click on the untitledModel branch on the left navigator to select it. You'll now be able to set its properties on the bottom-right panel.
- In the Name field, write the model's name; it will be the product name in the installation area of Plone. In our case, type
poxContentTypes
(after PloneOpenX ContentTypes).
The top-right panel is where we're going to draw the model. Add a new package to our model:
- Click on the third icon (New Package) in the toolbar.
- Click on the top-right "drawing" panel to create the package.
- You can drag and drop its corners to make it bigger.
- Double-click its header and change its title into
content
to set its name. Usingcontent
as the package name for content type definitions is common practice in Plone products.
Inside this package we'll create the class (or classes) we need.
- Click on the fourth icon (New Class) in the toolbar.
- Click inside the
content
package to create the class inside it. If you are not sure whether it is inside the package, check on the left-hand navigator and expand the branches. - Double-click the class header (first rectangle) and change its title to
XNewsItem
(after eXtended News Item).
Many times during products development we will already have a base class to inherit from. In this particular case, we want the XNewsItem
content type to inherit all the functionalities, which the native Plone News Item
content type has.
To inherit from existing classes, we have several options; the most straightforward one is applying stereotypes.
- Click on the XNewsItem class just drawn and go to the Stereotype tab in the bottom-right panel.
- Click on the atnewsitem [Class] option in the Available Stereotypes list on the left and press the >> button to apply that stereotype. This will add a <<atnewsitem>> line on the class header.
After having turned our class into a News Item, let's add new fields to get it closer to the requirements.
- Double-click on the class attributes panel (middle rectangle) to add a new attribute. Add a name, a colon, and a type. The new attribute Properties tab will automatically open. You can change the name, type, and other properties here.
- If not specified during creation, add the name of the new attribute:
lead
. - If not specified on creation, add the type of the new attribute:
string
. - Go to the Tagged Values tab to set some other advanced properties:
Note
Almost all the Tagged Values will be treated by ArchGenXML as
string
values. There are a few exceptions likerequired
, which expects abool
value. If you want to make sure ArchGenXML will get the correct data type, add apython:
prefix; for instance:python:True
orpython:['high', 'medium', 'low']
.For a complete list of available Archetypes fields and their properties, go to http://plone.org/documentation/manual/archetypes-developer-manual/fields/fields-reference.
- Let's add another field with some more options. Double-click on the class attributes panel and add a new attribute with these characteristics:
- Name:
country
- Type:
string
- Name:
- Then go to the Tagged Values tab and add the following tags:
Note
For a complete list of available Archetypes widgets and their configuration options go to http://plone.org/documentation/manual/archetypes-developer-manual/fields/widgets-reference.
Sometimes we learn that there are already some fields in the base class we're working with (ATNewsItem
, in our example) that might need various minor changes to meet our requirements. Instead of creating new fields and hiding or removing them, we can reuse the existing fields.
Plone's News
Item
content type has a special relatedItems field in the Categorization tab to select already created content that will be displayed as links when reading the document.
- Double-click on the class attributes panel (second rectangle) to add a new attribute. Add
relatedItems
as its name, a colon, andcopy
as its type. The new attribute Properties tab will open automatically. Ensure thatcopy
is the selected type:copy
is a special data type that tells ArchGenXML that it must reuse an existing field and override some of its properties. - Go to the Tagged Values tab to make the
relatedItems
field the one we want: add a schemata tag and set its value todefault
. This is the way to change the tab where this field will appear in edition mode.
We now have an XNewsItem
content type that looks a lot like how we expected. However, there's a countryVocabulary
method required by country
field that we must define in order to prevent errors on instance start-up. Let's see how to add methods to the content type class:
- Double-click on the class operations panel (third rectangle) to add a new method. Add its name. The new method Properties tab will automatically open. You can change its name there if you have misspelled it.
- If not specified on creation, add the name of the new method:
countryVocabulary
. - Go to the Tagged Values tab to add some other changes: if your method is a one-liner, go ahead and add a code tag and set its value:
return (('AQ', 'Antartiqa'), ('BS', 'Bahamas'), ('CM', 'Cameroon'), ).
How it works…
After having defined the product name (Steps 1 and 2) and added a new package (Steps 3 to 6), we finally created a new class (Steps 7 to 9), which will be, at the end of the day, our content type's class.
At that stage XNewsItem
is just a copy of BaseContent
class, which is the core of almost every content type in Plone. It has an id
, a title
, description
, and all the metadata fields and methods to support the Dublin Core convention.
By applying atnewsitem
stereotype (Steps 10 to 11), we change the base class of XNewsItem
from BaseContent
to ATNewsItem
. But again, there already is a News Item content type in Plone; we must keep making changes in our model for it to be of use. In Steps 12 to 17, we added new fields and reused some other existing ones.
Finally, in Steps 20 to 22, we added a short method that will be used to provide the options in the just created country
field.
There's more…
We have specified the countryVocabulary
method as the list of options for the country
field. This isn't a really good example. It's more likely that we will want to use a configurable list of countries; even better, a list of countries with their ISO 3166 two-digit codes. To achieve this, we can use ATVocabularyManager and take advantage of its integration on ArchGenXML. Nevertheless, take our choice as a simple example.
Note
The ATVocabularyManager project page is http://plone.org/products/atvocabularymanager.
More about ATVocabularyManager-ArchGenXML integration can be found at http://plone.org/documentation/manual/archgenxml2/3rdparty/atvocabularymanager.
We can also use a Zope 3 vocabulary—it is actually a named utility —together with the vocabulary_factory
attribute for an options field. Although there's no vocabulary_factory
tagged value in AGXProfile, you can manually add it in ArgoUML. For instructions on creating a Zope 3 vocabulary, check Adding configuration options in Plone control panel.
See also
- Adding configuration options in Plone control panel
- Configuring ArgoUML