Search in sources :

Example 1 with GetFacilityState

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

the class FacilitiesPropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    final TabItem tab = this;
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    help.setHTML(0, 0, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 0, "100px");
    help.setHTML(0, 1, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 1, "50px");
    help.getFlexCellFormatter().setStyleName(0, 1, "green");
    help.setHTML(0, 2, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 3, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 3, "notdetermined");
    /*
			 help.setHTML(0, 4, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 4, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 4, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.refreshButton(), ButtonTranslation.INSTANCE.refreshPropagationResults(), SmallIcons.INSTANCE.updateIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().reloadTab(tab);
        }
    });
    help.setWidget(0, 5, cb);
    help.getFlexCellFormatter().setWidth(0, 5, "200px");
    help.setHTML(0, 6, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetFacilityState callback = new GetFacilityState(0, 0, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<FacilityState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<FacilityState>().sortByNumberOfDestinations(list);
                ArrayList<FacilityState> clusters = new ArrayList<FacilityState>();
                ArrayList<FacilityState> hosts = new ArrayList<FacilityState>();
                for (final FacilityState state : list) {
                    if (state.getDestinations().size() > 1) {
                        clusters.add(state);
                    } else {
                        hosts.add(state);
                    }
                }
                clusters = new TableSorter<FacilityState>().sortByFacilityName(clusters);
                hosts = new TableSorter<FacilityState>().sortByFacilityName(hosts);
                for (final FacilityState state : clusters) {
                    content.setHTML(mainrow, 0, "<strong>" + SafeHtmlUtils.fromString(state.getFacility().getName()).asString() + "</strong>");
                    final FlowPanel inner = new FlowPanel();
                    content.setWidget(mainrow + 1, 0, inner);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    int width = 0;
                    for (String dest : destinations) {
                        destList.add(dest);
                        if (dest.indexOf(".") * 8 > width) {
                            width = dest.indexOf(".") * 8;
                        }
                    }
                    Collections.sort(destList, new Comparator<String>() {

                        @Override
                        public int compare(String o1, String o2) {
                            return TableSorter.smartCompare(o1, o2);
                        }
                    });
                    for (final String dest : destList) {
                        String show = dest.substring(0, dest.indexOf("."));
                        if (show.length() == 0) {
                            show = dest;
                            width = dest.length() * 8;
                        }
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((show != null) ? show : "").asString() + "</span>");
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        inner.add(hyp);
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        notDeterminedCounter++;
                    }
                    mainrow++;
                    mainrow++;
                }
                // PROCESS HOSTS (with one or less destination)
                // FIX WIDTH
                int width = 0;
                for (FacilityState state : hosts) {
                    if (state.getDestinations().size() < 2) {
                        if (state.getFacility().getName().length() * 8 > width) {
                            width = state.getFacility().getName().length() * 8;
                        }
                    }
                }
                FlowPanel inner = new FlowPanel();
                for (final FacilityState state : hosts) {
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    for (String dest : destinations) {
                        destList.add(dest);
                    }
                    Collections.sort(destList, new Comparator<String>() {

                        @Override
                        public int compare(String o1, String o2) {
                            return TableSorter.smartCompare(o1, o2);
                        }
                    });
                    for (final String dest : destList) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((dest != null) ? dest : "").asString() + "</span>");
                        inner.add(hyp);
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((state.getFacility().getName() != null) ? state.getFacility().getName() : "").asString() + "</span>");
                        inner.add(hyp);
                        hyp.addStyleName("notdetermined");
                        notDeterminedCounter++;
                    }
                }
                if (!hosts.isEmpty()) {
                    content.setHTML(mainrow, 0, "<strong>Single hosts</strong>");
                    mainrow++;
                }
                content.setWidget(mainrow, 0, inner);
                content.getFlexCellFormatter().setStyleName(mainrow, 0, "propagationTablePadding");
                mainrow++;
            }
            // set counters
            help.setHTML(0, 1, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 2, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        // help.setHTML(0, 4, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Set(java.util.Set) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) GetFacilityState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState) FacilityState(cz.metacentrum.perun.webgui.model.FacilityState) Comparator(java.util.Comparator) GetFacilityState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) JSONString(com.google.gwt.json.client.JSONString) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 2 with GetFacilityState

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

the class PropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    final TabItem tab = this;
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    help.setHTML(0, 0, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 0, "100px");
    help.setHTML(0, 1, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 1, "50px");
    help.getFlexCellFormatter().setStyleName(0, 1, "green");
    help.setHTML(0, 2, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 3, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 3, "notdetermined");
    /*
			 help.setHTML(0, 4, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 4, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 4, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.refreshButton(), ButtonTranslation.INSTANCE.refreshPropagationResults(), SmallIcons.INSTANCE.updateIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().reloadTab(tab);
        }
    });
    help.setWidget(0, 5, cb);
    help.getFlexCellFormatter().setWidth(0, 5, "200px");
    help.setHTML(0, 6, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetFacilityState callback = new GetFacilityState(0, 0, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<FacilityState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<FacilityState>().sortByNumberOfDestinations(list);
                ArrayList<FacilityState> clusters = new ArrayList<FacilityState>();
                ArrayList<FacilityState> hosts = new ArrayList<FacilityState>();
                for (final FacilityState state : list) {
                    if (state.getDestinations().size() > 1) {
                        clusters.add(state);
                    } else {
                        hosts.add(state);
                    }
                }
                clusters = new TableSorter<FacilityState>().sortByFacilityName(clusters);
                hosts = new TableSorter<FacilityState>().sortByFacilityName(hosts);
                for (final FacilityState state : clusters) {
                    content.setHTML(mainrow, 0, "<strong>" + SafeHtmlUtils.fromString((state.getFacility().getName() != null) ? state.getFacility().getName() : "").asString() + "</strong>");
                    final FlowPanel inner = new FlowPanel();
                    content.setWidget(mainrow + 1, 0, inner);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    int width = 0;
                    for (String dest : destinations) {
                        destList.add(dest);
                        if (dest.indexOf(".") * 8 > width) {
                            width = dest.indexOf(".") * 8;
                        }
                    }
                    Collections.sort(destList, new Comparator<String>() {

                        @Override
                        public int compare(String o1, String o2) {
                            return TableSorter.smartCompare(o1, o2);
                        }
                    });
                    for (final String dest : destList) {
                        String show = SafeHtmlUtils.fromString(dest.substring(0, dest.indexOf("."))).asString();
                        if (show.length() == 0) {
                            show = dest;
                            width = dest.length() * 8;
                        }
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + show + "</span>");
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, true));
                            }
                        });
                        inner.add(hyp);
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        notDeterminedCounter++;
                    }
                    mainrow++;
                    mainrow++;
                }
                // PROCESS HOSTS (with one or less destination)
                // FIX WIDTH
                int width = 0;
                for (FacilityState state : hosts) {
                    if (state.getDestinations().size() < 2) {
                        if (state.getFacility().getName().length() * 8 > width) {
                            width = state.getFacility().getName().length() * 8;
                        }
                    }
                }
                FlowPanel inner = new FlowPanel();
                for (final FacilityState state : hosts) {
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    for (String dest : destinations) {
                        destList.add(dest);
                    }
                    Collections.sort(destList, new Comparator<String>() {

                        @Override
                        public int compare(String o1, String o2) {
                            return TableSorter.smartCompare(o1, o2);
                        }
                    });
                    for (final String dest : destList) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((dest != null) ? dest : "").asString() + "</span>");
                        inner.add(hyp);
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, true));
                            }
                        });
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((state.getFacility().getName() != null) ? state.getFacility().getName() : "").asString() + "</span>");
                        inner.add(hyp);
                        hyp.addStyleName("notdetermined");
                        notDeterminedCounter++;
                    }
                }
                if (!hosts.isEmpty()) {
                    content.setHTML(mainrow, 0, "<strong>Single hosts</strong>");
                    mainrow++;
                }
                content.setWidget(mainrow, 0, inner);
                content.getFlexCellFormatter().setStyleName(mainrow, 0, "propagationTablePadding");
                mainrow++;
            }
            // set counters
            help.setHTML(0, 1, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 2, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        // help.setHTML(0, 4, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities for VO
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Set(java.util.Set) DestinationResultsTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.DestinationResultsTabItem) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) GetFacilityState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState) FacilityState(cz.metacentrum.perun.webgui.model.FacilityState) Comparator(java.util.Comparator) GetFacilityState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) JSONString(com.google.gwt.json.client.JSONString) DestinationResultsTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.DestinationResultsTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JSONString (com.google.gwt.json.client.JSONString)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 GetFacilityState (cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState)2 FacilityState (cz.metacentrum.perun.webgui.model.FacilityState)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 Set (java.util.Set)2 DestinationResultsTabItem (cz.metacentrum.perun.webgui.tabs.facilitiestabs.DestinationResultsTabItem)1