当我以编程方式创建包时,包不会出现在Project浏览器中 创建类和属性很好,但不是包。有什么建议? THX ...
这是我的创建包功能:
public void addNewPackage(String packageName, Package parentPackage, string elementType)
{
// for every package under the Root Model->Folder->...
foreach (Package pack in r.Models)
{
foreach (Package package in pack.Packages)
{
foreach (Package innerPackage in package.Packages)
{
// ----addOrUpdateElement
Package myPackage;
// try to find existing class with the given name
// this will only work correctly if there is only one element with the given name, and if it is a class
myPackage = getPackageElementByName(parentPackage, packageName);
if ((myPackage == null))
{
// no existing class, create new
myPackage = parentPackage.Elements.AddNew(packageName, elementType);
}
// set properties
// save class
myPackage.Update();
// refresh elements collection
parentPackage.Elements.Refresh();
innerPackage.Packages.Refresh();
}
package.Packages.Refresh();
package.Update();
}
r.RefreshModelView(pack.PackageID);
}
models.Refresh();
MessageBox.Show("Pack adding Ended: " + models.GetLastError());
}
答案 0 :(得分:3)
您似乎正在将自己的软件包添加到Package.Elements
集合中。它们应该在Package.Packages
。一个UML包由EA Element
和Package
表示,但Element
是在您创建Package
时自动创建的。
所以你需要做一些像
这样的事情if (elementType.Equals("Package"))
{
Package myPackage = parentPackage.Packages.AddNew(elementName, elementType);
myPackage.Update();
parentPackage.Packages.Refresh();
}
else
{
Element myElement = parentPackage.Elements.AddNew(elementName, elementType);
myElement.Update();
parentPackage.Elements.Refresh();
}