use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class EditMailFooterTabItem method draw.
public Widget draw() {
final FlexTable content = new FlexTable();
content.setStyleName("inputFormFlexTable");
content.setWidth("360px");
final TextArea footer = new TextArea();
footer.setSize("340px", "200px");
content.setHTML(0, 0, "Footer text:");
content.getFlexCellFormatter().setStyleName(0, 0, "itemName");
content.setWidget(1, 0, footer);
content.setHTML(2, 0, "This text will be added as footer for all email notifications (replacing {mailFooter} tag in mail definition).");
content.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
final Map<String, Integer> ids = new HashMap<String, Integer>();
if (group == null) {
ids.put("vo", voId);
} else {
ids.put("group", groupId);
}
final ArrayList<Attribute> list = new ArrayList<Attribute>();
final GetListOfAttributes call = new GetListOfAttributes(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
list.addAll(JsonUtils.<Attribute>jsoAsList(jso));
// only if attribute exists
if (list != null && !list.isEmpty()) {
for (Attribute a : list) {
if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
// if value not null - enter
if (!a.getValue().equalsIgnoreCase("null")) {
footer.setText(a.getValue());
}
}
}
}
}
});
ArrayList<String> l = new ArrayList<String>();
if (group == null) {
l.add("urn:perun:vo:attribute-def:def:mailFooter");
} else {
l.add("urn:perun:group:attribute-def:def:mailFooter");
}
call.getListOfAttributes(ids, l);
final TabItem tab = this;
VerticalPanel vp = new VerticalPanel();
TabMenu menu = new TabMenu();
final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveMailFooter());
save.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// will be set
ArrayList<Attribute> toSend = new ArrayList<Attribute>();
// will be removed
ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
for (Attribute a : list) {
String oldValue = a.getValue();
String newValue = "";
if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
newValue = footer.getText();
} else {
// other than mailFooter attributes must be skipped
continue;
}
if (oldValue.equalsIgnoreCase(newValue) || (oldValue.equalsIgnoreCase("null") && newValue.equalsIgnoreCase(""))) {
// skip this cycle
continue;
} else {
if (newValue.equalsIgnoreCase("")) {
// value was cleared
toRemove.add(a);
} else {
// set value
a.setValue(newValue);
// value was changed / added
toSend.add(a);
}
}
}
// requests
SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
RemoveAttributes removeRequest = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
// send if not empty
if (!toRemove.isEmpty()) {
removeRequest.removeAttributes(ids, toRemove);
}
if (!toSend.isEmpty()) {
request.setAttributes(ids, toSend);
}
}
});
menu.addWidget(save);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(content);
vp.add(menu);
vp.setCellHeight(menu, "30px");
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 AssignServiceTabItem method draw.
public Widget draw() {
titleWidget.setText("Assign service");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
final GetServices services = new GetServices();
final CellTable<Service> table = services.getEmptyTable(new FieldUpdater<Service, String>() {
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ResourceSettingsTabItem(resource, object));
}
});
// remove already assigned services from offering
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// second callback
final GetAssignedServices alreadyAssigned = new GetAssignedServices(resourceId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
JsArray<Service> srvToRemove = JsonUtils.jsoAsArray(jso);
for (int i = 0; i < srvToRemove.length(); i++) {
services.removeFromTable(srvToRemove.get(i));
}
if (services.getList().size() == 1) {
table.getSelectionModel().setSelected(services.getList().get(0), true);
}
}
});
alreadyAssigned.retrieveData();
}
};
services.setEvents(localEvents);
final TabItem tab = this;
// button
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedServicesToResource());
assignButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Service> servicesToAssign = services.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(servicesToAssign)) {
for (int i = 0; i < servicesToAssign.size(); i++) {
if (i != servicesToAssign.size() - 1) {
// call json normaly
AssignService request = new AssignService(JsonCallbackEvents.disableButtonEvents(assignButton));
request.assignService(servicesToAssign.get(i).getId(), resourceId);
} else {
// last change - call json with update
AssignService request = new AssignService(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
request.assignService(servicesToAssign.get(i).getId(), resourceId);
}
}
}
}
});
menu.addWidget(assignButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
menu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
services.filterTable(text);
if (services.getList().size() == 1) {
table.getSelectionModel().setSelected(services.getList().get(0), true);
}
}
}, "Filter services by name");
vp.add(menu);
vp.setCellHeight(menu, "30px");
services.retrieveData();
assignButton.setEnabled(false);
JsonUtils.addTableManagedButton(services, table, assignButton);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class GroupResourceRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings for " + Utils.getStrippedStringWithEllipsis(resource.getName()));
if (JsonUtils.isExtendedInfoVisible()) {
columnId = 3;
} else {
columnId = 2;
}
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final Label facilityId = new Label();
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Facility fac = (Facility) jso;
facilityId.setText(String.valueOf(fac.getId()));
}
};
GetFacility facility = new GetFacility(resourceId, events);
facility.retrieveData();
mainTab.add(new HTML("<hr size=\"2px\" />"));
// set attributes type to group_resource
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("group", groupId);
// gets all required group attributes for specified group and resource
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
reqAttrsTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// get all required group_resource attributes too
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
final ListBoxWithObjects<RichMember> listBox = new ListBoxWithObjects<RichMember>();
listBox.setTitle(WidgetTranslation.INSTANCE.selectingMember());
// local event fills the listBox
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
mems = new TableSorter<RichMember>().sortByName(mems);
listBox.addNotSelectedOption();
for (int i = 0; i < mems.size(); i++) {
listBox.addItem(mems.get(i));
}
listBox.addAllOption();
}
};
final GetGroupRichMembers getGroupRichMembers = new GetGroupRichMembers(groupId, localEvents);
getGroupRichMembers.retrieveData();
reqAttrsTable.addStyleName("perun-table");
final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
sp.addStyleName("perun-tableScrollPanel");
// store for column with values
final Column<Attribute, ?> columnStore = reqAttrsTable.getColumn(columnId);
listBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int selectedIndex = listBox.getSelectedIndex();
// no member selected
if (selectedIndex == 0) {
// offer just group and group resource attributes
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get groups attributes
ids.put("group", groupId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// get group_resource attributes
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
reqAttrs.sortTable();
// some member is selected
} else {
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get member, member-resource, user, user-facility attributes
ids.put("member", listBox.getSelectedObject().getId());
ids.put("resource", resourceId);
// to get user, user-facility attrs
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// all members are selected
if (selectedIndex == 1) {
// remove value column
reqAttrsTable.removeColumn(columnId);
// create own value column
// Value column
Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {
public Attribute getValue(Attribute attribute) {
attribute.setValueAsJso(null);
return attribute;
}
}, new FieldUpdater<Attribute, Attribute>() {
public void update(int index, Attribute object, Attribute value) {
object = value;
reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
}
});
// add to table
reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
} else {
// member selected
// return original column
reqAttrsTable.removeColumn(columnId);
reqAttrsTable.insertColumn(columnId, columnStore, "Value");
}
}
}
});
CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// send lists
ArrayList<Attribute> groupList = new ArrayList<Attribute>();
ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> memberList = new ArrayList<Attribute>();
ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> userList = new ArrayList<Attribute>();
ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
SetAttributes request = new SetAttributes();
int selectedIndex = listBox.getSelectedIndex();
// if all selected
if (selectedIndex == 1) {
// TODO - USE NEW CONFIRM DESIGN
if (!Window.confirm("Same values for selected attributes will be set to all members in group." + "\n\nDo you want to continue ?")) {
return;
}
}
// get different attributes
for (Attribute attr : list) {
if (attr.getNamespace().contains("urn:perun:group:")) {
groupList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
groupResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member:")) {
memberList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member_resource:")) {
memberResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user:")) {
userList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user_facility:")) {
userFacilityList.add(attr);
}
}
// if not empty, send request
if (!(groupList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
request.setAttributes(ids, groupList);
}
if (!(groupResourceList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
ids.put("resource", resourceId);
request.setAttributes(ids, groupResourceList);
}
if (!(memberList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberList);
}
} else {
// for one member
ids.clear();
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberList);
}
}
if (!(memberResourceList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("resource", resourceId);
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberResourceList);
}
} else {
// for one member
ids.clear();
ids.put("resource", resourceId);
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberResourceList);
}
}
if (!(userList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", (listBox.getObjectAt(i)).getUser().getId());
request.setAttributes(ids, userList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
request.setAttributes(ids, userList);
}
}
if (!(userFacilityList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", listBox.getObjectAt(i).getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
}
reqAttrs.clearTableSelectedSet();
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
saveChangesButton.setEnabled(false);
menu.addWidget(new HTML("<strong>Group members:</strong>"));
menu.addWidget(listBox);
// table content
session.getUiElements().resizePerunTable(sp, 350, this);
mainTab.add(menu);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
mainTab.setCellHeight(menu, "30px");
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class GroupDetailTabItem method open.
public void open() {
session.getUiElements().getMenu().openMenu(MainMenu.GROUP_ADMIN);
if (vo == null) {
new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
vo = jso.cast();
session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "VO: " + vo.getName(), VosTabs.URL + UrlMapper.TAB_NAME_SEPARATOR + "detail?id=" + vo.getId(), "Group: " + group.getName(), getUrlWithParameters());
}
@Override
public void onError(PerunError error) {
session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "Group: " + group.getName(), getUrlWithParameters());
}
}).retrieveData();
} else {
session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "VO: " + vo.getName(), VosTabs.URL + UrlMapper.TAB_NAME_SEPARATOR + "detail?id=" + vo.getId(), "Group: " + group.getName(), getUrlWithParameters());
}
if (group != null) {
session.setActiveGroup(group);
} else {
session.setActiveGroupId(groupId);
}
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class GroupDetailTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()));
// main panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// The table
AbsolutePanel dp = new AbsolutePanel();
//dp.setStyleName("decoration");
final FlexTable menu = new FlexTable();
menu.setCellSpacing(5);
// Add group information
menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.groupIcon()));
Label groupName = new Label();
groupName.setText(Utils.getStrippedStringWithEllipsis(group.getName(), 40));
groupName.setStyleName("now-managing");
groupName.setTitle(group.getName());
menu.setWidget(0, 1, groupName);
final JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
new GetEntityById(PerunEntity.RICH_GROUP, groupId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
group = jso.cast();
open();
draw();
}
}).retrieveData();
}
};
menu.setHTML(0, 2, " ");
menu.getFlexCellFormatter().setWidth(0, 2, "25px");
int column = 3;
CustomButton change;
if (group.isCoreGroup()) {
change = new CustomButton("", "Core group's name and description can't be changed", SmallIcons.INSTANCE.applicationFormEditIcon());
change.setEnabled(false);
} else {
change = new CustomButton("", ButtonTranslation.INSTANCE.editGroupDetails(), SmallIcons.INSTANCE.applicationFormEditIcon());
}
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
change.setEnabled(false);
change.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new EditGroupDetailsTabItem(group, events));
}
});
menu.setWidget(0, column, change);
column++;
menu.setHTML(0, column, " ");
menu.getFlexCellFormatter().setWidth(0, column, "25px");
column++;
if (JsonUtils.isExtendedInfoVisible()) {
menu.setHTML(0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + group.getId() + "</span>");
column++;
menu.setHTML(0, column, " ");
menu.getFlexCellFormatter().setWidth(0, column, "25px");
column++;
}
/*
String text = (((RichGroup)group).isSyncEnabled()) ? "Enabled" : "Disabled";
text += (((RichGroup)group).getAuthoritativeGroup().equals("1")) ? " / Authoritative" : "";
menu.setHTML(0, column, "<strong>Sync:</strong><br/><span class=\"inputFormInlineComment\">"+text+"</span>");
column++;
*/
menu.setHTML(0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + group.getDescription() + " </span>");
dp.add(menu);
vp.add(dp);
vp.setCellHeight(dp, "30px");
tabPanel.clear();
tabPanel.add(new GroupMembersTabItem(group), "Members");
if (!group.isCoreGroup()) {
tabPanel.add(new SubgroupsTabItem(group), "Subgroups");
tabPanel.add(new GroupRelationsTabItem(group), "Relations");
}
tabPanel.add(new GroupResourcesTabItem(group), "Resources");
if (!group.isCoreGroup()) {
tabPanel.add(new GroupApplicationsTabItem(group), "Applications");
tabPanel.add(new GroupApplicationFormSettingsTabItem(group), "Application form");
}
tabPanel.add(new GroupSettingsTabItem(group), "Settings");
if (!group.isCoreGroup()) {
// core groups can't have managers
tabPanel.add(new GroupManagersTabItem(group), "Managers");
}
if (!group.isCoreGroup()) {
// core groups can't have ext sources
tabPanel.add(new GroupExtSourcesTabItem(group), "External sources");
}
// Resize must be called after page fully displays
Scheduler.get().scheduleDeferred(new Command() {
@Override
public void execute() {
tabPanel.finishAdding();
}
});
vp.add(tabPanel);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations