use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class CreateThanksTabItem method draw.
public Widget draw() {
// MAIN PANEL
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// CALLBACK
final GetOwners owners = new GetOwners();
// MENU
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
// add button
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add acknowledgement for selected owner(s)");
final TabItem tab = this;
// click handler
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ArrayList<Owner> list = owners.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
for (int i = 0; i < list.size(); i++) {
final String name = list.get(i).getName();
// add name events
JsonCallbackEvents thanksEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
updateAlreadyAdded(name);
}
};
// merge with refresh?
if (i == list.size() - 1 && events != null) {
thanksEvents = JsonCallbackEvents.mergeEvents(thanksEvents, events);
}
CreateThanks request = new CreateThanks(publicationId, JsonCallbackEvents.disableButtonEvents(addButton, thanksEvents));
request.createThanks(list.get(i).getId());
if (i == list.size() - 1) {
owners.clearTableSelectedSet();
}
}
}
}
});
menu.addWidget(addButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// trigger refresh of sub-tab via event
events.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
// add already added
vp.add(alreadyAddedOwners);
vp.setCellHeight(alreadyAddedOwners, "30px");
// TABLE
// show only administrative contacts
owners.setFilterByType("administrative");
CellTable<Owner> table = owners.getTable();
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
// resize small tab panel to correct size on screen
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(owners, table, addButton);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddFacilityDestinationTabItem method draw.
public Widget draw() {
titleWidget.setText("Add destination");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
layout.setWidth("350px");
final ExtendedSuggestBox destination = new ExtendedSuggestBox();
final ListBox type = new ListBox();
type.addItem("HOST", "host");
type.addItem("USER@HOST", "user@host");
type.addItem("USER@HOST:PORT", "user@host:port");
type.addItem("URL", "url");
type.addItem("MAIL", "email");
type.addItem("SIGNED MAIL", "semail");
type.addItem("SERVICE SPECIFIC", "service-specific");
final ListBoxWithObjects<Service> services = new ListBoxWithObjects<Service>();
final CheckBox useHosts = new CheckBox(WidgetTranslation.INSTANCE.useFacilityHostnames(), false);
useHosts.setTitle(WidgetTranslation.INSTANCE.useFacilityHostnamesTitle());
final CheckBox onlyAssignedServices = new CheckBox("Show only services on facility", false);
onlyAssignedServices.setTitle("Click to show all possible services");
onlyAssignedServices.setValue(true);
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDestination());
// fill oracle with hosts of facility
GetHosts getHosts = new GetHosts(facilityId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Host> ho = JsonUtils.jsoAsList(jso);
for (Host h : ho) {
hosts.addAll(ho);
destination.getSuggestOracle().add(h.getName());
}
}
});
getHosts.retrieveData();
JsonCallbackEvents fillAssignedServices = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
services.removeAllOption();
services.clear();
ArrayList<Service> ses = JsonUtils.jsoAsList(jso);
if (ses != null && !ses.isEmpty()) {
ses = new TableSorter<Service>().sortByName(ses);
services.addAllItems(ses);
services.addAllOption();
services.setSelectedIndex(0);
} else {
services.addItem("No service available");
}
addButton.setEnabled(true);
type.setEnabled(true);
}
@Override
public void onError(PerunError error) {
services.removeAllOption();
services.clear();
services.addItem("Error while loading");
addButton.setEnabled(true);
type.setEnabled(true);
}
@Override
public void onLoadingStart() {
services.removeAllOption();
services.clear();
services.addItem("Loading...");
addButton.setEnabled(false);
type.setEnabled(false);
}
};
final GetFacilityAssignedServices getAssignedServices = new GetFacilityAssignedServices(facility.getId(), fillAssignedServices);
getAssignedServices.retrieveData();
final GetServices getAllServices = new GetServices(fillAssignedServices);
onlyAssignedServices.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (onlyAssignedServices.getValue() == false) {
onlyAssignedServices.setTitle("Click to show only services on facility");
getAllServices.retrieveData();
} else {
onlyAssignedServices.setTitle("Click to show all possible services");
getAssignedServices.retrieveData();
}
}
});
final Label destinationLabel = new Label();
destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
final ExtendedSuggestBox.SuggestBoxValidator validator = new ExtendedSuggestBox.SuggestBoxValidator() {
@Override
public boolean validateSuggestBox() {
if (destination.getSuggestBox().getText().trim().isEmpty() && useHosts.getValue() == false) {
destination.setError("Destination value can't be empty.");
return false;
}
// check as email
if (type.getSelectedIndex() > 3 && type.getSelectedIndex() < 6) {
if (!JsonUtils.isValidEmail(destination.getSuggestBox().getText().trim())) {
destination.setError("Not valid email address.");
return false;
} else {
destination.setOk();
return true;
}
}
destination.setOk();
return true;
}
};
destination.setValidator(validator);
type.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// if hosts - checkbox visible
if (type.getSelectedIndex() == 0) {
useHosts.setVisible(true);
} else {
useHosts.setVisible(false);
useHosts.setValue(false);
destination.getSuggestBox().setEnabled(true);
}
if (type.getSelectedIndex() < 3) {
destination.getSuggestOracle().clear();
for (Host h : hosts) {
destination.getSuggestOracle().add(h.getName());
}
} else {
destination.getSuggestOracle().clear();
}
// set label
if (type.getSelectedIndex() == 0) {
destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
} else if (type.getSelectedIndex() == 1) {
destinationLabel.getElement().setInnerHTML("<strong>User@host:</strong>");
} else if (type.getSelectedIndex() == 2) {
destinationLabel.getElement().setInnerHTML("<strong>User@host:port:</strong>");
} else if (type.getSelectedIndex() == 3) {
destinationLabel.getElement().setInnerHTML("<strong>URL:</strong>");
} else if (type.getSelectedIndex() == 4) {
destinationLabel.getElement().setInnerHTML("<strong>Mail:</strong>");
} else if (type.getSelectedIndex() == 5) {
destinationLabel.getElement().setInnerHTML("<strong>Signed mail:</strong>");
} else if (type.getSelectedIndex() == 6) {
destinationLabel.getElement().setInnerHTML("<strong>Service specific:</strong>");
}
// run validation
validator.validateSuggestBox();
}
});
useHosts.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (useHosts.getValue() == true) {
destination.getSuggestBox().setEnabled(false);
destination.setOk();
} else {
destination.getSuggestBox().setEnabled(true);
}
}
});
cellFormatter.setColSpan(0, 0, 2);
HTML text = new HTML("Please add destinations for service configuration delivery. New service configuration can be performed directly on facility (dest. type HOST) or sent to URL or by an email.");
text.setStyleName("inputFormInlineComment");
layout.setWidget(0, 0, text);
layout.setHTML(1, 0, "Service:");
layout.setWidget(1, 1, services);
layout.setWidget(2, 1, onlyAssignedServices);
layout.setHTML(3, 0, "Type:");
layout.setWidget(3, 1, type);
layout.setWidget(4, 0, destinationLabel);
layout.setWidget(4, 1, destination);
layout.setWidget(5, 1, useHosts);
for (int i = 1; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
final TabItem tab = this;
TabMenu menu = new TabMenu();
menu.addWidget(addButton);
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (services.isEmpty()) {
// no services available
addButton.setEnabled(false);
}
if (validator.validateSuggestBox()) {
if (services.getSelectedIndex() == 0) {
// selected all
if (useHosts.getValue() == true) {
// auto by hosts
AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
request.addDestinationByHosts(services.getAllObjects());
} else {
// default
AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getAllObjects());
}
} else {
// selected one
if (useHosts.getValue() == true) {
// auto by hosts
AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
request.addDestinationByHosts(services.getSelectedObject());
} else {
// default
AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getSelectedObject());
}
}
}
}
});
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddFacilityManagerGroupTabItem method fillGroupsContent.
private Widget fillGroupsContent(GetAllGroups groups, TabMenu tabMenu, final ListBoxWithObjects<VirtualOrganization> box) {
getAllGroups = groups;
getAllGroups.setCoreGroupsCheckable(true);
final CellTable<Group> table = getAllGroups.getTable();
getAllGroups.getSelectionModel().addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
private boolean found = false;
@Override
public void onSelectionChange(SelectionChangeEvent event) {
for (Group g : getAllGroups.getTableSelectedList()) {
if (g.isCoreGroup()) {
if (!found) {
// display only once
UiElements.generateInfo("You have selected 'all vo members' group", "If this group will be added as 'manager group', all new members of VO " + box.getSelectedObject().getName() + " will be automatically managers of your Facility and all removed members will lose management rights.");
}
found = true;
return;
}
}
found = false;
}
});
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersGroupToGroup());
tabMenu.addWidget(0, addButton);
final TabItem tab = this;
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Group> list = getAllGroups.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// close tab and refresh table
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
request.addFacilityAdminGroup(facility, list.get(i));
} else {
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton));
request.addFacilityAdminGroup(facility, list.get(i));
}
}
}
}
});
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(getAllGroups, table, addButton);
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
return table;
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AttributeDefinitionDetailTabItem method draw.
public Widget draw() {
titleWidget.setText(def.getName());
final TabItem tab = this;
// create main panel for content
final FlexTable mainPage = new FlexTable();
mainPage.setWidth("100%");
final ExtendedTextBox description = new ExtendedTextBox();
description.setWidth("100%");
description.getTextBox().setText(def.getDescription());
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (description.getTextBox().getText().trim().isEmpty()) {
description.setError("Description can't be empty.");
return false;
}
description.setOk();
return true;
}
};
final ExtendedTextBox displayName = new ExtendedTextBox();
displayName.setWidth("100%");
displayName.getTextBox().setText(def.getDisplayName());
final ExtendedTextBox.TextBoxValidator validatorName = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (displayName.getTextBox().getText().trim().isEmpty()) {
displayName.setError("Display name can't be empty.");
return false;
}
displayName.setOk();
return true;
}
};
description.setValidator(validator);
displayName.setValidator(validatorName);
FlexTable attributeDetailTable = new FlexTable();
attributeDetailTable.setStyleName("inputFormFlexTable");
final CustomButton updateButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
updateButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
for (AttributeRights r : rights) {
if (r.getRole().equalsIgnoreCase("SELF")) {
list.add(getRightsFromWidgets(selfRead, selfWrite, r));
} else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
list.add(getRightsFromWidgets(voRead, voWrite, r));
} else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
list.add(getRightsFromWidgets(groupRead, groupWrite, r));
} else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
}
}
if ((!def.getDescription().equals(description.getTextBox().getText().trim()) || !def.getDisplayName().equals(displayName.getTextBox().getText().trim()))) {
if (!validator.validateTextBox() || !validatorName.validateTextBox())
return;
def.setDescription(description.getTextBox().getText().trim());
def.setDisplayName(displayName.getTextBox().getText().trim());
UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// after update - update rights
SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
enableDisableWidgets(true);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
}
}));
request.setAttributeRights(list);
}
}));
request.updateAttribute(def);
} else {
// after update - update rights
SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
enableDisableWidgets(true);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
}
}));
request.setAttributeRights(list);
}
}
});
attributeDetailTable.setHTML(0, 0, "Display name:");
attributeDetailTable.setWidget(0, 1, displayName);
attributeDetailTable.setHTML(1, 0, "Description:");
attributeDetailTable.setWidget(1, 1, description);
for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
final FlexTable rightsTable = new FlexTable();
rightsTable.setStyleName("inputFormFlexTable");
rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
rightsTable.setHTML(0, 2, "<strong>VO</strong>");
rightsTable.setHTML(0, 3, "<strong>GROUP</strong>");
rightsTable.setHTML(0, 4, "<strong>FACILITY</strong>");
rightsTable.setHTML(1, 0, "<strong>READ</strong>");
rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
rightsTable.setWidget(1, 1, selfRead);
rightsTable.setWidget(2, 1, selfWrite);
rightsTable.setWidget(1, 2, voRead);
rightsTable.setWidget(2, 2, voWrite);
rightsTable.setWidget(1, 3, groupRead);
rightsTable.setWidget(2, 3, groupWrite);
rightsTable.setWidget(1, 4, facilityRead);
rightsTable.setWidget(2, 4, facilityWrite);
rightsTable.addStyleName("centeredTable");
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(updateButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, false);
}
}));
GetAttributeRights rightsCall = new GetAttributeRights(def.getId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
rights = JsonUtils.jsoAsList(jso);
for (AttributeRights r : rights) {
if (r.getRole().equalsIgnoreCase("SELF")) {
setRightsToWidgets(selfRead, selfWrite, r);
} else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
setRightsToWidgets(voRead, voWrite, r);
} else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
setRightsToWidgets(groupRead, groupWrite, r);
} else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
setRightsToWidgets(facilityRead, facilityWrite, r);
}
}
enableDisableWidgets(true);
rightsTable.setVisible(true);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
rightsTable.setVisible(false);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
rightsTable.setVisible(false);
}
});
rightsCall.retrieveData();
// create new instance for jsonCall
final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
services.setCheckable(false);
CellTable<Service> attrDefTable = services.getTable(new FieldUpdater<Service, String>() {
@Override
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ServiceDetailTabItem(object));
}
});
attrDefTable.setStyleName("perun-table");
ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
scrollTable.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(scrollTable, 350, this);
// set content to page
mainPage.setWidget(0, 0, menu);
mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);
mainPage.setWidget(1, 0, attributeDetailTable);
mainPage.setWidget(1, 1, rightsTable);
mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");
HTML title = new HTML("<p>Required by service</p>");
title.setStyleName("subsection-heading");
mainPage.setWidget(2, 0, title);
mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);
// put page into scroll panel
mainPage.setWidget(3, 0, scrollTable);
mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");
this.contentWidget.setWidget(mainPage);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class CreateGroupTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
// used for closing
final TabItem tab = this;
// form inputs
final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
final TextBox groupDescriptionTextBox = new TextBox();
final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
vosGroups.setVisible(false);
final CheckBox asSubGroup = new CheckBox("", false);
TabMenu menu = new TabMenu();
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
final HTML parentGroupText = new HTML("Parent group:");
parentGroupText.setVisible(false);
final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
vosGroups.clear();
ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
retGroups = new TableSorter<Group>().sortByName(retGroups);
for (Group g : retGroups) {
if (!g.isCoreGroup()) {
// SKIP CORE GROUPS !!
vosGroups.addItem(g);
if (g.getId() == groupId) {
// select default if passed to tab
vosGroups.setSelected(g, true);
}
}
}
if (vosGroups.getAllObjects().isEmpty()) {
vosGroups.addItem("No groups found");
} else {
createButton.setEnabled(true);
}
// call finished when user changed his mind
if (!asSubGroup.getValue()) {
createButton.setEnabled(true);
}
}
public void onLoadingStart() {
vosGroups.clear();
vosGroups.addItem("Loading...");
createButton.setEnabled(false);
}
public void onError(PerunError error) {
vosGroups.clear();
vosGroups.addItem("Error while loading");
if (!asSubGroup.getValue()) {
createButton.setEnabled(true);
}
}
});
// set title
if (PerunEntity.GROUP.equals(entity)) {
this.titleWidget.setText("Create sub-group");
asSubGroup.setValue(true);
createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
parentGroupText.setVisible(true);
vosGroups.setVisible(true);
groupsCall.retrieveData();
} else {
this.titleWidget.setText("Create group");
createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
}
asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
if (booleanValueChangeEvent.getValue() == true) {
// set title
titleWidget.setText("Create sub-group");
vosGroups.setVisible(true);
parentGroupText.setVisible(true);
groupsCall.retrieveData();
createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
} else {
titleWidget.setText("Create group");
vosGroups.setVisible(false);
parentGroupText.setVisible(false);
createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
createButton.setEnabled(true);
}
}
});
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
groupNameTextBox.setError("Name can't be empty.");
} else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
groupNameTextBox.setError("Name can contain only a-z, A-Z, numbers, spaces, dots, '_' and '-'.");
} else {
groupNameTextBox.setOk();
return true;
}
return false;
}
};
groupNameTextBox.setValidator(validator);
// send button
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!validator.validateTextBox())
return;
// creates a new request
CreateGroup cg = new CreateGroup(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
if (asSubGroup.getValue()) {
if (vosGroups.getSelectedObject() != null) {
cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
} else {
UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
}
} else {
cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
}
}
});
// cancel button
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, groupNameTextBox);
layout.setHTML(1, 0, "Description:");
layout.setWidget(1, 1, groupDescriptionTextBox);
layout.setHTML(2, 0, "As sub-group:");
layout.setWidget(2, 1, asSubGroup);
layout.setWidget(3, 0, parentGroupText);
layout.setWidget(3, 1, vosGroups);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
// button align
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