I'm new to JAVA SWT, but however I managed to create a table and populate values in to the table using the contentProvider and labelProvider.
Now I want to update the status column value from not processed -->in progress-->complete based on the response returned by the server.
How can I achieve this ?
While I was googling I found display.syncExec. But when I tried this I'm getting NullPointerException.
public Thread refresh( final InvoiceShadow shadow, final GenericCommunicationResponse response, final List shadowList){
return new Thread() {
public void run() {
display.syncExec( new Runnable() {
public void run() {
refreshStatus( shadow, response,shadowList );
}
});
}
};
}
public void refreshStatus( InvoiceShadow shadow, GenericCommunicationResponse response, List shadowList ){
tableViewer.setInput(shadowList);
if(response.isSuccess()){
shadow.setStatus(new InvoiceStatusType("Varianced"));
} else {
shadow.setStatus(new InvoiceStatusType("NotVarianced"));
}
tableViewer.refresh();
}
Please help me in this and please let me know if there is any other way to update the column.
Related
I have the following ButtonCell. How do I make it respond to a click please (e.g., addClickHandler)? I have tried a number of ways I have found yet none work. None of the Window.alert return a response.
ButtonCell selectButton = new ButtonCell();
Column <HikingMeals,String> update = new Column <HikingMeals,String>(selectButton){
#Override
public String getValue(HikingMeals selectButton)
{
return "Select";
}
public void execute(HikingMeals selectButton) {
// EDIT CODE
Window.alert("Pressed");
}
//#Override
public void update(int index, HikingMeals object, String value) {
// The user clicked on the button for the passed auction.
Window.alert("Pressed2");
}
};
table.addColumn(update, "Select");
You just need to set a FieldUpdater on the update column:
update.setFieldUpdater(new FieldUpdater<HikingMeals, String>() {
#Override
public void update(int index, HikingMeals object, String value) {
Window.alert("Pressed");
}
});
Trying to make my CellTable Colum sortable but I'm not getting it to work. I'm having an MVP application which gets data from a rest service. To show the data within the table works fine but to sort is doesn't work.
public class LicenseUsageUserViewImpl<T> extends Composite implements LicenseUsageUserView<T> {
#UiTemplate("LicenseUsageUserView.ui.xml")
interface LicenseDataViewUiBinder extends UiBinder<ScrollPanel,LicenseUsageUserViewImpl> {}
private static LicenseDataViewUiBinder uiBinder = GWT.create(LicenseDataViewUiBinder.class);
#UiField
CellTable<GWTLicenseUser> licenseUserCellTable;
List<GWTLicenseUser> licenseUsers;
ListDataProvider<GWTLicenseUser> dataProvider;
public List<GWTLicenseUser> getLicenseUsers() {
return licenseUsers;
}
public void setLicenseUsers(List<GWTLicenseUser> licenseUsers) {
this.licenseUsers = licenseUsers;
}
#UiField Label header;
ListHandler<GWTLicenseUser> sortHandler;
public LicenseUsageUserViewImpl() {
initWidget(uiBinder.createAndBindUi(this));
initCellTable();
}
#Override
public void setLicenseUsersTable(List<GWTLicenseUser> tmpLicenseUsers) {
if (tmpLicenseUsers.isEmpty()) {
licenseUserCellTable.setVisible(false);
} else {
setLicenseUsers(tmpLicenseUsers);
licenseUserCellTable.setWidth("100%");
licenseUserCellTable.setVisible(true);
licenseUserCellTable.setPageSize(getLicenseUsers().size());
licenseUserCellTable.setRowCount(getLicenseUsers().size(), false);
licenseUserCellTable.setRowData(0, getLicenseUsers());
licenseUserCellTable.setVisibleRange(new Range(0, licenseUserCellTable.getRowCount()));
sortHandler.setList(getLicenseUsers());
dataProvider.getList().clear();
dataProvider.getList().addAll(getLicenseUsers());
}
}
#Override
public void initCellTable() {
sortHandler = new ListHandler<GWTLicenseUser>(getLicenseUsers());
licenseUserCellTable.addColumnSortHandler(sortHandler);
licenseUserCellTable.setWidth("100%");
licenseUserCellTable.setVisible(true);
licenseUserCellTable.setVisibleRange(new Range(0, licenseUserCellTable.getRowCount()));
// Create a data provider.
dataProvider = new ListDataProvider<GWTLicenseUser>();
// Connect the table to the data provider.
dataProvider.addDataDisplay(licenseUserCellTable);
licenseUserCellTable.setWidth("100%");
licenseUserCellTable.setAutoHeaderRefreshDisabled(true);
licenseUserCellTable.setAutoFooterRefreshDisabled(true);
// userID
TextColumn<GWTLicenseUser> userIdColumn = new TextColumn<GWTLicenseUser>() {
#Override
public String getValue(GWTLicenseUser object) {
if (object != null ){
return object.getUserId();
} else {
return "NULL";
}
}
};
userIdColumn.setSortable(true);
sortHandler.setComparator(userIdColumn, new Comparator<GWTLicenseUser>() {
#Override
public int compare(GWTLicenseUser o1, GWTLicenseUser o2) {
return o1.getUserId().compareTo(o2.getUserId());
}
});
licenseUserCellTable.addColumn(userIdColumn, "User ID");
// more column entries
licenseUserCellTable.getColumnSortList().push(userIdColumn);
licenseUserCellTable.getColumnSortList().push(countColumn);
licenseUserCellTable.addColumnSortHandler(sortHandler);
}
}
setLicenseUsersTable is called from my activity with the response list of my users. When I start my application and make a rest call my data is provide and put into my list also shown within the CellTable but its not sortable, but I have this sort icon before my colum name. I figured I post the whole code because I think its know easier to see what I'm trying to do.
Thanks for any help.
Remove this line:
sortHandler.setList(getLicenseUsers());
You already passed a List into the SortHandler constructor in
sortHandler = new ListHandler<GWTLicenseUser>(getLicenseUsers());
Also, instead of
setLicenseUsers(tmpLicenseUsers);
you may need to use
licenseUsers.addAll(tmpLicenseUsers);
I hope one of them fixes the problem.
I have a GWT CellTable that I have just moved from a PopupPresenter to a regular nested PresenterWidget. I am using GWTP.
Since moving it, the FieldUpdater on my ButtonCell is not calling the update() method at all. I have tried a test button and the same thing happens.
// edit offer
Column<OfferDto, String> buttonColumn = new Column<OfferDto, String>(new ButtonCell(IconType.PLUS, ButtonType.SUCCESS))
{
#Override
public String getValue(OfferDto object)
{
return "View/Edit";
}
};
buttonColumn.setFieldUpdater(new FieldUpdater<OfferDto, String>()
{
#Override
public void update(int index, OfferDto object, String value)
{
// NOTHING IN HERE IS BEING CALLED
System.out.println("Update called in setFieldUpdater...");
getUiHandlers().onAddCommsClick(index, object);
}
});
table.addColumn(buttonColumn);
I'm at a loss as to what could be causing it. Other regular buttons in the same View still work OK, it's just the CellTable.
This is the problem, I have a vaadin table that represent people information (for example) and when someone clicks on a row I want to extract the cellphone number.
Here is part of the code of the listener:
table_2.addListener(new ItemClickEvent.ItemClickListener() {
#Override
public void itemClick(ItemClickEvent event) { // TODOAuto-generated // method stub
String resultado = (table_2.getItem((Object)event.getItemId()))
+ "";
resultado = resultado.substring(resultado.indexOf("phone"),
resultado.indexOf("|weight"));
label_3.setValue(resultado);
}
});
It worked one time but now it doesn't. The code returns a Null, so when I try to parse the object to string it crash.
Try the following:
table.addListener(new ItemClickListener() {
#Override
public void itemClick(ItemClickEvent event) {
Property itemProperty = event.getItem().getItemProperty("cellphone");
itemProperty.getValue(); // TODO: Do something with this value.
}
});
#Before public void setUp() {
Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();
ApplicationLauncher.application("myApp").start();
Pause.pause(5, TimeUnit.SECONDS);
frame = WindowFinder.findFrame("frame0").using(robot);
JTableFixture table = frame.table(new GenericTypeMatcher<JTable>(JTable.class) {
#Override protected boolean isMatching(JTable table) {
return (table instanceof myTreeTable);
}
});
}
This code works well. If we remove the 5 seconds pause, then the table is not found because it takes some seconds to the app to load it.
I would like to know if there is a cleaner way of doing it. I tried with robot.waitForIdle() after ApplicationLauncher (I guess once EDT is empty, everything is loaded), but it just doesn´t work.
I know pause can use some conditions as an event on when to stop, but I don´t understand how to write it since JavaDoc and official doc is poor.
Pause.pause(WaitForComponentToShowCondition.untilIsShowing(frame.component())) : I need a component, if I pass the wrapper frame it does not work. And I cannot pass the table because thats precisely what I am waiting for to get.
I understand then I should probably work with ComponentFoundCondition but I dont get it! I tired with:
ComponentMatcher matcher = new GenericTypeMatcher<JTable>(JTable.class) {
#Override protected boolean isMatching(JTable table) {
return (table instanceof myTreeTable);
}
};
Pause.pause(new ComponentFoundCondition("DebugMsg", frame.robot.finder(), matcher));
Any help?
You could use ComponentFinder to locate the component. For example, based on the matcher in the question:
final ComponentMatcher matcher = new TypeMatcher(myTreeTable.class);
Pause.pause(new Condition("Waiting for myTreeTable") {
#Override
public boolean test() {
Collection<Component> list =
window.robot.finder().findAll(window.target, matcher);
return list.size() > 0;
}
}, 5000);
Here is an alternative with lookup by name:
final ComponentMatcher nameMatcher = new ComponentMatcher(){
#Override
public boolean matches(Component c) {
return "ComponentName".equals(c.getName()) && c.isShowing();
}
};
Pause.pause(new Condition("Waiting") {
#Override
public boolean test() {
Collection<Component> list =
window.robot.finder().findAll(window.target, nameMatcher);
return list.size() > 0;
}
}, 5000);