enterprise-architect - Enterprise Architect 使用 java 编写脚本 - 添加 CustomProperty

标签 enterprise-architect

我想在我的事件图中添加一个图例,该图例将由 java 和 ea-api 以编程方式生成。 我已经知道如何创建图例元素并在图表中显示它(类型:“文本”和子类型: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());

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

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

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

这是一个示例图例:

enter image description here

问候, 菲尔

编辑 在 Geert Bellekens 的帮助下,我解决了我的问题。现在我使用 repository.Execute(String sqlStmt) 方法在 t_xref 中插入自定义属性。 以下代码是其工作原理的一个小示例:

//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 我为字段 XrefID 生成一个新的 GUID。

顺便说一句:要将 RGB 颜色转换为 Enterprise Architect 可以接受的颜色,您可以使用以下公式:

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

(RGB 颜色模型)

最佳答案

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

@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;

如果我在你那里,我会使用带有脏 SQL 插入语句的 Repository.Execute() 来完成工作。

关于enterprise-architect - Enterprise Architect 使用 java 编写脚本 - 添加 CustomProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26280146/

相关文章:

enterprise-architect - 企业架构师 : how to synchronize with source code (source -> model) when its in a different absolute path in the disc?

uml - 如何转换.eap 文件?

enterprise-architect - 有没有办法在 Sparx Enterprise Architect 中搜索元素类型?

report - Sparx Enterprise Architect EA 在发布过程中截断图表

refactoring - Enterprise Architect 对象图重构

xml - 从 SVG 文件到 XML 文件的转换

svn - 如何打开 eap 文件

architecture - 在 UML 组件图中重用子组件

enterprise-architect - 如何隐藏 EA 属性对话框?

visio - 将 Enterprise Architect 序列图转换为 Visio