use of cz.metacentrum.perun.webgui.widgets.CustomButton 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.widgets.CustomButton 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();
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class EditFormItemTabItem method buildItemsTable.
private FlexTable buildItemsTable(final FlexTable boxItemTable, final Map<String, String> values, final String locale) {
// clear before rebuild
boxItemTable.clear(true);
int boxRow = 0;
// clear options boxes
final Map<TextBox, TextBox> currentOptions = new HashMap<TextBox, TextBox>();
optionsBoxes.put(locale, currentOptions);
boxRow++;
Label boxContentLabel = new Label(item.getType().substring(0, 1) + item.getType().toLowerCase().substring(1) + " options:");
boxItemTable.setWidget(boxRow, 0, boxContentLabel);
boxItemTable.getFlexCellFormatter().setStyleName(boxRow, 0, "itemName");
boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 4);
boxRow++;
HTML comment = new HTML("Define possible options for selection in SELECTIONBOX, COMBOBOX, CHECKBOX, RADIO widget. Empty options are not used.");
comment.setStyleName("inputFormInlineComment");
boxItemTable.setWidget(boxRow, 0, comment);
boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 4);
boxRow++;
TabMenu menu = new TabMenu();
//menu.setWidth("100%");
boxItemTable.setWidget(boxRow, 0, menu);
boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 4);
boxRow++;
final CustomButton sortButton = new CustomButton("Sort by label (A-Z)", SmallIcons.INSTANCE.sortAscendingIcon());
menu.addWidget(sortButton);
final CustomButton sortButton2 = new CustomButton("Sort by label (Z-A)", SmallIcons.INSTANCE.sortDescendingIcon());
menu.addWidget(sortButton2);
sortButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// OPTIONS
Map<TextBox, TextBox> localeTextboxes = optionsBoxes.get(locale);
Map<String, String> keyValue = new HashMap<String, String>();
for (Map.Entry<TextBox, TextBox> textBoxes : localeTextboxes.entrySet()) {
String key = textBoxes.getKey().getText();
String value = textBoxes.getValue().getText();
if (key != null && !key.equals("") && value != null && !value.equals("")) {
keyValue.put(key.trim(), value.trim());
}
}
List<String> values = new ArrayList<String>(keyValue.values());
Collections.sort(values, Collator.getNativeComparator());
Map<String, String> sortedValues = new HashMap<String, String>();
for (String value : values) {
for (String key : keyValue.keySet()) {
if (Objects.equals(keyValue.get(key), value)) {
sortedValues.put(key, keyValue.get(key));
}
}
}
buildItemsTable(boxItemTable, sortedValues, locale);
}
});
sortButton2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// OPTIONS
Map<TextBox, TextBox> localeTextboxes = optionsBoxes.get(locale);
Map<String, String> keyValue = new HashMap<String, String>();
for (Map.Entry<TextBox, TextBox> textBoxes : localeTextboxes.entrySet()) {
String key = textBoxes.getKey().getText();
String value = textBoxes.getValue().getText();
if (key != null && !key.equals("") && value != null && !value.equals("")) {
keyValue.put(key.trim(), value.trim());
}
}
List<String> values = new ArrayList<String>(keyValue.values());
Collections.sort(values, Collections.reverseOrder(Collator.getNativeComparator()));
Map<String, String> sortedValues = new HashMap<String, String>();
for (String value : values) {
for (String key : keyValue.keySet()) {
if (Objects.equals(keyValue.get(key), value)) {
sortedValues.put(key, keyValue.get(key));
}
}
}
buildItemsTable(boxItemTable, sortedValues, locale);
}
});
// for each add new row
for (Map.Entry<String, String> entry : values.entrySet()) {
final TextBox keyTextBox = new TextBox();
final TextBox valueTextBox = new TextBox();
currentOptions.put(keyTextBox, valueTextBox);
keyTextBox.setText(entry.getKey());
valueTextBox.setText(entry.getValue());
boxItemTable.setHTML(boxRow, 0, "Value:");
boxItemTable.getFlexCellFormatter().setStyleName(boxRow, 0, "itemName");
boxItemTable.setWidget(boxRow, 1, keyTextBox);
boxItemTable.setHTML(boxRow, 2, "Label:");
boxItemTable.getFlexCellFormatter().setStyleName(boxRow, 2, "itemName");
boxItemTable.setWidget(boxRow, 3, valueTextBox);
boxRow++;
}
// button for adding new
CustomButton addNewButton = new CustomButton(ButtonTranslation.INSTANCE.addButton(), ButtonTranslation.INSTANCE.addNewSelectionBoxItem(), SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
final int r = boxItemTable.getRowCount();
final TextBox keyTextBox = new TextBox();
final TextBox valueTextBox = new TextBox();
currentOptions.put(keyTextBox, valueTextBox);
boxItemTable.insertRow(r - 1);
boxItemTable.setHTML(r - 1, 0, "Value:");
boxItemTable.getFlexCellFormatter().setStyleName(r - 1, 0, "itemName");
boxItemTable.setWidget(r - 1, 1, keyTextBox);
boxItemTable.setHTML(r - 1, 2, "Label:");
boxItemTable.getFlexCellFormatter().setStyleName(r - 1, 2, "itemName");
boxItemTable.setWidget(r - 1, 3, valueTextBox);
UiElements.runResizeCommands(tab);
}
});
boxItemTable.setWidget(boxRow, 0, addNewButton);
boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 2);
return boxItemTable;
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class EditMailFooterTabItem method draw.
public Widget draw() {
final FlexTable content = new FlexTable();
content.setStyleName("inputFormFlexTable");
content.setWidth("360px");
final TextArea footer = new TextArea();
footer.setSize("340px", "200px");
content.setHTML(0, 0, "Footer text:");
content.getFlexCellFormatter().setStyleName(0, 0, "itemName");
content.setWidget(1, 0, footer);
content.setHTML(2, 0, "This text will be added as footer for all email notifications (replacing {mailFooter} tag in mail definition).");
content.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
final Map<String, Integer> ids = new HashMap<String, Integer>();
if (group == null) {
ids.put("vo", voId);
} else {
ids.put("group", groupId);
}
final ArrayList<Attribute> list = new ArrayList<Attribute>();
final GetListOfAttributes call = new GetListOfAttributes(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
list.addAll(JsonUtils.<Attribute>jsoAsList(jso));
// only if attribute exists
if (list != null && !list.isEmpty()) {
for (Attribute a : list) {
if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
// if value not null - enter
if (!a.getValue().equalsIgnoreCase("null")) {
footer.setText(a.getValue());
}
}
}
}
}
});
ArrayList<String> l = new ArrayList<String>();
if (group == null) {
l.add("urn:perun:vo:attribute-def:def:mailFooter");
} else {
l.add("urn:perun:group:attribute-def:def:mailFooter");
}
call.getListOfAttributes(ids, l);
final TabItem tab = this;
VerticalPanel vp = new VerticalPanel();
TabMenu menu = new TabMenu();
final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveMailFooter());
save.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// will be set
ArrayList<Attribute> toSend = new ArrayList<Attribute>();
// will be removed
ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
for (Attribute a : list) {
String oldValue = a.getValue();
String newValue = "";
if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
newValue = footer.getText();
} else {
// other than mailFooter attributes must be skipped
continue;
}
if (oldValue.equalsIgnoreCase(newValue) || (oldValue.equalsIgnoreCase("null") && newValue.equalsIgnoreCase(""))) {
// skip this cycle
continue;
} else {
if (newValue.equalsIgnoreCase("")) {
// value was cleared
toRemove.add(a);
} else {
// set value
a.setValue(newValue);
// value was changed / added
toSend.add(a);
}
}
}
// requests
SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
RemoveAttributes removeRequest = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
// send if not empty
if (!toRemove.isEmpty()) {
removeRequest.removeAttributes(ids, toRemove);
}
if (!toSend.isEmpty()) {
request.setAttributes(ids, toSend);
}
}
});
menu.addWidget(save);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(content);
vp.add(menu);
vp.setCellHeight(menu, "30px");
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class MailsTabItem method draw.
public Widget draw() {
final GetApplicationMails mailsRequest;
String title = "";
if (group != null) {
title = group.getName();
entity = PerunEntity.GROUP;
entityId = group.getId();
mailsRequest = new GetApplicationMails(entity, group.getId());
} else {
title = vo.getName();
entityId = vo.getId();
mailsRequest = new GetApplicationMails(entity, vo.getId());
}
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(title) + ": " + "Email notifications");
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// add button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateMailTabItem(vo, group, form));
}
}));
// remove button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMail());
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
String text = "Following mail definitions will be removed and users won't receive them anymore.";
UiElements.showDeleteConfirm(list, text, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1) {
DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton));
request.deleteMail(list.get(i).getId(), entityId);
} else {
// refresh table on last call
DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(mailsRequest)));
request.deleteMail(list.get(i).getId(), entityId);
}
}
}
});
}
});
// enable button
CustomButton enableButton = TabMenu.getPredefinedButton(ButtonType.ENABLE, ButtonTranslation.INSTANCE.enableMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
request.setEnabled(list, true);
}
}
});
menu.addWidget(enableButton);
// disable button
CustomButton disableButton = TabMenu.getPredefinedButton(ButtonType.DISABLE, ButtonTranslation.INSTANCE.disableMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
request.setEnabled(list, false);
}
}
});
menu.addWidget(disableButton);
menu.addWidget(new CustomButton(ButtonTranslation.INSTANCE.mailFooterButton() + "…", ButtonTranslation.INSTANCE.editMailFooter(), SmallIcons.INSTANCE.emailIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (group == null) {
session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(vo));
} else {
session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(group));
}
}
}));
CustomButton copy;
if (group == null) {
copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromVoButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromVo(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(voId, 0));
}
});
} else {
copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromGroupButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromGroup(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(group.getVoId(), groupId));
}
});
}
menu.addWidget(copy);
// TABLE
CellTable<ApplicationMail> table = mailsRequest.getTable(new FieldUpdater<ApplicationMail, String>() {
public void update(int index, ApplicationMail appMail, String value) {
session.getTabManager().addTabToCurrentTab(new EditMailTabItem(appMail));
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
removeButton.setEnabled(false);
enableButton.setEnabled(false);
disableButton.setEnabled(false);
JsonUtils.addTableManagedButton(mailsRequest, table, removeButton);
JsonUtils.addTableManagedButton(mailsRequest, table, enableButton);
JsonUtils.addTableManagedButton(mailsRequest, table, disableButton);
session.getUiElements().resizePerunTable(sp, 100);
firstTabPanel.add(sp);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations