Question

I have a subclass of MultiViewEditorElement. I know the class is being instantiated, but for some reason the componentOpened and componentActivated are not being fired when I open a file. Am I doing something wrong here ? I have only included the code I thought is relevant, please let me know if you need to the entire class.

Class Declaration

@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");        
}

}

Method that instantiates the above class

@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));
}
Was it helpful?

Solution

This is happening because I didn't have custom mime type. So essentially with the code above I was seeing three different views in a tab, two source tabs and a history tab.

@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");        
}

}

Remove the Annotation from the method.

public static MultiViewEditorElement createEditor(Lookup lkp) {
    return ((MultiViewEditorElement) new pumlVisualElement(lkp));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top