Creating An Explorer View with the Visual Library

Toni has been experimenting with creating new explorer views (here). This one below is the one he got the students to create during the recent training in Goettingen. The lower view below is Toni's new explorer view, based on the Visual Library, which displays the same nodes as are displayed by the ExplorerManager that handles the upper view. My contribution is that selecting a node in the lower view synchronizes it with the upper view (i.e., a SelectProvider):

public class VisualLibraryView extends JScrollPane {

    Scene scene;
    ExplorerManager em;

    @Override
    public void addNotify() {
        super.addNotify();
        em = ExplorerManager.find(this);
        if (em != null) {
            scene = new Scene();
            Node root = em.getRootContext();
            addWidgetsForNode(scene, root.getChildren().getNodes());
            setViewportView(scene.createView());
        }
    }

    private void addWidgetsForNode(Scene scene, Node[] nodes) {
        for (int i = 0; i < nodes.length; i++) {
            Node node = nodes[i];
            IconNodeWidget widget = new IconNodeWidget(scene);
            widget.setLabel(node.getDisplayName());
            widget.setImage(node.getIcon(BeanInfo.ICON_COLOR_32x32));
            widget.getActions().addAction(ActionFactory.createMoveAction());
            widget.getActions().addAction(ActionFactory.createSelectAction(new SelectProviderImpl(node)));
            scene.addChild(widget);
        }
    }

    private class SelectProviderImpl implements SelectProvider {

        private final Node node;

        public SelectProviderImpl(Node node) {
            this.node = node;
        }

        public boolean isAimingAllowed(Widget widget, Point localLocation, boolean invertSelection) {
            return false;
        }

        public boolean isSelectionAllowed(Widget widget, Point localLocation, boolean invertSelection) {
            return true;
        }

        public void select(Widget widget, Point localLocation, boolean invertSelection) {
            try {
                em.setSelectedNodes(new Node[]{node});
            } catch (PropertyVetoException ex) {
                Exceptions.printStackTrace(ex);
            }
        }

    }

}

Comments:

The use of the VL as an Explorer is a very good move. For instance, in blueMarine I'd like to replace all the thumbnail viewers with an implementation based on the VL. At the moment, there's a specific viewer, the Light Table, based on it, with specific capabilities. Joining everything together would simplify the code _and_ allow to seamlessly switch from a function to the other; in addition, you could insert simple animantions à la Mac OS X. I'm really longing to finish the mavenization of the project which is keeping other developments stopped :-)

Posted by Fabrizio Giudici on October 02, 2009 at 07:28 PM PDT #

Can you publish this as a module that others can reuse and contribute to? It would be better to mutually fix one module than copy and duplicate not perfect code. Why not perfect, for example your code does not listen on changes in nodes, neither it listens to changes in ExplorerManager.

Posted by Jaroslav Tulach on October 04, 2009 at 10:29 AM PDT #

Jarda,

you're right, the example is very basic and it was only intended as a staring point for creating your own Explorer Views. It would be cool though to build this into a working explorerview, that can also display node hierarchies. It would be cool to have this as an example...

The basic code is in my slides (Gj has them), so it's publicly available.

cheers

--Toni

Posted by Toni Epple on October 04, 2009 at 05:58 PM PDT #

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
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today