use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class UiElements method runResizeCommandsForCurrentTab.
/**
* Runs resize commands for the active tab
*/
public static void runResizeCommandsForCurrentTab() {
if (PerunWebSession.getInstance().getTabManager() == null) {
return;
}
TabItem activeTab = PerunWebSession.getInstance().getTabManager().getActiveTab();
TabItem activeOverlayTab = PerunWebSession.getInstance().getTabManager().getActiveOverlayTab();
// if no active tab, do nothing
if (activeTab != null) {
runResizeCommands(activeTab);
}
// if no active overlay tab, do nothing
if (activeOverlayTab != null) {
runResizeCommands(activeOverlayTab);
}
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddMemberToResourceTabItem method draw.
@Override
public Widget draw() {
this.titleWidget.setText("Add member(s) to resource");
final TabItem tab = this;
if (state == State.SELECT_MEMBERS) {
this.contentWidget.clear();
session.getTabManager().changeStyleOfInnerTab(true);
// main tab
FlexTable hp = new FlexTable();
hp.setSize("100%", "100%");
hp.setCellPadding(5);
// members list
VerticalPanel membersListPanel = new VerticalPanel();
membersListPanel.setSize("100%", "100%");
TabMenu membersListMenu = new TabMenu();
membersListPanel.add(membersListMenu);
membersListPanel.setCellHeight(membersListMenu, "30px");
// members list callback
final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
membersListMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
if (UiElements.searchStingCantBeEmpty(text)) {
findMembers.searchFor(text);
}
}
}, ButtonTranslation.INSTANCE.searchMemberInVo());
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected members to list", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
ArrayList<RichMember> list = findMembers.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
selectedMembers.addItems(list);
findMembers.clearTableSelectedSet();
}
}
});
membersListMenu.addWidget(addButton);
membersListMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab);
}
}));
final CustomButton continueButton = TabMenu.getPredefinedButton(ButtonType.CONTINUE, "Continue to resource selection", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// change state
state = State.SELECT_RESOURCE_OR_FACILITY;
// redraw the page
tab.draw();
}
});
membersListMenu.addWidget(continueButton);
// if no member selected, disable
if (selectedMembers.getList().size() == 0) {
continueButton.setEnabled(false);
}
// selection of some member will enable continue button
selectedMembers.setEvents(new AddRemoveItemsTable.HandleItemsAction<RichMember>() {
@Override
public void onAdd(RichMember object) {
continueButton.setEnabled(true);
}
@Override
public void onRemove(RichMember object) {
if (selectedMembers.getList().size() == 0) {
continueButton.setEnabled(false);
}
}
});
// put table in content
ScrollPanel tableWrapper = new ScrollPanel();
tableWrapper.setWidth("100%");
CellTable<RichMember> table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {
// when user click on a row -> open new tab
public void update(int index, RichMember object, RichMember value) {
session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), 0));
}
});
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(findMembers, table, addButton);
table.addStyleName("perun-table");
table.setWidth("100%");
tableWrapper.setWidget(table);
tableWrapper.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(tableWrapper, 350, this);
membersListPanel.add(tableWrapper);
// selected members
VerticalPanel selectedMembersPanel = new VerticalPanel();
selectedMembersPanel.setSize("100%", "100%");
TabMenu selectedMembersMenu = new TabMenu();
selectedMembersPanel.add(selectedMembersMenu);
selectedMembersPanel.setCellHeight(selectedMembersMenu, "30px");
selectedMembersMenu.addWidget(new HTML("<h3>Selected members:</h3>"));
selectedMembersPanel.add(selectedMembers);
hp.setWidget(0, 0, membersListPanel);
hp.setWidget(0, 1, selectedMembersPanel);
hp.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
hp.getFlexCellFormatter().setWidth(0, 0, "80%");
hp.getFlexCellFormatter().setWidth(0, 1, "20%");
this.contentWidget.add(hp);
} else if (state == State.SELECT_RESOURCE_OR_FACILITY) {
this.contentWidget.clear();
session.getTabManager().changeStyleOfInnerTab(false);
FlexTable layout = new FlexTable();
layout.setSize("100%", "100%");
TabMenu menu = new TabMenu();
if (!startedAtTwo) {
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.BACK, "Back to members selection", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// get back and reload
state = State.SELECT_MEMBERS;
tab.draw();
}
}));
} else {
this.titleWidget.setText("Add member to resource");
}
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CONTINUE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
state = State.SELECT_GROUP;
tab.draw();
}
}));
// RESOURCE LAYOUT
FlexTable resourceLayout = new FlexTable();
resourceLayout.setStyleName("inputFormFlexTable");
// by default do not choose facility or service
facilitiesListbox.addNotSelectedOption();
servicesListbox.addNotSelectedOption();
// TODO
servicesListbox.setEnabled(false);
// fill services event
final JsonCallbackEvents fillServEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
services.setHTML("");
ArrayList<Service> servList = JsonUtils.jsoAsList(jso);
servList = new TableSorter<Service>().sortByName(servList);
for (Service s : servList) {
services.setHTML(services.getHTML().concat(s.getName() + "</br>"));
}
}
@Override
public void onError(PerunError errro) {
services.setHTML("Error while loading available services.");
}
};
// fill resources event
final JsonCallbackEvents fillResEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// list of VO facilities filled by loaded resources
ArrayList<Facility> facs = new ArrayList<Facility>();
ArrayList<RichResource> resList = JsonUtils.jsoAsList(jso);
resList = new TableSorter<RichResource>().sortByName(resList);
Set<String> unificator = new HashSet<String>();
for (RichResource r : resList) {
allResources.add(r);
resourcesListbox.addItem(r);
if (r.getFacility() != null && !unificator.contains(r.getFacility().getName())) {
unificator.add(r.getFacility().getName());
facs.add(r.getFacility());
}
}
// sort and fill facilities
facs = new TableSorter<Facility>().sortByName(facs);
facilitiesListbox.addAllItems(facs);
// initial setup
// refresh rest
description.setText(resourcesListbox.getSelectedObject().getDescription());
GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
servCall.retrieveData();
}
@Override
public void onLoadingStart() {
resourcesListbox.clear();
}
@Override
public void onError(PerunError error) {
resourcesListbox.addItem("Error while loading");
}
};
resourcesListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
description.setText(resourcesListbox.getSelectedObject().getDescription());
// fill information about services on resource
GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
servCall.retrieveData();
}
});
facilitiesListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (facilitiesListbox.getSelectedIndex() > 0) {
// fill only resources on facility
resourcesListbox.clear();
for (RichResource r : allResources) {
if (r.getFacility().getId() == facilitiesListbox.getSelectedObject().getId()) {
resourcesListbox.addItem(r);
}
}
} else {
// fill all resources
resourcesListbox.clear();
resourcesListbox.addAllItems(allResources);
}
// refresh rest
description.setText(resourcesListbox.getSelectedObject().getDescription());
GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
servCall.retrieveData();
}
});
GetRichResources resCall = new GetRichResources(voId, fillResEvent);
if (allResources.isEmpty()) {
resCall.retrieveData();
}
resourceLayout.setHTML(0, 0, "Filter by Facility:");
resourceLayout.setWidget(0, 1, facilitiesListbox);
//resourceLayout.setHTML(1, 0, "Filter by Service:");
//resourceLayout.setWidget(1, 1, servicesListbox);
resourceLayout.setHTML(1, 0, "Selected resource:");
resourceLayout.setWidget(1, 1, resourcesListbox);
resourceLayout.setHTML(2, 0, "Description:");
resourceLayout.setWidget(2, 1, description);
resourceLayout.setHTML(3, 0, "Services on Resource:");
resourceLayout.setWidget(3, 1, services);
for (int i = 0; i < resourceLayout.getRowCount(); i++) {
resourceLayout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
}
// set layout
layout.setWidget(0, 0, menu);
layout.setWidget(1, 0, resourceLayout);
this.contentWidget.add(layout);
} else if (state == State.SELECT_GROUP) {
this.contentWidget.clear();
session.getTabManager().changeStyleOfInnerTab(true);
final GetAssignedGroups assGroupCall = new GetAssignedGroups(resourcesListbox.getSelectedObject().getId());
assGroupCall.setSingleSelection(true);
assGroupCall.setCoreGroupsCheckable(false);
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.BACK, "Back to resource selection", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// get back and reload
state = State.SELECT_RESOURCE_OR_FACILITY;
tab.draw();
}
}));
final CustomButton addToGroupButton = new CustomButton("Add to Group", "Add members to selected Group", SmallIcons.INSTANCE.addIcon());
menu.addWidget(addToGroupButton);
addToGroupButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (UiElements.cantSaveEmptyListDialogBox(assGroupCall.getTableSelectedList())) {
final Group grp = assGroupCall.getTableSelectedList().get(0);
final FlexTable content = new FlexTable();
GetAssignedResources getRes = new GetAssignedResources(grp.getId(), PerunEntity.GROUP, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Resource> rr = JsonUtils.jsoAsList(jso);
String items = new String("<ul>");
for (Resource r : rr) {
items += "<li>" + r.getName() + "</li>";
}
items += "</ul>";
ScrollPanel sp = new ScrollPanel();
sp.add(new HTML(items));
sp.setSize("300px", "150px");
content.setWidget(1, 0, sp);
}
public void onError(PerunError error) {
content.setWidget(1, 0, new AjaxLoaderImage().loadingError(error));
}
});
getRes.retrieveData();
content.setHTML(0, 0, "<p><strong>By adding member into this group, he/she will gain access to following resources:</strong>");
content.setWidget(1, 0, new AjaxLoaderImage().loadingStart());
Confirm c = new Confirm("Confirm add action", content, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addToGroupButton));
for (RichMember m : selectedMembers.getList()) {
request.addMemberToGroup(grp, m);
}
}
}, true);
c.setNonScrollable(true);
c.show();
}
}
});
menu.addWidget(new CustomButton("Create group…", "Create new empty group", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// get back and reload
state = State.CREATE_GROUP;
tab.draw();
}
}));
CustomButton finish = TabMenu.getPredefinedButton(ButtonType.FINISH, "Close the tab", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
finish.setImageAlign(true);
menu.addWidget(finish);
menu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
menu.addWidget(new HTML("<strong>Please select group in which you wish to add members to."));
CellTable<Group> table = assGroupCall.getTable();
addToGroupButton.setEnabled(false);
JsonUtils.addTableManagedButton(assGroupCall, table, addToGroupButton);
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
vp.add(menu);
vp.add(sp);
this.contentWidget.add(vp);
} else if (state == State.CREATE_GROUP) {
session.getTabManager().changeStyleOfInnerTab(false);
VerticalPanel vp = new VerticalPanel();
// form inputs
final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
final TextBox groupDescriptionTextBox = new TextBox();
final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
vosGroups.setVisible(false);
final CheckBox asSubGroup = new CheckBox("", false);
cz.metacentrum.perun.webgui.widgets.TabMenu menu = new cz.metacentrum.perun.webgui.widgets.TabMenu();
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
final HTML parentGroupText = new HTML("Parent group:");
parentGroupText.setVisible(false);
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
groupNameTextBox.setError("Name can't be empty.");
} else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
groupNameTextBox.setError("Name can contain only letters, numbers, spaces, dots, '_' and '-'.");
} else {
groupNameTextBox.setOk();
return true;
}
return false;
}
};
groupNameTextBox.setValidator(validator);
final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
vosGroups.clear();
ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
retGroups = new TableSorter<Group>().sortByName(retGroups);
for (Group g : retGroups) {
if (g.isCoreGroup()) {
// SKIP CORE GROUPS !!
continue;
}
vosGroups.addItem(g);
}
createButton.setEnabled(true);
}
public void onLoadingStart() {
vosGroups.clear();
vosGroups.addItem("Loading...");
createButton.setEnabled(false);
}
public void onError(PerunError error) {
vosGroups.clear();
vosGroups.addItem("Error while loading");
if (asSubGroup.getValue()) {
createButton.setEnabled(false);
} else {
createButton.setEnabled(true);
}
}
});
asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
if (booleanValueChangeEvent.getValue() == true) {
// set title
vosGroups.setVisible(true);
parentGroupText.setVisible(true);
groupsCall.retrieveData();
createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
} else {
createButton.setEnabled(true);
vosGroups.setVisible(false);
parentGroupText.setVisible(false);
createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
}
}
});
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// send button
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!validator.validateTextBox())
return;
// redirect event
final JsonCallbackEvents redirectEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
state = State.SELECT_GROUP;
session.getTabManager().changeStyleOfInnerTab(true);
tab.draw();
}
};
// assign group after creation
final JsonCallbackEvents assignEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
Group g = jso.cast();
if (g != null) {
AssignGroupToResources assign = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(createButton, redirectEvent));
assign.assignGroupToResources(g, JsonUtils.<RichResource>toList(resourcesListbox.getSelectedObject()));
}
}
};
// creates a new request
CreateGroup cg = new CreateGroup(JsonCallbackEvents.disableButtonEvents(createButton, assignEvent));
if (asSubGroup.getValue()) {
if (vosGroups.getSelectedObject() != null) {
cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText());
} else {
UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
}
} else {
cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText());
}
}
});
// cancel button
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// redirect back to select group
state = State.SELECT_GROUP;
session.getTabManager().changeStyleOfInnerTab(true);
tab.draw();
}
});
// Add some standard form options
layout.setHTML(0, 0, "Name:");
layout.setWidget(0, 1, groupNameTextBox);
layout.setHTML(1, 0, "Description:");
layout.setWidget(1, 1, groupDescriptionTextBox);
layout.setHTML(2, 0, "As sub-group:");
layout.setWidget(2, 1, asSubGroup);
layout.setWidget(3, 0, parentGroupText);
layout.setWidget(3, 1, vosGroups);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
// button align
menu.addWidget(createButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
}
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddMemberToVoTabItem method draw.
public Widget draw() {
titleWidget.setText("Add member(s)");
// draw the main tab
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
final TabMenu tabMenu = new TabMenu();
mainTab.add(tabMenu);
mainTab.setCellHeight(tabMenu, "30px");
addCandidatesButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedCandidateToVo());
inviteCandidatesButton = new CustomButton("Invite selected", SmallIcons.INSTANCE.emailIcon());
final FindCandidatesOrUsersToAddToVo findAll = new FindCandidatesOrUsersToAddToVo(voId, 0, "");
final CustomButton searchButton = new CustomButton("Search", SmallIcons.INSTANCE.findIcon());
final CellTable<Candidate> candidatesTable = findAll.getEmptyTable();
final ScrollPanel scrollPanel = new ScrollPanel();
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
findAll.searchFor(text);
}
}, searchButton);
searchBox.getTextBox().setText(searchString);
// search candidate - select if found one
JsonCallbackEvents selectOneEvent = JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
searchBox.getTextBox().setEnabled(true);
// check in candidates table
if (findAll.getList().size() == 1) {
findAll.setSelected(findAll.getList().get(0));
}
tabMenu.addWidget(2, addCandidatesButton);
}
@Override
public void onLoadingStart() {
searchBox.getTextBox().setEnabled(false);
}
@Override
public void onError(PerunError error) {
searchBox.getTextBox().setEnabled(true);
}
});
// set event for search
findAll.setEvents(selectOneEvent);
tabMenu.addWidget(2, addCandidatesButton);
tabMenu.addWidget(3, inviteCandidatesButton);
inviteCandidatesButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// we expect, that candidate is always single
Candidate candid = findAll.getSelected();
if (candid != null) {
if (candid.getObjectType().equalsIgnoreCase("Candidate")) {
SendInvitation invite = new SendInvitation(voId, 0);
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteCandidatesButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findAll.clearTableSelectedSet();
}
}));
invite.inviteUser(candid);
} else {
SendInvitation invite = new SendInvitation(voId, 0);
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteCandidatesButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findAll.clearTableSelectedSet();
}
}));
User user = candid.cast();
invite.inviteUser(user);
}
}
}
});
final TabItem tab = this;
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
// add candidate button
addCandidatesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Candidate candidateToBeAdded = findAll.getSelected();
if (candidateToBeAdded == null) {
UiElements.cantSaveEmptyListDialogBox(null);
} else {
if (candidateToBeAdded.getObjectType().equalsIgnoreCase("Candidate")) {
CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addCandidatesButton, new JsonCallbackEvents() {
private Candidate saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
if (saveSelected != null) {
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
}
findAll.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
@Override
public void onLoadingStart() {
saveSelected = findAll.getSelected();
}
}));
request.createMember(voId, candidateToBeAdded);
} else {
CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addCandidatesButton, new JsonCallbackEvents() {
private User saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
if (saveSelected != null) {
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
findAll.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
}
@Override
public void onLoadingStart() {
Candidate cand = findAll.getSelected();
saveSelected = cand.cast();
}
}));
User user = candidateToBeAdded.cast();
request.createMember(voId, user);
}
}
}
});
addCandidatesButton.setEnabled(false);
JsonUtils.addTableManagedButton(findAll, candidatesTable, addCandidatesButton);
inviteCandidatesButton.setEnabled(false);
JsonUtils.addTableManagedButton(findAll, candidatesTable, inviteCandidatesButton);
// tables
candidatesTable.addStyleName("perun-table");
scrollPanel.add(candidatesTable);
scrollPanel.addStyleName("perun-tableScrollPanel");
// load if stored search string is not empty
findAll.searchFor(searchString);
rebuildAlreadyAddedWidget();
mainTab.add(alreadyAdded);
// style
// do not use resizePerunTable() when tab is in overlay - wrong width is calculated
session.getUiElements().resizeSmallTabPanel(scrollPanel, 350, this);
// add table to page
mainTab.add(scrollPanel);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class CreateServiceMemberInVoTabItem method draw.
public Widget draw() {
titleWidget.setText("Create service member");
final TabItem tab = this;
// draw the main tab
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
final ExtendedTextBox serviceUserName = new ExtendedTextBox();
final ExtendedTextBox serviceUserEmail = new ExtendedTextBox();
final ExtendedTextBox serviceUserLogin = new ExtendedTextBox();
final ExtendedPasswordBox serviceUserPassword = new ExtendedPasswordBox();
final ExtendedPasswordBox serviceUserPassword2 = new ExtendedPasswordBox();
final ListBox namespace = new ListBox();
final ExtendedTextBox certDN = new ExtendedTextBox();
final ExtendedTextBox cacertDN = new ExtendedTextBox();
final ListBox userType = new ListBox();
userType.addItem("Service", "SERVICE");
userType.addItem("Sponsored", "SPONSORED");
serviceUserPassword.getTextBox().setWidth("200px");
serviceUserPassword2.getTextBox().setWidth("200px");
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserName.getTextBox().getValue().trim().isEmpty()) {
serviceUserName.setError("Name can't be empty!");
return false;
}
serviceUserName.setOk();
return true;
}
};
serviceUserName.setValidator(nameValidator);
final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (namespace.getSelectedIndex() == 0) {
// do not validate if namespace is not selected
serviceUserLogin.getTextBox().setValue(null);
serviceUserLogin.setOk();
return true;
}
if (serviceUserLogin.getTextBox().getValue().trim().isEmpty()) {
serviceUserLogin.setError("Login can't be empty!");
return false;
}
RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
boolean match = regExp.test(serviceUserLogin.getTextBox().getValue().trim());
if (!match) {
serviceUserLogin.setError("Invalid format!");
return false;
}
if (serviceUserLogin.isProcessing() || serviceUserLogin.isHardError()) {
// keep original message
return false;
}
serviceUserLogin.setOk();
return true;
}
};
serviceUserLogin.setValidator(loginValidator);
final ExtendedTextBox.TextBoxValidator emailValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!JsonUtils.isValidEmail(serviceUserEmail.getTextBox().getValue().trim())) {
serviceUserEmail.setError("Wrong email format!");
return false;
}
serviceUserEmail.setOk();
return true;
}
};
serviceUserEmail.setValidator(emailValidator);
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserPassword.getTextBox().getValue().trim().isEmpty()) {
serviceUserPassword.setError("Password can't be empty !");
return false;
} else if (!serviceUserPassword.getTextBox().getValue().trim().equals(serviceUserPassword2.getTextBox().getValue().trim())) {
serviceUserPassword.setError("Password in both textboxes must be the same !");
return false;
} else {
serviceUserPassword.setOk();
serviceUserPassword2.setOk();
return true;
}
}
};
serviceUserPassword.setValidator(validator);
final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceUserPassword2.getTextBox().getValue().trim().isEmpty()) {
serviceUserPassword2.setError("Password can't be empty !");
return false;
} else if (!serviceUserPassword2.getTextBox().getValue().trim().equals(serviceUserPassword.getTextBox().getValue().trim())) {
serviceUserPassword2.setError("Password in both textboxes must be the same !");
return false;
} else {
serviceUserPassword2.setOk();
serviceUserPassword.setOk();
return true;
}
}
};
serviceUserPassword2.setValidator(validator2);
final ExtendedTextBox.TextBoxValidator certDNValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if ((certDN.getTextBox().getValue().trim().isEmpty() && cacertDN.getTextBox().getValue().trim().isEmpty()) || (!certDN.getTextBox().getValue().trim().isEmpty() && !cacertDN.getTextBox().getValue().trim().isEmpty())) {
certDN.setOk();
cacertDN.setOk();
return true;
} else {
if (certDN.getTextBox().getValue().trim().isEmpty()) {
certDN.setError("Value can't be empty!");
}
if (cacertDN.getTextBox().getValue().trim().isEmpty()) {
cacertDN.setError("Value can't be empty!");
}
}
return false;
}
};
certDN.setValidator(certDNValidator);
cacertDN.setValidator(certDNValidator);
// make value empty
namespace.addItem("Not selected", "");
for (String name : Utils.getSupportedPasswordNamespaces()) {
namespace.addItem(name.toUpperCase(), name);
}
final FlexTable layout = new FlexTable();
layout.setCellPadding(5);
layout.setHTML(0, 0, "<h3>1. Create service identity</h3>");
layout.getFlexCellFormatter().setColSpan(0, 0, 3);
layout.setHTML(1, 0, "<strong>Member's name: </strong>");
layout.setWidget(1, 1, serviceUserName);
layout.setHTML(2, 0, "<strong>Member's email: </strong>");
layout.setWidget(2, 1, serviceUserEmail);
layout.setHTML(3, 0, "<strong>Namespace: </strong>");
layout.setWidget(3, 1, namespace);
layout.setHTML(4, 0, "<strong>Login: </strong>");
layout.setWidget(4, 1, serviceUserLogin);
final Label label = new Label("You will be assigned with available login");
label.setVisible(false);
layout.setWidget(5, 0, label);
layout.getFlexCellFormatter().setStyleName(5, 0, "inputFormInlineComment");
layout.getFlexCellFormatter().setColSpan(5, 0, 2);
layout.setHTML(6, 0, "<strong>Subject DN: </strong>");
layout.setWidget(6, 1, certDN);
layout.setHTML(7, 0, "<strong>Issuer DN: </strong>");
layout.setWidget(7, 1, cacertDN);
if (session.isPerunAdmin()) {
layout.setHTML(8, 0, "<strong>User type: </strong>");
layout.setWidget(8, 1, userType);
}
final FlexTable firstTabLayout = new FlexTable();
firstTabLayout.setSize("100%", "100%");
firstTabLayout.setVisible(false);
final AddRemoveItemsTable<User> itemsTable = new AddRemoveItemsTable<User>(true);
itemsTable.addItem(session.getUser());
final VerticalPanel secondTabPanel = new VerticalPanel();
secondTabPanel.setSize("100%", "100%");
secondTabPanel.setVisible(false);
mainTab.add(layout);
mainTab.add(firstTabLayout);
mainTab.add(secondTabPanel);
// disable login by default (first option)
serviceUserLogin.getTextBox().setEnabled(false);
final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
// check
if (!namespace.getSelectedValue().equals("mu") && namespace.getSelectedIndex() != 0 && !loginValidator.validateTextBox())
return;
if (!nameValidator.validateTextBox())
return;
if (!emailValidator.validateTextBox())
return;
if (!certDNValidator.validateTextBox())
return;
// change to lager tab
session.getTabManager().changeStyleOfInnerTab(true);
// first tab panel
firstTabLayout.setHTML(0, 0, "<h3>2. Associate real users</h3>");
firstTabLayout.getFlexCellFormatter().setColSpan(0, 0, 2);
layout.setVisible(false);
firstTabLayout.setVisible(true);
final FindUsersInVo callback = new FindUsersInVo();
// Service users can't own another Service or Guest (Sponsored) account.
callback.hideService(true);
if (userType.getSelectedValue().equals("SPONSORED")) {
// Sponsored account can't sponsor another !
callback.setHideSponsored(true);
}
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<User> table = callback.getTable();
// search textbox
ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
callback.searchFor(text, voId);
searchString = text;
}
}, ButtonTranslation.INSTANCE.searchUsers());
final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.arrowRightIcon());
cb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
// check
if (itemsTable.getList().isEmpty()) {
new Confirm("No user associated", new HTML("You must associate at least one real user to service member."), true).show();
return;
}
// create member + user
CreateSpecificMember request = new CreateSpecificMember(JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
final Member member = jso.cast();
for (User u : itemsTable.getList()) {
if (u.getId() == session.getUser().getId()) {
// set local authz if one of associated users is us
session.addEditableUser(member.getUserId());
}
}
if (namespace.getSelectedIndex() == 0) {
// we didn't set login, hence skip password setting
session.getTabManager().closeTab(tab, true);
return;
}
// change to small tab
session.getTabManager().changeStyleOfInnerTab(false);
secondTabPanel.add(new HTML("<h3>3.Set password for: " + serviceUserLogin.getTextBox().getValue().trim() + "</h3>"));
final CustomButton button = new CustomButton("Set password", SmallIcons.INSTANCE.keyIcon());
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (!validator.validateTextBox() && !validator2.validateTextBox()) {
return;
}
final String namespaceValue = namespace.getSelectedValue();
if ("mu".equals(namespaceValue)) {
final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
req2.validateMemberAsync(member);
}
}));
// validate login returned from account generation
req.validateAndSetUserExtSources(member.getUserId(), login, namespaceValue);
// show assigned login
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
}
@Override
public void onError(PerunError error) {
UiElements.generateError(error, "Saving login failed", "You were assigned with login <b>" + login + "</b> in namespace MU but saving it to user failed. <b>Please copy your login and contact support at <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">" + Utils.perunReportEmailAddress() + "</a>.</b>");
// validate member when all logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
req2.validateMemberAsync(member);
}
}));
setLogin.setLogin(member.getUserId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
RichMember rm = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
req.generateAccount(namespaceValue, serviceUserPassword.getTextBox().getValue().trim(), params);
}
}));
get.retrieveData();
} else {
// create password which sets also user ext sources
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
req2.validateMemberAsync(member);
}
}));
req.createPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue, serviceUserPassword.getTextBox().getValue().trim());
}
}
});
final CustomButton skipButton = new CustomButton("Skip", SmallIcons.INSTANCE.arrowRightIcon());
skipButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
final String namespaceValue = namespace.getSelectedValue();
if ("mu".equals(namespaceValue)) {
final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
req2.validateMemberAsync(member);
}
}));
// validate login returned from account generation
req.validateAndSetUserExtSources(member.getUserId(), login, namespaceValue);
// show assigned login
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
}
@Override
public void onError(PerunError error) {
// validate member when all logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
req2.validateMemberAsync(member);
}
}));
setLogin.setLogin(member.getUserId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
RichMember rm = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
req.generateAccount(namespaceValue, null, params);
}
}));
get.retrieveData();
} else {
CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(skipButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// validate member when all kerberos logins are set
ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(skipButton, tab));
req2.validateMemberAsync(member);
}
}));
// set empty password for service member if "skipped"
req.createRandomPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue);
}
}
});
FlexTable ft = new FlexTable();
ft.setStyleName("inputFormFlexTable");
ft.setWidth("400px");
ft.setHTML(0, 0, "Password:");
ft.setWidget(0, 1, serviceUserPassword);
ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
ft.setHTML(1, 0, "Re-type password:");
ft.setWidget(1, 1, serviceUserPassword2);
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
ft.setWidget(2, 1, skipButton);
ft.getFlexCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_RIGHT);
ft.setWidget(3, 1, button);
ft.getFlexCellFormatter().setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_RIGHT);
secondTabPanel.add(ft);
// hide 2nd panel
firstTabLayout.setVisible(false);
// show 3rd panel
secondTabPanel.setVisible(true);
}
;
}));
request.createMember(voId, serviceUserName.getTextBox().getValue().trim(), serviceUserEmail.getTextBox().getValue().trim(), itemsTable.getList(), namespace.getValue(namespace.getSelectedIndex()), serviceUserLogin.getTextBox().getValue().trim(), certDN.getTextBox().getValue().trim(), cacertDN.getTextBox().getValue().trim(), userType.getSelectedValue());
}
});
// we have ourselves already assigned
//cb.setEnabled(false);
CustomButton button = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected users to service member");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
ArrayList<User> list = callback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// skip self
ArrayList<User> list2 = new ArrayList<User>();
for (User user : list) {
if (user != null && user.getId() != session.getUser().getId()) {
list2.add(user);
}
}
itemsTable.addItems(list2);
cb.setEnabled(true);
callback.clearTableSelectedSet();
}
}
});
button.setEnabled(false);
tabMenu.addWidget(button);
JsonUtils.addTableManagedButton(callback, table, button);
// add finish button to menu
tabMenu.addWidget(cb);
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
callback.searchFor(searchString, voId);
}
final ScrollPanel sp = new ScrollPanel(table);
table.addStyleName("perun-table");
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, tab);
firstTabLayout.setWidget(1, 0, tabMenu);
firstTabLayout.setWidget(2, 0, sp);
firstTabLayout.setHTML(1, 1, "<h3>To be associated:</h3>");
firstTabLayout.setWidget(2, 1, itemsTable);
firstTabLayout.getFlexCellFormatter().setWidth(2, 0, "75%");
firstTabLayout.getFlexCellFormatter().setWidth(2, 1, "25%");
firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 1, HasVerticalAlignment.ALIGN_TOP);
firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
// actions when added items or removed items
itemsTable.setEvents(new AddRemoveItemsTable.HandleItemsAction<User>() {
@Override
public void onAdd(User object) {
cb.setEnabled(true);
}
@Override
public void onRemove(User object) {
if (object.equals(session.getUser())) {
itemsTable.addItem(object);
UiElements.generateInfo("Can't remove yourself", "<p>You can't remove yourself yet. You wouldn't be able to finish service member configuration. Please remove yourself afterwards.");
}
if (itemsTable.getList().isEmpty()) {
cb.setEnabled(false);
}
}
});
}
});
// check login availability
serviceUserLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {
if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
// do not trigger when no text input
return;
}
final String login = serviceUserLogin.getTextBox().getValue().trim();
final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
// trigger new validation on checked input or if previously was hard error
if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
BasicOverlayType bo = jso.cast();
serviceUserLogin.setProcessing(false);
if (!bo.getBoolean()) {
serviceUserLogin.setHardError("Login is already in use!");
} else {
serviceUserLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.removeHardError();
serviceUserLogin.setProcessing(true);
}
}
@Override
public void onError(PerunError error) {
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.setProcessing(false);
serviceUserLogin.setHardError("Unable to check if login is available!");
}
}
}).retrieveData();
}
}
});
namespace.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (namespace.getSelectedIndex() == 0) {
// do not set login
serviceUserLogin.getTextBox().setEnabled(false);
serviceUserLogin.getTextBox().setValue(null);
label.setVisible(false);
} else if (namespace.getSelectedValue().equals("mu")) {
serviceUserLogin.getTextBox().setEnabled(false);
label.setVisible(true);
} else {
serviceUserLogin.getTextBox().setEnabled(true);
label.setVisible(false);
}
final String login = serviceUserLogin.getTextBox().getValue().trim();
final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.setProcessing(false);
BasicOverlayType bo = jso.cast();
if (!bo.getBoolean()) {
serviceUserLogin.setHardError("Login is already in use!");
} else {
serviceUserLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.removeHardError();
serviceUserLogin.setProcessing(true);
loginValidator.validateTextBox();
}
}
@Override
public void onError(PerunError error) {
if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
serviceUserLogin.setProcessing(false);
serviceUserLogin.setHardError("Unable to check if login is available!");
}
}
}).retrieveData();
}
}
});
if (session.isPerunAdmin()) {
layout.setWidget(9, 0, cb);
layout.getFlexCellFormatter().setHorizontalAlignment(9, 0, HasHorizontalAlignment.ALIGN_RIGHT);
layout.getFlexCellFormatter().setColSpan(9, 0, 2);
} else {
layout.setWidget(8, 0, cb);
layout.getFlexCellFormatter().setHorizontalAlignment(8, 0, HasHorizontalAlignment.ALIGN_RIGHT);
layout.getFlexCellFormatter().setColSpan(8, 0, 2);
}
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class MemberAddToGroupTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Add to group(s)");
// main widget panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
final GetAllGroups groups = new GetAllGroups(member.getVoId());
menu.addFilterWidget(new ExtendedSuggestBox(groups.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
groups.filterTable(text);
if (groups.getList().size() == 1) {
// select if filtered result is single group
groups.getSelectionModel().setSelected(groups.getList().get(0), true);
}
}
}, "Filter groups by name");
final TabItem tab = this;
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add member to selected group(s)");
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
ArrayList<Group> list = groups.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// TODO - should have only one callback to core
for (int i = 0; i < list.size(); i++) {
final Group g = list.get(i);
AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
groups.getSelectionModel().setSelected(g, false);
alreadyAddedList.add(g);
rebuildAlreadyAddedWidget();
}
}));
request.addMemberToGroup(g, member);
}
}
}
});
menu.addWidget(addButton);
addButton.setEnabled(false);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, false);
}
}));
CellTable<Group> table = groups.getTable();
JsonUtils.addTableManagedButton(groups, table, addButton);
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
rebuildAlreadyAddedWidget();
vp.add(alreadyAdded);
vp.add(sp);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations