Friday, August 1, 2014

Re: DialogBox centering with UiBinder & DataGrid programmatic sorting

About center the dialog. Call the center method using scheduleDeferred.


2014-08-01 6:50 GMT-03:00 Jack Thompson <re6dghrt@gmail.com>:
Hello,

I have a dialog class inherited from DialogBox and using UiBinder template as the widget for it, which is set in the constructor setWidget(uiBinder.createAndBindUi(this)). When the a dialog class instance is shown using the center() method, the dialog is shown but it is not properly centered, the top left corner of the dialog is at the exact center of the browser window. If the same instance is shown second time, only then it is centered as it should.

Second problem I have encountered is that I am not able to get DataGrid sorting working programmatically. With the below code the DataGrid appears with showing a list of usernames. The DataGrid header shows the sorting triangle pointing upwards as if it were sorted, but the rows are in the order as they were in the original list. However if the sorting triangle is clicked on the header, the sorting works as it should. It's just that it does not work when sorted programmatically.

public class AdministrationView extends Composite {


private static AdministrationViewUiBinder uiBinder = GWT.create(AdministrationViewUiBinder.class);

interface AdministrationViewUiBinder extends UiBinder<Widget, AdministrationView> {}


private TextColumn<User> tableColumn;

private Header<String> tableHeader;

private ListDataProvider<User> tableDataProvider;

private ListHandler<User> tableListHandler;


@UiField(provided = true) DataGrid<User> adminUsersTable;


public AdministrationView() {

setUpAdminUsersTable();

initWidget(uiBinder.createAndBindUi(this));

}


public void setAdminUserList(List<User> adminList) {

tableDataProvider.getList().clear();

tableDataProvider.getList().addAll(adminList);

if(tableListHandler == null) {

tableListHandler = new ListHandler<User>(tableDataProvider.getList());

tableListHandler.setComparator(tableColumn, new User.UsernameComparator());

adminUsersTable.addColumnSortHandler(tableListHandler);

}

adminUsersTable.getColumnSortList().push(tableColumn);

}


private void setUpAdminUsersTable() {

adminUsersTable = new DataGrid<User>();

adminUsersTable.setSize("100%", "100%");

tableColumn = new TextColumn<User>() {

@Override

public String getValue(User object) {

return object.username;

}

};

tableColumn.setSortable(true);

tableHeader = new Header<String>(new TextCell()) {

@Override

public String getValue() {

return "User accounts";

}

};

adminUsersTable.addColumn(tableColumn, tableHeader);

adminUsersTable.setColumnWidth(0, 100, Unit.PCT);

tableDataProvider = new ListDataProvider<User>();

tableDataProvider.addDataDisplay(adminUsersTable);

}

}


public class User {


public static class UsernameComparator implements Comparator<User> {

@Override

public int compare(User u1, User u2) {

String name1 = u1 == null ? null : u1.username;

String name2 = u2 == null ? null : u2.username;

name1 = name1 == null ? "" : name1;

name2 = name2 == null ? "" : name2;

return name1.compareToIgnoreCase(name2);

}

}


public Long userId;

public String username;


}



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment