Button newGroupButton = new Button("New...");
newGroupButton.setTitle("Create a New Group");
newGroupButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final UserGroup group = new UserGroup();
group.setOwner(user);
editGroupPanel = new EditGroupPanel(callback, EditGroupsPanel.this, users, group, false, true);
final PromptDialogBox editGroupDialogBox = new PromptDialogBox("Create New Group", "OK", null, "Cancel", false, true);
editGroupDialogBox.setContent(editGroupPanel);
editGroupDialogBox.setCallback(new IDialogCallback() {
public void okPressed() {
if (!editGroupPanel.apply()) {
editGroupDialogBox.center();
} else {
populateUI();
if (callback != null) {
callback.userGroupsFetched(groups);
}
}
}
public void cancelPressed() {
}
});
editGroupDialogBox.center();
}
});
deleteGroupButton.setTitle("Delete Group");
deleteGroupButton.setEnabled(false);
deleteGroupButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (groupsList.getSelectedIndex() < 0) {
return;
}
final UserGroup group = groupMap.get(groupsList.getItemText(groupsList.getSelectedIndex()));
final PromptDialogBox deleteGroupDialogBox = new PromptDialogBox("Confirm", "Yes", null, "No", false, true);
deleteGroupDialogBox.setContent(new Label("Delete Group: " + group.getName() + "?"));
deleteGroupDialogBox.setCallback(new IDialogCallback() {
public void okPressed() {
final AsyncCallback<Void> deleteGroupCallback = new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
MessageDialogBox dialog = new MessageDialogBox("Error", caught.getMessage(), true, true, true);
dialog.center();
}
public void onSuccess(Void nothing) {
groups.remove(group);
lastListSelection = null;
populateUI();
if (callback != null) {
callback.userGroupsFetched(groups);
}
};
};
BaseServiceCache.getService().deleteGroup(group, deleteGroupCallback);
}
public void cancelPressed() {
}
});
deleteGroupDialogBox.center();
}
});
editGroupButton.setTitle("Edit Group Settings");
editGroupButton.setEnabled(false);
editGroupButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (groupsList.getSelectedIndex() < 0) {
return;
}
final UserGroup group = groupMap.get(groupsList.getItemText(groupsList.getSelectedIndex()));
editGroupPanel = new EditGroupPanel(callback, EditGroupsPanel.this, users, group, false, true);
final PromptDialogBox editGroupDialogBox = new PromptDialogBox("Edit Group", "OK", null, "Cancel", false, true);
editGroupDialogBox.setContent(editGroupPanel);
editGroupDialogBox.setCallback(new IDialogCallback() {
public void okPressed() {