使用Java的Enterprise Architect脚本-添加CustomProperty [英] Enterprise Architect scripting with java - add CustomProperty

查看:203
本文介绍了使用Java的Enterprise Architect脚本-添加CustomProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在活动图中添加一个图例,该图例将由java和ea-api以编程方式生成。
我已经知道如何创建图例元素并将其显示在图中(类型:文本和子类型:76):

I want to add a legend to my activity diagram, which will be generate programatically by java and the ea-api. I already know how to create the legend element and show it in the diagram (Type: "Text" und Subtype: 76):

Element legend = elements.AddNew("Color Legend", "Text");
elements.Refresh();

legend.SetSubtype(76);
legend.Update();

//Show in diagram
DiagramObject diagramObject = diagramObjects.AddNew("l=0; r=100; t=0; b=-100;", "");
diagramObjects.Refresh();
// reference the DiagramObject to the before created element
diagramObject.SetElementID(legend.GetElementID());

但这只是一个空的传说。所以我的问题是,如何向CustomProperties中添加一个CustomProperty。我的第一种方法是以下代码:

But this is only an empty legend. So my question is, how to add an CustomProperty to the CustomProperties. My first approach was the following code:

Collection<CustomProperty> customProperties = legend.GetCustomProperties();
CustomProperty cp = customProperties.AddNew("LegendEntryTest", "Back_Ground_Color=2124031;");
customProperties.Refresh();
legend.Update();

但这不起作用,图例仍然为空:(

But this don't work, the legend is still empty:(

以下是示例示例:

问候,
Phil

Regards, Phil

编辑
在Geert Bellekens的帮助下,我解决了我的问题,现在我使用repository.Execute(String sqlStmt)方法将自定义属性插入 t_xref
下面的代码是一个小例子:

EDIT With the help of Geert Bellekens I had solved my problem. Now I use the repository.Execute(String sqlStmt) method to insert the custom property in the t_xref. The following code is a small example how it work's:

//get elementGUID of legend
String legendGUID = legend.GetElementGUID();

//create the description value for one custom_property
String name="TestColor1";
String color="3381504";
int customPropertyIndex = 0;

String description = "@PROP=@NAME="+name+"@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#="+color+";#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT="+customPropertyIndex +"@ENDPRMT;@ENDPROP;"

//add description part for the legend
description += "@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;"

String sqlInsertStmt="INSERT INTO t_xref "
            + "(" 
                + "Client,"
                + "XrefID,"
                + "Type,"
                + "Name,"
                + "Visibility,"
                + "Partition,"
                + "Supplier,"
                + "Description"
            + ") "
            + " VALUES ("
                +"'"+legendGUID+ "',"
                + "'{"+UUID.randomUUID().toString()+"}',"
                + "'element property',"
                + "'CustomProperties',"
                + "'Public',"
                + "'0',"
                + "'&lt;none&gt;',"
                + "'"+description+"'"
            + ");"
                ;

repository.Execute(sqlInsertStmt);

使用 java.util.UUID 生成

字段的新GUID:将RGB颜色转换为由Enterprise Architect接受,您可以使用以下公式:

By the way: To convert a RGB-color to that which will accept by Enterprise Architect you can use the following formular:

 int colorValue = color.getRed() + (color.getGreen() * 256)
            + (color.getBlue() * 256 * 256);

(RGB色彩模型)

推荐答案

您可以尝试使用代码添加自定义属性,但是我敢肯定,您必须借助SQL hack才能填写所有必需的详细信息。
如果您检查数据库,将会发现图例的所有自定义属性都存储在表t_xref的一行中。
客户端列包含t_object.ea_guid,描述列包含自定义属性的所有详细信息。
我做了一个小测试,这就是描述中存储的内容(我添加了换行符以提高可读性)

You can try to add the custom property using code, but I'm pretty sure you'll have to resort to an SQL hack to be able to fill in all the required details. If you check the database you'll find that a all the custom properties of your legend are stored in a single row in the table t_xref. The column Client contains the t_object.ea_guid and the description column contains all the details of your custom properties. I did a small test and this is what was stored in the description (I added newlines for the readability)

@PROP=@NAME=Wit@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16777215;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=0@ENDPRMT;@ENDPROP;
@PROP=@NAME=rood@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=255;#Pen_Color#=255;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=1@ENDPRMT;@ENDPROP;
@PROP=@NAME=blauw@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16711680;#Pen_Color#=16711680;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=2@ENDPRMT;@ENDPROP;
@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;

如果我在哪里,我会使用Repository.Execute()和肮脏的SQL插入语句来获取工作完成。

If I where you I would use Repository.Execute() with a dirty SQL insert statement to get the job done.

这篇关于使用Java的Enterprise Architect脚本-添加CustomProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆