use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class FacilityHostsSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
// main panel
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
final GetAttributesV2 attrs = new GetAttributesV2();
final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
// refresh attributes for hosts
listbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (listbox.getSelectedObject() != null) {
lastSelectedHostId = listbox.getSelectedObject().getId();
attrs.getHostAttributes(lastSelectedHostId);
attrs.retrieveData();
} else {
lastSelectedHostId = 0;
}
}
});
// retrieve hosts
final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listbox.clear();
ArrayList<Host> result = JsonUtils.jsoAsList(jso);
if (result != null && !result.isEmpty()) {
for (Host h : result) {
listbox.addItem(h);
if (h.getId() == lastSelectedHostId) {
listbox.setSelected(h, true);
}
}
if (lastSelectedHostId == 0) {
lastSelectedHostId = listbox.getSelectedObject().getId();
}
attrs.getHostAttributes(lastSelectedHostId);
attrs.retrieveData();
}
}
@Override
public void onError(PerunError error) {
listbox.clear();
listbox.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
listbox.clear();
listbox.addItem("Loading...");
}
});
hosts.retrieveData();
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
// menu
TabMenu menu = new TabMenu();
// Save changes button
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
SetAttributes request = new SetAttributes(saveChangesButtonEvent);
request.setAttributes(ids, list);
}
}
});
// Remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
}
}));
menu.addWidget(removeButton);
menu.addWidget(new HTML("<strong>Select host:</strong>"));
menu.addWidget(listbox);
// attrs table
CellTable<Attribute> table = attrs.getEmptyTable();
// 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(menu);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class FacilityHostsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts");
// main panel
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
final GetHosts hosts = new GetHosts(facilityId);
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(hosts);
// menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addHost(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new AddHostsTabItem(facility));
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeHosts());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Host> hostsForRemoving = hosts.getTableSelectedList();
String text = "<span class=\"serverResponseLabelError\"><strong>Removing host(s) won't stop services propagation. For this please remove proper 'Services destinations'.</strong></span><p>Following hosts will be removed from facility.";
UiElements.showDeleteConfirm(hostsForRemoving, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < hostsForRemoving.size(); i++) {
if (i == hostsForRemoving.size() - 1) {
RemoveHosts request = new RemoveHosts(facilityId, JsonCallbackEvents.disableButtonEvents(removeButton, events));
request.removeHost(hostsForRemoving.get(i).getId());
} else {
RemoveHosts request = new RemoveHosts(facilityId, JsonCallbackEvents.disableButtonEvents(removeButton));
request.removeHost(hostsForRemoving.get(i).getId());
}
}
}
});
}
});
menu.addWidget(removeButton);
menu.addFilterWidget(new ExtendedSuggestBox(hosts.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
hosts.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterHosts());
// Hosts table
CellTable<Host> table = hosts.getTable(new FieldUpdater<Host, String>() {
@Override
public void update(int index, Host object, String value) {
session.getTabManager().addTab(new FacilityHostsSettingsTabItem(facility, object));
}
});
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(hosts, table, removeButton);
// 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(menu);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class FacilityOwnersTabItem method draw.
public Widget draw() {
// TITLE
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Owners");
// CONTENT
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// MENU
TabMenu menu = new TabMenu();
// CALLBACK
final GetFacilityOwners jsonCallback = new GetFacilityOwners(facility);
// AUTHZ
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// add button
CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addNewOwners());
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddFacilityOwnerTabItem(facility), true);
}
});
// remove button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedOwners());
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Owner> list = jsonCallback.getTableSelectedList();
UiElements.showDeleteConfirm(list, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
RemoveOwner request = new RemoveOwner(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(jsonCallback)));
request.removeFacilityOwner(facilityId, list.get(i).getId());
} else {
RemoveOwner request = new RemoveOwner(JsonCallbackEvents.disableButtonEvents(removeButton));
request.removeFacilityOwner(facilityId, list.get(i).getId());
}
}
}
});
}
});
menu.addWidget(addButton);
menu.addWidget(removeButton);
menu.addFilterWidget(new ExtendedSuggestBox(jsonCallback.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
jsonCallback.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterOwners());
// TABLE
CellTable<Owner> table = jsonCallback.getTable();
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(jsonCallback, table, removeButton);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class EditFacilityDetailsTabItem method draw.
public Widget draw() {
titleWidget = new Label("Edit facility");
VerticalPanel vp = new VerticalPanel();
// textboxes which set the class data when updated
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
nameTextBox.getTextBox().setText(facility.getName());
final TextBox descriptionTextBox = new TextBox();
descriptionTextBox.setText(facility.getDescription());
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setError("Name can't be empty.");
return false;
} else if (!nameTextBox.getTextBox().getText().trim().matches(Utils.FACILITY_NAME_MATCHER)) {
nameTextBox.setError("Name can contain only letters, numbers, dash, dot and underscore.");
return false;
} else {
nameTextBox.setOk();
return true;
}
}
};
nameTextBox.setValidator(validator);
// 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 saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveFacilityDetails());
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox()) {
Facility fac = JsonUtils.clone(facility).cast();
fac.setName(nameTextBox.getTextBox().getText().trim());
fac.setDescription(descriptionTextBox.getText().trim());
UpdateFacility request = new UpdateFacility(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
request.updateFacility(fac);
}
}
});
// 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(saveButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class FacilityAllowedGroupsTabItem method draw.
public Widget draw() {
// set title
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Allowed Groups");
final ListBoxWithObjects<VirtualOrganization> vosListbox = new ListBoxWithObjects<VirtualOrganization>();
final ListBoxWithObjects<Service> servicesListbox = new ListBoxWithObjects<Service>();
final GetAllowedGroups jsonCallback = new GetAllowedGroups(facilityId);
jsonCallback.setCheckable(false);
// content
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(new HTML("<strong>Filter by VO:</strong>"));
menu.addWidget(vosListbox);
menu.addWidget(new HTML("<strong>Filter by service:</strong>"));
menu.addWidget(servicesListbox);
// get the table
final GetAllowedVos vosCall = new GetAllowedVos(facilityId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
vosListbox.clear();
vosListbox.removeAllOption();
vosListbox.addAllItems(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
vosListbox.addAllOption();
if (lastSelectedVoId == 0) {
vosListbox.setSelectedIndex(0);
} else {
for (VirtualOrganization vo : vosListbox.getAllObjects()) {
if (vo.getId() == lastSelectedVoId) {
vosListbox.setSelected(vo, true);
break;
}
}
}
jsonCallback.setVos(vosListbox.getAllObjects());
vosCallDone = true;
}
public void onLoadingStart() {
vosListbox.removeAllOption();
vosListbox.clear();
vosListbox.addItem("Loading...");
vosCallDone = false;
}
public void onError(PerunError error) {
vosListbox.clear();
vosListbox.removeAllOption();
vosListbox.addItem("Error while loading");
vosCallDone = false;
}
});
vosCall.retrieveData();
GetFacilityAssignedServices servCall = new GetFacilityAssignedServices(facilityId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
servicesListbox.clear();
servicesListbox.removeAllOption();
servicesListbox.addAllItems(new TableSorter<Service>().sortByName(JsonUtils.<Service>jsoAsList(jso)));
servicesListbox.addAllOption();
if (servicesListbox.isEmpty()) {
servicesListbox.addItem("No service available on facility");
}
if (lastSelectedServiceId == 0) {
// choose all
servicesListbox.setSelectedIndex(0);
} else {
for (Service s : servicesListbox.getAllObjects()) {
if (s.getId() == lastSelectedServiceId) {
servicesListbox.setSelected(s, true);
break;
}
}
}
callDone = true;
}
public void onLoadingStart() {
servicesListbox.removeAllOption();
servicesListbox.clear();
servicesListbox.addItem("Loading...");
callDone = false;
}
public void onError(PerunError error) {
servicesListbox.clear();
servicesListbox.removeAllOption();
servicesListbox.addItem("Error while loading");
callDone = false;
}
});
servCall.retrieveData();
Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
if (vosCallDone && callDone) {
jsonCallback.setVoId(lastSelectedVoId);
jsonCallback.setServiceId(lastSelectedServiceId);
jsonCallback.retrieveData();
return false;
} else {
return true;
}
}
}, 200);
vosListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (vosListbox.getSelectedIndex() > 0) {
jsonCallback.setVoId(vosListbox.getSelectedObject().getId());
lastSelectedVoId = vosListbox.getSelectedObject().getId();
} else {
jsonCallback.setVoId(0);
lastSelectedVoId = 0;
}
jsonCallback.retrieveData();
}
});
servicesListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (servicesListbox.getSelectedIndex() > 0) {
jsonCallback.setServiceId(servicesListbox.getSelectedObject().getId());
lastSelectedServiceId = servicesListbox.getSelectedObject().getId();
} else {
jsonCallback.setServiceId(0);
lastSelectedServiceId = 0;
}
jsonCallback.retrieveData();
}
});
CellTable<Group> table = jsonCallback.getEmptyTable(new FieldUpdater<Group, String>() {
@Override
public void update(int i, Group group, String s) {
if (session.isVoAdmin(group.getVoId()) || session.isGroupAdmin(group.getId())) {
session.getTabManager().addTab(new GroupDetailTabItem(group));
} else {
// show alert
UiElements.generateInfo("You are not VO / Group manager of this group", "You MUST be VO manager or Group manager of group: <strong>" + group.getName() + "</strong> to view it's details.");
}
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations