Model Elements > Sub Class

Hello again,

I was just wondering if there is a way to use the ID property in the Model Element class to link to (instantiate) sub classes (ie IUseCaseDiagram, ICollaboration, etc). The report I currently generate to help resolve conflicts when merging with git distinguishes differences in commits between Model Elements in each commit. However I noticed that these sub classes contain more information that I could use on the reports. Currently I store 10 properties from the get methods in each Model Element. Are there any methods that I may have missed that would help me instantiate a sub class for a particular model element? Am I mistaken with my logic? If so please let me know.

Note: The information provided above is for your understanding of the way I am utilizing the classes. I am not interested in performing any of the tasks mentioned above through a purchasable product (Unless the product can utilize git version control). If there is a solution, I would prefer an Open API solution.

Thank you in advance,

Michael Lantz

Hello Michael,

Thank you for your message, but I’m sorry that I don’t quite get your meaning about “link by the ID”. Would you mind show me some example about your problem?

Best regards,
Rain

Hello Rain,

Below is a snippet of code that I had used to obtain model elements (don’t mind the messy code as this was in my very early testing). Unforutnately as a Database Specialist I tend to think of everything through as relationial based using an ID. I was wondering if any similar task has been implemented through the Open API. Any way I can link a generic Model Element to instantiate a specific Model Type class? I’m would like this functinality as it gives more in depth information than a generic model element can provide.

          
            Iterator iter3 = ApplicationManager.instance().getProjectManager().getProject().allLevelModelElementIterator();
            int int_count = 0;
            while (iter3.hasNext()) {
                iter3.next();
                int_count++;
            }

            iter3 = ApplicationManager.instance().getProjectManager().getProject().allLevelModelElementIterator();
            String[][] arr_str_modelelements = new String [int_count][10];
            int_count = 0;
            while (iter3.hasNext()) {
                IModelElement modelElement = (IModelElement) iter3.next();
                arr_str_modelelements[int_count][0] = modelElement.getId();
        }

Thanks in advance,

Michael Lantz


ID_Linking_to_Model_Type.jpg

Hi Michael,

Thank you for your post. But I am sorry that we still do not quite get… From both of your posts you mentioned ID, and from the code snippet it looks like you are retrieving a model element. Do you want to retrieve a model element by ID? If so, the following code snippet can help:

ApplicationManager.instance().getProjectManager().getProject().getModelElementById(id);

You also mentioned to use ID to instantiate elements like use case, collaboration. We do not understand this… When you create a use case you do not need to care about ID. Do you mean you want to create say a use case, and at the same time set its ID manually? ID is used internally, and not supposed to be set by user…

Best regards,
Jick

Hello Jick,

After closer examination I have realized that my thought process was wrong. Using the IModelElement toPropertiesString() I’ve been able to get additional information I was looking for. I am now attempting to perform the action on a instance of a diagram element . The method is not available in this class. I have the property headers/names and I would like to find the values. I am aware there are get methods that can retrieve various properties values, however I am using reflection to dynamically gather properties as opposed to statically coding get statements.

The property names are found from the following variables.

PROPERTY_BACKGROUND = “background”;
PROPERTY_FOREGROUND = “foreground”;
PROPERTY_SHAPE_GROUP = “qShGrp”;
PROPERTY_LINE = “line”;
PROPERTY_LAYER = “layer”;
PROPERTY_ELEMENT_FONT = “elementFont”;
PROPERTY_CAPTION_UI_MODEL = “captionUIModel”;
PROPERTY_META_MODEL_ELEMENT = “metaModelElement”;
PROPERTY_STYLE = “style”;
PROPERTY_X = “x”;
PROPERTY_Y = “y”;
PROPERTY_WIDTH = “width”;
PROPERTY_HEIGHT = “height”;
PROPERTY_Z_ORDER = “zOrder”;
PROPERTY_CREATOR_DIAGRAM_TYPE = “creatorDiagramType”;
PROPERTY_SELECTABLE = “selectable”;
PROPERTY_REQUEST_RESET_CAPTION = “requestResetCaption”;
PROPERTY_REQUEST_RESET_CAPTION_SIZE = “requestResetCaptionSize”;

Any help would be greatly appreciated.

Thank you,

Michael Lantz

Hello Michael,

May I know what you mean by “The method is not available in this class”? Do you mean you want to set the value of an element, but don’t know the method?

Best regards,
Rain

Hello Rain

I have no intention of setting any values. I want to extract the properties as if I was using the toPropertiesString method in the IModelElement and IDiagramUIModel. I need to have a consistent method to extract the property values in the IDiagramElement class. By property values I don’t mean the headers as in:

PROPERTY_BACKGROUND = “background”;
PROPERTY_FOREGROUND = “foreground”;
PROPERTY_SHAPE_GROUP = “qShGrp”;
PROPERTY_WIDTH = “width”

I need to have the corresponding values for each property

eg:

width=440;background=something;foreground=something else

I have tried utilizing properties contained in each property variable, but due to the little amount of documentation I am at a loss to how to match the property names/headers to the corresponding value. Basically my need is to imitate the toPropertiesString method in the IModelElement one way or another. I need this to be done with the IDiagramElement class. The need is for dynamically generating headers and their corresponding values without having to statically program headers. I would like to avoid manually initiating each get method if at all possible. If each class eventually (IModelElement, IDiagramElement, etc) gets additional properties I would like my plugin to be prepared for this occasion as I have already noticed additional get methods being added with each Visual Paradigm update.

I appreciate any help regarding this matter. If any javadocs or developer documentation (other than the basic user manual) exist I would greatly appreciate having access to it. The Open API has many features that I could be utilizing if I knew the inner workings of some of the classes.

Thank you,

Michael Lantz

Hello Michael,

Currently we do not have toPropertiesString method for the IDiagramElement, and we are adding it now. And about the header, so your main difficulties is understand which property the header meaning?

Best regards,
Rain

Hello Rain,

My main difficulty is being able to link the associated property header to the actual value in the property. Using reflection I am able to dynamically gather all variables that contain a propery header. Once I have the header I would like to be able to have the corresponding value to that property. From the openapi.jar it appears there is no value for the property, only the contstant headers embeeded in each property variable. I would like to know if the property values are embedded privately within this class or can be called from a base class, Factory class, etc. It would be nice to have this method available for any other class that may have properties. I have to restructure the way properties are stored in my plugin I would like to have a toPropertiesString() method it consistent through all of the OpenAPI classes I may be trying to utilize. It would be extremely beneficial to have dynamic generated headers as I store all property headers/values dynamically in a embedded database. I would like to avoid coding get statements for each property.

Thank you,

Michael Lantz

Hello Michael,

Actually we do support getting the property value via property object (as the following example)


		IModelElement lModel = ...;
		IModelProperty[] lProperties = lModel.toModelPropertyArray();
		int lCount = lProperties == null ? 0 : lProperties.length;
		for (int i = 0; i < lCount; i++) {
			IModelProperty lProperty = lProperties[i];
			if (lProperty.getType() == IModelProperty.TYPE_MODEL) { // check is ModelRef property, get the value as Model
				IModelElement lModelRef = lProperty.getValueAsModel();
			}
			else if (lProperty.getType() == IModelProperty.TYPE_MODEL_COLLECTION) { // check is ModelRefCollection property, get the value as Model[]
				IModelElement[] lModelRefs = lProperty.getValueAsModelCollection();
			}
			else if (lProperty.getType() == IModelProperty.TYPE_TEXT_MODEL) { // check is Model/Text property, get the value as Model first, if no model, try to get as String
				IModelElement lModelRef = lProperty.getValueAsModel();
				if (lModelRef == null) {
					String lValue = lProperty.getValueAsString();
				}
			}
			else if (lProperty.getType() == IModelProperty.TYPE_STRING) { // check if it is string property, get the value as String.
				String lValue = lProperty.getValueAsString();
			}
			else if (lProperty.getType() == IModelProperty.TYPE_XXX) { // have another type, e.g. int, boolean, etc..
				
			}
		}
		
		// beside IModelElement; IDiagramUIModel or IDiagramElement also have toPropertyArray() function
		IDiagramUIModel lDiagram = ...;
		IDiagramProperty[] lDiagramProperties = lDiagram.toDiagramPropertyArray();
		IDiagramElement lDiagramElement = ...;
		IDiagramElementProperty[] lDiagramElementProperties = lDiagramElement.toDiagramElementPropertyArray();

Do you think this can help and works better then using the toPropertyString?

Best regards,
Rain

Hello Rain,

I had done some looking and found Model Elements contained the toPropertyArray. Even so I hadn’t investigated the proper usage of that class. I hadn’t seen that particular type of method on the IDiagramElement class. If this was an oversight on my part it may be exactly what I’m looking for. I will let you know when I take a look at it later today. Thank you for your help with this issue. Also thank you for the snippet of code (saves me some testing time).

Thank you once again,

Michael Lantz

Hello Rain,

I tried locating the class and method you described for the IDiagramElement class and was unable to do so. I updated the VP Suite (build is currently sp2_20100603). Have you tested the code provided above? If so, am I using the wrong openapi.jar?

C:\Program Files\VP Suite 4.2\lib\openapi.jar

Thank you,

Michael Lantz


IDiagramElement-toDiagramElementPropertyArray.jpg

Hi Michael ,

The openapi file is updated to include the method Rain mentioned. Please run the updater to advance to patch release. Instruction:

Best regards,
Jick

Greetings,

I just wanted to thank you for the patch that updated IDiagramElement. It now has the exact functionality I was looking for when utilizing the Model Element, Diagram, and Diagram element classes. The amount of data may be too much for the user to utilize properly, but I would rather have that then a lack of data (after all I could always hide data). I now have a more dynamic way of capturing changes between vpp files, and as long as the toPropertiesStiring method remains current (not deprecated) between all three classes this will help prepare for any future property expansions. I was pleasantly surprised to see the differences in properties between different model element types, diagram types, and diagram element types. This confirms my doubts of not capturing all applicable data by using the individual get methods.

Thank you for your diligent efforts. I just wanted to let you know that your hard work is appreciated.

Sincerely,

Michael Lantz