use of cz.metacentrum.perun.webgui.model.ServicesPackage in project perun by CESNET.
the class ServicePackagesTabItem method draw.
public Widget draw() {
// create widget for the whole page
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
// create widget for menu on page
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// get services
final GetServicesPackages services = new GetServicesPackages();
services.setEditable(true);
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(services);
// get the table of services with custom field updater (lines are clickable and open service details)
CellTable<ServicesPackage> table = services.getTable(new FieldUpdater<ServicesPackage, String>() {
// when user click on a row -> open new tab
public void update(int index, ServicesPackage object, String value) {
session.getTabManager().addTabToCurrentTab(new ServicePackageDetailTabItem(object), true);
}
});
// create button
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createServicePackage(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new CreateServicePackageTabItem());
}
}));
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteSelectedServicePackages());
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get selected items
final ArrayList<ServicesPackage> itemsToRemove = services.getTableSelectedList();
UiElements.showDeleteConfirm(itemsToRemove, "Following services packages will be deleted.", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < itemsToRemove.size(); i++) {
DeleteServicePackage request;
if (i == itemsToRemove.size() - 1) {
request = new DeleteServicePackage(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
} else {
request = new DeleteServicePackage(JsonCallbackEvents.disableButtonEvents(deleteButton));
}
request.deleteServicePackage(itemsToRemove.get(i).getId());
}
}
});
}
});
tabMenu.addWidget(deleteButton);
tabMenu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
services.filterTable(text);
}
}, "Filter service package by name");
final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInServicesPackages());
save.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get selected items
final ArrayList<ServicesPackage> itemsToUpdate = services.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(itemsToUpdate)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < itemsToUpdate.size(); i++) {
UpdateServicePackage request;
if (i == itemsToUpdate.size() - 1) {
request = new UpdateServicePackage(JsonCallbackEvents.disableButtonEvents(save, events));
} else {
request = new UpdateServicePackage(JsonCallbackEvents.disableButtonEvents(save));
}
request.updateServicePackage(itemsToUpdate.get(i));
}
}
}
});
tabMenu.addWidget(save);
// add menu to page itself
mainTab.add(tabMenu);
mainTab.setCellHeight(tabMenu, "30px");
// add styling to table with services
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
mainTab.add(sp);
deleteButton.setEnabled(false);
save.setEnabled(false);
JsonUtils.addTableManagedButton(services, table, deleteButton);
JsonUtils.addTableManagedButton(services, table, save);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.ServicesPackage in project perun by CESNET.
the class GetServicesPackages method getEmptyTable.
/**
* Returns empty table of ServicePackages
*
* @return empty table widget
*/
public CellTable<ServicesPackage> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<ServicesPackage>(list);
// Cell table
table = new PerunTable<ServicesPackage>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<ServicesPackage> columnSortHandler = new ListHandler<ServicesPackage>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<ServicesPackage>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("There are no services packages.");
// checkbox column column
if (checkable) {
table.addCheckBoxColumn();
}
table.addIdColumn("ServicesPackage Id", tableFieldUpdater, 110);
if (!editable) {
table.addNameColumn(tableFieldUpdater);
table.addDescriptionColumn(tableFieldUpdater);
} else {
// NAME COLUMN
final Column<ServicesPackage, String> nameColumn = new Column<ServicesPackage, String>(new TextInputCell()) {
public String getValue(ServicesPackage object) {
return object.getName();
}
};
nameColumn.setFieldUpdater(new FieldUpdater<ServicesPackage, String>() {
@Override
public void update(int i, final ServicesPackage object, final String s) {
object.setName(s.trim());
selectionModel.setSelected(object, true);
}
});
nameColumn.setSortable(true);
columnSortHandler.setComparator(nameColumn, new Comparator<ServicesPackage>() {
public int compare(ServicesPackage o1, ServicesPackage o2) {
return o1.getName().compareTo(o2.getName());
}
});
// DESCRIPTION COLUMN
final Column<ServicesPackage, String> descriptionColumn = new Column<ServicesPackage, String>(new TextInputCell()) {
public String getValue(ServicesPackage object) {
return object.getDescription();
}
};
descriptionColumn.setFieldUpdater(new FieldUpdater<ServicesPackage, String>() {
@Override
public void update(int i, final ServicesPackage object, final String s) {
object.setDescription(s.trim());
selectionModel.setSelected(object, true);
}
});
descriptionColumn.setSortable(true);
columnSortHandler.setComparator(descriptionColumn, new Comparator<ServicesPackage>() {
public int compare(ServicesPackage o1, ServicesPackage o2) {
return o1.getDescription().compareTo(o2.getDescription());
}
});
// Link COLUMN
final Column<ServicesPackage, String> linkColumn = new Column<ServicesPackage, String>(new CustomClickableTextCell()) {
public String getValue(ServicesPackage object) {
return "View services in package";
}
};
linkColumn.setFieldUpdater(tableFieldUpdater);
table.addColumn(nameColumn, "Name");
table.setColumnWidth(nameColumn, "250px");
table.addColumn(descriptionColumn, "Description");
table.setColumnWidth(descriptionColumn, "250px");
table.addColumn(linkColumn, "Manage services");
}
return table;
}
use of cz.metacentrum.perun.webgui.model.ServicesPackage in project perun by CESNET.
the class GetServicesPackages method filterTable.
@Override
public void filterTable(String filter) {
// store list only for first time
if (backupList.isEmpty() || backupList == null) {
backupList.addAll(list);
}
// always clear selected items
selectionModel.clear();
list.clear();
if (filter.equalsIgnoreCase("")) {
list.addAll(backupList);
} else {
for (ServicesPackage s : backupList) {
// store facility by filter
if (s.getName().toLowerCase().startsWith(filter.toLowerCase())) {
list.add(s);
}
}
}
if (list.isEmpty() && !filter.isEmpty()) {
loaderImage.setEmptyResultMessage("No services package matching '" + filter + "' found.");
} else {
loaderImage.setEmptyResultMessage("There are no services packages.");
}
dataProvider.flush();
dataProvider.refresh();
loaderImage.loadingFinished();
}
use of cz.metacentrum.perun.webgui.model.ServicesPackage in project perun by CESNET.
the class GetServicesPackages method setList.
public void setList(ArrayList<ServicesPackage> list) {
clearTable();
this.list.addAll(list);
for (ServicesPackage s : list) {
oracle.add(s.getName());
}
dataProvider.flush();
dataProvider.refresh();
}
Aggregations