use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class SelfResourcesSettingsTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Resources settings");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
final ScrollPanel scroll = new ScrollPanel();
scroll.setWidget(vp);
scroll.setStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(scroll, 350, this);
scroll.setWidth("100%");
final AjaxLoaderImage loader = new AjaxLoaderImage();
// RETRIEVES ALL VOS WHERE USER IS A MEMBER
GetVosWhereUserIsMember vosRequest = new GetVosWhereUserIsMember(userId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
vp.getWidget(1).removeFromParent();
ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
vos = new TableSorter<VirtualOrganization>().sortByName(vos);
// if vos length = 1, load immediately all resources
final boolean loadImmediately = (vos.size() == 1);
// FOR EACH VO, FIND THE MEMBER
for (final VirtualOrganization innerVo : vos) {
final FlexTable header = new FlexTable();
header.setWidth("100%");
header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.buildingIcon()));
header.getFlexCellFormatter().setWidth(0, 0, "40px");
Anchor a = new Anchor("<p class=\"now-managing disclosurePanelHeader\">" + innerVo.getName() + "</p>", true);
header.setWidget(0, 1, a);
header.setTitle("Click to show resources for " + innerVo.getName());
// disclosure panel
final DisclosurePanel settings = new DisclosurePanel();
settings.setWidth("100%");
settings.setHeader(header);
// load content on open
settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (settings.getContent() == null) {
GetMemberByUser memberRequest = new GetMemberByUser(innerVo.getId(), userId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
Member member = jso.cast();
// set content
settings.setContent(userSettingsForVo(innerVo, member));
}
});
memberRequest.retrieveData();
}
}
});
vp.add(settings);
settings.setOpen((vos.size() == 1) || (vo != null && vo.getId() == innerVo.getId()));
}
}
@Override
public void onLoadingStart() {
vp.add(loader);
}
@Override
public void onError(PerunError error) {
loader.loadingError(error);
}
});
vosRequest.retrieveData();
this.contentWidget.setWidget(scroll);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class UsersTabItem method draw.
public Widget draw() {
CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton));
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// search textbox
ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
startSearching(text);
searchString = text;
}
}, searchButton);
// get the table
final CellTable<User> table = users.getTable(new FieldUpdater<User, String>() {
public void update(int index, User object, String value) {
// opens the tab
session.getTabManager().addTab(new UserDetailTabItem(object));
}
});
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
startSearching(searchString);
}
/*
Button b1 = tabMenu.addButton("List all", SmallIcons.INSTANCE.userGrayIcon(), new ClickHandler(){
public void onClick(ClickEvent event) {
GetCompleteRichUsers callback = new GetCompleteRichUsers(new JsonCallbackEvents(){
public void onLoadingStart() {
table.setEmptyTableWidget(new AjaxLoaderImage().loadingStart());
}
public void onFinished(JavaScriptObject jso) {
users.setList(JsonUtils.<User>jsoAsList(jso));
users.sortTable();
table.setEmptyTableWidget(new AjaxLoaderImage().loadingFinished());
}
public void onError(PerunError error){
users.clearTable();
table.setEmptyTableWidget(new AjaxLoaderImage().loadingError(error));
}
});
callback.retrieveData();
}
});
b1.setTitle("List of all users in Perun");
*/
final CustomButton withoutVoButton = new CustomButton(ButtonTranslation.INSTANCE.listUsersWithoutVoButton(), ButtonTranslation.INSTANCE.listUsersWithoutVo(), SmallIcons.INSTANCE.userRedIcon());
withoutVoButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
GetCompleteRichUsers callback = new GetCompleteRichUsers(null, new JsonCallbackEvents() {
public void onLoadingStart() {
users.clearTable();
table.setEmptyTableWidget(new AjaxLoaderImage().loadingStart());
withoutVoButton.setProcessing(true);
}
public void onFinished(JavaScriptObject jso) {
users.setList(JsonUtils.<User>jsoAsList(jso));
users.sortTable();
table.setEmptyTableWidget(new AjaxLoaderImage().loadingFinished());
withoutVoButton.setProcessing(false);
}
public void onError(PerunError error) {
table.setEmptyTableWidget(new AjaxLoaderImage().loadingError(error));
withoutVoButton.setProcessing(false);
}
});
callback.getWithoutVo(true);
callback.retrieveData();
}
});
tabMenu.addWidget(withoutVoButton);
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// 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.widgets.AjaxLoaderImage in project perun by CESNET.
the class AddMemberToGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add member(s)");
// MAIN PANEL
final VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
boolean isMembersGroup = group.isCoreGroup();
// if members or admins group, hide
if (isMembersGroup) {
firstTabPanel.add(new HTML("<p>Group \"" + group.getName() + "\" can't have members managed from Group admin. Please use VO admin section.</p>"));
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
// MENU
TabMenu tabMenu = new TabMenu();
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
// for resize
final TabItem tab = this;
// CALLBACKS
// for both
final FindCompleteRichMembers findMembers;
// for both
final GetCompleteRichMembers getAllMembers;
// for VO/group admin differs search
final FindCandidatesOrUsersToAddToVo findCandidatesOrUsersToAddToVo;
// elements handled by callback events
final CustomButton searchButton = new CustomButton("Search in VO", ButtonTranslation.INSTANCE.searchMemberInVo(), SmallIcons.INSTANCE.findIcon());
final CustomButton searchGloballyButton = new CustomButton("Search globally", ButtonTranslation.INSTANCE.searchForMembersInExtSources(), SmallIcons.INSTANCE.findIcon());
final CustomButton listAllButton = new CustomButton("List all VO members", ButtonTranslation.INSTANCE.listAllMembersInVo(), SmallIcons.INSTANCE.userGreenIcon());
final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
// search through whole VO
findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), "", null);
getAllMembers = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), null);
if (session.isVoAdmin(group.getVoId())) {
// will search vo ext sources and users
findCandidatesOrUsersToAddToVo = new FindCandidatesOrUsersToAddToVo(group.getVoId(), 0, "", null);
} else {
// will search group ext sources only
findCandidatesOrUsersToAddToVo = new FindCandidatesOrUsersToAddToVo(group.getVoId(), group.getId(), "", null);
}
final CellTable<Candidate> candidatesTable = findCandidatesOrUsersToAddToVo.getEmptyTable();
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(), groupId));
}
});
final CustomButton inviteButton = new CustomButton("Invite selected", SmallIcons.INSTANCE.emailIcon());
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedMemberToGroup());
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
public void searchFor(String text) {
searchString = text;
findMembers.searchFor(searchString);
search = true;
searchCandidates = false;
// remove previous table
firstTabPanel.getWidget(2).removeFromParent();
firstTabPanel.add(sp);
UiElements.runResizeCommands(tab);
}
}, searchButton);
searchBox.getTextBox().setText(searchString);
// bind text box also to search globally
searchBox.getTextBox().addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
if (!searchBox.getTextBox().getText().trim().isEmpty()) {
searchGloballyButton.setEnabled(true);
// do not trigger search on both !!
} else {
searchGloballyButton.setEnabled(false);
}
}
});
searchBox.getTextBox().addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
// fake some meaningless KeyUpEvent
DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN), searchBox.getTextBox());
}
});
searchBox.getTextBox().addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
// fake some meaningless KeyUpEvent
DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN), searchBox.getTextBox());
}
});
// button click triggers action
searchGloballyButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (UiElements.searchStingCantBeEmpty(searchBox.getTextBox().getText().trim())) {
new PerunSearchEvent() {
public void searchFor(String text) {
searchString = text;
findCandidatesOrUsersToAddToVo.searchFor(searchString);
searchCandidates = true;
search = false;
// remove previous table
firstTabPanel.getWidget(2).removeFromParent();
firstTabPanel.add(sp2);
UiElements.runResizeCommands(tab);
}
}.searchFor(searchBox.getTextBox().getText().trim());
}
}
});
searchGloballyButton.setEnabled(false);
findMembers.setEvents(JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
listAllButton.setEnabled(true);
searchGloballyButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
ArrayList<RichMember> list = JsonUtils.jsoAsList(jso);
if (list != null && list.size() == 1) {
findMembers.getSelectionModel().setSelected(list.get(0), true);
}
}
@Override
public void onError(PerunError error) {
listAllButton.setEnabled(true);
searchGloballyButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
}
@Override
public void onLoadingStart() {
listAllButton.setEnabled(false);
searchGloballyButton.setEnabled(false);
disabled.setVisible(false);
searchBox.getTextBox().setEnabled(false);
addButton.setEnabled(false);
inviteButton.setEnabled(false);
}
}));
getAllMembers.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.");
searchButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
}
@Override
public void onError(PerunError error) {
// pass data to table handling callback
findMembers.onError(error);
searchButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
}
@Override
public void onLoadingStart() {
searchButton.setEnabled(false);
disabled.setVisible(true);
searchBox.getTextBox().setEnabled(false);
addButton.setEnabled(false);
inviteButton.setEnabled(false);
}
}));
findCandidatesOrUsersToAddToVo.setEvents(JsonCallbackEvents.disableButtonEvents(searchGloballyButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
listAllButton.setEnabled(true);
searchButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
ArrayList<Candidate> list = JsonUtils.jsoAsList(jso);
if (list != null && list.size() == 1) {
findCandidatesOrUsersToAddToVo.setSelected(list.get(0));
}
}
@Override
public void onError(PerunError error) {
listAllButton.setEnabled(true);
searchButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
}
@Override
public void onLoadingStart() {
disabled.setVisible(false);
listAllButton.setEnabled(false);
searchButton.setEnabled(false);
searchBox.getTextBox().setEnabled(false);
addButton.setEnabled(false);
inviteButton.setEnabled(false);
}
}));
// DISABLED CHECKBOX
disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
disabled.setVisible(false);
// checkbox click handler
disabled.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
getAllMembers.excludeDisabled(!disabled.getValue());
findMembers.clearTable();
getAllMembers.retrieveData();
}
});
listAllButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
search = false;
searchCandidates = false;
searchString = "";
searchBox.getTextBox().setText("");
findMembers.clearTable();
findCandidatesOrUsersToAddToVo.clearTable();
getAllMembers.retrieveData();
// remove previous table
firstTabPanel.getWidget(2).removeFromParent();
firstTabPanel.add(sp);
UiElements.runResizeCommands(tab);
}
});
// click handler
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (searchCandidates) {
// searched users or candidates
Candidate candidateToBeAdded = findCandidatesOrUsersToAddToVo.getSelected();
if (candidateToBeAdded == null) {
UiElements.cantSaveEmptyListDialogBox(null);
} else {
if (candidateToBeAdded.getObjectType().equalsIgnoreCase("Candidate")) {
CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
private Candidate saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
if (saveSelected != null) {
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
}
findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
@Override
public void onLoadingStart() {
saveSelected = findCandidatesOrUsersToAddToVo.getSelected();
}
}));
request.createMember(group.getVoId(), group, candidateToBeAdded);
} else {
CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
private User saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
if (saveSelected != null) {
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
}
@Override
public void onLoadingStart() {
Candidate cand = findCandidatesOrUsersToAddToVo.getSelected();
saveSelected = cand.cast();
}
}));
User user = candidateToBeAdded.cast();
request.createMember(group.getVoId(), group, user);
}
}
} else {
// searched members / all members
final ArrayList<RichMember> membersToAdd = findMembers.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(membersToAdd)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < membersToAdd.size(); i++) {
final int n = i;
AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
private RichMember saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// unselect added person
findMembers.getSelectionModel().setSelected(saveSelected, false);
// put names to already added
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
@Override
public void onLoadingStart() {
saveSelected = membersToAdd.get(n);
}
}));
request.addMemberToGroup(group, membersToAdd.get(i));
}
}
}
}
});
tabMenu.addWidget(searchGloballyButton);
tabMenu.addWidget(listAllButton);
tabMenu.addWidget(addButton);
tabMenu.addWidget(inviteButton);
inviteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (searchCandidates) {
// we expect, that candidate is always single
Candidate candid = findCandidatesOrUsersToAddToVo.getSelected();
if (candid != null) {
if (candid.getObjectType().equalsIgnoreCase("Candidate")) {
SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
}
}));
invite.inviteUser(candid);
} else {
SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
}
}));
User user = candid.cast();
invite.inviteUser(user);
}
}
} else {
// members / all members
SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
ArrayList<RichMember> usrs = findMembers.getTableSelectedList();
for (int i = 0; i < usrs.size(); i++) {
if (i == usrs.size() - 1) {
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findMembers.clearTableSelectedSet();
}
}));
} else {
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton));
}
invite.inviteUser(usrs.get(i).getUser());
}
}
}
});
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// with refresh if somebody was added
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
tabMenu.addWidget(disabled);
rebuildAlreadyAddedWidget();
firstTabPanel.add(alreadyAdded);
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(findMembers, table, addButton);
inviteButton.setEnabled(false);
JsonUtils.addTableManagedButton(findMembers, table, inviteButton);
JsonUtils.addTableManagedButton(findCandidatesOrUsersToAddToVo, candidatesTable, addButton);
JsonUtils.addTableManagedButton(findCandidatesOrUsersToAddToVo, candidatesTable, inviteButton);
table.addStyleName("perun-table");
sp.setWidget(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
candidatesTable.addStyleName("perun-table");
sp2.setWidget(candidatesTable);
sp2.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp2, 350, this);
// if not empty - start searching
if (search) {
findMembers.searchFor(searchString);
firstTabPanel.add(sp);
} else if (searchCandidates) {
findCandidatesOrUsersToAddToVo.searchFor(searchString);
firstTabPanel.add(sp2);
} else {
getAllMembers.excludeDisabled(!disabled.getValue());
getAllMembers.retrieveData();
firstTabPanel.add(sp);
}
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.
the class PropagationsTabItem 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, true));
}
});
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, true));
}
});
// 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 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 GroupMembersTabItem method draw.
public Widget draw() {
// SET TAB NAME
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": members");
// MAIN PANEL
final VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// MENU
final 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);
// CALLBACKS
final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.GROUP, groupId, null);
final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.GROUP, groupId, "", null);
members.excludeDisabled(!wasDisabled);
members.setIndirectCheckable(false);
findMembers.setIndirectCheckable(false);
final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInGroup());
final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInGroup());
if ((!session.isVoAdmin(group.getVoId()) && !session.isGroupAdmin(groupId)) || group.isCoreGroup()) {
findMembers.setCheckable(false);
}
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(), groupId));
}
});
tableWidget = table.getEmptyTableWidget();
// refresh
tabMenu.addWidget(UiElements.getRefreshButton(this));
// ADD
CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToGroup(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddMemberToGroupTabItem(groupId), true);
}
});
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
addButton.setEnabled(false);
CustomButton inviteButton = new CustomButton("Invite member…", SmallIcons.INSTANCE.emailAddIcon(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new InviteUserTabItem(group.getVoId(), group));
}
});
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
inviteButton.setEnabled(false);
// REMOVE
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromGroup());
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
removeButton.setEnabled(false);
if (!group.isCoreGroup()) {
tabMenu.addWidget(addButton);
tabMenu.addWidget(inviteButton);
tabMenu.addWidget(removeButton);
}
// 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 group. They will lose access to resources provided by this group.";
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++) {
RemoveMember request;
if (i == membersForRemoving.size() - 1) {
request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
} else {
request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.removeMemberFromGroup(group, membersForRemoving.get(i));
}
}
});
}
});
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
public void searchFor(String text) {
table.setEmptyTableWidget(tableWidget);
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("Group 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() {
table.setEmptyTableWidget(tableWidget);
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) {
table.setEmptyTableWidget(tableWidget);
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 {
GetGroupMembersCount count = new GetGroupMembersCount(groupId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
int membersCount = ((BasicOverlayType) jso.cast()).getInt();
if (membersCount > 1000) {
FlexTable panel = new FlexTable();
panel.setSize("100%", "150px");
HTML label = new HTML();
label.setHTML("<h2>Group has " + membersCount + " members. We suggest you to use search instead.</h2><h2>You can search member by name, login, email or click List all to see all members.</h2>");
panel.setWidget(0, 0, label);
panel.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
table.setEmptyTableWidget(panel);
} else {
// load all members
members.excludeDisabled(!disabled.getValue());
members.retrieveData();
}
onceAsked = true;
}
@Override
public void onError(PerunError error) {
// load all members
members.excludeDisabled(!disabled.getValue());
members.retrieveData();
}
@Override
public void onLoadingStart() {
}
});
if (!onceAsked) {
count.retrieveData();
} else {
// load all members
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();
}
Aggregations