MultiView of the Next Release

True to the traditions of this blog, you will now be told the possible future. After all, 7.0 is old news. New news is the next release, where you'll have (if API reviews go according to plan) this in your New File Type wizard; take note of the "Use MultiView" checkbox:

Your DataObject will now have this content:

public class AbcDataObject extends MultiDataObject implements Callable<CloneableEditorSupport.Pane> {

    public AbcDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
        super(pf, loader);
        CookieSet cookies = getCookieSet();
        cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies, this));
    }

    @Override
    protected Node createNodeDelegate() {
        return new DataNode(this, Children.LEAF, getLookup());
    }

    @Override
    public Lookup getLookup() {
        return getCookieSet().getLookup();
    }

    @Override
    public Pane call() {
        return (Pane) MultiViews.createCloneableMultiView("text/x-abc", this);
    }

    @MultiViewElement.Registration(displayName = "#LBL_Abc_EDITOR",
       iconBase = "org/newft/organismIcon.gif",
       mimeType = "text/x-abc",
       persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
       preferredID = "Abc1",
       position = 1000)
    public static MultiViewEditorElement createEditor(Lookup lkp) {
        return new MultiViewEditorElement(lkp);
    }

}

That gives me this:


Now, look at the @MultiViewElement annotation. That's pretty cool, enabling me to create new tabs in the multiview editor like this:

import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JToolBar;
import org.netbeans.core.spi.multiview.CloseOperationState;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
import org.openide.awt.UndoRedo;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.windows.TopComponent;

@MultiViewElement.Registration(displayName = "#LBL_VisualMultiViewEditorElement_1",
    iconBase = "org/module5/rss16.gif",
    mimeType = "text/x-abc",
    persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
    preferredID = "VisualMultiViewEditorElement_1",
    position = 1200)
@Messages("LBL_VisualMultiViewEditorElement_1=Visual 1")
public class VisualMultiViewEditorElement_1 implements MultiViewElement {

    @Override
    public JComponent getVisualRepresentation() {
        return new TopComponent();
    }

    @Override
    public JComponent getToolbarRepresentation() {
        return new JToolBar();
    }

    @Override
    public Action[] getActions() {
        return null;
    }

    @Override
    public Lookup getLookup() {
        InstanceContent ic = new InstanceContent();
        return new AbstractLookup(ic);
    }

    @Override
    public void componentOpened() {
    }

    @Override
    public void componentClosed() {
    }

    @Override
    public void componentShowing() {
    }

    @Override
    public void componentHidden() {
    }

    @Override
    public void componentActivated() {
    }

    @Override
    public void componentDeactivated() {
    }

    @Override
    public org.openide.awt.UndoRedo getUndoRedo() {
        return UndoRedo.NONE;
    }

    @Override
    public void setMultiViewCallback(MultiViewElementCallback callback) {
    }

    @Override
    public CloseOperationState canCloseElement() {
        return CloseOperationState.STATE_OK;
    }

}

Once I've got three of the above classes, I have three visual tabs, as you can see here:


And that's how easy it will be.

Follow this issue: http://netbeans.org/bugzilla/show_bug.cgi?id=196810

Comments:

Nice modification. Love the way Multiviews are evolving.

Posted by Vadiraj on May 16, 2011 at 05:34 PM PDT #

Which version do you refer to?

Posted by guest on June 28, 2011 at 08:05 PM PDT #

I have removed the editor tab area from my customized application. But I need to completely remove that multiview toolbar space of the editor. Can you please redirect me to learn how to remove that space as well. Thanks in Advance.

Posted by gderanga on June 17, 2012 at 11:23 PM PDT #

I have removed the editor tab area from my customized application. But I need to completely remove that multiview toolbar space of the editor. Can you please redirect me to learn how to remove that space as well. Thanks in Advance.

Posted by Dushantha on June 18, 2012 at 02:50 AM PDT #

dev@platform.netbeans.org is the mailing list to write to.

Posted by Geertjan on June 18, 2012 at 03:03 AM PDT #

Hi,
your MultiviewElement example: Typically getVisualRepresentation() should not return a TopComponent?
best regards
Oliver

Posted by Oliver Rettig on February 01, 2013 at 01:03 PM PST #

No, why should it. I normally return a JPanel.

Posted by Geertjan on February 02, 2013 at 01:07 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
23
24
25
26
27
28
29
30
   
       
Today