ScrollingGraphicalViewer Select and Unselect listener - eclipse-gef

I need to fire a method when a figure is selected in GEF diagram.
addSelectionChangedListener works well when I select a figure, but if i click on the same figure again ("unselect") the listener doesn't fire.
How can i fix it?
final GraphicalViewer viewer = new ScrollingGraphicalViewer();
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
//Fired when figure is selected, but not when same figure is selected again
}
});

I don't think you can implement a toggling behaviour for a GEF figure through the selection mechanism. The selectionChanged event gets fired when the selection changes, so clicking twice on the same figure is not going to make it.
Maybe a different approach is needed taking into consideration that a figure is deselected when another figure gets selected and that you can retrieve the that element from the SelectionChangedEvent object passed in.
Also, you should only care about the user selecting a figure within the diagram and not a different element from any other workbench part.

Related

Selection box is dragged, but not the object

I'm using FabricJS for some project, and my goal now is to save the new coordinates when the user drag an object. My issue is that when I select an object and move it, the selection box moves but not the object.
Image there:
I have some code which deal with object selection and mouse click and move events, so I tried to remove them but the issue persists.
Edit: looks like it's only a graphical issue, because the object:moved event is well triggered.
Edit 2 : after some progress in the development, this bug has mutated: now the object and the selection box move together, but I have to click two times on the object to make the selection box appear (while the selection events are triggered on the first click).

Save cell changes when pressing on another cell

I have a kendo ui grid which has an incell editing mode.
Required is when altering a value in a cell and pressing anywhere else a confirmation window to appear to save/cancel the change.
Right now i have managed to make it partially work. In other words when i change a value and press somewhere on the web page or a button i get the confirmation window as requested.
When i press on another cell nothing happens. The pressed cell gets in edit mode, the "edit" function is fired but the previous cell loses its value and the binded function is never called.
So in a few words, i need to call my confirmation function every time a value is changed and the user presses anywhere else. Right now it partially works. It seems that the function is not fired when pressing on another cell.
My source right now is like that.
edit: function(e) {
e.model.unbind("change", confirmationFun).bind("change", confirmationFun);
}
function confirmationFun(e){
// open confirmation dialog and call save function
}
I tried to combine my confirmation with the change: function(e) but the change is fired every time i press on a cell, even before i change a value.
Instead of using edit event, you might use blur. After the initialization of your grid add the following command that binds any blur to your confirmationFun function.
$('#grid').on("blur", "input", confirmationFun);
Where grid is the id of your KendoUI grid.
The problem was finally resolved by removing the selectable: "multiple cell"
part from my code. Now by pressing on a different cell i get the confirmation dialog as required.
Thank you.

MonoDroid Click Delegate and Swipe Detection

I have a checkbox with a custom image for the button. I used the click delegate to perform an action whenever the button is clicked:
box.Click += { //do some stuff... }
This is working great.
However, now I have been given the requirement to add swipe detection to this checkbox (Sounds crazy but it does actually make sense for this app).
I added the swipe detection using the standard methods I am used to with normal Android in Java: I subclassed GestureDetector.SimpleOnGestureListener and also implemented View.IOnTouchListener.
I added the swipe detection to the checkbox as follows:
/*
SwipeListener implements View.IOnTouchListener
SwipeDetector is a subclass of GestureDetector.SimpleOnGestureListener
*/
SwipeListener listener = new SwipeListener(new GestureDetector(new SwipeDetector(this)));
box.SetOnTouchListener(listener);
When I do this, the swipe works great. But the click delegate no longer gets activated. I tried moving my code for the click to my SwipeDetector class, and that seemed to work.
But then I noticed that my checkbox was no longer getting its checked/unchecked state and so my custom image for it never changed.
I know this has got to be something simple, but I'm not seeing it... What is the proper way to have a click and a swipe on a view (checkbox) in Android/MonoDroid?
My guess without seeing your code is that you are returning true from OnTouch, meaning you have consumed the event and do not wish any further processing to occur using the event. Try returning false if you want the rest of the event to fire.
http://developer.android.com/reference/android/view/View.OnTouchListener.html

How to make slider labels clickable [Flex 3]

I have a simple slider, with only 3 options. It seems strange to force the user to drag the small thumbnail on the slider, when it would be a lot easier to click one of the 3 actual labels by the side of the slider. Does anyone know how to accomplish this?
This is a cool problem.
The Label object used by Slider turns out to be a subclass of Label (called SliderLabel). So, probably the best approach would be to subclass Slider and add event listeners to the labels.
I think you could successfully add event listeners in either the commitProperties method or the updateDisplayList method. I'm not sure if one would be preferable to the other, but commitProperties seems like the more correct choice.
So, in your subclass of Slider:
override protected function commitProperties():void
{
super.commitProperties();
for(var i:int = 0; i < labelObjects.numChildren; i++)
{
if(!SliderLabel(labelObjects.getChildAt(i)).hasEventListener(MouseEvent.CLICK))
{
SliderLabel(labelObjects.getChildAt(i)).addEventListener(MouseEvent.CLICK,sliderLabelClickListener);
}
}
}
and then maybe something like this for sliderLabelClickListener:
private function sliderLabelClickListener(e:MouseEvent):void
{
dispatchEvent( new SliderLabelClickEvent(e.target) );
}
I think you'd want a custom event there, rather than dispatching a regular Event, so you could include the name/id/value of the label.
Also, you may want to put in a 'dispose' method to remove the CLICK event listener from the labels when the Slider is removed from the stage. It's not an issue if you aren't going to be removing the Slider, but if you are, what I normally do is create a method called dispose and put all my manual removal logic there (removing event listeners, unwatching/removing ChangeWatchers). Then I assign a listener to the component's REMOVED_FROM_STAGE event and call the dispose method from that listener.
Are you sure a slider is the best component to use in this case? Generally speaking, sliders are to be used when the user has a large range of contiguous options to choose from, where the precision of a user's choice doesn't really matter (e.g. a volume slider - having volume at 51% as opposed to 50% really won't make much of a difference).
If you only have three options, and the user is only allowed to select one of those three options, I would suggest using either a combo box or a radio button group.

Silverlight 2.0 RC Drag and drop ordering of a ListBox

I am trying to give a ListBox drag and drop ordering functionality and I have hit a wall. I got it to work when I specify the list box items in xaml but it does not work when I bind to a list it no longer works because the items are no longer of a listboxitem type.
I found this code http://blog.dobaginski.com/josh/?p=52 that allows me to get the underlying ListBoxItem but I can't get the mouse move event to fire.
I have went through other tutorials but have not been able to find one that deals with a ListBox. Has anyone done this with a ListBox.
The events I am using are SelectedChange, MouseMove, and LeftMouseButtonUp (I think that name is right). I am not using LeftMouseButtonDown because I couldn't get it to fire.
As far as i know you cannot get at the listbox item container when using data binding. YOu could in Beta 1.
You also cannot set a mouse event handler in the style, you must use a data template, just so you know.
You will likely have to use the mouse move event from a parent element, probably the UserControl or main layout control that hosts the listbox.
State changes and animations need to be in the style though so... you still cant get at the listbox item, just the element inside it in the data template.
Oh and if doing drag and drop HitTest is now protected so that will make the Drop harder.
since today you can download the final 2.0 version of Silverlight with some add ons, check the Scott's web log
I've been trying to do the same thing in WPF,
but have only found many buggy implementations.
One person has guided me towards the blog of Beatriz Costa,
and from what I remember she's one of those rare geniouses,
so I suggest you read that as well... I know I will
Blog of Beatriz Costa

Resources