Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse 在我的ecore模型中生成一些子对象_Eclipse_Emf_Ecore_Eclipse Sirius - Fatal编程技术网

Eclipse 在我的ecore模型中生成一些子对象

Eclipse 在我的ecore模型中生成一些子对象,eclipse,emf,ecore,eclipse-sirius,Eclipse,Emf,Ecore,Eclipse Sirius,为了简化我的问题,我做了一个小模型 在这个模型中,我在模拟中有一个平面。我想用一段代码生成一个具有相同子类(MotorType、OtherClass1、OtherClass2)和相同值的其他平面,除了MotorType中随每次迭代递增的数值之外 例如,我有一个模拟,由一个名为“plane1”的平面、一个值为10的MotorType=TypeB和一个OtherClass1组成 我想生成10架新飞机,其中OtherClass1具有相同的值和相同的发动机类型,但“值”增加了10 如何生成模拟的某个新平

为了简化我的问题,我做了一个小模型

在这个模型中,我在模拟中有一个平面。我想用一段代码生成一个具有相同子类(MotorType、OtherClass1、OtherClass2)和相同值的其他平面,除了MotorType中随每次迭代递增的数值之外

例如,我有一个模拟,由一个名为“plane1”的平面、一个值为10的MotorType=TypeB和一个OtherClass1组成

我想生成10架新飞机,其中OtherClass1具有相同的值和相同的发动机类型,但“值”增加了10

如何生成模拟的某个新平面子对象,该子对象是现有平面的副本,但增加了一个参数?
有没有可能通过右键点击我的飞机来复制天狼星


您可能希望在原始模拟上使用创建副本

然后,使用JavaEMFAPI,您可以在副本内部导航,并根据需要对其进行修改

如果希望每个模拟都位于其自己的文件中,则必须创建适当的EMF资源,并在保存之前将新创建的模拟添加到其内容中


在实现了执行上述所有操作的Java方法之后,您可以使用

从Sirius图调用它。您应该通过扩展来定义自己的EMF复制器

通过这种方式,您可以覆盖默认的复印机行为,并使用一些自定义行为处理感兴趣的EStructuralFeature

class PlaneCopier extends Copier {

    int motorType;

    public EObject copy(EObject eObject, int motorType) {
        this.motorType = motorType
        return super.copy(eObject);
    }

    @Override
    protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) {
        if (eAttribute.equals(YouEMFPackage.Literals.PLANE__MOTOR_TYPE)) {
            copyEObject.eSet(YouEMFPackage.Literals.PLANE__MOTOR_TYPE, motorType);
        } else {
            super.copyAttribute(eAttribute, eObject, copyEObject);
        }
    }
}
并在循环中使用它:

PlaneCopier copier = new PlaneCopier();
Plane templatePlane = ...
int motorType = 0;
for (var i=0; i<nbPlanes; i++) {
    motorType += 10;
    newPlane = copier.copy(templatePlane, motorType);
}
PlaneCopier复印机=新的PlaneCopier();
平面模板平面=。。。
int motorType=0;

对于(var i=0;iExcellent first question buddy.干得好!非常感谢!@Rann Lifshitz是否可以在Sirius树中执行此操作?我已经创建了我的java服务,在plugin.xml的扩展中添加org.eclipse.Sirius.externalJavaAction,添加java操作以引用我的java类,并在弹出菜单中创建一个外部java操作,但我看不到我的菜单中的操作…可能我遗漏了什么,或者可能在树描述中不可能?回答得好,伙计!使用我在回答中引用的Java服务,而不是Java操作。它也应该在树中工作。