0

我有一个MultiViewEditorElement. 我知道该类正在被实例化,但是由于某种原因,当我打开文件时没有触发 componentOpened 和 componentActivated。我在这里做错了吗?我只包含了我认为相关的代码,如果您需要整个课程,请告诉我。

类声明

@MultiViewElement.Registration(
    displayName = "#LBL_puml_EDITOR",
iconBase = "org/netbeans/modules/plantumlnb/icon.png",
mimeType = "text/plain",
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
preferredID = "puml",
position = 1000)
@Messages("LBL_puml_EDITOR=Source")
public final class pumlVisualElement extends MultiViewEditorElement {


public pumlVisualElement(Lookup lkp) {
    super(lkp);
    obj = lkp.lookup(pumlDataObject.class);
    System.out.println("================ Inside Constructor.");
    assert obj != null;
}


@Override
public void componentOpened() {
    super.componentOpened();
    System.out.println(" ========================= Here");
}

@Override
public void componentActivated() {
    super.componentActivated();
    System.out.println(" ========================= Here");        
}

}

实例化上述类的方法

@MultiViewElement.Registration(
    displayName = "#LBL_puml_EDITOR",
iconBase = "org/netbeans/modules/plantumlnb/icon.png",
mimeType = "text/x-puml",
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
preferredID = "puml",
position = 1200)
@Messages("LBL_puml_EDITOR=Source")
public static MultiViewEditorElement createEditor(Lookup lkp) {
    return ((MultiViewEditorElement) new pumlVisualElement(lkp));
}
4

1 回答 1

0

发生这种情况是因为我没有自定义 mime 类型。所以基本上使用上面的代码,我在一个选项卡中看到了三个不同的视图,两个源选项卡和一个历史选项卡。

@MultiViewElement.Registration(
    displayName = "#LBL_puml_EDITOR",
iconBase = "org/netbeans/modules/plantumlnb/icon.png",
mimeType = "text/x-puml",
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
preferredID = "puml",
position = 1000)
@Messages("LBL_puml_EDITOR=Source")
public final class pumlVisualElement extends MultiViewEditorElement {


public pumlVisualElement(Lookup lkp) {
    super(lkp);
    obj = lkp.lookup(pumlDataObject.class);
    System.out.println("================ Inside Constructor.");
    assert obj != null;
}


@Override
public void componentOpened() {
    super.componentOpened();
    System.out.println(" ========================= Here");
}

@Override
public void componentActivated() {
    super.componentActivated();
    System.out.println(" ========================= Here");        
}

}

从方法中删除注释。

public static MultiViewEditorElement createEditor(Lookup lkp) {
    return ((MultiViewEditorElement) new pumlVisualElement(lkp));
}
于 2013-03-23T19:50:41.040 回答