Avoid GWT DataGrid Rows Scrolling - gwt

In a GWT DataGrid I wan to to avoid / prevent the table data rows scrolling in case of some peculiar application status.
I already tried to catch ScrollEvent, but I think that such event was fired “after” rows scrolling has been done.
I also tried to “hide” every “tool” that a user can manage in order to get rows scrolling; so I tried:
.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
and
scrollPanel.removeVerticalScrollbar();
but Mouse Wheel Actions still keep fire rows scrolling ... therefore maybe should be enough to avoid mouse wheel scrolling actions to reach my goal ?
Please note that I don’t want to remove Horizontal Scrolling.
Any suggestions will be appreciated.
Thanks in advance

Here are two solutions. try any one
DOM.sinkEvents(getDocElement(), Event.ONMOUSEWHEEL);
Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(final NativePreviewEvent event) {
if (event.getTypeInt() == Event.ONMOUSEWHEEL) {
event.getNativeEvent().preventDefault();
}
}
});
dataGrid.sinkEvents(Event.ONMOUSEWHEEL);
Not a good solution but still you can try this one also.
dataGrid.addCellPreviewHandler(new Handler<Contact>() {
#Override
public void onCellPreview(CellPreviewEvent<Contact> event) {
dataGrid.getRowElement(0).scrollIntoView();
}
});

Related

How to detect the scroll panel is still scrolling or not in GWT?

I need checkpoint to detect the scrollpanel is still scrolling or not. I am sending the server request while scrolling the scroll bar with the delay of 100 milliseconds.
I meant, every 100 milliseconds i am sending the request to server while scrolling. This is fine when i do scroll slowly in the grid. But, when I drag from page top to bottom
I could see there are multiple request is going to server. I want to know is there any flag to delete the long scroll. Please find the code
#Override
public void onScroll(final ScrollEvent scrollEvent)
{
int delay = 100;
super.onScroll(scrollEvent, delay);
}
I am using GWT class com.google.gwt.dom.client.BrowserEvents.ScrollEvent. I need below kind of logic
#Override
public void onScroll(final ScrollEvent scrollEvent)
{
int delay = 100;
if(stillScollbarScrolling) {
return;
} else {
super.onScroll(scrollEvent, delay);
}
}
So, I need to consider last request only as valid request. All the previous requests are invalid. I have logic to cancel all the previous logic. But, I need check point to still scroll bar is scrolling without release the bar.
Please help me..
If I understand you well, you need to cancel repeating scroll events. If so, you can use a Timer to do that.
Once a scroll event occurs you start a timer. If next scroll event is fired you check if a timer is still running. If so, it means that you have a repeating event that should be cancelled. If a timer is not running than it is not a repeating event and a request should be done.
Here is the code:
Timer timer = new Timer() {
#Override
public void run() {
// do nothing...
}
};
#Override
public void onScroll(final ScrollEvent scrollEvent) {
if(timer.isRunning()) {
// timer is running - stop the timer and do nothing (cancel event)
timer.cancel();
}
else
// timer is not running - do request
super.onScroll(scrollEvent);
// restart the timer with 100ms delay
timer.schedule(100);
}
Please, notice that the first scroll event will cause doing the request because the timer is not started yet.

function after andengine EntityModifier completed

In the game menu i want the menu items slide away from the screen and then scene changes.
I can't seem to make it work one by one, they seems to execute the same time so there is no time for the menu items to move.
#Override
public void onBackKeyPressed()
{
// SceneManager.getInstance().loadMenuScene(engine);
if(hasChildScene()) {
/* Remove the menu and reset it. */
menuOut();
this.gameMenuChildScene.back();
} else {
/* Attach the menu. */
createGameMenuChildScene();
}
}
The AndEngine Cookbook designed an animated game menu by making it an Entity and attaching it to the HUD, no Scene changes at all.
Otherwise, why don't you make a Callback once the animation is complete to change the scene?
-Sorry i can't comment yet and i wanted to help
U can do it like this: where 2f is time in seconds. It's not nice but it should work.
this.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback() {
public void onTimePassed(final TimerHandler pTimerHandler) {
resourcesManager.engine.unregisterUpdateHandler(pTimerHandler);
//change scene here
}
}));
You also have isFinished() method in your EntityModifier. You can initialize onUpdate and check isFinished() method. When it returns true you will change the scene. It more elastic and nicer way to do it. I can't verify it right now so you have to check the soultion yourself.

How to set the Droppable/Draggable Event on the mouse cursor

I've implemented the Drag-n-Drop effects in Wicket using the Ajax Behavior. If I dragg the Image over the tree nodes, the position of droppable accept is in the middle of image. How to set this position (event) on the cursor?
Thank you.
Also I found it. The solution is:
DroppableAjaxBehavior b = new DroppableAjaxBehavior() {
#Override
public void onDrop(Component droppedComponent, AjaxRequestTarget target) {
//do something to handle event
}
};
b.setTolerance(ToleranceEnum.POINTER);

Programatically Detect window maximization/Minimization??? Eclipse RCP

As the title shows, I want to add a listener to my rcp user interface in order to detect maximization and minimization. Actually, it not that my real purpose, but I think it is a way to solve my problem. I have a view with some shapes in the center, and I wonna keep the drawing exactly in the center even if the window is resized. To do so, I used the following listener :
public void createPartControl(final Composite parent) {
display = parent.getDisplay();
white= display.getSystemColor(SWT.COLOR_WHITE);
parent.setLayout(new FillLayout(SWT.VERTICAL));
final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinHeight(100);
sc.setMinWidth(100);
sc.setSize(565, 305);
final Composite child = new Composite(sc,SWT.NONE);
child.setLayout(new FillLayout());
// Set child as the scrolled content of the ScrolledComposite
sc.setContent(child);
child.setBackground(white);
gc = new GC(child);
parent.addListener (SWT.Resize, new Listener () {
public void handleEvent (Event e) {
x = child.getBounds().width/2;
y = child.getBounds().height/2;
child.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
dessin(gc); // draw my shapes
}
});
}
everything goes well except when I maximize the window and then minimize it, in this case I loose the drawing (it is in the corner).
Any idea please? I'm I thinking in the right way?
The two events to detect minimization and un-minimization (not necessarily maximization) are Iconify and Deiconify which only occur on the Shell. See the javadocs for Shell.
Consider moving the resize event is seen for the parent, as the child need not necessarily be resized yet.
In order to keep something in the center of something else all you need is the SWT.Resize event, so this question is a classic case of the XY Problem. (Except that the OP in this case seems to already suspect that this may be an XY Problem.)
However, many people arrive at this question with a legitimate need to programmatically detect window minimized / maximized / restored events, for the following reason:
If you want to be able to save the bounds of your application window on exit, you cannot just save whatever is returned by Shell.getBounds(), because your application may be terminated while minimized or maximized or fullscreen, in which case its bounds should not be persisted. What should be persisted is the minimized/normal/maximized/fullscreen state of the shell, (I call it "posture",) and the bounds of the shell last time its posture was "normal". So, essentially, you need to keep track of when the posture is "normal", and for that you need to have a "posture changed" event.
The problem is that when SWT issues the "deiconified" event, it has not calculated the bounds of the shell yet, so the value that you get in that case is bogus.
So, here is the solution to that:
You are going to need a method which recalculates the posture as follows:
private void recalculatePosture()
{
Posture posture = swtShell.getFullScreen()? Posture.FULLSCREEN
: swtShell.getMinimized()? Posture.MINIMIZED
: swtShell.getMaximized()? Posture.MAXIMIZED
: Posture.NORMAL;
if( posture != previousPosture )
{
issue event...
previousPosture = posture;
}
}
In order to generate the "maximized", "restored (from maximized)" and "fullscreen" events you can use Shell.addListener() to listen for the SWT.Move and SWT.Resize event, and invoke recalculatePosture() when they occur.
In order to generate the "minimized" event you can use the shellIconified() method of the ShellListener as #the.duckman said, and again, invoke recalculatePosture().
In order to generate the "restored (from minimized)" event, you need to do the following in your ShellListener:
#Override
protected void onShellDeiconified( ShellEvent e )
{
display.asyncExec( () -> recalculatePosture() );
}
This will cause the recalculation of posture a short time after the 'deiconified' event, at which point SWT will have gotten around to properly calculating the bounds of the shell.

Catching the scrolling event in gtk#

Which event from which widget should I catch when I need to run some code when ScrolledWindow is scrolled?
Ths widgets tree I am using is:
(my widget : Gtk.Container) > Viewport > ScrolledWindow
I tried many combinations of ScrollEvent, ScrollChild, etc. event handlers connected to all of them, but the only one that runs anything is an event from Viewport that about SetScrollAdjutstments being changed to (x=0,y=0) when the application starts.
You should attach to the GtkAdjustment living in the relevant scrollbar, and react to its "changed" event. Since Scrollbars are Ranges, you use the gtk_range_get_adjustment() call to do this.
unwind's answer was correct.
Just posting my code in case someone needs a full solution:
// in the xxx : Gtk.Container class:
protected override void OnParentSet(Widget previous_parent) {
Parent.ParentSet += HandleParentParentSet;
}
void HandleParentParentSet(object o, ParentSetArgs args) {
ScrolledWindow swn = (o as Widget).Parent as ScrolledWindow;
swn.Vadjustment.ValueChanged += HandleScrollChanged;
}
void HandleScrollChanged(object sender, EventArgs e) {
// vertical value changed
}
If you need to change the parent of any of those widgets, or may need to change the types and change the hardcoded types and handle disconnecting from the previous parent.