componentOpened未在MultiViewEditorElement的子类上触发

时间:2013-03-23 01:41:49

标签: netbeans-platform

我有一个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));
}

1 个答案:

答案 0 :(得分: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));
}