PDA

View Full Version : how to add double click and on click in grid at the same time



mvillamor
6 Oct 2010, 10:44 PM
grid.addListener(Events.OnClick, new Listener<GridEvent<_Messages>>() {

@Override
public void handleEvent(GridEvent<_Messages> be) {
if (be.getModel() != null) {
bottom.mask("Loading mail, please wait..");
mmc.GetEmailPreview(be.getModel().getIDMessage(), bottom);
}
}
});

grid.addListener(Events.OnDoubleClick, new Listener<GridEvent<_Messages>>() {

@Override
public void handleEvent(GridEvent<_Messages> be) {

MessageBox.alert("open", "test", null);
}
});

sven
7 Oct 2010, 1:30 AM
You cannot do it at onle line but in two.


Listener<GridEvent<_Messages>> l = new Listener<GridEvent<_Messages>>() {

@Override
public void handleEvent(GridEvent<_Messages> be) {
if(be.getType()==Events.OnDoubleClick){
MessageBox.alert("open", "test", null);
} else if (be.getType()==Events.OnClick){
if (be.getModel() != null) {
bottom.mask("Loading mail, please wait..");
mmc.GetEmailPreview(be.getModel().getIDMessage(), bottom);
}
}
}
}

grid.addListener(Events.OnClick, l);
grid.addListener(Events.OnDoubleClick, l);

Code is untested.

mvillamor
7 Oct 2010, 2:00 AM
Hi thank you for the quick response:

I tried using your code thought it only works only one event.
But I need to catch the two events if doubleclick it will only work on double click.
But if onclick it will work onclick as well. If there is anything to add on this code.

thnx.



You cannot do it at onle line but in two.


Listener<GridEvent<_Messages>> l = new Listener<GridEvent<_Messages>>() {

@Override
public void handleEvent(GridEvent<_Messages> be) {
if(be.getType()==Events.OnDoubleClick){
MessageBox.alert("open", "test", null);
} else if (be.getType()==Events.OnClick){
if (be.getModel() != null) {
bottom.mask("Loading mail, please wait..");
mmc.GetEmailPreview(be.getModel().getIDMessage(), bottom);
}
}
}
}

grid.addListener(Events.OnClick, l);
grid.addListener(Events.OnDoubleClick, l);Code is untested.

sven
7 Oct 2010, 2:05 AM
A doubleclick will generate two clicks before. You need to change your logic to keep this inmind.

mvillamor
7 Oct 2010, 2:15 AM
sorry I weren't able to get it quickly but can you expound 'coz in our implementation we need the grid to have 2 events the double click and on click.
if I double click , on click must not be triggered . Is there any replacement for a double click event . Thnx ahead.

sven
7 Oct 2010, 2:16 AM
A doubleclick will always generate two clicks before. You can defer your click logic so it checks before if it was a doubleclick.

But i would never recommend to have two logics behind a click and a doubleclick. It is not very easy for the user to understand.

mvillamor
7 Oct 2010, 2:20 AM
Hi sven,

'Coz we have it in gwt lower version kindly check the code:
Do we have equivalent for gxt for this? Or I will use rowclick and row double click. thanks again

g.addGridRowListener(new GridRowListener() {

public void onRowClick(final GridPanel grid, int rowIndex, EventObject e) {
if (previewT == null) {
previewT = new Timer() {

@Override
public void run() {
previewT = null;
// do action

}
};
previewT.schedule(400);
}
}

public void onRowDblClick(GridPanel grid, int rowIndex, EventObject e) {
if (previewT != null) {
previewT.cancel();
previewT = null;
}
// do action

}

public void onRowContextMenu(GridPanel grid, int rowIndex, EventObject e) {
//do action
});

return g;
}

sven
7 Oct 2010, 2:22 AM
You are defering your action there too. You can even copy & paste that logic.

mvillamor
7 Oct 2010, 2:41 AM
hi I would like to give you a better scenario why Im having the two events.

click once: will load the preview at the bottom panel.
double click: will open new window.

same behavior with outlook.

Is there anything a work around on this.

thnx again.

cheers!

sven
7 Oct 2010, 2:50 AM
I already gave you how you need to implement it and you gave me the algorithm too (already coded). What else are yuo looking for?

You only need to combine the two codesnippets

mvillamor
7 Oct 2010, 7:36 AM
hello sven,

I tried the implementation you gave but still won't work. The one I gave was the gwt ext version. I just would like
to know the equivalent for addGridRowListener in gxt. Can't find exactly the listeners for gxt version.

Hope this not much to ask. thnx.

cheers!

sven
7 Oct 2010, 7:37 AM
You need to combine the logic i gave you and the logic that is within the code you gave me. You already implemented the deferring there.

mvillamor
12 Oct 2010, 1:50 AM
thnx.. i got the solution already just add timer to delayed the behaviour. thnx