Hi All,

I was working on a BeanTreeView in a platform app and found a strange
oddity that I'm not sure if I'm dealing with it the right way.  If I
implement clipboardCut() in a way similarly to that found in:

https://blogs.oracle.com/geertjan/node-cutcopypastedeletemovereorderdragdrop-on-the-netbeans-platform

I can drag nodes and drop them and have them removed from source and
pasted into the target (awesome!).  However, if I add a CutAction to
my list of actions for the node, then use:

actions.put(DefaultEditorKit.cutAction,
ExplorerUtils.actionCut(explorerManager));

in my actionMap, I found that using the Cut operation from the popup
menu for the node did not really cut the node (i.e., copy to copy to
clipboard then delete). I checked and in the Netbeans IDE I also find
the same thing happens if I try to cut a Java class node from a
package using the cut menu option.

As a workaround, I used this:


        actions.put(DefaultEditorKit.cutAction, new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent ev) {

                if (explorerManager == null) {
                    return;
                }
                var explorerCut = ExplorerUtils.actionCut(explorerManager);

                Node[] sel = explorerManager.getSelectedNodes();
                explorerCut.actionPerformed(ev);
                for (var n : sel) {
                    try {
                        n.destroy();
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            }
        }
        );

This seems to work. The action in the map is called-back to when using
the popup menu action, but the node drag and drop does not use this
action and instead has its own handling.

Prior to this, I had tried calling destroy in clipboardCut() but that
did not work as I had expected. Dragging a node would call
clipboardCut() and the node would get immediately destroyed before I
even dropped (or worse, cancelled the action).

So... this seems to work for me, but I wanted to check to see if there
was another way of doing this that would be recommended. Also, could
someone clarify why cut does not actually cut and only copies in
Netbeans IDE?

Thanks!
Steven

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to