java - Drag and Drop in JTree - can importData modify the tree? -
i experiencing difficulty drag , drop in jtree
component. drag , drop allow user rearrange nodes in tree. implementation works fine, in situations there null pointer exception when moving node in between of children, on picture below dragging c under b (between b , a):
the direct cause of exception seems while performing cleanup of dnd framework, path item being dragged invalidated changes have performed on tree implement required move.
more specifically, callstack this:
javax.swing.plaf.basic.basictreeui#getdroplinerect java.beans.propertychangesupport#firepropertychange ... javax.swing.transferhandler.drophandler#cleanup ... javax.swing.transferhandler.swingdroptarget#drop
the getdroplinerect
attempting evaluate rectangle path in tree no longer exists, node deleted when move performed in importdata
function.
my question is: expected? considered unsafe perform data changes while dnd has not completed yet, , should queued , performed later? did not see such requirement in documentation, , did not see such async implementation in of examples or tutorials.
imho not saver - stated - data modifications after drop occured, easier implement. if remove node on drag event, need have rollback @ hand handle situation of removing node window or making illegal drop. on other hand, if use drag event gain needed information successful drop , don't change in data yet, stated problems dissapear. on drop, use remembered information drag , complete whole operation, or discard drop, in return rollbacks visual actions (though i'm not 100% sure here), remaining consistent state time.
edit: "my question is: expected?": think exception occurs logic of changing tree model in between drag , drop, making inconsitent @ time event dispatching thread trying redraw model. apologies not being able state "this how it's done", maybe else finds quote swing tree dnd doc.
Comments
Post a Comment