use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class SelfResourcesSettingsTabItem method userSettingsForVo.
/**
* User settings for the VO
* @param vo
* @param member
* @return
*/
protected Widget userSettingsForVo(final VirtualOrganization vo, Member member) {
final VerticalPanel vp = new VerticalPanel();
vp.setWidth("100%");
GetAllowedResources resourcesCallback = new GetAllowedResources(member.getId(), new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
vp.clear();
vp.add(new AjaxLoaderImage());
}
@Override
public void onFinished(JavaScriptObject jso) {
vp.clear();
// convert & sort
ArrayList<Resource> resources = JsonUtils.jsoAsList(jso);
resources = new TableSorter<Resource>().sortByDescription(resources);
// if empty
if (resources.isEmpty() || resources == null) {
FlexTable ft = new FlexTable();
ft.setHTML(0, 0, "<p><strong>VO " + vo.getName() + " doesn't provide any resources to configure.</strong></p>");
vp.add(ft);
return;
}
// process
for (Resource r : resources) {
DisclosurePanel settings = new DisclosurePanel();
settings.setWidth("100%");
final FlexTable header = new FlexTable();
header.setWidth("100%");
header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.databaseServerIcon()));
header.getFlexCellFormatter().setWidth(0, 0, "40px");
Anchor a = new Anchor("<p class=\"now-managing\">" + r.getDescription() + " (" + r.getName() + ")</p>", true);
header.setWidget(0, 1, a);
header.setTitle("Click to show setting for resource " + r.getName());
settings.setHeader(header);
// load content for each resource
vp.add(loadSettings(settings, r));
}
}
});
resourcesCallback.retrieveData();
return vp;
}
use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class ResourceSettingsTabItem method draw.
public Widget draw() {
if (service != null) {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
} else {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
}
vp.setSize("100%", "100%");
vp.clear();
// menu
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// callback
final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
resAttrs.setIds(ids);
final GetAttributesV2 attrs = new GetAttributesV2();
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
resAttrs.setCheckable(false);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
attrs.setCheckable(false);
// puts first table
final CellTable<Attribute> table = resAttrs.getEmptyTable();
final CellTable<Attribute> table2 = attrs.getEmptyTable();
// if for one service only modify empty table message
if (service != null) {
AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
}
final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
sp.setWidget(table);
sp2.setWidget(table2);
// switch between assigned and all
final CheckBox chb = new CheckBox();
chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
// default true
chb.setValue(lastOfferAvailableOnly);
// event which fills the listbox and call getRequiredAttributes
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// clear services list
servList.clear();
// process services
ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
srv = new TableSorter<Service>().sortByName(srv);
for (int i = 0; i < srv.size(); i++) {
// fill listbox
servList.addItem(srv.get(i));
}
if (servList.isEmpty()) {
servList.addNotSelectedOption();
lastSelectedService = 0;
indexInList = 0;
attrs.retrieveData();
setTable(false);
return;
}
if (lastSelectedService == 0 && chb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
if (indexInList == 0) {
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
} else if (indexInList == 1) {
servList.setSelectedIndex(1);
}
} else if (lastSelectedService == 0 && chb.getValue() == false) {
servList.addNotSelectedOption();
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
} else if (lastSelectedService != 0) {
if (chb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
} else {
servList.addNotSelectedOption();
}
// remove last service, we can't be sure it was loaded again
ids.remove("service");
// either all or specific service
servList.setSelectedIndex(1);
for (Service s : servList.getAllObjects()) {
if (s.getId() == lastSelectedService) {
// service selected last time was found in a list
servList.setSelected(s, true);
ids.put("service", s.getId());
break;
}
}
}
// make call
resAttrs.clearTable();
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
;
@Override
public void onError(PerunError error) {
servList.clear();
servList.addItem("Error while loading");
if (required) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
} else {
((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
}
}
;
@Override
public void onLoadingStart() {
servList.removeAllOption();
servList.removeNotSelectedOption();
servList.clear();
servList.addItem("Loading...");
}
};
final GetAssignedServices services = new GetAssignedServices(resourceId, event);
final GetServices allServices = new GetServices(event);
// offer services selection
if (serviceId == 0) {
// services listbox
servList.setTitle("Services");
attrs.setIds(ids);
// on change of service update table
servList.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// if service selected
if (servList.getSelectedIndex() == 0) {
attrs.retrieveData();
setTable(false);
lastSelectedService = 0;
indexInList = 0;
return;
} else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
ids.remove("service");
lastSelectedService = 0;
indexInList = 1;
} else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
ids.put("service", servList.getSelectedObject().getId());
lastSelectedService = servList.getSelectedObject().getId();
}
lastOfferAvailableOnly = chb.getValue();
resAttrs.clearTable();
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
});
if (chb.getValue() == false) {
allServices.retrieveData();
} else {
services.retrieveData();
}
} else {
// retrieve data for selected service only
lastSelectedService = serviceId;
lastOfferAvailableOnly = chb.getValue();
ids.put("service", serviceId);
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
// refresh table event - refresh only on finished / on error keep selected
final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
// add save changes to menu
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
menu.addWidget(saveChangesButton);
// set button disable event
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
saveChangesButton.setEnabled(false);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getTableSelectedList();
} else {
list = attrs.getTableSelectedList();
}
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
request.setAttributes(ids, list);
}
}
});
// add set new to menu
CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getList();
} else {
list = attrs.getList();
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
setNewAttributeButton.setEnabled(false);
if (service == null) {
menu.addWidget(setNewAttributeButton);
}
// fill button
final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
menu.addWidget(fillDefaultButton);
// remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
// remove button event
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
removeButton.setEnabled(false);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getTableSelectedList();
} else {
list = attrs.getTableSelectedList();
}
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeButton);
// add service selection to menu and switcher
if (serviceId == 0) {
menu.addWidget(new HTML("<strong>Selected service: </strong>"));
menu.addWidget(servList);
menu.addWidget(chb);
}
// checkbox switcher on click
chb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (chb.getValue() == false) {
lastOfferAvailableOnly = false;
allServices.retrieveData();
} else {
lastOfferAvailableOnly = true;
services.retrieveData();
}
}
});
fillDefaultButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// automatically try to fill all attributes
ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
if (required) {
prepareList = resAttrs.getTableSelectedList();
} else {
prepareList = attrs.getTableSelectedList();
}
final ArrayList<Attribute> list = prepareList;
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {
boolean wasRequiredTable = required;
@Override
public void onFinished(JavaScriptObject jso) {
// remove attribute from original table and put new ones
ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
for (Attribute a : newList) {
for (Attribute oldA : list) {
// deselect old
if (a.getId() == oldA.getId()) {
if (wasRequiredTable) {
resAttrs.getSelectionModel().setSelected(oldA, false);
resAttrs.removeFromTable(oldA);
} else {
attrs.getSelectionModel().setSelected(oldA, false);
attrs.removeFromTable(oldA);
}
}
}
if (wasRequiredTable) {
//add new
resAttrs.addToTable(a);
// select returned
resAttrs.getSelectionModel().setSelected(a, true);
} else {
//add new
attrs.addToTable(a);
// select returned
attrs.getSelectionModel().setSelected(a, true);
}
}
if (wasRequiredTable) {
resAttrs.sortTable();
} else {
attrs.sortTable();
}
}
}));
request.fillAttributes(ids, list);
}
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
fillDefaultButton.setEnabled(false);
/* TODO - not implemented
Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
menu.addWidget(checkValuesButton);
checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");
checkValuesButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
*/
table.addStyleName("perun-table");
table.setWidth("100%");
table2.addStyleName("perun-table");
table2.setWidth("100%");
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
sp2.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp2, 350, this);
// default is required attributes
setTable(true);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class VoResourcesPropagationsTabItem method draw.
public Widget draw() {
mainrow = 0;
okCounter = 0;
errorCounter = 0;
notDeterminedCounter = 0;
procesingCounter = 0;
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources state");
final TabItem tab = this;
VerticalPanel mainTab = new VerticalPanel();
mainTab.setWidth("100%");
// 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%");
final CustomButton cb = UiElements.getRefreshButton(this);
help.setWidget(0, 0, cb);
help.getFlexCellFormatter().setWidth(0, 0, "80px");
help.setHTML(0, 1, "<strong>Color notation:</strong>");
help.getFlexCellFormatter().setWidth(0, 1, "100px");
help.setHTML(0, 2, "<strong>OK</strong>");
help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
help.getFlexCellFormatter().setWidth(0, 2, "50px");
help.getFlexCellFormatter().setStyleName(0, 2, "green");
help.setHTML(0, 3, "<strong>Error</strong>");
help.getFlexCellFormatter().setWidth(0, 3, "50px");
help.getFlexCellFormatter().setStyleName(0, 3, "red");
help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
help.setHTML(0, 4, "<strong>Not determined</strong>");
help.getFlexCellFormatter().setWidth(0, 4, "50px");
help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
help.getFlexCellFormatter().setStyleName(0, 4, "notdetermined");
/*
help.setHTML(0, 5, "<strong>Processing</strong>");
help.getFlexCellFormatter().setWidth(0, 5, "50px");
help.getFlexCellFormatter().setStyleName(0, 5, "yellow");
help.getFlexCellFormatter().setHorizontalAlignment(0, 5, HasHorizontalAlignment.ALIGN_CENTER);
*/
help.setHTML(0, 5, " ");
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 GetAllResourcesState callback = new GetAllResourcesState(voId, 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<ResourceState> list = JsonUtils.jsoAsList(jso);
if (list != null && !list.isEmpty()) {
list = new TableSorter<ResourceState>().sortByResourceName(list);
for (final ResourceState state : list) {
content.setHTML(mainrow, 0, new Image(LargeIcons.INSTANCE.serverGroupIcon()) + "<span class=\"now-managing\" style=\"display: inline-block; position: relative; top: -8px;\">" + state.getResource().getName() + "</span>");
ArrayList<Task> tasks = new TableSorter<Task>().sortByService(JsonUtils.<Task>jsoAsList(state.getTasks()));
if (tasks == null || tasks.isEmpty())
notDeterminedCounter++;
boolean allOk = true;
for (Task tsk : tasks) {
if (tsk.getStatus().equalsIgnoreCase("ERROR")) {
errorCounter++;
allOk = false;
break;
}
}
if (allOk && tasks != null && !tasks.isEmpty())
okCounter++;
ListDataProvider<Task> dataProvider = new ListDataProvider<Task>();
PerunTable<Task> table;
// Table data provider.
dataProvider = new ListDataProvider<Task>(tasks);
// Cell table
table = new PerunTable<Task>(tasks);
table.removeRowCountChangeHandler();
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ColumnSortEvent.ListHandler<Task> columnSortHandler = new ColumnSortEvent.ListHandler<Task>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// set empty content & loader
AjaxLoaderImage loaderImage = new AjaxLoaderImage();
loaderImage.setEmptyResultMessage("No service configuration was propagated to this resource.");
table.setEmptyTableWidget(loaderImage);
loaderImage.loadingFinished();
table.addIdColumn("Task Id");
// Service column
Column<Task, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {
public String getValue(Task task) {
return String.valueOf(task.getExecService().getService().getName());
}
}, null);
// status column
Column<Task, String> statusColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {
public String getValue(Task task) {
return String.valueOf(task.getStatus());
}
}, null);
// start COLUMN
TextColumn<Task> startTimeColumn = new TextColumn<Task>() {
public String getValue(Task result) {
return result.getStartTime();
}
};
// end COLUMN
TextColumn<Task> endTimeColumn = new TextColumn<Task>() {
public String getValue(Task result) {
return result.getEndTime();
}
};
// schedule COLUMN
TextColumn<Task> scheduleColumn = new TextColumn<Task>() {
public String getValue(Task result) {
return result.getSchedule();
}
};
// Add the columns.
table.addColumn(serviceColumn, "Service");
table.addColumn(statusColumn, "Status");
table.addColumn(scheduleColumn, "Scheduled");
table.addColumn(startTimeColumn, "Started");
table.addColumn(endTimeColumn, "Ended");
// set row styles based on task state
table.setRowStyles(new RowStyles<Task>() {
public String getStyleNames(Task row, int rowIndex) {
if (row.getStatus().equalsIgnoreCase("NONE")) {
return "rowdarkgreen";
} else if (row.getStatus().equalsIgnoreCase("DONE")) {
return "rowgreen";
} else if (row.getStatus().equalsIgnoreCase("PROCESSING")) {
return "rowyellow";
} else if (row.getStatus().equalsIgnoreCase("ERROR")) {
return "rowred";
}
return "";
}
});
table.setWidth("100%");
content.setWidget(mainrow + 1, 0, table);
content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
mainrow++;
mainrow++;
}
}
// set counters
help.setHTML(0, 2, "<strong>Ok (" + okCounter + ")</strong>");
help.setHTML(0, 3, "<strong>Error (" + errorCounter + ")</strong>");
help.setHTML(0, 4, "<strong>Not determined (" + notDeterminedCounter + ")</strong>");
//help.setHTML(0, 5, "<strong>Processing (" + procesingCounter + ")</strong>");
}
});
// get for all facilities for VO
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.widgets.AjaxLoaderImage in project perun by CESNET.
the class VoMembersTabItem method draw.
public Widget draw() {
// SET TAB NAME
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": members");
// MAIN PANEL
final VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// MENU
TabMenu tabMenu = new TabMenu();
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
// DISABLED CHECKBOX
final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
disabled.setValue(wasDisabled);
disabled.setVisible(false);
// CALLBACKS
final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, null);
final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
members.excludeDisabled(!wasDisabled);
final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInVo());
final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInVo());
if (!session.isVoAdmin(voId))
findMembers.setCheckable(false);
final CellTable<RichMember> table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {
// when user click on a row -> open new tab
public void update(int index, RichMember object, RichMember value) {
session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), 0));
}
});
// refresh
tabMenu.addWidget(UiElements.getRefreshButton(this));
// ADD
CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToVo(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddMemberToVoTabItem(voId), true);
}
});
if (!session.isVoAdmin(voId))
addButton.setEnabled(false);
tabMenu.addWidget(addButton);
// REMOVE
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromVo());
if (!session.isVoAdmin(voId))
removeButton.setEnabled(false);
tabMenu.addWidget(removeButton);
/*
final CustomButton addServiceButton = new CustomButton(ButtonTranslation.INSTANCE.createServiceMemberButton(), ButtonTranslation.INSTANCE.createServiceMember(), SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new CreateServiceMemberInVoTabItem(vo));
}
});
if (!session.isVoAdmin(voId)) addServiceButton.setEnabled(false);
tabMenu.addWidget(addServiceButton);
*/
// refreshMembers
final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (search) {
findMembers.searchFor(searchString);
} else {
findMembers.clearTable();
members.retrieveData();
}
}
};
// add click handler for remove button
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// state specific events
final ArrayList<RichMember> membersForRemoving = findMembers.getTableSelectedList();
String text = "Following members will be removed from VO and their settings will be lost.<p>You can consider changing their status to \"DISABLED\", which will prevent them from accessing VO resources.";
UiElements.showDeleteConfirm(membersForRemoving, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < membersForRemoving.size(); i++) {
DeleteMember request;
if (i == membersForRemoving.size() - 1) {
request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
} else {
request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.deleteMember(membersForRemoving.get(i).getId());
}
}
});
}
});
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
public void searchFor(String text) {
searchString = text;
search = true;
findMembers.searchFor(text);
}
}, searchButton);
searchBox.getTextBox().setText(searchString);
// checkbox click handler
disabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
wasDisabled = disabled.getValue();
if (search) {
// case when update but not triggered by button
searchString = searchBox.getTextBox().getText();
members.excludeDisabled(!disabled.getValue());
} else {
members.excludeDisabled(!disabled.getValue());
members.retrieveData();
}
}
});
findMembers.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
searchBox.getTextBox().setEnabled(true);
listAllButton.setEnabled(true);
}
@Override
public void onError(PerunError error) {
searchBox.getTextBox().setEnabled(true);
listAllButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
searchBox.getTextBox().setEnabled(false);
listAllButton.setEnabled(false);
disabled.setVisible(false);
}
}));
members.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(listAllButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// pass data to table handling callback
findMembers.onFinished(jso);
((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("VO has no members.");
searchBox.getTextBox().setEnabled(true);
searchButton.setEnabled(true);
}
@Override
public void onError(PerunError error) {
// pass data to table handling callback
findMembers.onError(error);
searchBox.getTextBox().setEnabled(true);
searchButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
searchBox.getTextBox().setEnabled(false);
searchButton.setEnabled(false);
disabled.setVisible(true);
// to show progress when reloading
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
}
}));
// LIST ALL BUTTON
listAllButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
search = false;
searchString = "";
searchBox.getTextBox().setText("");
findMembers.clearTable();
members.retrieveData();
}
});
tabMenu.addWidget(listAllButton);
tabMenu.addWidget(disabled);
/* WHEN TAB RELOADS, CHECK THE STATE */
if (search) {
findMembers.searchFor(searchString);
} else {
members.excludeDisabled(!disabled.getValue());
members.retrieveData();
}
ScrollPanel tableWrapper = new ScrollPanel();
table.addStyleName("perun-table");
tableWrapper.setWidget(table);
tableWrapper.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(tableWrapper, 350, this);
// add menu and the table to the main panel
firstTabPanel.add(tableWrapper);
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(findMembers, table, removeButton);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class FacilitySettingsTabItem method draw.
public Widget draw() {
// set title
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Service settings");
// content
vp.setSize("100%", "100%");
vp.clear();
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
// Get Attributes method
final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2();
final GetAttributesV2 attrs = new GetAttributesV2();
attrs.getFacilityAttributes(facilityId);
// get empty table
final CellTable<Attribute> table = reqAttrs.getEmptyTable();
final CellTable<Attribute> table2 = attrs.getEmptyTable();
sp.setWidget(table);
sp2.setWidget(table2);
// ids to retrieve data from rpc
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("facility", facility.getId());
// service switcher checkbox
final CheckBox switchServicesChb = new CheckBox(WidgetTranslation.INSTANCE.offerAvailableServicesOnly(), false);
// selected by default - unselected if switch hidden
switchServicesChb.setValue(lastCheckBoxValue);
switchServicesChb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
// services listbox
final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
// on change of service update table
servList.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (servList.getSelectedIndex() == 0) {
// show all facility attributes
attrs.retrieveData();
setTable(false);
lastServiceId = 0;
indexInList = 0;
return;
}
if (switchServicesChb.getValue() == true && servList.getSelectedIndex() == 1) {
// show required attrs for all assigned services
ids.remove("service");
lastServiceId = 0;
indexInList = 1;
} else if ((switchServicesChb.getValue() == true && servList.getSelectedIndex() > 1) || (switchServicesChb.getValue() == false && servList.getSelectedIndex() > 0)) {
// show required attrs for selected service
// >0 when listing all services
// >1 when listing assigned services
ids.put("service", servList.getSelectedObject().getId());
lastServiceId = servList.getSelectedObject().getId();
}
// load req attrs
reqAttrs.setIds(ids);
reqAttrs.clearTable();
reqAttrs.retrieveData();
setTable(true);
}
});
// event which fills the listbox and call getRequiredAttributes
final JsonCallbackEvents event = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
servList.clear();
ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
srv = new TableSorter<Service>().sortByName(srv);
for (int i = 0; i < srv.size(); i++) {
servList.addItem(srv.get(i));
}
// no services available - load all facility attrs
if (servList.isEmpty()) {
servList.addNotSelectedOption();
lastServiceId = 0;
indexInList = 0;
attrs.retrieveData();
setTable(false);
return;
}
// offer only available
if (switchServicesChb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
if (lastServiceId == 0) {
if (indexInList == 1) {
// all
servList.setSelectedIndex(1);
} else if (indexInList == 0) {
// not selected - load all fac attrs
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
}
}
} else {
// offer all services
servList.addNotSelectedOption();
if (lastServiceId == 0) {
// if no service selected, load all fac attrs
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
}
}
// if some service was selected
if (lastServiceId != 0) {
// remove service since we can't be sure, it was loaded again
ids.remove("service");
// either all or first service in a list
servList.setSelectedIndex(1);
for (Service s : servList.getAllObjects()) {
if (s.getId() == lastServiceId) {
// if found, select it
servList.setSelected(s, true);
ids.put("service", lastServiceId);
break;
}
}
}
// get required attrs for service
reqAttrs.clearTable();
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
setTable(true);
}
@Override
public void onError(PerunError error) {
servList.clear();
if (required) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
} else {
((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
}
servList.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
servList.removeAllOption();
servList.removeNotSelectedOption();
servList.clear();
servList.addItem("Loading...");
}
};
final GetServices allServices = new GetServices(event);
final GetFacilityAssignedServices assignedServices = new GetFacilityAssignedServices(facility.getId(), event);
// if hide and unchecked or just unchecked
if (!lastCheckBoxValue) {
allServices.retrieveData();
} else {
assignedServices.retrieveData();
}
// Save changes button
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
final JsonCallbackEvents refreshEvents = JsonCallbackEvents.refreshTableEvents(reqAttrs);
final JsonCallbackEvents refreshEvents2 = JsonCallbackEvents.refreshTableEvents(attrs);
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents);
final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents2);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
request.setAttributes(ids, list);
}
}
});
// Remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents);
final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents2);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("facility", facilityId);
RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
request.removeAttributes(ids, list);
}
}
});
// switch serv checkbox
switchServicesChb.addClickHandler(new ClickHandler() {
// load proper set of services on click
public void onClick(ClickEvent event) {
lastCheckBoxValue = switchServicesChb.getValue();
if (switchServicesChb.getValue() == true) {
assignedServices.retrieveData();
} else {
allServices.retrieveData();
}
}
});
// allow to set new (currently unused facility attribute)
CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("facility", facility.getId());
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, (required) ? reqAttrs.getList() : attrs.getList()), true);
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
menu.addWidget(setNewAttributeButton);
menu.addWidget(removeButton);
menu.addWidget(new HTML("<strong>Service: </strong>"));
menu.addWidget(servList);
if (!hide) {
menu.addWidget(switchServicesChb);
}
/* TODO - not yet implemented
CustomButton fillDefaultButton = new CustomButton("Fill default values", SmallIcons.INSTANCE.scriptGoIcon(), new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
fillDefaultButton.setTitle("Fill default values for this service/facility - nothing is saved unless you click on 'Save changes'");
CustomButton checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon(), new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");
menu.addWidget(fillDefaultButton);
menu.addWidget(checkValuesButton);
*/
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
table.setWidth("100%");
table2.addStyleName("perun-table");
table2.setWidth("100%");
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
sp2.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp2, 350, this);
// add menu and the table to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
// default is required attributes
setTable(true);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations