use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class ApplicationFormPage method formError.
/**
* Form error
*/
protected void formError(PerunError error) {
if (error != null) {
submittedOrError = true;
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
bodyContents.setWidget(ft);
if (error.getName().equalsIgnoreCase("ApplicationNotCreatedException")) {
// application WAS NOT SAVED
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>" + ApplicationMessages.INSTANCE.errorWhileCreatingApplication() + "</h2>" + "<p><strong>" + ApplicationMessages.INSTANCE.errorWhileCreatingApplicationMessage() + "</strong></p>");
// back to form button to prevent user from losing data
final CustomButton back = new CustomButton("Back", "Back to application form", SmallIcons.INSTANCE.arrowLeftIcon());
ft.setWidget(1, 0, back);
ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
back.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
submittedOrError = false;
bodyContents.setWidget(formContent);
}
});
} else {
// some minor error - application WAS SAVED
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>" + ApplicationMessages.INSTANCE.errorWhileCreatingApplication() + "</h2>" + "<p><strong>" + ApplicationMessages.INSTANCE.voAdministratorWasNotified() + "</strong>" + "<p>" + ApplicationMessages.INSTANCE.ifEmailProvidedCheckInbox() + "</p>");
}
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
}
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class PasswordResetFormPage method getContent.
/**
* Returns page content
*
* @return page content
*/
public Widget getContent() {
bodyContents.clear();
final VerticalPanel vp = new VerticalPanel();
vp.setSize("50%", "50%");
vp.getElement().setAttribute("style", "margin: auto; position: relative; top: 50px;");
bodyContents.setWidget(vp);
// if using backup pwd-reset option, draw different content
if (Location.getParameterMap().keySet().contains("m") && Location.getParameterMap().keySet().contains("i") && session.getRpcUrl().startsWith("/non/rpc")) {
return drawNonAuthzPasswordReset(vp);
}
if (Location.getParameter("login-namespace") != null && !Location.getParameter("login-namespace").isEmpty()) {
namespace = Location.getParameter("login-namespace");
} else {
namespace = "";
}
final Label headerLabel = new Label();
final ExtendedPasswordBox passBox = new ExtendedPasswordBox();
final ExtendedPasswordBox secondPassBox = new ExtendedPasswordBox();
final ExtendedTextBox.TextBoxValidator validator;
final ExtendedTextBox.TextBoxValidator validator2;
final CustomButton resetPass = new CustomButton("Reset password", "Reset password in namespace: " + namespace, SmallIcons.INSTANCE.keyIcon());
validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (passBox.getTextBox().getValue().trim().isEmpty()) {
passBox.setError("Password can't be empty !");
return false;
} else if (!passBox.getTextBox().getValue().trim().equals(secondPassBox.getTextBox().getValue().trim())) {
passBox.setError("Password in both textboxes must be the same !");
return false;
} else {
passBox.setOk();
secondPassBox.setOk();
return true;
}
}
};
validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (secondPassBox.getTextBox().getValue().trim().isEmpty()) {
secondPassBox.setError("Password can't be empty !");
return false;
} else if (!secondPassBox.getTextBox().getValue().trim().equals(passBox.getTextBox().getValue().trim())) {
secondPassBox.setError("Password in both textboxes must be the same !");
return false;
} else {
secondPassBox.setOk();
passBox.setOk();
return true;
}
}
};
passBox.setValidator(validator);
secondPassBox.setValidator(validator2);
FlexTable ft = new FlexTable();
ft.setSize("300px", "100px");
ft.addStyleName("inputFormFlexTable");
ft.getElement().setAttribute("style", "margin: auto;");
ft.setHTML(1, 0, "New password:");
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
ft.setWidget(1, 1, passBox);
ft.setHTML(2, 0, "Retype new password:");
ft.getFlexCellFormatter().setStyleName(2, 0, "itemName");
ft.setWidget(2, 1, secondPassBox);
final FlexTable header = new FlexTable();
header.setWidget(0, 0, new AjaxLoaderImage());
header.setWidget(0, 1, headerLabel);
GetLogins loginsCall = new GetLogins(session.getUser().getId(), new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Error occurred when getting your login from Perun. Please, reload page to retry.</h2><p>" + error.getErrorId() + ": " + error.getErrorInfo() + "</p>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
@Override
public void onFinished(JavaScriptObject jso) {
header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.keyIcon()));
logins = JsonUtils.jsoAsList(jso);
if (logins != null && !logins.isEmpty()) {
for (Attribute a : logins) {
// if have login in namespace
if (a.getFriendlyNameParameter().equals(namespace)) {
boolean found = false;
for (String name : Utils.getSupportedPasswordNamespaces()) {
if (a.getFriendlyNameParameter().equalsIgnoreCase(name)) {
found = true;
}
}
if (found) {
// HAVE LOGIN AND SUPPORTED
headerLabel.setText("Password reset for " + a.getValue() + "@" + namespace);
return;
} else {
// NOT SUPPORTED
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Password reset in selected namespace is not supported !</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
return;
}
}
}
}
// DO NOT HAVE LOGIN IN NAMESPACE
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
if (namespace != null && !namespace.isEmpty()) {
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You don't have login in selected namespace !</h2>");
} else {
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You must specify login-namespace in URL !</h2>");
}
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
});
loginsCall.retrieveData();
resetPass.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.disableButtonEvents(resetPass, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>Password successfully changed!</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setHTML(1, 0, "<h2>New password will work on all resources in approx. 15 minutes after reset.</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
}), false);
if (validator.validateTextBox() && validator2.validateTextBox()) {
changepw.changePassword(session.getUser(), namespace, "", passBox.getTextBox().getText().trim());
}
}
});
headerLabel.setText("Password reset for ");
headerLabel.setStyleName("now-managing");
vp.add(header);
vp.add(ft);
TabMenu menu = new TabMenu();
menu.addWidget(resetPass);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
return bodyContents;
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class AddDependencyTabItem method draw.
public Widget draw() {
// TITLE
titleWidget.setText("Add dependency");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
// fill listbox after callback finishes
final JsonCallbackEvents localEvents = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listBox.clear();
ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
if (execs != null && !execs.isEmpty()) {
execs = new TableSorter<ExecService>().sortByService(execs);
for (int i = 0; i < execs.size(); i++) {
listBox.addItem(execs.get(i));
if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
// preselect different type of exec service from same service
listBox.setSelected(execs.get(i), true);
}
}
addButton.setEnabled(true);
} else {
listBox.addItem("No exec service available");
}
}
@Override
public void onLoadingStart() {
listBox.clear();
listBox.addItem("Loading...");
addButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
listBox.addItem("Error while loading");
addButton.setEnabled(false);
}
};
// callback for all services
ListExecServices callback = new ListExecServices(0, localEvents);
callback.retrieveData();
// layout
layout.setHTML(0, 0, "ExecService:");
layout.setHTML(1, 0, "Depend On:");
layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
layout.setWidget(1, 1, listBox);
final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
CreateDependency request = new CreateDependency(closeTabEvents);
request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
}
});
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(addButton);
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.widgets.CustomButton in project perun by CESNET.
the class AddExecServiceTabItem method draw.
public Widget draw() {
titleWidget.setText("Create exec service");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
layout.setWidth("350px");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// define objects
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createExecService());
Label serviceLabel = new Label();
serviceLabel.setText(service.getName() + " (" + serviceId + ")");
final ListBox type = new ListBox();
type.addItem("GENERATE", "GENERATE");
type.addItem("SEND", "SEND");
final VerticalPanel fp = new VerticalPanel();
final RadioButton radio1 = new RadioButton("rd-type", "GENERATE + SEND");
final RadioButton radio2 = new RadioButton("rd-type", "GENERATE");
final RadioButton radio3 = new RadioButton("rd-type", "SEND");
radio1.setValue(true);
fp.add(radio1);
fp.add(radio2);
fp.add(radio3);
final CheckBox enabled = new CheckBox();
enabled.setText("Enabled / Disabled");
enabled.setValue(true);
final ExtendedTextBox delay = new ExtendedTextBox();
delay.getTextBox().setText(DEFAULT_DELAY);
final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
delay.setError("Delay must be a number (time in minutes) !");
return false;
} else {
delay.setOk();
return true;
}
}
};
delay.setValidator(delayValidator);
final ExtendedTextBox scriptPath = new ExtendedTextBox();
final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (scriptPath.getTextBox().getText().trim().isEmpty()) {
scriptPath.setError("Script path can't be empty !");
return false;
} else {
scriptPath.setOk();
return true;
}
}
};
scriptPath.setValidator(scriptValidator);
// put default path
scriptPath.getTextBox().setValue("./" + service.getName());
// layout
layout.setHTML(0, 0, "Service:");
layout.setHTML(1, 0, "Type:");
layout.setHTML(2, 0, "Status:");
layout.setHTML(3, 0, "Delay:");
layout.setHTML(4, 0, "Script path:");
layout.setWidget(0, 1, serviceLabel);
layout.setWidget(1, 1, fp);
layout.setWidget(2, 1, enabled);
layout.setWidget(3, 1, delay);
layout.setWidget(4, 1, scriptPath);
// send button
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (delayValidator.validateTextBox() && scriptValidator.validateTextBox()) {
int delayNum = Integer.parseInt(delay.getTextBox().getText().trim());
InsertExecService request = new InsertExecService(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
if (radio1.getValue()) {
request.addExecService(service, "GENERATE", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
request.addExecService(service, "SEND", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
} else if (radio2.getValue()) {
request.addExecService(service, "GENERATE", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
} else if (radio3.getValue()) {
request.addExecService(service, "SEND", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
}
}
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
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.widgets.CustomButton in project perun by CESNET.
the class EditExecServiceTabItem method draw.
public Widget draw() {
titleWidget = new Label("Edit ExecService");
VerticalPanel vp = new VerticalPanel();
final CheckBox enabled = new CheckBox();
enabled.setText("Enabled / Disabled");
enabled.setValue(execService.isEnabled());
final ExtendedTextBox delay = new ExtendedTextBox();
delay.getTextBox().setText("" + execService.getDefaultDelay());
final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
delay.setError("Delay must be a number (time in minutes) !");
return false;
} else {
delay.setOk();
return true;
}
}
};
delay.setValidator(delayValidator);
final ExtendedTextBox scriptPath = new ExtendedTextBox();
scriptPath.getTextBox().setValue(execService.getScriptPath());
final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (scriptPath.getTextBox().getText().trim().isEmpty()) {
scriptPath.setError("Script path can't be empty !");
return false;
} else {
scriptPath.setOk();
return true;
}
}
};
scriptPath.setValidator(scriptValidator);
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// send button
final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes of ExecService");
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!scriptValidator.validateTextBox() && !delayValidator.validateTextBox())
return;
ExecService es = JsonUtils.clone(execService).cast();
es.setEnabled(enabled.getValue());
es.setDefaultDelay(Integer.parseInt(delay.getTextBox().getValue().trim()));
es.setScriptPath(scriptPath.getTextBox().getValue().trim());
UpdateExecService request = new UpdateExecService(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
request.updateExecService(es);
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
// Add some standard form options
layout.setHTML(0, 0, "Enabled:");
layout.setWidget(0, 1, enabled);
layout.setHTML(1, 0, "Script path:");
layout.setWidget(1, 1, scriptPath);
layout.setHTML(2, 0, "Delay:");
layout.setWidget(2, 1, delay);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(saveButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations