Help: Generating instances of different Objects

Yeah, now we’re both getting somewhere.

First: you already did it. Things work as expected. You created a class model element and have also successfully applied the stereotype. The only problem you have right now is the formatting; so defining how your class model element should look like.

What happens if you create a new class within Visual Paradigm? For example by dragging it in from the palette? Am I right to assume that you’ll end up with a blue model element (as shown on the left)?

There are 2 ways how you can solve this. First is to define a default formatting within Visual Paradigm, this will ensure that every class model element you create will be using the same format. It’s really easy:

  • Right click on a model element, then select “Styles and Formatting => Formats…” (so: hover over the Styles and Formatting section, then select Formats from the new menu).
  • Select the format you want set default (in the above example that would be the background), then click the “Set as Default” option. Be sure to limit yourself to the class type if you want to use a different color scheme for different model elements.

Example:

formats

The second option, a bit harder, is to apply this formatting manually to your newly created model element.

Note: when I talk about model elements I’m talking about the different components within Visual Paradigm which make up your diagram. But within a plugin these consist of 2 parts which @peter.wong already mentioned above: the model element and its shape.

And a diagram shape roughly defines how the model element should look. Think of the width and height. But sometimes a model element has more properties, such as the fill color mentioned above. That’s when you need to use shape models within the plugin.

Something like this:

// Add the newly created IClass model element to the current diagram
IDiagramElement myClassElement = dm.createDiagramElement(currentClassDiagram, myClass);

if (myClassElement instanceof IShapeUIModel) {
   IShapeUIModel myClassShape = (IShapeUIModel) myClassElement;
   myClassShape.getFillColor().setColor1(Color.orange);
}

The result would be your newly created class model element now getting an orange fill color.

Hope this can give you some ideas… This can be a bit complex, so if something isn’t fully clear then please let me know.

But bottom line: you already solved the problem with creating a class while using a specific stereotype!