use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.
the class GetAttributesDefinitionWithRights method onFinished.
/**
* Called, when operation finishes successfully.
*/
public void onFinished(JavaScriptObject jso) {
clearTable();
for (Attribute a : JsonUtils.<Attribute>jsoAsList(jso)) {
// check namespace for core
if (noCore && a.getDefinition().equals("core")) {
// do not add anything
} else {
// if not empty, proceed to check
if (!entities.isEmpty()) {
if (entities.contains(a.getEntity())) {
// add
addToTable(a);
}
} else {
addToTable(a);
}
}
}
sortTable();
loaderImage.loadingFinished();
session.getUiElements().setLogText("Attribute definitions loaded: " + list.size());
events.onFinished(jso);
}
use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.
the class GetRequiredAttributes method onFinished.
/**
* Called, when operation finishes successfully.
*/
public void onFinished(JavaScriptObject jso) {
clearTable();
for (Attribute a : JsonUtils.<Attribute>jsoAsList(jso)) {
if (!a.getDefinition().equals("core")) {
addToTable(a);
}
}
sortTable();
loaderImage.loadingFinished();
session.getUiElements().setLogText("Required attributes loaded: " + list.size());
events.onFinished(jso);
}
use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.
the class GetRequiredAttributes method getEmptyTable.
/**
* Returns empty table widget with attributes
*
* @return table widget
*/
public CellTable<Attribute> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<Attribute>(list);
// Cell table
table = new PerunTable<Attribute>(list);
// remove row count change handler
table.removeRowCountChangeHandler();
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<Attribute> columnSortHandler = new ListHandler<Attribute>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Attribute>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
// because of tab index
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// checkbox column
Column<Attribute, Attribute> checkBoxColumn = new Column<Attribute, Attribute>(new PerunCheckboxCell<Attribute>(true, false, false)) {
@Override
public Attribute getValue(Attribute object) {
// Get the value from the selection model.
GeneralObject go = object.cast();
go.setChecked(selectionModel.isSelected(object));
return go.cast();
}
};
// updates the columns size
table.setColumnWidth(checkBoxColumn, 40.0, Unit.PX);
// Add the columns
// Checkbox column header
CheckboxCell cb = new CheckboxCell();
Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {
public Boolean getValue() {
//return true to see a checked checkbox.
return false;
}
};
checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {
public void update(Boolean value) {
// sets selected to all, if value = true, unselect otherwise
for (Attribute obj : list) {
if (obj.isWritable()) {
selectionModel.setSelected(obj, value);
}
}
}
});
table.addColumn(checkBoxColumn, checkBoxHeader);
// Create ID column.
table.addIdColumn("Attribute ID");
// Name column
Column<Attribute, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {
public String getValue(Attribute attribute) {
return attribute.getFriendlyName();
}
}, this.tableFieldUpdater);
// Create ENTITY column
Column<Attribute, String> entityColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {
public String getValue(Attribute g) {
return g.getEntity();
}
}, this.tableFieldUpdater);
// Create def type column
Column<Attribute, String> defTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {
public String getValue(Attribute g) {
return g.getDefinition();
}
}, this.tableFieldUpdater);
// Create type column.
Column<Attribute, String> typeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {
public String getValue(Attribute attribute) {
return renameContent(attribute.getType());
}
}, this.tableFieldUpdater);
// Create value column.
Column<Attribute, String> valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {
public String getValue(Attribute attribute) {
if (attribute.getValue() == null)
return "";
return attribute.getValue();
}
}, new FieldUpdater<Attribute, String>() {
public void update(int index, Attribute object, String newText) {
if (object.setValue(newText)) {
selectionModel.setSelected(object, true);
} else {
selectionModel.setSelected(object, false);
UiElements.cantSaveAttributeValueDialogBox(object);
}
}
});
// Sorting name column
nameColumn.setSortable(true);
columnSortHandler.setComparator(nameColumn, new Comparator<Attribute>() {
public int compare(Attribute o1, Attribute o2) {
return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
}
});
// Sorting type column
typeColumn.setSortable(true);
columnSortHandler.setComparator(typeColumn, new Comparator<Attribute>() {
public int compare(Attribute o1, Attribute o2) {
return o1.getType().compareToIgnoreCase(o2.getType());
}
});
// Sorting value column
valueColumn.setSortable(true);
columnSortHandler.setComparator(valueColumn, new Comparator<Attribute>() {
public int compare(Attribute o1, Attribute o2) {
return o1.getValue().compareToIgnoreCase(o2.getValue());
}
});
// Sorting value column
entityColumn.setSortable(true);
columnSortHandler.setComparator(entityColumn, new Comparator<Attribute>() {
public int compare(Attribute o1, Attribute o2) {
return o1.getEntity().compareToIgnoreCase(o2.getEntity());
}
});
// Sorting value column
defTypeColumn.setSortable(true);
columnSortHandler.setComparator(defTypeColumn, new Comparator<Attribute>() {
public int compare(Attribute o1, Attribute o2) {
return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
}
});
// Add the columns.
this.table.addColumnSortHandler(columnSortHandler);
// updates the columns size
this.table.setColumnWidth(entityColumn, 100.0, Unit.PX);
this.table.setColumnWidth(defTypeColumn, 110.0, Unit.PX);
this.table.setColumnWidth(typeColumn, 100.0, Unit.PX);
this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);
this.table.setColumnWidth(valueColumn, 200.0, Unit.PX);
// Add the columns.
this.table.addColumn(nameColumn, "Name");
this.table.addColumn(entityColumn, "Entity");
this.table.addColumn(defTypeColumn, "Definition");
this.table.addColumn(typeColumn, "Value type");
this.table.addColumn(valueColumn, "Value");
this.table.addDescriptionColumn();
return this.table;
}
use of cz.metacentrum.perun.webgui.model.Attribute 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.model.Attribute in project perun by CESNET.
the class GetCompleteRichUsers method getTable.
/**
* Returns table of users.
* @return
*/
public CellTable<User> getTable() {
// retrieve data
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<User>(list);
// Cell table
table = new PerunTable<User>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<User> columnSortHandler = new ListHandler<User>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<User>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
// columns
if (checkable) {
table.addCheckBoxColumn();
}
table.addIdColumn("User ID", tableFieldUpdater);
// NAME COLUMN
Column<User, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User user) {
return user.getFullName();
}
}, tableFieldUpdater);
nameColumn.setSortable(true);
columnSortHandler.setComparator(nameColumn, new Comparator<User>() {
public int compare(User o1, User o2) {
return o1.getLastName().compareToIgnoreCase(o2.getLastName());
}
});
// Create organization column.
Column<User, String> organizationColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:organization");
String value = "";
if (at != null) {
value = at.getValue();
}
return value;
}
}, this.tableFieldUpdater);
// Create e-mail column.
Column<User, String> emailColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
String value = "";
if (at != null) {
value = at.getValue();
// replace "," to " " in emails
value = value.replace(",", " ");
}
return value;
}
}, this.tableFieldUpdater);
// Create name column.
Column<User, String> loginsColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
return object.getLogins();
}
}, this.tableFieldUpdater);
organizationColumn.setSortable(true);
columnSortHandler.setComparator(organizationColumn, new RichUserComparator(RichUserComparator.Column.ORGANIZATION));
emailColumn.setSortable(true);
columnSortHandler.setComparator(emailColumn, new RichUserComparator(RichUserComparator.Column.EMAIL));
// SERVICE COLUMN
Column<User, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User user) {
if (user.isServiceUser()) {
return "Service";
} else if (user.isSponsoredUser()) {
return "Sponsored";
} else {
return "Person";
}
}
}, tableFieldUpdater);
serviceColumn.setSortable(true);
columnSortHandler.setComparator(serviceColumn, new Comparator<User>() {
public int compare(User o1, User o2) {
String type1 = "Person";
if (o1.isServiceUser()) {
type1 = "Service";
} else if (o1.isSponsoredUser()) {
type1 = "Sponsored";
}
String type2 = "Person";
if (o2.isServiceUser()) {
type2 = "Service";
} else if (o2.isSponsoredUser()) {
type2 = "Sponsored";
}
return type1.compareTo(type2);
}
});
// Add the other columns.
table.addColumn(nameColumn, "Name");
table.addColumn(organizationColumn, "Organization");
table.addColumn(emailColumn, "E-mail");
table.addColumn(loginsColumn, "Logins");
table.addColumn(serviceColumn, "User type");
return table;
}
Aggregations