如何在eclipse中创建自定义向导,该向导从EMF ecore模型读取类数据,创建其对象(通过向导)并在导航器中显示它?

问题描述 投票:1回答:1

我正在学习使用EMF模型进行的eclipse插件开发,并希望在eclipse中创建一个向导(就像创建类的向导一样),该向导读取EMF ecore模型并提供通过向导在ecore模型中创建类对象的功能。

然后,该对象应出现在导航器视图中(例如,程序包浏览器),在适当的组下。 (按类及其引用分组)

我有以下ecore模型。在这里,我有两个课程课程学生。每个课程可以有很多学生。这两个类都有两个属性IdName。课程还有另一个属性,即参加该课程的学生列表(Students)。

Ecore Model

我还有另一个插件项目,在这里我想使用来自ecore模型的元数据,并创建一个向导来为这些类创建对象。请参见下面的Student类的示例向导。

Student Wizard

单击完成后,该对象应显示在导航器中,如下所示。单击该对象将打开并进行编辑以对其进行编辑。请注意,文件夹Course1Course2实际上不是文件夹,而是Course类的对象。因此,还需要CoursesStudents下的节点分组。Student Explorer/Editor

到目前为止我所做的。

  • 创建了ecore模型并生成了代码。
  • 在另一个看起来像第二个图像的插件中创建了一个向导。
  • 以下是学生向导首页的代码。

公共类StudentPageOne扩展了WizardPage {

private Text texts[]; //texts for Id and Name
private Composite container;

public StudentPageOne() {

}

@Override
public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;

    SimpleExamplePackage eINSTANCE = SimpleExample.impl.SimpleExamplePackageImpl.init();
    int student_features = SimpleExamplePackage.STUDENT_FEATURE_COUNT;

    texts = new Text[student_features];
    for(int i =0;i<student_features;i++) {

        System.out.println(eINSTANCE.getStudent().getEStructuralFeature(i).getName());
        Label label = new Label(container, SWT.NONE);
        label.setText(eINSTANCE.getStudent().getEStructuralFeature(i).getName());

        texts[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
        texts[i].setText("");
        texts[i].addKeyListener(new KeyListener() {

            @Override
            public void keyPressed(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {

            }

        });
        texts[i].setLayoutData(gd);

    }

    // required to avoid an error in the system
    setControl(container);
    setPageComplete(false);

}

public Text[] getTexts() {
    return texts;
}

}

  • 我从第一页(通过getTexts方法)获得IdName并创建对象student,如以下代码所示。

    public boolean performFinish() {
    Text[] texts = one.getTexts();      
    
    SimpleExamplePackage.eINSTANCE.eClass();
    SimpleExampleFactory factory = SimpleExampleFactory.eINSTANCE;
    SimpleExample.Student student = factory.createStudent();
    
    student.setId(Integer.parseInt(texts[0].getText()));
    student.setName(texts[1].getText());
    
    return true;
    }
    

接下来我要做什么

我现在想在导航器(第三幅图像)中从上述代码中显示student对象,并创建一个编辑器来编辑其属性。

此外,我想将整个项目存储为xml。

[请让我知道,到目前为止,是否有更好的方法可以完成我所做的事情,如果在线上有一些参考或教程可以实现这一目标。

java eclipse-plugin emf eclipse-pde eclipse-emf-ecore
1个回答
0
投票
您可能想看看EMF Parsley

使用Parsley,您可以相对容易地基于EMF模型创建自定义编辑器和视图。或者可以在向导页面中使用其组件。

© www.soinside.com 2019 - 2024. All rights reserved.