use of cz.metacentrum.perun.webgui.model.MemberCandidate in project perun by CESNET.
the class GetCompleteCandidates method getEmptyTable.
/**
* Returns the empty table widget
*
* @return table widget
*/
public CellTable<MemberCandidate> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<MemberCandidate>(list);
// Cell table
table = new PerunTable<MemberCandidate>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<MemberCandidate> columnSortHandler = new ListHandler<MemberCandidate>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// Table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<MemberCandidate>createCheckboxManager());
// Set empty content & loader
table.setEmptyTableWidget(loaderImage);
// checkbox column column
Column<MemberCandidate, MemberCandidate> checkBoxColumn = new Column<MemberCandidate, MemberCandidate>(new PerunCheckboxCell<MemberCandidate>(true, false, (groupId == 0))) {
@Override
public MemberCandidate getValue(MemberCandidate object) {
// Get the value from the selection model.
GeneralObject go = object.cast();
go.setChecked(selectionModel.isSelected(object));
return go.cast();
}
};
// updates the columns size
table.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
table.addColumn(checkBoxColumn);
// is member
TextColumn<MemberCandidate> memberColumn = new TextColumn<MemberCandidate>() {
@Override
public String getValue(MemberCandidate candidate) {
if (groupId == 0) {
if (candidate.getMember() != null)
return "Member of VO";
} else {
if (candidate.getMember() != null && candidate.getMember().getSourceGroupId() != 0 && "DIRECT".equalsIgnoreCase(candidate.getMember().getMembershipType()))
return "Member of Group";
if (candidate.getMember() != null && candidate.getMember().getSourceGroupId() != 0 && "INDIRECT".equalsIgnoreCase(candidate.getMember().getMembershipType()))
return "Indirect member of Group";
if (candidate.getMember() != null)
return "Member of VO";
}
return "";
}
};
// Status column
final Column<MemberCandidate, String> statusColumn = new Column<MemberCandidate, String>(new PerunStatusCell()) {
@Override
public String getValue(MemberCandidate object) {
if (object.getMember() != null) {
return object.getMember().getStatus();
} else {
return null;
}
}
};
// Full Name Column
TextColumn<MemberCandidate> fullNameColumn = new TextColumn<MemberCandidate>() {
@Override
public String getValue(MemberCandidate candidate) {
return getFullNameColumnValue(candidate);
}
};
// E-mail column
TextColumn<MemberCandidate> emailColumn = new TextColumn<MemberCandidate>() {
@Override
public String getValue(MemberCandidate candidate) {
return getEmailColumnValue(candidate);
}
};
// Login Column
TextColumn<MemberCandidate> loginColumn = new TextColumn<MemberCandidate>() {
@Override
public String getValue(MemberCandidate candidate) {
return getLoginFromExtSourceOrAllLogins(candidate);
}
};
// Ext Source Column
TextColumn<MemberCandidate> extSourceColumn = new TextColumn<MemberCandidate>() {
@Override
public String getValue(MemberCandidate candidate) {
return getExtSourceNameOrOrganizationColumn(candidate);
}
};
// already Column
TextColumn<MemberCandidate> alreadyInPerunColumn = new TextColumn<MemberCandidate>() {
@Override
public String getValue(MemberCandidate candidate) {
if (candidate.getRichUser() != null) {
return "Local";
} else {
return "External identity";
}
}
};
alreadyInPerunColumn.setSortable(true);
columnSortHandler.setComparator(alreadyInPerunColumn, new Comparator<MemberCandidate>() {
public int compare(MemberCandidate o1, MemberCandidate o2) {
String o1Val = "External identity";
String o2Val = "External identity";
if (o1.getRichUser() != null) {
o1Val = "Local";
}
if (o2.getRichUser() != null) {
o2Val = "Local";
}
return o1Val.compareTo(o2Val);
}
});
memberColumn.setSortable(true);
columnSortHandler.setComparator(memberColumn, new Comparator<MemberCandidate>() {
public int compare(MemberCandidate o1, MemberCandidate o2) {
String o1Val = "1";
String o2Val = "1";
if (o1.getMember() != null)
o1Val = "0";
if (o2.getMember() != null)
o2Val = "0";
o1Val += getFullNameColumnValue(o1);
o2Val += getFullNameColumnValue(o2);
return o1Val.compareTo(o2Val);
}
});
loginColumn.setSortable(true);
columnSortHandler.setComparator(loginColumn, new Comparator<MemberCandidate>() {
public int compare(MemberCandidate o1, MemberCandidate o2) {
return getLoginFromExtSourceOrAllLogins(o1).compareToIgnoreCase(getLoginFromExtSourceOrAllLogins(o2));
}
});
fullNameColumn.setSortable(true);
columnSortHandler.setComparator(fullNameColumn, new Comparator<MemberCandidate>() {
public int compare(MemberCandidate o1, MemberCandidate o2) {
return getFullNameColumnValue(o1).compareToIgnoreCase(getFullNameColumnValue(o2));
}
});
extSourceColumn.setSortable(true);
columnSortHandler.setComparator(extSourceColumn, new Comparator<MemberCandidate>() {
public int compare(MemberCandidate o1, MemberCandidate o2) {
return getExtSourceNameOrOrganizationColumn(o1).compareToIgnoreCase(getExtSourceNameOrOrganizationColumn(o2));
}
});
emailColumn.setSortable(true);
columnSortHandler.setComparator(emailColumn, new Comparator<MemberCandidate>() {
public int compare(MemberCandidate o1, MemberCandidate o2) {
return getEmailColumnValue(o1).compareToIgnoreCase(getEmailColumnValue(o2));
}
});
table.addColumnSortHandler(columnSortHandler);
// Add the columns.
table.addColumn(statusColumn, "Status");
table.addColumn(fullNameColumn, "Full name");
table.addColumn(extSourceColumn, "Organization or Ext source");
table.addColumn(emailColumn, "E-mail");
table.addColumn(loginColumn, "Logins");
table.addColumn(memberColumn, "Already member");
table.addColumn(alreadyInPerunColumn, "Source");
return table;
}
use of cz.metacentrum.perun.webgui.model.MemberCandidate in project perun by CESNET.
the class AddMemberToGroupTabItem method rebuildAlreadyAddedWidget.
/**
* Rebuild already added widget based on already added members
*/
private void rebuildAlreadyAddedWidget() {
alreadyAdded.setStyleName("alreadyAdded");
alreadyAdded.setVisible(!alreadyAddedList.isEmpty());
alreadyAdded.setWidget(new HTML("<strong>Already added: </strong>"));
for (int i = 0; i < alreadyAddedList.size(); i++) {
if (alreadyAddedList.get(i).getObjectType().equals("MemberCandidate")) {
MemberCandidate c = alreadyAddedList.get(i).cast();
if (c.getCandidate() != null) {
alreadyAdded.getWidget().getElement().setInnerHTML(alreadyAdded.getWidget().getElement().getInnerHTML() + ((i != 0) ? ", " : "") + SafeHtmlUtils.fromString(c.getCandidate().getFullName()).asString());
} else {
alreadyAdded.getWidget().getElement().setInnerHTML(alreadyAdded.getWidget().getElement().getInnerHTML() + ((i != 0) ? ", " : "") + SafeHtmlUtils.fromString(c.getRichUser().getFullName()).asString());
}
} else if (alreadyAddedList.get(i).getObjectType().equals("User") || alreadyAddedList.get(i).getObjectType().equals("RichUser")) {
User u = alreadyAddedList.get(i).cast();
alreadyAdded.getWidget().getElement().setInnerHTML(alreadyAdded.getWidget().getElement().getInnerHTML() + ((i != 0) ? ", " : "") + SafeHtmlUtils.fromString(u.getFullName()).asString());
} else {
RichMember m = alreadyAddedList.get(i).cast();
alreadyAdded.getWidget().getElement().setInnerHTML(alreadyAdded.getWidget().getElement().getInnerHTML() + ((i != 0) ? ", " : "") + SafeHtmlUtils.fromString(m.getUser().getFullName()).asString());
}
}
}
use of cz.metacentrum.perun.webgui.model.MemberCandidate 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 GetCompleteRichMembers getAllMembers;
// for VO/group admin differs search
final GetCompleteCandidates findCandidates;
// elements handled by callback events
final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchMemberInVo(), 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
getAllMembers = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), null);
findCandidates = new GetCompleteCandidates(group.getVoId(), group.getId(), "", null);
final CellTable<MemberCandidate> candidatesTable = findCandidates.getEmptyTable();
final CellTable<RichMember> table = getAllMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {
@Override
public void update(int i, RichMember o, RichMember o2) {
session.getTabManager().addTab(new MemberDetailTabItem(o.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;
findCandidates.searchFor(searchString);
search = true;
// remove previous table
firstTabPanel.getWidget(2).removeFromParent();
firstTabPanel.add(sp2);
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()) {
searchButton.setEnabled(true);
// do not trigger search on both !!
} else {
searchButton.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
searchButton.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
searchButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
}
@Override
public void onError(PerunError error) {
// pass data to table handling callback
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);
}
}));
findCandidates.setEvents(JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
listAllButton.setEnabled(true);
searchButton.setEnabled(true);
searchBox.getTextBox().setEnabled(true);
if (findCandidates.getList().size() == 1) {
if (findCandidates.getList().get(0).getMember() == null || findCandidates.getList().get(0).getMember().getSourceGroupId() == 0) {
// select first if selectable
findCandidates.setSelected(findCandidates.getList().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());
getAllMembers.clearTable();
getAllMembers.retrieveData();
}
});
listAllButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
search = false;
searchString = "";
searchBox.getTextBox().setText("");
getAllMembers.clearTable();
findCandidates.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 (search) {
// searched users or candidates
MemberCandidate candidateToBeAdded = findCandidates.getSelected();
if (candidateToBeAdded == null) {
UiElements.cantSaveEmptyListDialogBox(null);
} else {
if (candidateToBeAdded.getMember() != null) {
// person is already member of VO
AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
private MemberCandidate saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
if (saveSelected != null) {
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
}
findCandidates.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
@Override
public void onLoadingStart() {
saveSelected = findCandidates.getSelected();
}
}));
// reconstruct rich member, since call methods requires it
RichMember mem = candidateToBeAdded.getMember().cast();
mem.setUser(candidateToBeAdded.getRichUser());
mem.setObjectType("RichMember");
request.addMemberToGroup(group, mem);
} else if (candidateToBeAdded.getCandidate() != null) {
// person is not in Perun or candidate was found for existing user (not yet member of VO)
CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
private MemberCandidate saveSelected;
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
if (saveSelected != null) {
GeneralObject go = saveSelected.cast();
alreadyAddedList.add(go);
}
findCandidates.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
@Override
public void onLoadingStart() {
saveSelected = findCandidates.getSelected();
}
}));
request.createMember(group.getVoId(), group, candidateToBeAdded.getCandidate());
} else {
// person is already user in Perun, no candidate was found
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);
findCandidates.clearTableSelectedSet();
rebuildAlreadyAddedWidget();
// clear search
searchBox.getTextBox().setText("");
}
}
@Override
public void onLoadingStart() {
MemberCandidate cand = findCandidates.getSelected();
saveSelected = cand.getRichUser();
}
}));
User user = candidateToBeAdded.getRichUser();
request.createMember(group.getVoId(), group, user);
}
}
} else {
// searched members / all members
final ArrayList<RichMember> membersToAdd = getAllMembers.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
getAllMembers.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(listAllButton);
tabMenu.addWidget(addButton);
tabMenu.addWidget(inviteButton);
inviteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (search) {
// we expect, that candidate is always single
MemberCandidate candid = findCandidates.getSelected();
if (candid != null) {
if (candid.getCandidate() != null) {
SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findCandidates.clearTableSelectedSet();
}
}));
invite.inviteUser(candid.getCandidate());
} else {
SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
findCandidates.clearTableSelectedSet();
}
}));
User user = candid.getRichUser();
invite.inviteUser(user);
}
}
} else {
// all members
SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
ArrayList<RichMember> usrs = getAllMembers.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) {
getAllMembers.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, isRefreshParentOnClose());
}
}));
tabMenu.addWidget(disabled);
rebuildAlreadyAddedWidget();
firstTabPanel.add(alreadyAdded);
addButton.setEnabled(false);
inviteButton.setEnabled(false);
JsonUtils.addTableManagedButton(getAllMembers, table, addButton);
JsonUtils.addTableManagedButton(getAllMembers, table, inviteButton);
JsonUtils.addTableManagedButton(findCandidates, candidatesTable, addButton);
JsonUtils.addTableManagedButton(findCandidates, 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) {
findCandidates.searchFor(searchString);
firstTabPanel.add(sp2);
} else {
getAllMembers.excludeDisabled(!disabled.getValue());
getAllMembers.clearTable();
getAllMembers.retrieveData();
firstTabPanel.add(sp);
}
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations