Search in sources :

Example 1 with ServicesPackage

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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) DeleteServicePackage(cz.metacentrum.perun.webgui.json.servicesManager.DeleteServicePackage) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetServicesPackages(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesPackages) UpdateServicePackage(cz.metacentrum.perun.webgui.json.servicesManager.UpdateServicePackage) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) ServicesPackage(cz.metacentrum.perun.webgui.model.ServicesPackage)

Example 2 with ServicesPackage

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;
}
Also used : CustomClickableTextCell(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) TextInputCell(com.google.gwt.cell.client.TextInputCell) Column(com.google.gwt.user.cellview.client.Column) ServicesPackage(cz.metacentrum.perun.webgui.model.ServicesPackage)

Example 3 with ServicesPackage

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();
}
Also used : ServicesPackage(cz.metacentrum.perun.webgui.model.ServicesPackage)

Example 4 with ServicesPackage

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();
}
Also used : ServicesPackage(cz.metacentrum.perun.webgui.model.ServicesPackage)

Aggregations

ServicesPackage (cz.metacentrum.perun.webgui.model.ServicesPackage)4 TextInputCell (com.google.gwt.cell.client.TextInputCell)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Column (com.google.gwt.user.cellview.client.Column)1 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 DeleteServicePackage (cz.metacentrum.perun.webgui.json.servicesManager.DeleteServicePackage)1 GetServicesPackages (cz.metacentrum.perun.webgui.json.servicesManager.GetServicesPackages)1 UpdateServicePackage (cz.metacentrum.perun.webgui.json.servicesManager.UpdateServicePackage)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)1 ArrayList (java.util.ArrayList)1