0

我正在开发一个 Eclipse RCP 插件。现在我需要创建一个能够在运行时动态添加选项卡的多选项卡编辑器,但我不知道该怎么做。有谁知道我该怎么做?

谢谢

4

2 回答 2

0

你应该能够做到这一点类似于MultiPageEditorPart- 它有几个addPage功能。要么按原样使用这个编辑器,要么用它来获得灵感。

于 2012-08-31T03:56:36.687 回答
0

为时已晚,但有些人可能会从这段代码中受益:

/** The text editor used in the new page. */
private TextEditor editor;


private StyledText text;
/**
 * Creates a multi-page editor example.
 */
public MultiPageEditor() {
    super();
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}

void createDynamicPage() {
    try {
        editor = new TextEditor();
        int index = addPage(editor, getEditorInput());
        setPageText(index, "new page"+index);
    } catch (PartInitException e) {
        ErrorDialog.openError(
            getSite().getShell(),
            "Error creating nested editor",
            null,
            e.getStatus());
    }
}


void createMainPage() {

    Composite composite = new Composite(getContainer(), SWT.NONE);
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    layout.numColumns = 2;

    Button clickButton = new Button(composite, SWT.NONE);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.horizontalSpan = 2;
    clickButton.setLayoutData(gd);
    clickButton.setText("click");

    clickButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
          createDynamicPage();
        }
    });

    int index = addPage(composite);

    setPageText(index, "main page");
}

/**
 * Creates the pages of the multi-page editor.
 */
protected void createPages() {
    createMainPage();
于 2015-01-30T20:47:56.867 回答