You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Jean-Marc Borer <jm...@gmail.com> on 2022/01/19 11:40:45 UTC

How to find the TopComponent(s) editor(s) for a DataLoader file

Hi there,

I am struggling how to get access to the TopComponent of a file editor from
MultidataDataObject.

I register a multi view editor for that object type and now have all the
default cookies installed. However, I want to selette the source editor
view on "Edit" acion and the visual view on "Open".

So I did:

public RosterDataObject(FileObject pf, MultiFileLoader loader) throws
DataObjectExistsException, IOException {
        super(pf, loader);
        registerEditor("text/roster+xml", true);
        getCookieSet().add(new OpenCookie() {
            @Override
            public void open() {
                EditorCookie ec =
getCookieSet().getCookie(EditorCookie.class);
                ((CloneableEditorSupport)ec).
                ec.open();
                // TC is now supposed to be open and activated so we get it
                TopComponent activated =
WindowManager.getDefault().getRegistry().getActivated();
                MultiViewHandler mvh =
MultiViews.findMultiViewHandler(activated);
                for (MultiViewPerspective perspective :
mvh.getPerspectives()) {
                    if
(RosterVisualElement.ID.equals(perspective.preferredID())) {
                        mvh.requestActive(perspective);
                    }
                    System.err.println(perspective);
                }
            }
        });
    }

However, the problem is that I open the editor twice and I am not sure the
latter one is actually the active one.