use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class GetGroupRichMembers method getTable.
/**
* Returns the table with rich members of group
*
* @return table widget
*/
public CellTable<RichMember> getTable() {
// retrieves data
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<RichMember>(list);
// Cell table
table = new PerunTable<RichMember>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<RichMember> columnSortHandler = new ListHandler<RichMember>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// Table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichMember>createCheckboxManager());
// Set empty content & loader
table.setEmptyTableWidget(loaderImage);
// Checkbox column column
table.addCheckBoxColumn();
// Status column
Column<RichMember, String> statusColumn = new Column<RichMember, String>(new PerunStatusCell()) {
@Override
public String getValue(RichMember object) {
return object.getStatus();
}
};
// own onClick tab for changing member's status
statusColumn.setFieldUpdater(new FieldUpdater<RichMember, String>() {
public void update(int index, final RichMember object, String value) {
FlexTable widget = new FlexTable();
final ListBox lb = new ListBox(false);
lb.addItem("VALID", "VALID");
lb.addItem("INVALID", "INVALID");
lb.addItem("SUSPENDED", "SUSPENDED");
lb.addItem("EXPIRED", "EXPIRED");
lb.addItem("DISABLED", "DISABLED");
widget.setHTML(0, 0, "<strong>Status: </strong>");
widget.setWidget(0, 1, lb);
// pick which one is already set
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.getItemText(i).equalsIgnoreCase(object.getStatus())) {
lb.setSelectedIndex(i);
}
}
Confirm conf = new Confirm("Change member's status: " + object.getUser().getFullName(), widget, true);
conf.setCancelButtonText("Cancel");
conf.setOkButtonText("Change status");
conf.setOkClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SetStatus call = new SetStatus(object.getId(), new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
clearTable();
retrieveData();
}
public void onError(PerunError error) {
clearTable();
retrieveData();
}
});
call.setStatus(lb.getValue(lb.getSelectedIndex()));
}
});
conf.show();
}
});
// status column sortable
statusColumn.setSortable(true);
columnSortHandler.setComparator(statusColumn, new GeneralComparator<RichMember>(GeneralComparator.Column.STATUS));
table.addColumn(statusColumn, "Status");
table.setColumnWidth(statusColumn, 20, Unit.PX);
// Create member ID column.
Column<RichMember, String> memberIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {
public String getValue(RichMember object) {
return String.valueOf(object.getId());
}
}, this.tableFieldUpdater);
// Create User ID column.
Column<RichMember, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {
public String getValue(RichMember object) {
return String.valueOf(object.getUser().getId());
}
}, this.tableFieldUpdater);
columnSortHandler.setComparator(memberIdColumn, new RichMemberComparator(RichMemberComparator.Column.MEMBER_ID));
memberIdColumn.setSortable(true);
userIdColumn.setSortable(true);
columnSortHandler.setComparator(userIdColumn, new RichMemberComparator(RichMemberComparator.Column.USER_ID));
table.setColumnWidth(memberIdColumn, 110.0, Unit.PX);
table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
// headers
if (JsonUtils.isExtendedInfoVisible()) {
table.addColumn(memberIdColumn, "Member ID");
table.addColumn(userIdColumn, "User ID");
}
table.addNameColumn(tableFieldUpdater);
return table;
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class CopyManagers method copyFacilityManagers.
/**
* Attempts to copy managers from one facility to another
*
* @param sourceFacility ID of source facility to get managers from
* @param destinationFacility ID of destination facility to copy managers to
*/
public void copyFacilityManagers(int sourceFacility, int destinationFacility) {
this.sourceFacility = sourceFacility;
this.destinationFacility = destinationFacility;
// test arguments
if (!this.testCreating()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Copying facility managers failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Facility managers copied.");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class CreateFacility method createFacility.
/**
* Attempts to create a new Facility, it first tests the values and then submits them.
*
* @param name Facility name
*/
public void createFacility(final String name, final String description) {
this.name = name;
this.description = description;
// test arguments
if (!this.testCreating()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Creating facility " + name + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Facility " + name + " created.");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class UpdateExecService method updateExecService.
/**
* Creates exec service in DB and associate it with service
*
* @param execService ExecService to update to
*/
public void updateExecService(ExecService execService) {
JSONObject execOrig = new JSONObject(execService);
// reconstruct exec service
JSONObject exec = new JSONObject();
exec.put("id", execOrig.get("id"));
exec.put("execServiceType", execOrig.get("execServiceType"));
exec.put("enabled", execOrig.get("enabled"));
exec.put("defaultDelay", execOrig.get("defaultDelay"));
exec.put("defaultRecurrence", execOrig.get("defaultRecurrence"));
// insert service into exec service
exec.put("service", execOrig.get("service"));
exec.put("script", execOrig.get("script"));
exec.put("beanName", execOrig.get("beanName"));
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("execService", exec);
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Update of exec service failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Exec service successfully updated!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class CreateGroup method createGroup.
/**
* Creates a new GROUP
* @param jsonQuery A JSON object prepared by createGroupInGroup and createGroupInVo methods.
*/
private void createGroup(JSONObject jsonQuery) {
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Creating group failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
Group gp = jso.cast();
// if group admin, grant access in GUI !!
if (session.isGroupAdmin() && gp != null) {
session.addEditableGroup(gp.getId());
session.getUiElements().setLogSuccessText("Group " + gp.getName() + " successfully created!");
}
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
Aggregations