use of cz.metacentrum.perun.webgui.model.Facility in project perun by CESNET.
the class UpdateFacility method updateFacility.
/**
* Updates facility details
*
* @param fac Facility with updated details
*/
public void updateFacility(Facility fac) {
if (fac == null) {
UiElements.generateAlert("Error updating facility", "Facility to update can't be null.");
return;
}
// GROUP OBJECT
JSONObject oldFacility = new JSONObject(fac);
// RECONSTRUCT OBJECT
JSONObject newFacility = new JSONObject();
newFacility.put("id", oldFacility.get("id"));
newFacility.put("name", oldFacility.get("name"));
newFacility.put("description", oldFacility.get("description"));
newFacility.put("type", oldFacility.get("type"));
newFacility.put("beanName", oldFacility.get("beanName"));
newFacility.put("createdAt", oldFacility.get("createdAt"));
newFacility.put("createdBy", oldFacility.get("createdBy"));
newFacility.put("modifiedAt", oldFacility.get("modifiedAt"));
newFacility.put("modifiedBy", oldFacility.get("modifiedBy"));
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("facility", newFacility);
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Updating facility failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
Facility fac = jso.cast();
session.getUiElements().setLogSuccessText("Facility " + fac.getName() + " successfully updated!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.Facility in project perun by CESNET.
the class FacilitiesTabItem method draw.
public Widget draw() {
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// TAB MENU
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// get RICH facilities request
final GetFacilities facilities = new GetFacilities(true);
// retrieve data (table)
final CellTable<Facility> table = facilities.getTable(new FieldUpdater<Facility, String>() {
public void update(int index, Facility object, String value) {
session.getTabManager().addTab(new FacilityDetailTabItem(object));
}
});
// add new facility button
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createFacility(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new CreateFacilityTabItem());
}
}));
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(facilities);
// add delete facilities button
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteFacilities());
tabMenu.addWidget(deleteButton);
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Facility> list = facilities.getTableSelectedList();
String text = "Following facilities will be deleted.";
UiElements.showDeleteConfirm(list, text, 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) {
DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
request.deleteFacility(list.get(i).getId());
} else {
DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton));
request.deleteFacility(list.get(i).getId());
}
}
}
});
}
});
// filter box
tabMenu.addFilterWidget(new ExtendedSuggestBox(facilities.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
facilities.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterFacilities());
deleteButton.setEnabled(false);
JsonUtils.addTableManagedButton(facilities, table, deleteButton);
// 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(sp);
firstTabPanel.setCellHeight(sp, "100%");
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.Facility in project perun by CESNET.
the class FacilitiesSelectTabItem method draw.
public Widget draw() {
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// TAB MENU
TabMenu tabMenu = new TabMenu();
// get RICH facilities request
final GetFacilities facilities = new GetFacilities(true);
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(facilities);
// retrieve data (table)
final CellTable<Facility> table = facilities.getTable(new FieldUpdater<Facility, String>() {
public void update(int index, Facility object, String value) {
session.getTabManager().addTab(new FacilityDetailTabItem(object));
}
});
tabMenu.addWidget(UiElements.getRefreshButton(this));
// add new facility button
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createFacility(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new CreateFacilityTabItem(facilities.getFullBackupList(), events));
}
}));
// add delete facilities button
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteFacilities());
if (session.isPerunAdmin()) {
tabMenu.addWidget(deleteButton);
}
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Facility> list = facilities.getTableSelectedList();
String text = "Following facilities will be deleted.";
UiElements.showDeleteConfirm(list, text, 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) {
DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
request.deleteFacility(list.get(i).getId());
} else {
DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton));
request.deleteFacility(list.get(i).getId());
}
}
}
});
}
});
// filter box
tabMenu.addFilterWidget(new ExtendedSuggestBox(facilities.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
facilities.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterFacilities());
tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
tabMenu.addWidget(new HTML("<strong>Please select Facility you want to manage.</strong>"));
deleteButton.setEnabled(false);
JsonUtils.addTableManagedButton(facilities, table, deleteButton);
// 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(sp);
firstTabPanel.setCellHeight(sp, "100%");
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.Facility in project perun by CESNET.
the class ServiceDestinationsTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Service destinations");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
// Adds menu to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
// buttons
final CustomButton addDestButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addDestination());
final CustomButton removeDestButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDestinations());
menu.addWidget(addDestButton);
menu.addWidget(removeDestButton);
menu.addWidget(new HTML("<strong>Selected facility:</strong>"));
// listbox with facilities
final ListBoxWithObjects<Facility> ls = new ListBoxWithObjects<Facility>();
menu.addWidget(ls);
// get empty table used for destinations
final GetAllRichDestinations callback = new GetAllRichDestinations(null, service);
callback.showFacilityColumn(true);
callback.showServiceColumn(false);
// do not make callback yet
final CellTable<Destination> table = callback.getEmptyTable();
if (lastSelectedFacilityId == 0) {
callback.retrieveData();
}
// refresh events called when selection changes or callback ends
final JsonCallbackEvents refreshEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
if (ls.getSelectedIndex() == 0) {
// fills table with destinations of all facilities
callback.clearTable();
callback.retrieveData();
} else {
callback.clearTable();
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
// fills table with destinations of selected facility
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
JsArray<Destination> dst = JsonUtils.jsoAsArray(jso);
for (int i = 0; i < dst.length(); i++) {
callback.addToTable(dst.get(i));
}
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
}
public void onError(PerunError error) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
}
};
final GetDestinations callback = new GetDestinations(ls.getSelectedObject(), service, localEvents);
callback.retrieveData();
}
}
};
// fills listbox and table with dest. for all service facilities
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ls.clear();
ArrayList<Facility> facs = JsonUtils.jsoAsList(jso);
facs = new TableSorter<Facility>().sortByName(facs);
// if no facility
if (facs.size() == 0) {
ls.addItem("No facility available");
return;
}
for (int i = 0; i < facs.size(); i++) {
ls.addItem(facs.get(i));
if (facs.get(i).getId() == lastSelectedFacilityId) {
ls.setSelected(facs.get(i), true);
}
}
ls.addAllOption();
if (lastSelectedFacilityId == 0) {
// select all
ls.setItemSelected(0, true);
} else {
// was selected
addDestButton.setEnabled(true);
refreshEvents.onFinished(null);
}
}
public void onError(PerunError error) {
ls.addItem("Error while loading");
addDestButton.setEnabled(false);
}
public void onLoadingStart() {
ls.clear();
ls.addItem("Loading...");
addDestButton.setEnabled(false);
}
};
final GetAssignedFacilities assignedFacilities = new GetAssignedFacilities(PerunEntity.SERVICE, serviceId, events);
assignedFacilities.retrieveData();
ls.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (ls.getSelectedIndex() > 0) {
// store last selected facility id
addDestButton.setEnabled(true);
lastSelectedFacilityId = ls.getSelectedObject().getId();
} else {
addDestButton.setEnabled(false);
lastSelectedFacilityId = 0;
}
refreshEvents.onFinished(null);
}
});
// CLICK HANDLERS FOR BUTTONS
addDestButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddFacilityDestinationTabItem(ls.getSelectedObject()));
}
});
removeDestButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// get
final ArrayList<Destination> destsToRemove = callback.getTableSelectedList();
UiElements.showDeleteConfirm(destsToRemove, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < destsToRemove.size(); i++) {
if (i == destsToRemove.size() - 1) {
RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton, refreshEvents));
request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
} else {
RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton));
request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
}
}
}
});
}
});
// filter box
menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
callback.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterDestinationByFacility());
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
removeDestButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeDestButton);
// add tabs to the main panel
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.Facility 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();
}
Aggregations