Search in sources :

Example 1 with GetAssignedRichResources

use of cz.metacentrum.perun.webgui.json.facilitiesManager.GetAssignedRichResources in project perun by CESNET.

the class FacilityResourcesTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Resources");
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // get VO resources
    final GetAssignedRichResources resources = new GetAssignedRichResources(facility.getId());
    // custom events for viewResource
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(resources);
    // create resource button
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createResource(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceTabItem(facility), false);
        }
    }));
    final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteResource());
    menu.addWidget(deleteButton);
    deleteButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            final ArrayList<RichResource> toDelete = resources.getTableSelectedList();
            String text = "Following resources will be deleted.";
            UiElements.showDeleteConfirm(toDelete, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < toDelete.size(); i++) {
                        if (i == toDelete.size() - 1) {
                            DeleteResource request = new DeleteResource(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
                            request.deleteResource(toDelete.get(i).getId());
                        } else {
                            DeleteResource request = new DeleteResource(JsonCallbackEvents.disableButtonEvents(deleteButton));
                            request.deleteResource(toDelete.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    menu.addFilterWidget(new ExtendedSuggestBox(resources.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            resources.filterTable(text);
        }
    }, "Filter resources by name or VO name");
    CellTable<RichResource> table = resources.getTable(new FieldUpdater<RichResource, String>() {

        public void update(int index, RichResource object, String value) {
            session.getTabManager().addTab(new ResourceDetailTabItem(object, facilityId));
        }
    });
    deleteButton.setEnabled(false);
    JsonUtils.addTableManagedButton(resources, table, deleteButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RichResource(cz.metacentrum.perun.webgui.model.RichResource) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) DeleteResource(cz.metacentrum.perun.webgui.json.resourcesManager.DeleteResource) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAssignedRichResources(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAssignedRichResources) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CreateFacilityResourceTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.CreateFacilityResourceTabItem) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetAssignedRichResources (cz.metacentrum.perun.webgui.json.facilitiesManager.GetAssignedRichResources)1 DeleteResource (cz.metacentrum.perun.webgui.json.resourcesManager.DeleteResource)1 RichResource (cz.metacentrum.perun.webgui.model.RichResource)1 CreateFacilityResourceTabItem (cz.metacentrum.perun.webgui.tabs.resourcestabs.CreateFacilityResourceTabItem)1 ResourceDetailTabItem (cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem)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 ArrayList (java.util.ArrayList)1