use of cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts 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.json.facilitiesManager.GetHosts 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.json.facilitiesManager.GetHosts 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();
}
Aggregations