Tuesday, May 1, 2012

Re: how to make a clickable image cell?

Let's say I created this for my AbstractCell:
sb.appendHtmlConstant("<div class = 'contactCell'>");
sb.appendHtmlConstant("<table>");      
sb.appendHtmlConstant("<tr>");
sb.appendHtmlConstant("<td id = contactId'>");    
sb.appendHtmlConstant("John Doe");    
sb.appendHtmlConstant("</td>");
sb.appendHtmlConstant("<td id = contactImage rowspan='3'>");    
sb.appendHtmlConstant("<img src = some_imge_url width=60 height=60>");
sb.appendHtmlConstant("</td>");
sb.appendHtmlConstant("</tr>");
sb.appendHtmlConstant("</table>");
sb.appendHtmlConstant("</div>");

Then, if I want the image to respond, I can check it by doing this:
EventTarget eventTarget = event.getEventTarget();
if(eventTarget.toString().contains("<td id=\"contactImage\">") && !eventTarget.toString().contains("<div class")){        
           Window.alert("image clicked!");
}else if(eventTarget.toString().contains("<td id=\"contactId\">") && !eventTarget.toString().contains("<div class")){         
           Window.alert("id clicked!");
}

Just try printing out eventTarget, then you'll see what kind of response you get when you click on the cell


On Mon, Apr 30, 2012 at 10:59 AM, Kei Kei <tong123123@gmail.com> wrote:
my method is similar to you, but I found one problem using these kind of method, the respond to click event is hard coded in
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater)
for example,
if I create an instance of HeaderCell() headerCell1, and then I create another instance headerCell2, click on these two instances will have the same response hard code in the class HeaderCell().
// do something if it's indeed the image that was clicked
what should I do if I want click on each instance of HeaderCell() will have its custom logic?



On Wed, Apr 25, 2012 at 4:10 PM, Interbooker App <interbookerapp@gmail.com> wrote:

I'm not really sure if this is the best implementation, but it works for me. -- First, add this to your constructor:

  public HeaderCell() {

   
super("click", "keydown");
}

-- Then, override the onBrowserEvent:

  @Override
   
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
     
// Let AbstractCell handle the keydown event.

     
super.onBrowserEvent(context, parent, value, event, valueUpdater);
 
     
// Handle the click event.
     
if ("click".equals(event.getType())) {
       
EventTarget eventTarget = event.getEventTarget();
       
// in here we check whether the cell that was being clicked is an image, not the entire cell
       
if(eventTarget.toString().contains("img src") && !eventTarget.toString().contains("<div class")){
           
// do something if it's indeed the image that was clicked
       
}
     
}
   
}

Cheers, Lin


On Fri, Apr 20, 2012 at 10:38 AM, tong123123 <tong123123@gmail.com> wrote:
I found the answer finally, I wrongly import the
com.google.gwt.user.client.Element;
instead of
com.google.gwt.dom.client.Element;

On Friday, April 20, 2012 4:14:44 PM UTC+8, tong123123 wrote:
I got some insight but still not clear, it show that

public void onBrowserEvent(Context context, Element parent, String value,
        NativeEvent event, ValueUpdater<String> valueUpdater)

in ClickableImageCell2 is not override

public void onBrowserEvent(Context context, Element parent, C value,
      NativeEvent event, ValueUpdater<C> valueUpdater)
in AbstractCell,
but why in the api,
http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/cell/client/AbstractCell.html#onBrowserEvent%28com.google.gwt.cell.client.Cell.Context,%20com.google.gwt.dom.client.Element,%20C,%20com.google.gwt.dom.client.NativeEvent,%20com.google.gwt.cell.client.ValueUpdater%29

Class ContactCell,

@Override      public void onBrowserEvent(Context context, Element parent, Contact value,          NativeEvent event, ValueUpdater<Contact> valueUpdater) 

is override of AbstractCell?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/nImJY4gKNjcJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment