use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class GroupResourceRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings for " + Utils.getStrippedStringWithEllipsis(resource.getName()));
if (JsonUtils.isExtendedInfoVisible()) {
columnId = 3;
} else {
columnId = 2;
}
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final Label facilityId = new Label();
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Facility fac = (Facility) jso;
facilityId.setText(String.valueOf(fac.getId()));
}
};
GetFacility facility = new GetFacility(resourceId, events);
facility.retrieveData();
mainTab.add(new HTML("<hr size=\"2px\" />"));
// set attributes type to group_resource
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("group", groupId);
// gets all required group attributes for specified group and resource
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
reqAttrsTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// get all required group_resource attributes too
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
final ListBoxWithObjects<RichMember> listBox = new ListBoxWithObjects<RichMember>();
listBox.setTitle(WidgetTranslation.INSTANCE.selectingMember());
// local event fills the listBox
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
mems = new TableSorter<RichMember>().sortByName(mems);
listBox.addNotSelectedOption();
for (int i = 0; i < mems.size(); i++) {
listBox.addItem(mems.get(i));
}
listBox.addAllOption();
}
};
final GetGroupRichMembers getGroupRichMembers = new GetGroupRichMembers(groupId, localEvents);
getGroupRichMembers.retrieveData();
reqAttrsTable.addStyleName("perun-table");
final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
sp.addStyleName("perun-tableScrollPanel");
// store for column with values
final Column<Attribute, ?> columnStore = reqAttrsTable.getColumn(columnId);
listBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int selectedIndex = listBox.getSelectedIndex();
// no member selected
if (selectedIndex == 0) {
// offer just group and group resource attributes
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get groups attributes
ids.put("group", groupId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// get group_resource attributes
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
reqAttrs.sortTable();
// some member is selected
} else {
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get member, member-resource, user, user-facility attributes
ids.put("member", listBox.getSelectedObject().getId());
ids.put("resource", resourceId);
// to get user, user-facility attrs
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// all members are selected
if (selectedIndex == 1) {
// remove value column
reqAttrsTable.removeColumn(columnId);
// create own value column
// Value column
Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {
public Attribute getValue(Attribute attribute) {
attribute.setValueAsJso(null);
return attribute;
}
}, new FieldUpdater<Attribute, Attribute>() {
public void update(int index, Attribute object, Attribute value) {
object = value;
reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
}
});
// add to table
reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
} else {
// member selected
// return original column
reqAttrsTable.removeColumn(columnId);
reqAttrsTable.insertColumn(columnId, columnStore, "Value");
}
}
}
});
CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// send lists
ArrayList<Attribute> groupList = new ArrayList<Attribute>();
ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> memberList = new ArrayList<Attribute>();
ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> userList = new ArrayList<Attribute>();
ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
SetAttributes request = new SetAttributes();
int selectedIndex = listBox.getSelectedIndex();
// if all selected
if (selectedIndex == 1) {
// TODO - USE NEW CONFIRM DESIGN
if (!Window.confirm("Same values for selected attributes will be set to all members in group." + "\n\nDo you want to continue ?")) {
return;
}
}
// get different attributes
for (Attribute attr : list) {
if (attr.getNamespace().contains("urn:perun:group:")) {
groupList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
groupResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member:")) {
memberList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member_resource:")) {
memberResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user:")) {
userList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user_facility:")) {
userFacilityList.add(attr);
}
}
// if not empty, send request
if (!(groupList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
request.setAttributes(ids, groupList);
}
if (!(groupResourceList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
ids.put("resource", resourceId);
request.setAttributes(ids, groupResourceList);
}
if (!(memberList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberList);
}
} else {
// for one member
ids.clear();
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberList);
}
}
if (!(memberResourceList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("resource", resourceId);
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberResourceList);
}
} else {
// for one member
ids.clear();
ids.put("resource", resourceId);
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberResourceList);
}
}
if (!(userList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", (listBox.getObjectAt(i)).getUser().getId());
request.setAttributes(ids, userList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
request.setAttributes(ids, userList);
}
}
if (!(userFacilityList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", listBox.getObjectAt(i).getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
}
reqAttrs.clearTableSelectedSet();
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
saveChangesButton.setEnabled(false);
menu.addWidget(new HTML("<strong>Group members:</strong>"));
menu.addWidget(listBox);
// table content
session.getUiElements().resizePerunTable(sp, 350, this);
mainTab.add(menu);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
mainTab.setCellHeight(menu, "30px");
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class AddGroupManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// pass empty items to menu to ensure drawing of rest
tabMenu.addWidget(UiElements.getRefreshButton(this));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(3, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(4, box);
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
final TabItem tab = this;
tabMenu.addWidget(2, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class AddFacilityManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// pass empty items to menu to ensure drawing of rest
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(2, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(3, box);
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
final TabItem tab = this;
tabMenu.addWidget(1, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// if (refreshEvents != null) refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class PublicationDetailTabItem method draw.
public Widget draw() {
// show only part of title
titleWidget.setText(Utils.getStrippedStringWithEllipsis(publication.getTitle()));
// MAIN PANEL
ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
VerticalPanel vp = new VerticalPanel();
vp.addStyleName("perun-table");
sp.add(vp);
// resize perun table to correct size on screen
session.getUiElements().resizePerunTable(sp, 350, this);
// content
final FlexTable ft = new FlexTable();
ft.setStyleName("inputFormFlexTable");
if (!publication.isLocked()) {
ft.setHTML(1, 0, "Id / Origin:");
ft.setHTML(2, 0, "Title:");
ft.setHTML(3, 0, "Year:");
ft.setHTML(4, 0, "Category:");
ft.setHTML(5, 0, "Rank:");
ft.setHTML(6, 0, "ISBN / ISSN:");
ft.setHTML(7, 0, "DOI:");
ft.setHTML(8, 0, "Full cite:");
ft.setHTML(9, 0, "Created by:");
ft.setHTML(10, 0, "Created date:");
for (int i = 0; i < ft.getRowCount(); i++) {
ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
ft.getFlexCellFormatter().setWidth(1, 0, "100px");
final ListBoxWithObjects<Category> listbox = new ListBoxWithObjects<Category>();
// fill listbox
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
for (Category cat : JsonUtils.<Category>jsoAsList(jso)) {
listbox.addItem(cat);
// if right, selected
if (publication.getCategoryId() == cat.getId()) {
listbox.setSelected(cat, true);
}
}
}
};
GetCategories categories = new GetCategories(events);
categories.retrieveData();
final TextBox rank = new TextBox();
rank.setWidth("30px");
rank.setMaxLength(4);
rank.setText(String.valueOf(publication.getRank()));
final TextBox title = new TextBox();
title.setMaxLength(1024);
title.setText(publication.getTitle());
title.setWidth("500px");
final TextBox year = new TextBox();
year.setText(String.valueOf(publication.getYear()));
year.setMaxLength(4);
year.setWidth("30px");
final TextBox isbn = new TextBox();
isbn.setText(publication.getIsbn());
isbn.setMaxLength(32);
final TextBox doi = new TextBox();
doi.setText(publication.getDoi());
doi.setMaxLength(256);
final TextArea main = new TextArea();
main.setText(publication.getMain());
main.setSize("500px", "70px");
// set max length
main.getElement().setAttribute("maxlength", "4000");
ft.setHTML(1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + SafeHtmlUtils.fromString(publication.getPublicationSystemName()).asString());
ft.setWidget(2, 1, title);
ft.setWidget(3, 1, year);
ft.setWidget(4, 1, listbox);
if (session.isPerunAdmin()) {
// only perunadmin can change rank
ft.setWidget(5, 1, rank);
} else {
ft.setHTML(5, 1, SafeHtmlUtils.fromString(String.valueOf(publication.getRank()) + "").asString());
}
ft.setWidget(6, 1, isbn);
ft.setWidget(7, 1, doi);
ft.setWidget(8, 1, main);
ft.setHTML(9, 1, SafeHtmlUtils.fromString((publication.getCreatedBy() != null) ? publication.getCreatedBy() : "").asString());
ft.setHTML(10, 1, SafeHtmlUtils.fromString((String.valueOf(publication.getCreatedDate()) != null) ? String.valueOf(publication.getCreatedDate()) : "").asString());
// update button
final CustomButton change = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in publication details");
change.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Publication pub = JsonUtils.clone(publication).cast();
if (!JsonUtils.checkParseInt(year.getText())) {
JsonUtils.cantParseIntConfirm("YEAR", year.getText());
} else {
pub.setYear(Integer.parseInt(year.getText()));
}
if (session.isPerunAdmin()) {
pub.setRank(Double.parseDouble(rank.getText()));
}
pub.setCategoryId(listbox.getSelectedObject().getId());
pub.setTitle(title.getText());
pub.setMain(main.getText());
pub.setIsbn(isbn.getText());
pub.setDoi(doi.getText());
UpdatePublication upCall = new UpdatePublication(JsonCallbackEvents.disableButtonEvents(change, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// refresh page content
Publication p = jso.cast();
publication = p;
draw();
}
}));
upCall.updatePublication(pub);
}
});
ft.setWidget(0, 0, change);
} else {
ft.getFlexCellFormatter().setColSpan(0, 0, 2);
ft.setWidget(0, 0, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " <strong>Publication is locked. Ask administrator to perform any changes for you at meta@cesnet.cz.</strong>"));
ft.setHTML(1, 0, "Id / Origin:");
ft.setHTML(2, 0, "Title:");
ft.setHTML(3, 0, "Year:");
ft.setHTML(4, 0, "Category:");
ft.setHTML(5, 0, "Rank:");
ft.setHTML(6, 0, "ISBN / ISSN:");
ft.setHTML(7, 0, "DOI:");
ft.setHTML(8, 0, "Full cite:");
ft.setHTML(9, 0, "Created by:");
ft.setHTML(10, 0, "Created date:");
for (int i = 0; i < ft.getRowCount(); i++) {
ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
ft.getFlexCellFormatter().setWidth(1, 0, "100px");
ft.setHTML(1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + SafeHtmlUtils.fromString(publication.getPublicationSystemName()).asString());
ft.setHTML(2, 1, SafeHtmlUtils.fromString((publication.getTitle() != null) ? publication.getTitle() : "").asString());
ft.setHTML(3, 1, SafeHtmlUtils.fromString((String.valueOf(publication.getYear()) != null) ? String.valueOf(publication.getYear()) : "").asString());
ft.setHTML(4, 1, SafeHtmlUtils.fromString((publication.getCategoryName() != null) ? publication.getCategoryName() : "").asString());
ft.setHTML(5, 1, SafeHtmlUtils.fromString(String.valueOf(publication.getRank()) + " (default is 0)").asString());
ft.setHTML(6, 1, SafeHtmlUtils.fromString((publication.getIsbn() != null) ? publication.getIsbn() : "").asString());
ft.setHTML(7, 1, SafeHtmlUtils.fromString((publication.getDoi() != null) ? publication.getDoi() : "").asString());
ft.setHTML(8, 1, SafeHtmlUtils.fromString((publication.getMain() != null) ? publication.getMain() : "").asString());
ft.setHTML(9, 1, SafeHtmlUtils.fromString((publication.getCreatedBy() != null) ? publication.getCreatedBy() : "").asString());
ft.setHTML(10, 1, SafeHtmlUtils.fromString((String.valueOf(publication.getCreatedDate()) != null) ? String.valueOf(publication.getCreatedDate()) : "").asString());
}
if (session.isPerunAdmin()) {
final CustomButton lock;
if (publication.isLocked()) {
lock = new CustomButton("Unlock", "Allow editing of publication details (for users).", SmallIcons.INSTANCE.lockOpenIcon());
ft.setWidget(0, 0, lock);
ft.getFlexCellFormatter().setColSpan(0, 0, 1);
ft.setWidget(0, 1, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " Publication is locked."));
} else {
lock = new CustomButton("Lock", "Deny editing of publication details (for users).", SmallIcons.INSTANCE.lockIcon());
ft.setWidget(0, 1, lock);
}
lock.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
LockUnlockPublications upCall = new LockUnlockPublications(JsonCallbackEvents.disableButtonEvents(lock, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// refresh page content
publication.setLocked(!publication.isLocked());
draw();
}
}));
Publication p = JsonUtils.clone(publication).cast();
upCall.lockUnlockPublication(!publication.isLocked(), p);
}
});
}
DisclosurePanel dp = new DisclosurePanel();
dp.setWidth("100%");
dp.setContent(ft);
dp.setOpen(true);
FlexTable detailsHeader = new FlexTable();
detailsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookIcon()));
detailsHeader.setHTML(0, 1, "<h3>Details</h3>");
dp.setHeader(detailsHeader);
vp.add(dp);
vp.add(loadAuthorsSubTab());
vp.add(loadThanksSubTab());
this.contentWidget.setWidget(sp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class AddUserExtSourceTabItem method draw.
public Widget draw() {
titleWidget.setText("Add ext. identity");
VerticalPanel vp = new VerticalPanel();
// get available ext sources
final ListBoxWithObjects<ExtSource> extSourcesDropDown = new ListBoxWithObjects<ExtSource>();
final TextBox externalLogin = new TextBox();
final TextBox loaTextBox = new TextBox();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add external identity to user");
// fill listbox
JsonCallbackEvents fillEvent = new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
extSourcesDropDown.clear();
extSourcesDropDown.addItem("Error while loading");
callDone = false;
}
@Override
public void onFinished(JavaScriptObject jso) {
extSourcesDropDown.clear();
ArrayList<ExtSource> list = JsonUtils.jsoAsList(jso);
list = new TableSorter<ExtSource>().sortByName(list);
if (list == null || list.isEmpty()) {
extSourcesDropDown.addItem("No external sources available");
return;
}
for (ExtSource ex : list) {
extSourcesDropDown.addItem(ex);
}
callDone = true;
if (!externalLogin.getText().isEmpty() && !extSourcesDropDown.isEmpty() && JsonUtils.checkParseInt(loaTextBox.getText()) && callDone) {
addButton.setEnabled(true);
}
}
@Override
public void onLoadingStart() {
extSourcesDropDown.clear();
extSourcesDropDown.addItem("Loading...");
callDone = false;
}
};
// callback
final GetExtSources extSources = new GetExtSources(fillEvent);
extSources.retrieveData();
// create layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
layout.setHTML(0, 0, "External login:");
layout.setWidget(0, 1, externalLogin);
layout.setHTML(1, 0, "External source:");
layout.setWidget(1, 1, extSourcesDropDown);
layout.setHTML(2, 0, "Level of Assurance:");
layout.setWidget(2, 1, loaTextBox);
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.setStyleName(i, 0, "itemName");
}
cellFormatter.setStyleName(3, 1, "inputFormInlineComment");
layout.setHTML(3, 1, "0 - not verified = default</br>1 - verified email</br>2 - verified identity</br>3 - verified identity, strict password strength");
TabMenu menu = new TabMenu();
// close tab events
final JsonCallbackEvents addExtSrcEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, this, true);
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ExtSource selected = extSourcesDropDown.getObjectAt(extSourcesDropDown.getSelectedIndex());
String login = externalLogin.getText();
AddUserExtSource request = new AddUserExtSource(addExtSrcEvents);
int loa = 0;
if (JsonUtils.checkParseInt(loaTextBox.getText())) {
loa = Integer.parseInt(loaTextBox.getText());
} else {
JsonUtils.cantParseIntConfirm("Level of Assurance", loaTextBox.getText());
return;
}
request.addUserExtSource(userId, login.trim(), selected, loa);
}
});
addButton.setEnabled(false);
menu.addWidget(addButton);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
KeyUpHandler handler = new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
if (!externalLogin.getText().isEmpty() && !extSourcesDropDown.isEmpty() && JsonUtils.checkParseInt(loaTextBox.getText()) && callDone) {
addButton.setEnabled(true);
} else {
addButton.setEnabled(false);
}
}
};
externalLogin.addKeyUpHandler(handler);
loaTextBox.addKeyUpHandler(handler);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations