ListView single selection change and drag event - javafx

I'm trying to understand sequencing of property changes and mouse events inside ListView.
To detect a change is there a difference between observing selectedIndex vs selectedItem?
To drag and drop ListView items is there any difference between registering onDrag.. events against ListView vs each ListCell?
Is there any scenario where a "onDragDetected" event would be received before the selection model (which I'm observing) is updated?
Thanks

To detect a change is there a difference between observing
selectedIndex vs selectedItem?
Not really; I think this is just a matter of whichever is the most convenient for you to use.
To drag and drop ListView items is there any difference between
registering onDrag.. events against ListView vs each ListCell?
I would advocate for registering with the ListCell. There's no direct way to check a mouse event on the ListView and then determine which cell the mouse event occurred on. You would have to fall back on the selected item, and that's not really semantically the same thing. (For example, how would you handle drag on empty cells, which wouldn't change the selection...?)
Is there any scenario where a "onDragDetected" event would be received
before the selection model (which I'm observing) is updated?
That's implementation dependent. I think the current implementation uses a mousePressed event to handle selection (though I'm not certain), so it should trigger before the drag is detected, but do you really want to rely on that implementation not changing in a future release?
IMHO, relying on the selected item just feels wrong here. It's semantically different to what you want: you actually want to know "which item the user clicked on", not "which item is selected". Sure, the two are related, but they're not the same thing, so in a way you'd be introducing a dependency on the selection API that should be independent of the thing you're trying to achieve. That is most definitely an opinion, though. Your mileage may vary...

Related

Qt event for delegate in table

Question/Issue
I tried reimplementing the event method in a custom delegate to handle clicks. The delegate is used to render table cells in a table view. However, I do not get any events for the delegate (the method is never called according to the debuger). Is there anything special I need to do so my delegate can track events (in particular mouse entering/exiting, clicks)?
Context
I would like to create my own data representation for table cells. The functionality should be close to a button, but slightly different. I read that the two options for implementing buttons in table are either setting a cell widget which supposedly has a high performance cost (I did not quite understand why) or using a delegate.
Since I want different behaviour than that of a button, and for the speed myth I decided to go with a delegate.
Mouse events are send to the QAbstractItemDelegate::editorEvent() method, even if they don't start editing of the item.
See: http://doc.qt.io/qt-5/qabstractitemdelegate.html#editorEvent

Flex - change and focusOut in one event?

I need to be able to trigger an event on change, but only when user focus out of the input text.
Is there any one event I can use?
I guess I can use a combination of both, by finding out which of them triggers last, and only use that, if the other has been called, but that introduces some complexity and clutters the code.
There's no single event that combines both of these concepts. You'll need to write some custom logic to do what you're describing.
Using the mx.managers.FocusManager getFocus() method you can find the component that currently has focus. In the change handler on the TextInput you can check if this TextInput currently is the component with focus. If not, you can go about your business.

How can I implement drag-out-to-delete in Flex?

I have a List component from which I'd like to be able to remove items using drag & drop, but without having a specific target. If you use the mac, the behaviour I'm looking for is something like what the Dock uses; when you drag something out of the bounds of the control it should get an icon that indicates that it'll be deleted (OSX uses a cloud or something?) and then if you release it it will be removed from the list.
How can I do this?
(If I need to provide a more clear description, please comment; I'll fill in what I can)
In my experience with drag/drop in Flex, you cannot simply drag something out and handle that. There is no dragOut event (unfortunately), so that would leave you up to the task of writing dragOver and dragDrop listeners on all the containers surrounding your dragInitiator and handling the process accordingly.
It's more time consuming and can become complicated if any of these controls already have specific dragOver and dragDrop event handlers.
Hope this helps.
Having no Flex experience all I can offer is some psuedo code which resembles how I implemented a similar effect in JavaScript, but hopefully it will get you started.
Essentially what you'll want to do is during your drag event measure the current coordinates of the object you're dragging to see if they intersect the original container and when they fall outside of its bounds call the logic to update the icon in order to indicate it will be removed. Then, on the drop event, check the coordinates once more and delete the item if needed.

Flex tree droplocation indicator stuck (edit 2/4/10, almost a totaly different question)

OK I've got a little more research on this done so I'm going to totally rephrase the question:
I have two trees, I want to be able to drag items from one tree to the other. In the receiving tree I have some logic that allows or denys the drop. I am using the native cursor feedback Like this :
DragManager.showFeedback(DragManager.COPY);
DragManager.showFeedback(DragManager.NONE);
When the logic determines NONE it properly rejects the item except the drop position indicator sticks like in the screenshot.
I know now that neither dragComplete, nor dragDrop are being fired in this situation, so I have no function to put code into that would clean that up. So how can I listen for this drag rejection?
ScreenShot shows app After drop
alt text http://img687.imageshack.us/img687/2245/treeindicatorstuck.png
Thanks
~Mike
PS with my other question: how-do-i-detect-that-drag-and-drop-operation-ended We have a way of getting an event to fire so we can clean up the tree control. I'm attaching an event listener to the stage so that as the mouse is moved (maybe I'll put it on a timer)it will constantly check if dragmanager.isdragging if it's not it will fire the tree.hideDropFeedBack. This still begs the question, what event is changing the isDragging Boolean and how do I listen for it?
You need to call tree.hideDropFeedback(); or event.target.hideDropFeedback(); to remove the drop indicators.

What the best way to coordinate loading initial values in syncronized Combo-Boxes & List Box

Environment: Flex/As3/Cairgorm/composite component.
I have two comboboxes and two datagrids such that the selection of combobox 1, inserts data into combobox two and the fist datagrid. The selection of combobox 2 inserts data into datagrid 2.
I have setup the change event so that the user selection on each of the combo boxes do the right thing. The problem is that on the initial load of the comboboxes, the change event does not fire and subsequent synchronization data loading does not happen.
Is there an event for getting the itemselected (1st item) after the combobox is initialized?
I found my own answer. Using the updateComplete event on each of the comboboxes did the trick.
[EDIT]
It turns out that updateComplete did not work as expected. What I really needed is the dataChange event. However, it appears that this event does not fire for comboboxes even though it is listed as a valid FlexEvent for this component.
I tried a number of other events (valueCommit, creationComplete, initialize) but all of these fire multiple times, overlap with change, and are not useful for this usecase.
In the end, I created a gludge of a chain of calls for the initialize path and change path.
If anyone else has a better way, I'd be very interested.

Resources