获取需要更改子元素顺序的选定元素
首先,我们必须从模型资源管理器树中获取所选的元素。
// Obtain the selected elements in Model Explorer treeObject[] selectedObjects = ApplicationManager.instance().getViewManager().getSelectedObjectsFromModelExplorer();if (selectedObjects != null && selectedObjects.length > 0) { // Get the first element in selection Object selectedObject = selectedObjects[0];
将子元素检索到数组中
一旦我们获得了选中的元素,我们就会将所有的子元素检索到一个数组中。
if (selectedObject instanceof IModelElement) { IModelElement parent = (IModelElement) selectedObject; // Obtain the child model element from the selected model element IModelElement[] children = parent.toChildArray();
更改子元素的顺序
接下来,我们将子元素的顺序从一个数组移到另一个数组中。
if (children != null && children.length > 0) { // Put the child elements into another collection with order shifted for one // then remove the child element form parent IModelElement[] newOrder = new IModelElement[children.length]; for (int i = 0; i < children.length; i++) { if (children.length > i+1) { newOrder[i+1] = children[i]; } else { newOrder[0] = children[i]; } parent.removeChild(children[i]); }
通过更改命令将子元素添加回父元素
最后,我们将子元素添加回父元素中。
// Add the child element back to parent according to the shifted orderfor (IModelElement child : newOrder) { parent.addChild(child);}
示例插件
示例插件展示了如何更改模型资源管理器中所选元素的子元素的顺序。当你将插件部署到Visual Paradigm之后,你可以从模型资源管理器(Model Explorer)树中选择元素然后点击插件按钮插件按钮来交换子元素的顺序。

相关:示例插件的下载地址>>
Visual Paradigm v14.1下载>>
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!