Search in sources :

Example 1 with AddServiceToServicesPackage

use of cz.metacentrum.perun.webgui.json.servicesManager.AddServiceToServicesPackage in project perun by CESNET.

the class ServicePackageDetailTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(servicesPackage.getName()) + ": assigned services");
    // create widget for the whole page
    HorizontalPanel mainTab = new HorizontalPanel();
    mainTab.setSize("100%", "100%");
    // get services
    final GetServices services = new GetServices();
    final GetServicesFromServicesPackage assignedServices = new GetServicesFromServicesPackage(servicePackageId);
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(services);
    final JsonCallbackEvents events2 = JsonCallbackEvents.refreshTableEvents(assignedServices);
    // get the table of services with custom field updater (lines are clickable and open service details)
    CellTable<Service> table = services.getTable(new FieldUpdater<Service, String>() {

        // when user click on a row -> open new tab
        public void update(int index, Service object, String value) {
            session.getTabManager().addTab(new ServiceDetailTabItem(object));
        }
    });
    // get the table of services with custom field updater (lines are clickable and open service details)
    CellTable<Service> table2 = assignedServices.getTable(new FieldUpdater<Service, String>() {

        // when user click on a row -> open new tab
        public void update(int index, Service object, String value) {
            session.getTabManager().addTab(new ServiceDetailTabItem(object));
        }
    });
    // add styling to table with services
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    VerticalPanel vp1 = new VerticalPanel();
    vp1.setSize("100%", "100%");
    TabMenu menu1 = new TabMenu();
    menu1.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            services.filterTable(text);
        }
    }, "Filter services by name");
    vp1.add(menu1);
    vp1.setCellHeight(menu1, "30px");
    vp1.add(sp);
    mainTab.add(vp1);
    mainTab.setCellWidth(vp1, "50%");
    // middle content
    final CustomButton add = new CustomButton("Add", "Add services to package", SmallIcons.INSTANCE.arrowRightIcon());
    add.setImageAlign(true);
    add.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Service> list = services.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                for (int i = 0; i < list.size(); i++) {
                    AddServiceToServicesPackage request;
                    final int ii = i;
                    if (i == list.size() - 1) {
                        request = new AddServiceToServicesPackage(JsonCallbackEvents.disableButtonEvents(add, JsonCallbackEvents.mergeEvents(new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                services.getSelectionModel().setSelected(list.get(ii), false);
                            }
                        }, events2)));
                    } else {
                        request = new AddServiceToServicesPackage(JsonCallbackEvents.disableButtonEvents(add, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                services.getSelectionModel().setSelected(list.get(ii), false);
                            }
                        }));
                    }
                    request.addServiceToServicesPackage(servicePackageId, list.get(i).getId());
                }
            }
        }
    });
    final CustomButton remove = new CustomButton("Remove", "Remove services from package", SmallIcons.INSTANCE.arrowLeftIcon());
    remove.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<Service> list = assignedServices.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                for (int i = 0; i < list.size(); i++) {
                    RemoveServiceFromServicesPackage request;
                    if (i == list.size() - 1) {
                        request = new RemoveServiceFromServicesPackage(JsonCallbackEvents.disableButtonEvents(remove, events2));
                    } else {
                        request = new RemoveServiceFromServicesPackage(JsonCallbackEvents.disableButtonEvents(remove));
                    }
                    request.removeServiceFromServicesPackage(servicePackageId, list.get(i).getId());
                }
            }
        }
    });
    final TabItem tab = this;
    CustomButton close = TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab);
        }
    });
    FlexTable ft = new FlexTable();
    ft.setWidget(0, 0, add);
    ft.setWidget(1, 0, remove);
    ft.setWidget(2, 0, close);
    ft.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
    ft.getFlexCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
    ft.getFlexCellFormatter().setAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
    ft.setWidth("130px");
    ft.setCellSpacing(10);
    mainTab.add(ft);
    mainTab.setCellVerticalAlignment(ft, HasVerticalAlignment.ALIGN_MIDDLE);
    // add styling to table2 with assigned services
    table2.addStyleName("perun-table");
    ScrollPanel sp2 = new ScrollPanel(table2);
    sp2.addStyleName("perun-tableScrollPanel");
    VerticalPanel vp2 = new VerticalPanel();
    vp2.setSize("100%", "100%");
    TabMenu menu2 = new TabMenu();
    menu2.addFilterWidget(new ExtendedSuggestBox(assignedServices.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            assignedServices.filterTable(text);
        }
    }, "Filter services by name");
    vp2.add(menu2);
    vp2.setCellHeight(menu2, "30px");
    vp2.add(sp2);
    mainTab.add(vp2);
    mainTab.setCellWidth(vp2, "50%");
    add.setEnabled(false);
    JsonUtils.addTableManagedButton(services, table, add);
    remove.setEnabled(false);
    JsonUtils.addTableManagedButton(assignedServices, table2, remove);
    session.getUiElements().resizeSmallTabPanel(mainTab, 350, this);
    session.getUiElements().resizePerunTable(sp, 350, this);
    session.getUiElements().resizePerunTable(sp2, 350, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetServicesFromServicesPackage(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesFromServicesPackage) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) RemoveServiceFromServicesPackage(cz.metacentrum.perun.webgui.json.servicesManager.RemoveServiceFromServicesPackage) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) AddServiceToServicesPackage(cz.metacentrum.perun.webgui.json.servicesManager.AddServiceToServicesPackage) Service(cz.metacentrum.perun.webgui.model.Service) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 AddServiceToServicesPackage (cz.metacentrum.perun.webgui.json.servicesManager.AddServiceToServicesPackage)1 GetServices (cz.metacentrum.perun.webgui.json.servicesManager.GetServices)1 GetServicesFromServicesPackage (cz.metacentrum.perun.webgui.json.servicesManager.GetServicesFromServicesPackage)1 RemoveServiceFromServicesPackage (cz.metacentrum.perun.webgui.json.servicesManager.RemoveServiceFromServicesPackage)1 Service (cz.metacentrum.perun.webgui.model.Service)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)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