use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class CreateVoTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
// textboxes which set the class data when updated
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final ExtendedTextBox shortNameTextBox = new ExtendedTextBox();
nameTextBox.getTextBox().setMaxLength(128);
shortNameTextBox.getTextBox().setMaxLength(32);
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setOk();
return true;
} else {
nameTextBox.setError("Name can't be empty.");
return false;
}
}
};
final ExtendedTextBox.TextBoxValidator shortNameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (shortNameTextBox.getTextBox().getText().trim().isEmpty()) {
shortNameTextBox.setError("Short name can't be empty.");
} else if (!shortNameTextBox.getTextBox().getText().trim().matches(Utils.VO_SHORT_NAME_MATCHER)) {
shortNameTextBox.setError("Short name can contain only letters, numbers, dash and underscore.");
} else {
shortNameTextBox.setOk();
return true;
}
return false;
}
};
nameTextBox.setValidator(nameValidator);
shortNameTextBox.setValidator(shortNameValidator);
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createVo());
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!nameValidator.validateTextBox())
return;
if (!shortNameValidator.validateTextBox())
return;
CreateVo request = new CreateVo(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// new VO must be editable by user in GUI, because it is already in PERUN
VirtualOrganization vo = jso.cast();
session.addEditableVo(vo.getId());
}
}));
request.createVo(nameTextBox.getTextBox().getText().trim(), shortNameTextBox.getTextBox().getText().trim());
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
// Add some standard form options
layout.setHTML(0, 0, "Full name:");
layout.setWidget(0, 1, nameTextBox);
layout.setHTML(1, 0, "Short name:");
layout.setWidget(1, 1, shortNameTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(createButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class UserDetailTabItem method loadExternalIdentities.
private Widget loadExternalIdentities() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final GetUserExtSources extSources = new GetUserExtSources(user.getId());
// reload tab events
final TabItem tab = this;
final JsonCallbackEvents reloadTabEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
session.getTabManager().reloadTab(tab);
}
};
// buttons
CustomButton addUserExtSourceButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new external identity to user", new ClickHandler() {
public void onClick(ClickEvent event) {
// when user click on add ext source btn
session.getTabManager().addTabToCurrentTab(new AddUserExtSourceTabItem(user.getId()));
}
});
final CustomButton removeUserExtSourceButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Removes selected external identities from this user");
removeUserExtSourceButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<UserExtSource> list = extSources.getTableSelectedList();
UiElements.showDeleteConfirm(list, "Following external identities will be removed from user.", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for (int i = 0; i < list.size(); i++) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
if (i == list.size() - 1) {
RemoveUserExtSource request = new RemoveUserExtSource(JsonCallbackEvents.disableButtonEvents(removeUserExtSourceButton, reloadTabEvents));
request.removeUserExtSource(user.getId(), list.get(i).getId());
} else {
RemoveUserExtSource request = new RemoveUserExtSource(JsonCallbackEvents.disableButtonEvents(removeUserExtSourceButton));
request.removeUserExtSource(user.getId(), list.get(i).getId());
}
}
}
});
}
});
menu.addWidget(addUserExtSourceButton);
menu.addWidget(removeUserExtSourceButton);
vp.add(menu);
vp.setCellHeight(menu, "30px");
CellTable<UserExtSource> table = extSources.getTable(new FieldUpdater<UserExtSource, String>() {
@Override
public void update(int index, UserExtSource object, String value) {
session.getTabManager().addTab(new UserExtSourceDetailTabItem(object));
}
});
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
vp.setCellHeight(sp, "100%");
session.getUiElements().resizeSmallTabPanel(sp, 320, this);
removeUserExtSourceButton.setEnabled(false);
JsonUtils.addTableManagedButton(extSources, table, removeUserExtSourceButton);
return vp;
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class UserDetailTabItem method loadMemberSubContent.
private void loadMemberSubContent(final SimplePanel subContent, final Hyperlink voLabel, final ListBoxWithObjects<VirtualOrganization> listbox) {
subContent.setWidget(new AjaxLoaderImage());
final GetMemberByUser gmbu = new GetMemberByUser(listbox.getSelectedObject().getId(), user.getId());
JsonCallbackEvents loadEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// get member
final Member member = jso.cast();
// create content panel and put it on page
final VerticalPanel entryPanel = new VerticalPanel();
entryPanel.setStyleName("perun-table");
entryPanel.setSize("100%", "100%");
subContent.setWidget(entryPanel);
voLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + listbox.getSelectedObject().getName() + "</h2>"));
voLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new VoDetailTabItem(listbox.getSelectedObject())));
// detail header
Widget memberHeader = new HTML("<h2>" + "Member details" + "</h2>");
entryPanel.add(memberHeader);
entryPanel.setCellHeight(memberHeader, "30px");
// detail content
FlexTable layout = new FlexTable();
layout.setCellSpacing(6);
// Add some standard form options
layout.setHTML(0, 0, "<strong>Member ID:</strong>");
layout.setHTML(0, 1, String.valueOf(member.getId()));
ImageResource ir = null;
// member status
if (member.getStatus().equalsIgnoreCase("VALID")) {
ir = SmallIcons.INSTANCE.acceptIcon();
} else if (member.getStatus().equalsIgnoreCase("INVALID")) {
ir = SmallIcons.INSTANCE.flagRedIcon();
} else if (member.getStatus().equalsIgnoreCase("SUSPENDED")) {
ir = SmallIcons.INSTANCE.stopIcon();
} else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
ir = SmallIcons.INSTANCE.flagYellowIcon();
} else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
ir = SmallIcons.INSTANCE.binClosedIcon();
}
HTML status = new HTML("<a>" + member.getStatus() + " " + new Image(ir) + "</a>");
layout.setHTML(1, 0, "<strong>Member status: </strong>");
layout.setWidget(1, 1, status);
// member status - on click action
status.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
FlexTable widget = new FlexTable();
final ListBox lb = new ListBox(false);
lb.addItem("VALID", "VALID");
lb.addItem("INVALID", "INVALID");
lb.addItem("SUSPENDED", "SUSPENDED");
lb.addItem("EXPIRED", "EXPIRED");
lb.addItem("DISABLED", "DISABLED");
widget.setHTML(0, 0, "<strong>Status: </strong>");
widget.setWidget(0, 1, lb);
// pick which one is already set
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
lb.setSelectedIndex(i);
}
}
Confirm conf = new Confirm("Change member's status", widget, true);
conf.setCancelButtonText("Cancel");
conf.setOkButtonText("Change status");
conf.setOkClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SetStatus call = new SetStatus(member.getId(), new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
subContent.setWidget(new AjaxLoaderImage());
}
public void onFinished(JavaScriptObject jso) {
subContent.setWidget(entryPanel);
gmbu.retrieveData();
}
public void onError(PerunError error) {
subContent.setWidget(entryPanel);
gmbu.retrieveData();
}
});
call.setStatus(lb.getValue(lb.getSelectedIndex()));
}
});
conf.show();
}
});
final ListBoxWithObjects<Resource> resList = new ListBoxWithObjects<Resource>();
GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
resList.clear();
ArrayList<Resource> list = JsonUtils.jsoAsList(jso);
if (list == null || list.isEmpty()) {
resList.addItem("No resources found");
} else {
list = new TableSorter<Resource>().sortByName(list);
resList.addNotSelectedOption();
resList.addAllItems(list);
}
}
@Override
public void onError(PerunError error) {
resList.clear();
resList.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
resList.clear();
resList.addItem("Loading...");
}
});
res.retrieveData();
// link to member's detail
Hyperlink link = new Hyperlink();
link.setText("View detail");
layout.setHTML(2, 0, "<strong>Member's detail page:</strong>");
layout.setWidget(2, 1, link);
link.setTargetHistoryToken(session.getTabManager().getLinkForTab(new MemberDetailTabItem(member.getId(), 0)));
// wrap the content in a DecoratorPanel
DecoratorPanel decPanel = new DecoratorPanel();
decPanel.setWidget(layout);
entryPanel.add(decPanel);
entryPanel.setCellHeight(decPanel, "50px");
// tables
// detail header
Widget groupHeader = new HTML("<h2>" + "Member groups" + "</h2>");
entryPanel.add(groupHeader);
entryPanel.setCellHeight(groupHeader, "30px");
final GetMemberGroups groups = new GetMemberGroups(member.getId());
groups.setCheckable(false);
groups.setEditable(false);
CellTable<Group> table = groups.getTable();
table.addStyleName("perun-table");
table.setWidth("100%");
entryPanel.add(table);
// detail header
Widget attrHeader = new HTML("<h2>" + "Member / Member-resource attributes" + "</h2>");
entryPanel.add(attrHeader);
entryPanel.setCellHeight(attrHeader, "30px");
final GetAttributesV2 attributes = new GetAttributesV2();
attributes.getMemberAttributes(member.getId());
resList.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (resList.getSelectedIndex() == 0) {
attributes.getMemberAttributes(member.getId());
attributes.retrieveData();
} else {
attributes.getMemberResourceAttributes(member.getId(), resList.getSelectedObject().getId());
attributes.retrieveData();
}
}
});
TabMenu menu = new TabMenu();
final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for member");
saveAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.setAttributes(ids, list);
}
}
});
menu.addWidget(saveAttrButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes for member", new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
}
}));
final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from member");
removeAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeAttrButton);
menu.addWidget(new HTML("<strong>Resource:</strong>"));
menu.addWidget(resList);
entryPanel.add(menu);
CellTable<Attribute> attrTable = attributes.getTable();
attrTable.addStyleName("perun-table");
attrTable.setWidth("100%");
entryPanel.add(attrTable);
}
@Override
public void onError(PerunError error) {
subContent.setWidget(new AjaxLoaderImage().loadingError(error));
}
};
// set events & load data
gmbu.setEvents(loadEvent);
gmbu.retrieveData();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class AddSecurityTeamManagerTabItem method draw.
public Widget draw() {
titleWidget.setText("Add member");
final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
ArrayList<User> list = JsonUtils.jsoAsList(jso);
if (list != null && list.size() == 1) {
users.getSelectionModel().setSelected(list.get(0), true);
}
}
}));
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<User> table;
if (session.isPerunAdmin()) {
table = users.getTable(new FieldUpdater<User, String>() {
public void update(int i, User user, String s) {
session.getTabManager().addTab(new UserDetailTabItem(user));
}
});
} else {
table = users.getTable();
}
rebuildAlreadyAddedWidget();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToSecurityTeam());
final TabItem tab = this;
// search textbox
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
startSearching(text);
searchString = text;
}
}, searchButton);
tabMenu.addWidget(addButton);
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<User> list = users.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
for (int i = 0; i < list.size(); i++) {
// FIXME - Should have only one callback to core
final int n = i;
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
alreadyAddedList.add(list.get(n));
rebuildAlreadyAddedWidget();
// unselect added person
users.getSelectionModel().setSelected(list.get(n), false);
// clear search
searchBox.getTextBox().setText("");
}
}));
request.addSecurityTeamAdmin(securityTeam, list.get(i));
}
}
}
});
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
startSearching(searchString);
}
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(users, table, addButton);
// 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(alreadyAdded);
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class CreateSecurityTeamTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
// textboxes which set the class data when updated
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final ExtendedTextBox descriptionTextBox = new ExtendedTextBox();
nameTextBox.getTextBox().setMaxLength(128);
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setOk();
return true;
} else {
nameTextBox.setError("Name can't be empty.");
return false;
}
}
};
nameTextBox.setValidator(nameValidator);
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createSecurityTeam());
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!nameValidator.validateTextBox())
return;
CreateSecurityTeam request = new CreateSecurityTeam(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// new SecTeam must be editable by user in GUI, because it is already in PERUN
SecurityTeam team = jso.cast();
session.addEditableSecurityTeam(team.getId());
}
}));
request.createSecurityTeam(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getTextBox().getText().trim());
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
// Add some standard form options
layout.setHTML(0, 0, "Name:");
layout.setWidget(0, 1, nameTextBox);
layout.setHTML(1, 0, "Description:");
layout.setWidget(1, 1, descriptionTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(createButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations