Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag & Drop treeview #17

Closed
retorquere opened this issue Jan 30, 2013 · 6 comments
Closed

Drag & Drop treeview #17

retorquere opened this issue Jan 30, 2013 · 6 comments

Comments

@retorquere
Copy link

Can someone help me to get this: http://stackoverflow.com/questions/11242847/is-drag-and-drop-supported-by-treeitem implemented using jrubyFX? I've got the tree working, which was simple, but the drag and drop bits use a callback mechanism which I'm not sure how to translate into jrubyfx.

@enebo
Copy link
Member

enebo commented Jan 30, 2013

I would try something like this:

class MyTreeCell < TreeCell
  def updateItem(item, empty)
    super(item, empty)
    text = item unless item
  end
end

#...in scenebuilding part of your code.
tree_view do
  set_cell_factory do
    MyTreeCell.new.tap do |tree_cell|
      tree_cell.set_on_drag_detected do |mouse_event|
        # ...
      end
    end
  end
end

@retorquere
Copy link
Author

I've tried this (https://gist.github.com/4678888), but that makes the textx not render, and I see no sign of dnd. I've found a more compicated (but more complete) sample of tree drag and drop in java. I'll see if I can make that work; do you want a pull request for a working sample if I do?

@retorquere
Copy link
Author

I've tried to translate https://gist.github.com/4009620 to jrubyfx, but I keep tripping up on the event handler stuff. Any general pointers on how to approach this?

@enebo
Copy link
Member

enebo commented Jan 31, 2013

I made a couple of tweaks to get (https://gist.github.com/4678888) working. I am unclear why MyTreeCell's super does not render the contents directly. It still seems like you want the method for updateItem I provided though (reversed unless to if and did self.text so we used text= method and not local variable text).

You will also notice I changed how tree_view and tree_item setup. This only works on master. After you reported this issue I decided to play with tree_view + tree_items and made some changes to have them behave more like the rest of the DSL.

FWIW, I don't know if set_on_drag_detected is all you need to do or not but I can see that method firing when I try to drag something. It just doesn't actually show any graphics of something being dragged...

@enebo
Copy link
Member

enebo commented Jan 31, 2013

Look at this sample:

https://github.com/nahi/jrubyfx/blob/master/samples/javafx/tree_view.rb

It basically implements reasonable drag and drop support. The code you had used was partially dependent on other classes in a framework. This code is not quite the same since I changed some behavior and I think fixed several corner cases. This was surprisingly tedious but I wanted to include a more sophisticated example.

I am resolving this issue because this example should show more than enough examples of how to work with Java classes and define event handlers.

@enebo enebo closed this as completed Jan 31, 2013
@retorquere
Copy link
Author

Splendid! Still requires master, right? No probs, loving this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants