Wednesday December 06, 2006
Convert your TopComponent to a MultiViewElement
A brief overview of how to convert a TopComponent to a visual page in a multiview editor. First we recognize a new file type, then we change the Open menu item to open a TopComponent instead of a data editor, and then we change the TopComponent to a multi view element.
- Use File Type wizard to let IDE recognize your new file type.
- Use Window Component wizard to create new TopComponent implementation.
- Create an OpenSupport class, extending OpenSupport and implementing OpenCookie and CloseCookie. Content of methods:
public MyOpenSupport(MyDataObject.Entry entry) { super(entry); } protected CloneableTopComponent createCloneableTopComponent() { MyDataObject dobj = (MyDataObject)entry.getDataObject(); MyTopComponent tc = new MyTopComponent(dobj); tc.setDisplayName(dobj.getName()); return tc; }In the data object, replace the DataEditorSupport's addition to the CookieSet by adding the OpenSupport class to the CookieSet:
cookies.add((Node.Cookie) new MyOpenSupport(getPrimaryEntry()));
- Change the TopComponent's extension class to CloneableTopComponent and receive the data object in the constructor (not doing anything with it here, but useful later). Return null in the getDefault() method.
- Install the module and when you double-click (or choose Open from the menu) on the file type, your TopComponent will open.
Now we'll convert the TopComponent to an element in a multiview editor.
- Add dependency on "Core - MultiView Windows".
- For each page in the multiview editor, create classes that implement MultiViewDescription and Serializable. The method createElement() returns a MultiViewElement. What you want to return here is your TopComponent, which means you must modify the TopComponent to extend JPanel and implement MultiViewElement.
- Repeat the last step for each page in the multiview editor.
- Change the createCloneableTopComponent method in the OpenSupport class to open your multiview elements (here we have two):
protected CloneableTopComponent createCloneableTopComponent() { // Create an array of multiview descriptors: MyPanelMultiViewDescriptor main1 = new MyPanelMultiViewDescriptor(); MyPanelMultiViewDescriptor2 main2 = new MyPanelMultiViewDescriptor2(); MultiViewDescription[] descArry = { main1, main2 }; // Create the multiview: CloneableTopComponent tc = MultiViewFactory.createCloneableMultiView(descArry, main1, null); return tc; } - Install and open the file again. Now you have a multiview editor (without a source view, currently). The second argument in MultiViewFactory.createCloneableMultiView determines which of the pages is open by default. Here it is "main1", the page defined by MyPanelMultiViewDescriptor1:
A lot more needs to be done (for example, with the above instructions you won't even be able to close the multiview editor), but the above is a start. Thanks Rich, as you can see I'm learning a lot from reviewing your document.
Dec 06 2006, 01:04:58 AM PST Permalink
Posted by Rich Unger on December 06, 2006 at 10:50 AM PST #
Posted by Gabriele Bulfon on December 19, 2006 at 04:28 AM PST #
Posted by Gabriele Bulfon on December 19, 2006 at 04:37 AM PST #
Posted by Gabriele Bulfon on December 19, 2006 at 04:41 AM PST #
Posted by Geertjan on December 19, 2006 at 05:27 AM PST #
But there is nowhere shown how to synchronize FileObject, Editor panel and Visual panel. In ManifestSupport example is it not finished
Posted by uf on September 17, 2008 at 05:30 AM PDT #
Thanks for these great tech bits Geertjan! I tried this and works great but getting into trouble when trying to update the title of the TopComponent of the MultiViewElements :( any where I can get more info on this?
Posted by Dushan on November 06, 2008 at 09:03 PM PST #


