use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class AddFacilityManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// pass empty items to menu to ensure drawing of rest
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(2, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(3, box);
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
final TabItem tab = this;
tabMenu.addWidget(1, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class CreateAttributeDefinitionTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// creates HTML elements
final ExtendedTextBox attributeDisplayName = new ExtendedTextBox();
final ExtendedTextBox attributeName = new ExtendedTextBox();
final ExtendedTextBox attributeDescription = new ExtendedTextBox();
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (attributeName.getTextBox().getText().trim().isEmpty()) {
attributeName.setError("Name of attribute can't be empty.");
} else if (!attributeName.getTextBox().getText().trim().matches(Utils.ATTRIBUTE_FRIENDLY_NAME_MATCHER)) {
attributeName.setError("Name of attribute can contain only letters, numbers, dash and colon.");
} else {
attributeName.setOk();
return true;
}
return false;
}
};
final ExtendedTextBox.TextBoxValidator descriptionValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!attributeDescription.getTextBox().getText().trim().isEmpty()) {
attributeDescription.setOk();
return true;
} else {
attributeDescription.setError("Description of attribute can't be empty.");
return false;
}
}
};
final ExtendedTextBox.TextBoxValidator displayNameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!attributeDisplayName.getTextBox().getText().trim().isEmpty()) {
attributeDisplayName.setOk();
return true;
} else {
attributeDisplayName.setError("Display name of attribute can't be empty.");
return false;
}
}
};
attributeName.setValidator(nameValidator);
attributeDisplayName.setValidator(displayNameValidator);
attributeDescription.setValidator(descriptionValidator);
final ListBox entityListBox = new ListBox();
final ListBox definitionListBox = new ListBox();
final ListBox typeListBox = new ListBox();
// fill listboxs with pre-defined values
entityListBox.addItem("facility", "urn:perun:facility:");
entityListBox.addItem("resource", "urn:perun:resource:");
entityListBox.addItem("group", "urn:perun:group:");
entityListBox.addItem("group_resource", "urn:perun:group_resource:");
entityListBox.addItem("host", "urn:perun:host:");
entityListBox.addItem("member", "urn:perun:member:");
entityListBox.addItem("member_group", "urn:perun:member_group:");
entityListBox.addItem("member_resource", "urn:perun:member_resource:");
entityListBox.addItem("user", "urn:perun:user:");
entityListBox.addItem("user_ext_source", "urn:perun:ues:");
entityListBox.addItem("user_facility", "urn:perun:user_facility:");
entityListBox.addItem("vo", "urn:perun:vo:");
entityListBox.addItem("entityless", "urn:perun:entityless:");
definitionListBox.addItem("def", "attribute-def:def");
definitionListBox.addItem("opt", "attribute-def:opt");
definitionListBox.addItem("virt", "attribute-def:virt");
definitionListBox.addItem("core", "attribute-def:core");
typeListBox.addItem("String", "java.lang.String");
typeListBox.addItem("Integer", "java.lang.Integer");
typeListBox.addItem("Boolean", "java.lang.Boolean");
typeListBox.addItem("Array", "java.util.ArrayList");
typeListBox.addItem("LinkedHashMap", "java.util.LinkedHashMap");
typeListBox.addItem("LargeString", Utils.largeStringClassName);
typeListBox.addItem("LargeArrayList", Utils.largeArrayListClassName);
// prepare layout for this tab
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
TabMenu menu = new TabMenu();
// BUTTONS
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createAttributeDefinition());
menu.addWidget(createButton);
// close tab events & enable, disable buttons
final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(createButton, this);
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (nameValidator.validateTextBox() && descriptionValidator.validateTextBox() && displayNameValidator.validateTextBox()) {
String displayName = attributeDisplayName.getTextBox().getText().trim();
String friendlyName = attributeName.getTextBox().getText().trim();
String description = attributeDescription.getTextBox().getText().trim();
String namespace = entityListBox.getValue(entityListBox.getSelectedIndex()) + definitionListBox.getValue(definitionListBox.getSelectedIndex());
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
CreateAttribute request = new CreateAttribute(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
AttributeDefinition a = jso.cast();
ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
AttributeRights right = AttributeRights.create(a.getId(), "SELF");
list.add(getRightsFromWidgets(selfRead, selfWrite, right));
AttributeRights right2 = AttributeRights.create(a.getId(), "VOADMIN");
list.add(getRightsFromWidgets(voRead, voWrite, right2));
AttributeRights right3 = AttributeRights.create(a.getId(), "GROUPADMIN");
list.add(getRightsFromWidgets(groupRead, groupWrite, right3));
AttributeRights right4 = AttributeRights.create(a.getId(), "FACILITYADMIN");
list.add(getRightsFromWidgets(facilityRead, facilityWrite, right4));
// after update - update rights
SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
enableDisableWidgets(true);
closeTabEvents.onFinished(jso);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
}
}));
request.setAttributeRights(list);
}
}));
request.createAttributeDefinition(displayName, friendlyName, description, namespace, type);
}
}
});
// insert layout
layout.setHTML(0, 0, "Friendly name:");
layout.setWidget(0, 1, attributeName);
layout.setHTML(1, 0, "Display name:");
layout.setWidget(1, 1, attributeDisplayName);
layout.setHTML(2, 0, "Description:");
layout.setWidget(2, 1, attributeDescription);
layout.setHTML(3, 0, "Entity:");
layout.setWidget(3, 1, entityListBox);
layout.setHTML(4, 0, "Definition type:");
layout.setWidget(4, 1, definitionListBox);
layout.setHTML(5, 0, "Value type:");
layout.setWidget(5, 1, typeListBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
final FlexTable rightsTable = new FlexTable();
rightsTable.setStyleName("inputFormFlexTable");
rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
rightsTable.setHTML(0, 2, "<strong>VO</strong>");
rightsTable.setHTML(0, 3, "<strong>GROUP</strong>");
rightsTable.setHTML(0, 4, "<strong>FACILITY</strong>");
rightsTable.setHTML(1, 0, "<strong>READ</strong>");
rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
rightsTable.setWidget(1, 1, selfRead);
rightsTable.setWidget(2, 1, selfWrite);
rightsTable.setWidget(1, 2, voRead);
rightsTable.setWidget(2, 2, voWrite);
rightsTable.setWidget(1, 3, groupRead);
rightsTable.setWidget(2, 3, groupWrite);
rightsTable.setWidget(1, 4, facilityRead);
rightsTable.setWidget(2, 4, facilityWrite);
rightsTable.addStyleName("centeredTable");
vp.add(layout);
vp.add(rightsTable);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class FacilitiesPropagationsTabItem method draw.
public Widget draw() {
mainrow = 0;
okCounter = 0;
errorCounter = 0;
notDeterminedCounter = 0;
procesingCounter = 0;
VerticalPanel mainTab = new VerticalPanel();
mainTab.setWidth("100%");
final TabItem tab = this;
// MAIN PANEL
final ScrollPanel firstTabPanel = new ScrollPanel();
firstTabPanel.setSize("100%", "100%");
firstTabPanel.setStyleName("perun-tableScrollPanel");
final FlexTable help = new FlexTable();
help.setCellPadding(4);
help.setWidth("100%");
help.setHTML(0, 0, "<strong>Color notation:</strong>");
help.getFlexCellFormatter().setWidth(0, 0, "100px");
help.setHTML(0, 1, "<strong>OK</strong>");
help.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
help.getFlexCellFormatter().setWidth(0, 1, "50px");
help.getFlexCellFormatter().setStyleName(0, 1, "green");
help.setHTML(0, 2, "<strong>Error</strong>");
help.getFlexCellFormatter().setWidth(0, 2, "50px");
help.getFlexCellFormatter().setStyleName(0, 2, "red");
help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
help.setHTML(0, 3, "<strong>Not determined</strong>");
help.getFlexCellFormatter().setWidth(0, 3, "50px");
help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
help.getFlexCellFormatter().setStyleName(0, 3, "notdetermined");
/*
help.setHTML(0, 4, "<strong>Processing</strong>");
help.getFlexCellFormatter().setWidth(0, 4, "50px");
help.getFlexCellFormatter().setStyleName(0, 4, "yellow");
help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
*/
final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.refreshButton(), ButtonTranslation.INSTANCE.refreshPropagationResults(), SmallIcons.INSTANCE.updateIcon(), new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
session.getTabManager().reloadTab(tab);
}
});
help.setWidget(0, 5, cb);
help.getFlexCellFormatter().setWidth(0, 5, "200px");
help.setHTML(0, 6, " ");
help.getFlexCellFormatter().setWidth(0, 6, "50%");
mainTab.add(help);
mainTab.add(new HTML("<hr size=\"2\" />"));
mainTab.add(firstTabPanel);
final FlexTable content = new FlexTable();
content.setWidth("100%");
content.setBorderWidth(0);
firstTabPanel.add(content);
content.setStyleName("propagationTable", true);
final AjaxLoaderImage im = new AjaxLoaderImage();
content.setWidget(0, 0, im);
content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
final GetFacilityState callback = new GetFacilityState(0, 0, new JsonCallbackEvents() {
public void onLoadingStart() {
im.loadingStart();
cb.setProcessing(true);
}
public void onError(PerunError error) {
im.loadingError(error);
cb.setProcessing(false);
}
public void onFinished(JavaScriptObject jso) {
im.loadingFinished();
cb.setProcessing(false);
content.clear();
content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
ArrayList<FacilityState> list = JsonUtils.jsoAsList(jso);
if (list != null && !list.isEmpty()) {
list = new TableSorter<FacilityState>().sortByNumberOfDestinations(list);
ArrayList<FacilityState> clusters = new ArrayList<FacilityState>();
ArrayList<FacilityState> hosts = new ArrayList<FacilityState>();
for (final FacilityState state : list) {
if (state.getDestinations().size() > 1) {
clusters.add(state);
} else {
hosts.add(state);
}
}
clusters = new TableSorter<FacilityState>().sortByFacilityName(clusters);
hosts = new TableSorter<FacilityState>().sortByFacilityName(hosts);
for (final FacilityState state : clusters) {
content.setHTML(mainrow, 0, "<strong>" + state.getFacility().getName() + "</strong>");
final FlowPanel inner = new FlowPanel();
content.setWidget(mainrow + 1, 0, inner);
content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
Set<String> destinations = state.getDestinations().keySet();
ArrayList<String> destList = new ArrayList<String>();
int width = 0;
for (String dest : destinations) {
destList.add(dest);
if (dest.indexOf(".") * 8 > width) {
width = dest.indexOf(".") * 8;
}
}
Collections.sort(destList);
for (final String dest : destList) {
String show = dest.substring(0, dest.indexOf("."));
Anchor hyp = new Anchor();
hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + show + "</span>");
hyp.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
}
});
inner.add(hyp);
// style
if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
hyp.addStyleName("red");
errorCounter++;
} else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
hyp.addStyleName("green");
okCounter++;
} else {
hyp.addStyleName("notdetermined");
notDeterminedCounter++;
}
}
if (destList.isEmpty()) {
notDeterminedCounter++;
}
mainrow++;
mainrow++;
}
// PROCESS HOSTS (with one or less destination)
// FIX WIDTH
int width = 0;
for (FacilityState state : hosts) {
if (state.getDestinations().size() < 2) {
if (state.getFacility().getName().length() * 8 > width) {
width = state.getFacility().getName().length() * 8;
}
}
}
FlowPanel inner = new FlowPanel();
for (final FacilityState state : hosts) {
Set<String> destinations = state.getDestinations().keySet();
ArrayList<String> destList = new ArrayList<String>();
for (String dest : destinations) {
destList.add(dest);
}
Collections.sort(destList);
for (final String dest : destList) {
Anchor hyp = new Anchor();
hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + dest + "</span>");
inner.add(hyp);
hyp.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
}
});
// style
if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
hyp.addStyleName("red");
errorCounter++;
} else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
hyp.addStyleName("green");
okCounter++;
} else {
hyp.addStyleName("notdetermined");
notDeterminedCounter++;
}
}
if (destList.isEmpty()) {
Anchor hyp = new Anchor();
hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + state.getFacility().getName() + "</span>");
inner.add(hyp);
hyp.addStyleName("notdetermined");
notDeterminedCounter++;
}
}
if (!hosts.isEmpty()) {
content.setHTML(mainrow, 0, "<strong>Single hosts</strong>");
mainrow++;
}
content.setWidget(mainrow, 0, inner);
content.getFlexCellFormatter().setStyleName(mainrow, 0, "propagationTablePadding");
mainrow++;
}
// set counters
help.setHTML(0, 1, "<strong>Ok (" + okCounter + ")</strong>");
help.setHTML(0, 2, "<strong>Error (" + errorCounter + ")</strong>");
help.setHTML(0, 3, "<strong>Not determined (" + notDeterminedCounter + ")</strong>");
//help.setHTML(0, 4, "<strong>Processing (" + procesingCounter + ")</strong>");
}
});
// get for all facilities
callback.retrieveData();
// resize perun table to correct size on screen
session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class AddGroupManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// pass empty items to menu to ensure drawing of rest
tabMenu.addWidget(UiElements.getRefreshButton(this));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(3, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(4, box);
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
final TabItem tab = this;
tabMenu.addWidget(2, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class UpdateUser method updateUser.
/**
* Updates user details
* @param user User with updated details
*/
public void updateUser(User user) {
if (user == null) {
UiElements.generateAlert("Parameter error", "User to update can't be null");
return;
}
// OBJECT
JSONObject oldUser = new JSONObject(user);
// RECONSTRUCT OBJECT
JSONObject newUser = new JSONObject();
newUser.put("id", oldUser.get("id"));
newUser.put("firstName", oldUser.get("firstName"));
newUser.put("middleName", oldUser.get("middleName"));
newUser.put("lastName", oldUser.get("lastName"));
newUser.put("titleBefore", oldUser.get("titleBefore"));
newUser.put("titleAfter", oldUser.get("titleAfter"));
newUser.put("serviceUser", oldUser.get("serviceUser"));
newUser.put("sponsoredUser", oldUser.get("sponsoredUser"));
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("user", newUser);
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Updating user failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
User u = jso.cast();
session.getUiElements().setLogSuccessText("User " + u.getFullNameWithTitles() + " successfully updated!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
Aggregations