X

Geertjan's Blog

  • May 16, 2011

MultiView of the Next Release

Geertjan Wielenga
Product Manager

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

Join the discussion

Comments ( 7 )
  • Vadiraj Tuesday, May 17, 2011
    Nice modification. Love the way Multiviews are evolving.
  • guest Wednesday, June 29, 2011

    Which version do you refer to?


  • gderanga Monday, June 18, 2012

    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.


  • Dushantha Monday, June 18, 2012

    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.


  • Geertjan Monday, June 18, 2012

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


  • Oliver Rettig Friday, February 1, 2013

    Hi,

    your MultiviewElement example: Typically getVisualRepresentation() should not return a TopComponent?

    best regards

    Oliver


  • Geertjan Saturday, February 2, 2013

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


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.