How can I design explorer views in Mantisse GUI editor?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

There is an open RFE [1] to include explorer views in the GUI designer palettes by default, but until it is implemented, you can follow the following procedure. (digested from the mailing list)

Add explorer views to palette manually

As suggested in several articles [2]/[3], adding the .jar file to the palette exposes the containers. Here the exact procedure to add the containers to the palette

  1. Right click in the Matisse palette

  2. "Add from JAR…​"

  3. Navigate to the org-openide-explorer.jar file, click "Next". On my system this is C:\Program\ Files\NetBeans\8.0.1\platform\modules\org-openide-explorer.jar

  4. Select available components, "Next"

  5. Select the destination palette category in which to add the explorer containers, "Finish"

After all that, the containers are all listed in the palette.

More explanations

(originally by Eirik Bakke)

I use explorer views in matisse all the time. You can add them to the matisse palette (via Palette Manager) or add any arbitrary class, including your own, using the "Beans→Add Bean" icon in the palette. If you make your own JComponents, they have to conform to the JavaBean conventions, i.e. have a public no-arg constructor.

For explorer views to work correctly, there must be an ExplorerManager.Provider in the component hierarchy. I use a simple custom JPanel for this purpose, see https://gist.github.com/anonymous/402e6d9956a77feaac60 (feel free to use). This "ExplorerManagerProviderPanel" can also be added to the hierarchy using Matisse.

import javax.swing.ActionMap;
import javax.swing.JPanel;
import javax.swing.text.DefaultEditorKit;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.util.Lookup;

public class ExplorerManagerProviderPanel extends JPanel
    implements ExplorerManager.Provider, Lookup.Provider
{
  private final ExplorerManager explorerManager = new ExplorerManager();
  private final Lookup lookup;

  public ExplorerManagerProviderPanel() {
    ActionMap map = this.getActionMap();
    map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(explorerManager));
    map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(explorerManager));
    map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(explorerManager));
    map.put("delete", ExplorerUtils.actionDelete(explorerManager, true));
    lookup = ExplorerUtils.createLookup(explorerManager, map);
  }

  @Override
  public final ExplorerManager getExplorerManager() {
    return explorerManager;
  }
  @Override
  public final Lookup getLookup() {
    return lookup;
  }
}

Resources