How do i make my FlexTable to implement OnClick event and PopUpPanel?

87 views
Skip to first unread message

AmaraSat

unread,
Jan 18, 2011, 4:06:34 PM1/18/11
to Google Web Toolkit
Hello everyone,

I am seeing so many examples all over the group, but my case is
different. Below is the code i have. I want to implement a situation
when a user clicks on my FlexTable i want to display a popup depending
on which row he clicks.

package com.google.gwt.sample.webapplication.client;

public class IntuneWebApplication implements EntryPoint {

private static final int REFRESH_INTERVAL = 15000;
private VerticalPanel mainPanel = new VerticalPanel();
private FlexTable propertyDisplayTable = new FlexTable();

public void onModuleLoad() {

propertyDisplayTable.setText(0, 0, "PropertyTag");
propertyDisplayTable.setText(0, 1, "Value");
propertyDisplayTable.setText(0, 2, "Remove");

Image UpdateImage4 = new Image("./images/redm.png");
propertyDisplayTable.setWidget(1, 2, UpdateImage4);

mainPanel.add(propertyDisplayTable);
}

private void refreshPropertyList() {
UpdateImage = new Image("./images/redm.png");
propertyDisplayTable.add(UpdateImage);
}
Message has been deleted
Message has been deleted

Ryan Mehregan

unread,
Jan 18, 2011, 4:15:49 PM1/18/11
to google-we...@googlegroups.com
if you are planning to populate your table with Data Objects,
I think it would be better to look into new Google Data Presentation
Widgets.

Cell Table for example has the feature you want, and many more, there
are code samples available too.

http://code.google.com/webtoolkit/doc/latest/DevGuideUiCellWidgets.html#celltable

Ryan

AmaraSat

unread,
Jan 18, 2011, 5:20:03 PM1/18/11
to Google Web Toolkit
I appreciate your suggestion, i am fine for now with the FlexTable.

**I was able to populate the rows and columns with data i am receiving
from an RPC call.
**i was able to update widgets in it depending on the data., in my
above code i have a FlexTable propertyDisplayTable, it is a global
variable. I want to implement an OnClick event for this table. From
the groups i see i need to implement a class of type FlexTable and
then proceed form there, this is what i have done:


package com.google.gwt.sample.webapplication.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.*;

/**
* A sample to show problems with trying to get the state of the
modifier
* keys during a click.
*/
public class WebApplication extends FlexTable
implements EntryPoint, ClickListener {

private static final int REFRESH_INTERVAL = 5000;
private String[] data = new String[] {
"Thelonious Monk",
"Misterioso",
"Jelly Roll Morton",
"Fickle Fay Creep",
"Sonny Rollins",
"EE-AH",
"Art Blakey and the Jazz Messengers",
"Ping Pong",
"Mose Allison",
"Mojo Woman"
};

public WebApplication() {
// Put some data into the table
for(int r=0; r<5; r++) {
for(int c=0; c<2; c++) {
// each cell in the table is a Label
that uses click notifications
Label cellLabel = new
RowLabel( data[(r*2) + c], r );
cellLabel.addClickListener(this);
this.setWidget(r, c, cellLabel);
}
}
}

/*
* It would be nice to be able to get the Event inside this
function...
*/
public void onClick(Widget sender) {
if( sender instanceof RowLabel ) {
GWT.log("onClick fired, row clicked: " +
Integer.toString(((RowLabel)sender).getRow()), null);
}
}

/*
* ...since this is fired after onClick; we can always set up
variables
* and wait for this to be called.
*/
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);

GWT.log("onBrowserEvent fired; modifiers: "
+ (DOM.eventGetAltKey(event) ? "ALT
" : "")
+ (DOM.eventGetCtrlKey(event) ? "CTRL
" : "")
+ (DOM.eventGetShiftKey(event) ?
"SHIFT " : ""),
null);
}

public void onModuleLoad() {
RootPanel.get("heatRateList").add(new
WebApplication());

Timer refreshTimer = new Timer() {
@Override
public void run() {
refreshPropertyList();
}
};
refreshTimer.scheduleRepeating(REFRESH_INTERVAL);
}

protected void refreshPropertyList() {
// TODO Auto-generated method stub
Label Updatelabel = new Label();
//WebApplication.setWidget(1, 2, UpdateImage4);
}

private class RowLabel extends Label {
int row;
public RowLabel(String text, int row) {
super(text);
this.row = row;
}

public int getRow() {
return row;
}
}
}


here the OnClick is working and i was able to know which row has been
clicked, but the commented out line

WebApplication.setWidget(1, 2, Updatelabel);

is not working it says

Cannot make a static reference to the non-static method setWidget(int,
int, Widget) from the type HTMLTable, it was not able to access the
table, now the question is How do i update the row of the table, the
table is inside the panel "RootPanel", how do i get the table out of
it and update its row?
> http://code.google.com/webtoolkit/doc/latest/DevGuideUiCellWidgets.ht...
>
> Ryan

AmaraSat

unread,
Jan 19, 2011, 11:12:31 AM1/19/11
to Google Web Toolkit
Solved Thanks!!

Just modified the class to implement ClickHandler

Captured the onClick event to get the x and y coordinates

tatsit!!
Reply all
Reply to author
Forward
0 new messages