use of cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUserForAppFormGui in project perun by CESNET.
the class UsersApplicationsPage method refresh.
/**
* Refresh the page
*/
private void refresh() {
bodyContents.clear();
String user = "";
if (session.getUser() != null) {
user = this.session.getUser().getFullNameWithTitles().trim();
} else {
PerunPrincipal pp = session.getPerunPrincipal();
if (!pp.getAdditionInformations("displayName").equals("")) {
user = pp.getAdditionInformations("displayName");
} else if (!pp.getAdditionInformations("cn").equals("")) {
user = pp.getAdditionInformations("cn");
} else {
if (pp.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
user = Utils.convertCertCN(pp.getActor());
} else {
user = pp.getActor();
}
}
}
bodyContents.add(new HTML("<h1>" + ApplicationMessages.INSTANCE.applicationsForUser(user) + "</h1>"));
// callback
int userId = 0;
if (session.getUser() != null) {
userId = session.getUser().getId();
}
final GetApplicationsForUserForAppFormGui req = new GetApplicationsForUserForAppFormGui(userId);
final ListBox listBox = new ListBox();
req.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Application> appls = JsonUtils.jsoAsList(jso);
ArrayList<String> vos = new ArrayList<String>();
for (Application app : appls) {
if (!vos.contains(app.getVo().getName())) {
vos.add(app.getVo().getName());
}
}
Collections.sort(vos);
for (String s : vos) {
listBox.addItem(s);
}
if (listBox.getItemCount() > 0) {
listBox.insertItem(WidgetTranslation.INSTANCE.listboxAll(), 0);
}
for (int i = 0; i < listBox.getItemCount(); i++) {
if (listBox.getItemText(i).equals(ApplicationFormGui.getVo().getName())) {
listBox.setSelectedIndex(i);
req.filterTable(ApplicationFormGui.getVo().getName());
break;
}
}
}
@Override
public void onError(PerunError error) {
}
@Override
public void onLoadingStart() {
listBox.clear();
}
});
req.setCheckable(false);
listBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (listBox.getSelectedIndex() > 0) {
req.filterTable(listBox.getItemText(listBox.getSelectedIndex()));
} else {
// show all
req.filterTable("");
}
}
});
final TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(new HTML("<strong>" + ApplicationMessages.INSTANCE.filterByVo() + ":</strong>"));
tabMenu.addWidget(listBox);
tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
tabMenu.addWidget(new HTML("<strong>" + ApplicationMessages.INSTANCE.clickOnApplicationToSee() + "</strong>"));
tabMenu.addStyleName("tabMenu");
final VerticalPanel applicationsWrapper = new VerticalPanel();
applicationsWrapper.setSize("100%", "100%");
applicationsWrapper.add(tabMenu);
final CellTable<Application> appsTable = req.getTable(new FieldUpdater<Application, String>() {
public void update(int index, Application object, String value) {
applicationsWrapper.clear();
applicationsWrapper.add(backButton);
applicationsWrapper.add(getApplicationDetailWidget(object));
}
});
appsTable.addStyleName("perun-table");
applicationsWrapper.add(appsTable);
backButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
applicationsWrapper.clear();
applicationsWrapper.add(tabMenu);
applicationsWrapper.add(appsTable);
}
});
bodyContents.add(applicationsWrapper);
}
Aggregations