Retrieving model elements

Hello,

There is a possibility to iterate over all model items, but I affraid it can be quite inefficient for larger projects.
It would be nice to be able to choose element type to iterate, e.g.:

 
IProject project = ApplicationManager.instance().getProjectManager().getProject();
Iterator it = .modelElementIterator(IModelElementFactory.MODEL_TYPE_CLASS);
while(it.hasNext()) {
  IClass cl = (IClass)it.next();
  // do something
}
 

Best regards,
Jacek

Wow,

You’ve added it in SP1!
Great job, thank You!

Jacek

Hello Jacek,

Oh, you are faster than me! I just wanted to show you the added methods and provide you with a sample. Anyway, I still post the information about this change in case you may have missed part of it.

Here are the added method calls:

IProject.
modelElementIterator(String modelType)
modelElementIterator(String[] modelTypes)
toModelElementArray(String modelType)
toModelElementArray(String[] modelTypes) 

Attached is a sample for you. To use it, follow the usual procedure for installing a plugin. From the application, select Edit > Show Models from the main menu. Then, enter the model type, the search result of model with the specified type will be printed in the message pane.

Note:
This method only work for root models. For models like attribute, operations, parameters, database columns, you cannot retrieve them by iterator.

Enjoy.

Best regards,
Jick
com.vp.plugin.sample.iteratemodel.zip

Hello Herbie,

Some of the items are not supported to get by iterator directly from the top level. Since attributes and operations are child of class, and parameters are child of operation, and database columns are child of entity, they only can be retrieved from the get iterator methods from parent.

So for your questions:

  • can the api retrieve attributes and operations from diagrams?
    Yes, you have to get all classes from the diagram then retrieve the attributes/operations one by one

  • does the api retrieve elements across all uml diagrams?
    We support retrieve elements in diagram based or directly from model repository (not consider they are in which diagram)

  • does the api support integration of the visual modeler?
    No, our Opan API only support accessing the project models. But since it is in Java, you can play around with it and see what you can do.

Hope this helps.

Best regards,
Rain Wong