Search in sources :

Example 1 with BanExecServiceOnFacility

use of cz.metacentrum.perun.webgui.json.generalServiceManager.BanExecServiceOnFacility 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.getSendTask() != null) {
                session.getTabManager().addTab(new TaskResultsTabItem(object.getSendTask()));
            }
        }
    });
    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 !!
                    BanExecServiceOnFacility request = new BanExecServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(blockButton));
                    if (list.get(i).getGenTask() != null)
                        request.banExecService(list.get(i).getGenTask().getExecService().getId());
                    // last event
                    BanExecServiceOnFacility sendRequest = new BanExecServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(blockButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(blockButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getSendTask() != null)
                        sendRequest.banExecService(list.get(i).getSendTask().getExecService().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 !!
                    FreeDenialOfExecServiceOnFacility request = new FreeDenialOfExecServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(allowButton));
                    if (list.get(i).getGenTask() != null)
                        request.freeDenialOfExecService(list.get(i).getGenTask().getExecService().getId());
                    // last event
                    FreeDenialOfExecServiceOnFacility sendRequest = new FreeDenialOfExecServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(allowButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(allowButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getSendTask() != null)
                        sendRequest.freeDenialOfExecService(list.get(i).getSendTask().getExecService().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));
                                if (ss.getGenTask() != null)
                                    deleteTask.deleteTask(ss.getGenTask().getId());
                                deleteTask.setEvents(JsonCallbackEvents.disableButtonEvents(deleteButton, JsonCallbackEvents.refreshTableEvents(callback)));
                                if (ss.getSendTask() != null)
                                    deleteTask.deleteTask(ss.getSendTask().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.generalServiceManager.ForceServicePropagation) GetFacilityServicesState(cz.metacentrum.perun.webgui.json.propagationStatsReader.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.propagationStatsReader.DeleteTask) BanExecServiceOnFacility(cz.metacentrum.perun.webgui.json.generalServiceManager.BanExecServiceOnFacility) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FreeDenialOfExecServiceOnFacility(cz.metacentrum.perun.webgui.json.generalServiceManager.FreeDenialOfExecServiceOnFacility)

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 BanExecServiceOnFacility (cz.metacentrum.perun.webgui.json.generalServiceManager.BanExecServiceOnFacility)1 ForceServicePropagation (cz.metacentrum.perun.webgui.json.generalServiceManager.ForceServicePropagation)1 FreeDenialOfExecServiceOnFacility (cz.metacentrum.perun.webgui.json.generalServiceManager.FreeDenialOfExecServiceOnFacility)1 DeleteTask (cz.metacentrum.perun.webgui.json.propagationStatsReader.DeleteTask)1 GetFacilityServicesState (cz.metacentrum.perun.webgui.json.propagationStatsReader.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