Search in sources :

Example 1 with GetFacilityServicesState

use of cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityServicesState in project perun by CESNET.

the class FacilityStatusTabItem method draw.

public Widget draw() {
    // title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Services status");
    // main content
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // get empty table
    final GetFacilityServicesState callback = new GetFacilityServicesState(facility.getId());
    CustomButton refreshButton = UiElements.getRefreshButton(this);
    // callback.setEvents(JsonCallbackEvents.disableButtonEvents(refreshButton));
    final CellTable<ServiceState> table = callback.getTable(new FieldUpdater<ServiceState, String>() {

        // on row click
        public void update(int index, final ServiceState object, String value) {
            // show results if any present
            if (object.getTask() != null) {
                session.getTabManager().addTab(new TaskResultsTabItem(object.getTask()));
            }
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    final CustomButton forceButton = new CustomButton(ButtonTranslation.INSTANCE.forcePropagationButton(), ButtonTranslation.INSTANCE.forcePropagation(), SmallIcons.INSTANCE.arrowRightIcon());
    forceButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> forceList = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(forceList)) {
                // TODO - translated Widget
                boolean denied = false;
                VerticalPanel vp = new VerticalPanel();
                vp.add(new HTML("<p>Some services can't be forcefully propagated, because they are <strong>blocked on facility</strong>. Please change their state to 'Allowed' before starting force propagation.</p>"));
                for (int i = 0; i < forceList.size(); i++) {
                    if (forceList.get(i).isBlockedOnFacility() || forceList.get(i).isBlockedGlobally()) {
                        vp.add(new Label(" - " + forceList.get(i).getService().getName()));
                        denied = true;
                    }
                }
                if (denied) {
                    // show conf
                    Confirm c = new Confirm("Can't propagated blocked services", vp, true);
                    c.show();
                    return;
                }
            }
            // show propagation status page on last call start
            JsonCallbackEvents events = new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // unselect all services
                    for (ServiceState service : forceList) {
                        callback.getSelectionModel().setSelected(service, false);
                    }
                }
            };
            // starts propagation for all selected services
            for (int i = 0; i < forceList.size(); i++) {
                if (i != forceList.size() - 1) {
                    // force propagation
                    ForceServicePropagation request = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(forceButton));
                    request.forcePropagation(facility.getId(), forceList.get(i).getService().getId());
                } else {
                    // force propagation with show status page
                    ForceServicePropagation request = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(forceButton, events));
                    request.forcePropagation(facility.getId(), forceList.get(i).getService().getId());
                }
            }
        }
    });
    final CustomButton blockButton = new CustomButton(ButtonTranslation.INSTANCE.blockPropagationButton(), ButtonTranslation.INSTANCE.blockServicesOnFacility(), SmallIcons.INSTANCE.stopIcon());
    final CustomButton allowButton = new CustomButton(ButtonTranslation.INSTANCE.allowPropagationButton(), ButtonTranslation.INSTANCE.allowServicesOnFacility(), SmallIcons.INSTANCE.acceptIcon());
    final CustomButton deleteButton = new CustomButton(ButtonTranslation.INSTANCE.deleteButton(), ButtonTranslation.INSTANCE.deleteTasks(), SmallIcons.INSTANCE.deleteIcon());
    blockButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    BlockServiceOnFacility sendRequest = new BlockServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(blockButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(blockButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getTask() != null)
                        sendRequest.blockService(list.get(i).getTask().getService().getId());
                }
            }
        }
    });
    allowButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    UnblockServiceOnFacility sendRequest = new UnblockServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(allowButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(allowButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getTask() != null)
                        sendRequest.unblockService(list.get(i).getTask().getService().getId());
                }
            }
        }
    });
    TabMenu menu = new TabMenu();
    menu.addWidget(refreshButton);
    menu.addWidget(forceButton);
    menu.addWidget(allowButton);
    menu.addWidget(blockButton);
    if (session.isPerunAdmin()) {
        menu.addWidget(deleteButton);
        deleteButton.setEnabled(false);
        JsonUtils.addTableManagedButton(callback, table, deleteButton);
        deleteButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                final ArrayList<ServiceState> list = callback.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(list)) {
                    UiElements.generateAlert("", "This action will also delete all propagation results. <p>If service is still assigned to any resource, it will be listed in a table.", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            for (ServiceState ss : list) {
                                DeleteTask deleteTask = new DeleteTask(JsonCallbackEvents.disableButtonEvents(deleteButton));
                                deleteTask.setEvents(JsonCallbackEvents.disableButtonEvents(deleteButton, JsonCallbackEvents.refreshTableEvents(callback)));
                                if (ss.getTask() != null)
                                    deleteTask.deleteTask(ss.getTask().getId());
                            }
                        }
                    });
                }
            }
        });
    }
    forceButton.setEnabled(false);
    allowButton.setEnabled(false);
    blockButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, forceButton);
    JsonUtils.addTableManagedButton(callback, table, allowButton);
    JsonUtils.addTableManagedButton(callback, table, blockButton);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ForceServicePropagation(cz.metacentrum.perun.webgui.json.servicesManager.ForceServicePropagation) GetFacilityServicesState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityServicesState) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) DeleteTask(cz.metacentrum.perun.webgui.json.tasksManager.DeleteTask) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) UnblockServiceOnFacility(cz.metacentrum.perun.webgui.json.servicesManager.UnblockServiceOnFacility) BlockServiceOnFacility(cz.metacentrum.perun.webgui.json.servicesManager.BlockServiceOnFacility)

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 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 BlockServiceOnFacility (cz.metacentrum.perun.webgui.json.servicesManager.BlockServiceOnFacility)1 ForceServicePropagation (cz.metacentrum.perun.webgui.json.servicesManager.ForceServicePropagation)1 UnblockServiceOnFacility (cz.metacentrum.perun.webgui.json.servicesManager.UnblockServiceOnFacility)1 DeleteTask (cz.metacentrum.perun.webgui.json.tasksManager.DeleteTask)1 GetFacilityServicesState (cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityServicesState)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1