com.clustercontrol.collect.composite.CollectGraphComposite.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.collect.composite.CollectGraphComposite.java

Source

/*
    
Copyright (C) 2006 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

package com.clustercontrol.collect.composite;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import com.clustercontrol.ClusterControlPlugin;
import com.clustercontrol.bean.Property;
import com.clustercontrol.collect.bean.SummaryTypeConstant;
import com.clustercontrol.collect.bean.SummaryTypeMessage;
import com.clustercontrol.collect.preference.PerformancePreferencePage;
import com.clustercontrol.collect.util.CollectGraphUtil;
import com.clustercontrol.collect.view.CollectGraphView;
import com.clustercontrol.monitor.action.CommentEvent;
import com.clustercontrol.monitor.action.GetEventListTableDefine;
import com.clustercontrol.monitor.dialog.EventInfoDialog;
import com.clustercontrol.monitor.view.action.MonitorModifyAction;
import com.clustercontrol.util.EndpointManager;
import com.clustercontrol.util.EndpointUnit;
import com.clustercontrol.util.HinemosMessage;
import com.clustercontrol.util.HtmlLoaderUtil;
import com.clustercontrol.util.Messages;
import com.clustercontrol.util.TimezoneUtil;
import com.clustercontrol.ws.collect.CollectKeyInfoPK;
import com.clustercontrol.ws.collect.HinemosUnknown_Exception;
import com.clustercontrol.ws.collect.InvalidRole_Exception;
import com.clustercontrol.ws.collect.InvalidUserPass_Exception;
import com.clustercontrol.ws.monitor.MonitorNumericValueInfo;
import com.clustercontrol.ws.repository.FacilityTreeItem;

/**
 * ??<BR>
 *
 * @version 5.0.0
 * @since 4.0.0
 */
public class CollectGraphComposite extends Composite {
    private static Log m_log = LogFactory.getLog(CollectGraphComposite.class);

    private Label settingLabel = null;

    /**
     * 
     */
    private Browser m_browserGraph;

    /**
     * 
     */
    private Browser m_browserSlider;

    /**
     * 
     */
    private CollectGraphView m_collectGraphView;

    /**
     * Browser??(true????????????true???????)
     */
    private boolean completed = false;
    private boolean slider_completed = false;

    /**
     * javascript??
     */
    private static final String CONTROL_CLASS_NAME_PIE = "ControlPiegraph";
    /**
     * javascript??
     */
    private static final String CONTROL_CLASS_NAME_SCATTER = "ControlScattergraph";
    /**
     * ????javascript??
     */
    private static final String CONTROL_CLASS_NAME_LINESTACK = "ControlGraph";
    /**
     * javascript??
     */
    private static final String CONTROL_CLASS_NAME_BARSTACK = "ControlBarGraph";
    /**
     * javascript??
     */
    private static final String GRAPH_CLASS_NAME_PIE = "Piegraph";
    /**
     * javascript??
     */
    private static final String GRAPH_CLASS_NAME_SCATTER = "Scattergraph";
    /**
     * ????javascript??
     */
    private static final String GRAPH_CLASS_NAME_LINESTACK = "NewGraph";
    /**
     * javascript??
     */
    private static final String GRAPH_CLASS_NAME_BARSTACK = "StackBarGraph";

    // javascript -> java????
    private static final String CALL_METHOD_NAME_NOTICEGRAPHZOOM = "noticeGraphZoom";
    private static final String CALL_METHOD_NAME_MOUSEUP = "mouseup";
    private static final String CALL_METHOD_NAME_BRUSHEND = "brushend";
    private static final String CALL_METHOD_NAME_NOTICESLIDERTYPE = "noticeSliderType";
    private static final String CALL_METHOD_NAME_NOTICESLIDER_BRUSHEND = "noticeSlider_brushend";
    private static final String CALL_METHOD_NAME_INPUTDATE = "inputdate";
    private static final String CALL_METHOD_NAME_AUTOZOOMGRAPH = "autoZoomGraph";
    private static final String CALL_METHOD_NAME_AUTODRAW = "autodraw";
    private static final String CALL_METHOD_NAME_CHANGETHRESHOLD = "changeThreshold";
    private static final String CALL_METHOD_NAME_OPEN_EVENT_DETAIL = "open_event_detail";
    private static final String CALL_METHOD_NAME_JAVASCRIPT_ERROR = "javascript_error";

    /** ID? */
    private static final String SUFFIX_PLUGIN_ID_NUM = "_N";

    private final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss.SSS";

    private String lastScript = "";

    /**
     * 
     *
     * @param settings ?
     * @param parent ??
     * @param style 
     */
    public CollectGraphComposite(Composite parent, int style, CollectGraphView collectGraphView) {
        super(parent, style);
        // ?
        initialize();
        m_collectGraphView = collectGraphView;

        // settingLabel
        settingLabel = new Label(this, SWT.LEFT | SWT.WRAP);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        settingLabel.setLayoutData(gridData);
        setSettingLabel(-1, new ArrayList<CollectKeyInfoPK>());

        try {
            m_browserSlider = new Browser(this, SWT.NONE);
            m_browserGraph = new Browser(this, SWT.NONE);

            gridData = new GridData();
            gridData.horizontalAlignment = GridData.FILL;
            gridData.verticalAlignment = GridData.FILL;
            gridData.minimumHeight = 100;
            gridData.heightHint = 100;
            m_browserSlider.setLayoutData(gridData);

            GridData gridData1;
            gridData1 = new GridData();
            gridData1.horizontalAlignment = GridData.FILL;
            gridData1.verticalAlignment = GridData.FILL;
            gridData1.grabExcessHorizontalSpace = true;
            gridData1.grabExcessVerticalSpace = true;
            m_browserGraph.setLayoutData(gridData1);

            loadBrowser();
            m_log.warn("set URL");

        } catch (Exception e) {
            m_log.warn("CollectGraphComposite : " + e.getMessage(), e);
            throw new RuntimeException(e);
        }

        this.addControlListener(new ControlListener() {

            @Override
            public void controlResized(ControlEvent e) {
                // nop
            }

            @Override
            public void controlMoved(ControlEvent e) {
                // ??????????
                Point point = CollectGraphComposite.this.getSize();
                m_log.debug("resize x:" + point.x + ", y:" + point.y);
                CollectGraphUtil.setM_screenWidth(point.x);
            }
        });
    }

    private void loadBrowser() {
        HtmlLoaderUtil.load(m_browserGraph, "graph.html", "com/clustercontrol/collect/composite/");
        m_browserGraph.addProgressListener(new ProgressListener() {
            public void completed(ProgressEvent event) {
                // ?????javascript?
                completed = true;
                new CustomFunction(m_browserGraph, "theJavaFunction");
                m_log.debug("graph completed!!!!!");
                m_collectGraphView.setItemCodeCheckedTreeItems();
            }

            public void changed(ProgressEvent event) {
            }
        });

        HtmlLoaderUtil.load(m_browserSlider, "slider.html", "com/clustercontrol/collect/composite/");
        m_browserSlider.addProgressListener(new ProgressListener() {
            public void completed(ProgressEvent event) {
                // ?????javascript?
                slider_completed = true;
                new CustomFunction(m_browserSlider, "theJavaFunction");
                m_log.debug("slider completed!!!!!");
            }

            public void changed(ProgressEvent event) {
            }
        });
    }

    class CustomFunction extends BrowserFunction {

        /**
         * 
         * @param browser
         * @param name
         */
        public CustomFunction(Browser browser, String name) {
            super(browser, name);
        }

        /**
         * javascript??<br>
         * <br>
         * ?????<br>
         * <br>
         *   ??????(noticeGraphZoom)<br>
         *     -> ?????????????<br>
         * <br>
         *   ??????(??)(mouseup)<br>
         *     -> ?????????????<br>
         * <br>
         *   ??????(brushend)<br>
         *     -> ?????????????<br>
         * <br>
         *   ?(10years, year, month, week, day)?????(noticeSliderType)<br>
         *     -> ??????????????<br>
         * <br>
         *   ?(10years, year, month, week, day)??????????(noticeSlider_brushend)<br>
         *     -> ???????????????????????????<br>
         * <br>
         *   ????????(inputdate)<br>
         *     -> ????????????????????<br>
         * <br>
         *   ???????(autoZoomGraph)<br>
         *     -> ?????(javascript???????????????Java????)<br>
         * <br>
         *   ???????(autodraw)<br>
         *     -> ????<br>
         * <br>
         *   ????(changeThreshold)<br>
         *     -> ?????????<br>
         * <br>
         *   ?????(open_event_detail)<br>
         *     -> ?????<br>
         * <br>
         *   javascript?????(javascript_error)<br>
         *     -> ???<br>
         */
        @Override
        public Object function(Object[] arguments) {
            Object retObj = null;
            try {
                retObj = executeFromJavascript(arguments);
            } catch (InvalidRole_Exception e) {
                m_log.error("function InvalidRole_Exception");
                MessageDialog.openInformation(null, Messages.getString("message"),
                        Messages.getString("message.accesscontrol.16"));
            } catch (InvalidUserPass_Exception e) {
                m_log.error("function InvalidUserPass_Exception");
                MessageDialog.openInformation(null, Messages.getString("message"),
                        Messages.getString("message.accesscontrol.45"));
            } catch (Exception e) {
                m_log.error("???? message=" + e.getMessage(), e);
                MessageDialog.openError(null, Messages.getString("error"),
                        Messages.getString("message.collection.graph.unexpected.error") + " : " + e.getMessage());
            }
            return retObj;
        }

        private Object executeFromJavascript(Object[] arguments)
                throws InvalidUserPass_Exception, HinemosUnknown_Exception, InvalidRole_Exception {
            SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
            dateFormat.setTimeZone(TimezoneUtil.getTimeZone());

            String ret = (String) arguments[0];
            m_log.debug("wow!called from javascript!" + ret);
            m_log.info("javascript call:" + ret);

            // json???<key, value>??
            ret = ret.replaceAll("\\{", "").replaceAll("\\}", "").replaceAll("\"", "");
            String rets[] = ret.split(",");
            HashMap<String, String> scriptMap = new HashMap<String, String>();
            for (String ret1 : rets) {
                String ret1s[] = ret1.split(":");
                if (ret1s.length == 2 && ret1s[0] != null && !ret1s[0].equals("") && ret1s[1] != null
                        && !ret1s[1].equals("")) {
                    scriptMap.put(ret1s[0], ret1s[1]);
                }
            }

            String methodName = scriptMap.get("method_name");

            // javascript???????????
            if (methodName.equals(CALL_METHOD_NAME_JAVASCRIPT_ERROR)) {
                m_log.error("executeFromJavascript() ERROR:" + ret);
                m_log.error("execScript:" + lastScript);
                if (lastScript.length() > 2000) {
                    lastScript = lastScript.substring(0, 2000) + "...";
                }
                MessageDialog.openInformation(null, Messages.getString("error"),
                        Messages.getString("message.collection.graph.unexpected.error") + "\n" + ret + "\n\n"
                                + lastScript);

                return null;
            }

            // javascript??????
            if (methodName.equals(CALL_METHOD_NAME_AUTOZOOMGRAPH)) {
                // ?????????
                // javascript????????????????????Java??????
                return CollectGraphUtil.getM_screenWidth();
            } else if (methodName.equals(CALL_METHOD_NAME_NOTICESLIDERTYPE)
                    || methodName.equals(CALL_METHOD_NAME_NOTICESLIDER_BRUSHEND)) {
                // ?(10year,year,month,week,day)????????
                // ????()???????
                CollectGraphUtil.setSliderStart(parseString2Long(scriptMap.get("start_date")));
                CollectGraphUtil.setSliderEnd(parseString2Long(scriptMap.get("end_date")));
                m_log.debug("function() noticeSliderType call term:"
                        + (CollectGraphUtil.getSliderEnd() - CollectGraphUtil.getSliderStart()));
                if (methodName.equals(CALL_METHOD_NAME_NOTICESLIDERTYPE)) {
                    return null;
                }
            } else if (methodName.equals(CALL_METHOD_NAME_NOTICEGRAPHZOOM)) {
                // ?????????
                // ????????
                CollectGraphUtil.setGraphZoomSize(scriptMap.get("graphZoomSize"));
                m_log.debug("function() noticeGraphZoom call zoomSize:" + CollectGraphUtil.getGraphZoomSize());
                return null;

            } else if (methodName.equals(CALL_METHOD_NAME_CHANGETHRESHOLD)) {
                // ??????
                // ?
                // EventModifyMonitorSettingAction?

                String infoMaxValue = scriptMap.get("info_max");
                String infoMinValue = scriptMap.get("info_min");
                String warnMaxValue = scriptMap.get("warn_max");
                String warnMinValue = scriptMap.get("warn_min");
                String itemName = scriptMap.get("itemname");
                String monitorId = scriptMap.get("monitorid");
                String managerName = scriptMap.get("managername");
                String pluginId = scriptMap.get("pluginid");

                // ???
                List<MonitorNumericValueInfo> numericValueInfo = CollectGraphUtil
                        .createMonitorNumericValueInfoList(infoMinValue, infoMaxValue, warnMinValue, warnMaxValue);
                MonitorModifyAction mmAction = new MonitorModifyAction();
                if (pluginId.endsWith(SUFFIX_PLUGIN_ID_NUM)) {
                    // ??????
                    mmAction.setGraphMonitorNumericValueInfo(numericValueInfo);
                }
                // ???????????
                if (mmAction.dialogOpen(m_collectGraphView.getSite().getShell(), managerName, pluginId,
                        monitorId) == IDialogConstants.OK_ID) {
                    // ???????????
                    String threshold = CollectGraphUtil.getThresholdData(managerName, monitorId);
                    if (threshold != null) {
                        infoMinValue = threshold.split(",")[0];
                        infoMaxValue = threshold.split(",")[1];
                        warnMinValue = threshold.split(",")[2];
                        warnMaxValue = threshold.split(",")[3];
                    }

                    String param = "ThresholdGraph.prototype.setThresholdParamMonitorId({" + "\'itemname\':\""
                            + itemName + "\", " + "\'monitorid\':\"" + monitorId + "\", " + "\'info_max\':"
                            + infoMaxValue + ", " + "\'info_min\':" + infoMinValue + ", " + "\'warn_max\':"
                            + warnMaxValue + ", " + "\'warn_min\':" + warnMinValue + "});";
                    executeScript(param, m_browserGraph);
                }
                return true;

            } else if (methodName.equals(CALL_METHOD_NAME_OPEN_EVENT_DETAIL)) {
                // ???????
                // ??
                // EventDetailAction?
                String managerName = scriptMap.get("managername");
                String facilityId = scriptMap.get("facilityid");
                Long date = Long.valueOf(scriptMap.get("datelong"));
                String pluginId = scriptMap.get("pluginid");
                String monitorDetailId = scriptMap.get("monitordetailid");
                if (monitorDetailId == null) {
                    // monitordetailid = displayname???????????
                    monitorDetailId = "";
                }
                String monitorId = scriptMap.get("monitorid");
                m_log.debug("open_event_detail managerName:" + managerName + ", facilityid:" + facilityId
                        + ", date:" + date + ", pluginid:" + pluginId + ", monitordetailid:" + monitorDetailId
                        + ", monitorid:" + monitorId);
                List<Object> list = new ArrayList<>();
                list.add(GetEventListTableDefine.MANAGER_NAME, managerName);
                list.add(1, "");
                list.add(GetEventListTableDefine.RECEIVE_TIME, new Date(date));
                list.add(3, "");
                list.add(GetEventListTableDefine.PLUGIN_ID, pluginId);
                list.add(GetEventListTableDefine.MONITOR_ID, monitorId);
                list.add(GetEventListTableDefine.MONITOR_DETAIL_ID, monitorDetailId);
                list.add(GetEventListTableDefine.FACILITY_ID, facilityId);

                EventInfoDialog dialog = new EventInfoDialog(m_collectGraphView.getSite().getShell(), list);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    Property prop = dialog.getInputData();
                    CommentEvent comment = new CommentEvent();
                    comment.updateComment(managerName, prop);
                }
                return null;
            }
            // autoZoomGraph noticeSliderType noticeGraphZoom changeThreshold openEventDetail????return
            // ???
            // brushend mouseup autodraw inputdate

            if (!scriptMap.containsKey("xaxis_min") || !scriptMap.containsKey("xaxis_max")) {
                m_log.info("xaxis_min or xaxis_max or id not define. FINISH.");
                return null;
            }
            Long xaxis_min = parseString2Long(scriptMap.get("xaxis_min"));
            Long xaxis_max = parseString2Long(scriptMap.get("xaxis_max"));

            m_log.info("?xaxis_min=" + new Date(xaxis_min).toString() + ", xaxis_max="
                    + new Date(xaxis_max).toString());
            m_log.info("?(DB??)select_start="
                    + new Date(CollectGraphUtil.getTargetConditionStartDate()).toString() + ", select_end="
                    + new Date(CollectGraphUtil.getTargetConditionEndDate()).toString());
            m_log.debug("plot start(now) :" + dateFormat.format(new Date()));

            // ???1???raw???????ave_hour??
            long date_diff = xaxis_max - xaxis_min;
            if (date_diff > CollectGraphUtil.MILLISECOND_DAY
                    && CollectGraphUtil.getSummaryType() == SummaryTypeConstant.TYPE_RAW) {
                m_log.info("raw?1????avg(hour)????");
                CollectGraphUtil.setSummaryType(SummaryTypeConstant.TYPE_AVG_HOUR);
                // ComboBox?
                m_collectGraphView.getCollectSettingComposite()
                        .setSummaryTypeComboBox(SummaryTypeConstant.TYPE_AVG_HOUR);
                // label?
                setSettingLabel(SummaryTypeConstant.TYPE_AVG_HOUR, CollectGraphUtil.getM_collectKeyInfoList());

                // ?RAW????avg_hour????????????plot?
                deletePlots(CALL_METHOD_NAME_BRUSHEND, xaxis_min, xaxis_max, true);
                CollectGraphUtil.setTargetConditionStartDate(Long.MAX_VALUE);
                CollectGraphUtil.setTargetConditionEndDate(0L);
            }

            if (methodName.equals(CALL_METHOD_NAME_MOUSEUP)) {
                // ???
                // inputdate???javascript?????????????
                String script = "BrushLine.prototype.moveTarget(" + xaxis_min + ", " + xaxis_max + ");";
                executeScript(script, m_browserSlider);

            }
            if (methodName.equals(CALL_METHOD_NAME_BRUSHEND) || methodName.equals(CALL_METHOD_NAME_INPUTDATE)
                    || methodName.equals(CALL_METHOD_NAME_NOTICESLIDER_BRUSHEND)) {
                // ?????(x??)?
                String script = getHeadControlClassName() + ".trimXAxis(" + xaxis_min + ", " + xaxis_max
                        + ", null);";
                executeScript(script, m_browserGraph);

            }
            if (methodName.equals(CALL_METHOD_NAME_AUTODRAW)) {
                // ???????????
                long term = xaxis_max - xaxis_min;
                xaxis_max = new Date().getTime();
                xaxis_min = xaxis_max - term;
                m_log.debug("autodraw -> xaxis_min:" + new Date(xaxis_min).toString() + ", xaxis_max:"
                        + new Date(xaxis_max).toString() + ", term:" + term);
                // ???
                String script = "BrushLine.prototype.moveTarget(" + xaxis_min + ", " + xaxis_max + ");";
                executeScript(script, m_browserSlider);
                // ?????(x??)?
                script = getHeadControlClassName() + ".trimXAxis(" + (xaxis_min) + ", " + (xaxis_max) + ", null);";
                executeScript(script, m_browserGraph);
            }

            // targetstart:??????x?targetend:?????x???<=?
            // ????????(min < targetstart && max < targetend)
            // ???????(min > targetstart && max > targetend, targetend < now)
            // ?????(min < targetstart && max > targetend, targetend < now)
            // ???????(min > targetend || max < targetstart)

            long conditionStart = xaxis_min;
            long conditionEnd = xaxis_max;
            // methodname?autodraw?????DB??????
            if (CollectGraphUtil.getTargetConditionStartDate() <= xaxis_min
                    && xaxis_max <= CollectGraphUtil.getTargetConditionEndDate()) {
                // ?????????????????????
                // ?if??hit???????
                m_log.debug("become small. delete invisible area. method_name:" + methodName);
            }

            // ?DB??????????????????????

            // ???
            deletePlots(methodName, xaxis_min, xaxis_max, false);

            // ?
            Long nowDate = System.currentTimeMillis();
            // DB??????(??????)
            long dbEndDate = xaxis_max;

            // ???????(??)
            if (xaxis_max <= CollectGraphUtil.getTargetConditionStartDate()) {
                m_log.debug("GET ALL side:startdate");
                addGraphPlot(xaxis_min, xaxis_max, xaxis_min, xaxis_max);
                if (xaxis_max > nowDate) {
                    dbEndDate = nowDate;
                }
                conditionStart = xaxis_min;
                conditionEnd = dbEndDate;
            }
            // ???????(?)
            if (xaxis_min >= CollectGraphUtil.getTargetConditionEndDate()) {
                m_log.debug("GET ALL side:enddate");
                if (xaxis_min > nowDate) {
                    // ?????????????????
                    m_log.debug("startdate is future. finish.");
                    // ??????????
                    conditionStart = CollectGraphUtil.getTargetConditionEndDate();
                    conditionEnd = CollectGraphUtil.getTargetConditionEndDate();
                } else {
                    addGraphPlot(xaxis_min, xaxis_max, xaxis_min, xaxis_max);
                    if (xaxis_max > nowDate) {
                        dbEndDate = nowDate;
                        m_log.debug("xaxis_max is :" + xaxis_max);
                    }
                    conditionStart = xaxis_min;
                    conditionEnd = xaxis_max;
                }
            }

            // ??????
            if (xaxis_min <= CollectGraphUtil.getTargetConditionStartDate()
                    && xaxis_max >= CollectGraphUtil.getTargetConditionStartDate()) {
                m_log.debug("GET FRONT");
                addGraphPlot(xaxis_min, CollectGraphUtil.getTargetConditionStartDate(), xaxis_min, xaxis_max);
                // ????????
                conditionStart = xaxis_min;
                conditionEnd = xaxis_max;
            }

            // ?????
            if (xaxis_max >= CollectGraphUtil.getTargetConditionEndDate()
                    && xaxis_min <= CollectGraphUtil.getTargetConditionEndDate()) {
                m_log.debug("GET BACK");
                addGraphPlot(CollectGraphUtil.getTargetConditionEndDate(), xaxis_max, xaxis_min, xaxis_max);
                if (xaxis_max > nowDate) {
                    dbEndDate = nowDate;
                    m_log.debug("xaxis_max is now.:" + xaxis_max);
                }
                conditionStart = xaxis_min;
                conditionEnd = dbEndDate;
            }

            // ?(???????????)

            CollectGraphUtil.setTargetConditionStartDate(conditionStart);
            CollectGraphUtil.setTargetConditionEndDate(conditionEnd);

            // y?????
            String yaxisParam = getHeadControlClassName() + ".trimBranch();";
            executeScript(yaxisParam, m_browserGraph);

            m_log.info(
                    "targetStartDate:" + dateFormat.format(new Date(CollectGraphUtil.getTargetConditionStartDate()))
                            + ", targetEndDate:"
                            + dateFormat.format(new Date(CollectGraphUtil.getTargetConditionEndDate())));
            m_log.info("addPoint end:" + dateFormat.format(new Date()));
            return true;
        }

        /**
         * ????????<br>
         * javascript??[brushend][autodraw][inputdate][noticeSlider_brushend]???????????????<br>
         * (javascript??[mouseup]????javascript??????)<br>
         * startdate?enddate????javascript??????<br>
         * 
         * @param methodName ?????????method_name
         * @param startdate ???(startdate?)
         * @param enddate ??(enddate?)
         * @param allDel ??????(raw?avg(hour)???????????????)
         */
        private void deletePlots(String methodName, Long startdate, Long enddate, boolean allDel) {
            if (methodName.equals(CALL_METHOD_NAME_BRUSHEND) || methodName.equals(CALL_METHOD_NAME_AUTODRAW)
                    || methodName.equals(CALL_METHOD_NAME_INPUTDATE)
                    || methodName.equals(CALL_METHOD_NAME_NOTICESLIDER_BRUSHEND)) {
                String script = getHeadGraphClassName() + ".prototype.removePoints(" + startdate + ", " + enddate
                        + ", " + allDel + ");";
                if (CollectGraphUtil.getStackFlg()) {
                    script = getHeadGraphClassName() + ".prototype.removeStack(" + startdate + ", " + enddate
                            + ");";
                }
                executeScript(script, m_browserGraph);
            }
        }

        /**
         * ???long????<br>
         * ??(String)????????<br>
         * NumberFormatException?????????
         * @param value
         * @return
         */
        private long parseString2Long(String value) {
            Double d_value = Double.valueOf(value);
            Long l_value = d_value.longValue();
            return l_value;
        }
    }

    /**
     * ??????
     * 
     * @param startDate DB????
     * @param endDate DB????
     * @param selectStartDate ?
     * @param selectEndDate ?
     * @throws InvalidRole_Exception 
     * @throws HinemosUnknown_Exception 
     * @throws InvalidUserPass_Exception 
     */
    private void addGraphPlot(Long startDate, Long endDate, Long selectStartDate, Long selectEndDate)
            throws InvalidUserPass_Exception, HinemosUnknown_Exception, InvalidRole_Exception {
        m_log.debug("addGraphPlot() start");
        StringBuffer sb = CollectGraphUtil.getAddGraphPlotJson(startDate, endDate, selectStartDate, selectEndDate);

        if (sb == null) {
            m_log.debug("addGraphPlot() add plot data 0.");
            return;
        }
        String addparam = getHeadControlClassName() + ".addPlotAtOnce(" + sb.toString() + ");";
        long start = System.currentTimeMillis();
        m_log.debug("addGraphPlot() ControlGraph.addPlotAtOnce start");
        executeScript(addparam, m_browserGraph);
        m_log.debug("addGraphPlot() ControlGraph.addPlotAtOnce end time:" + (System.currentTimeMillis() - start)
                + "ms");
    }

    /**
     * ?????
     *
     * @param parent
     * @param style
     */
    private void initialize() {
        GridLayout layout = new GridLayout();
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        layout.horizontalSpacing = 0;
        layout.verticalSpacing = 0;
        this.setLayout(layout);

        // ??????
        CollectGraphUtil.init(false, false, new ArrayList<CollectKeyInfoPK>(), false, false, false, "");
    }

    /**
     * ???????????
     * 
     * @param summaryType
     * @param itemCodeList
     */
    private void setSettingLabel(int summaryType, List<CollectKeyInfoPK> itemCodeList) {
        ArrayList<String> itemCodeNameList = new ArrayList<>();
        for (EndpointUnit unit : EndpointManager.getActiveManagerList()) {
            for (CollectKeyInfoPK itemCode : itemCodeList) {
                String displayName = itemCode.getDisplayName();
                String itemName = itemCode.getItemName();
                if (!displayName.equals("") && !itemName.endsWith("[" + displayName + "]")) {
                    itemName += "[" + displayName + "]";
                }

                String str = itemName + CollectSettingComposite.SEPARATOR_AT + itemCode.getMonitorId() + "("
                        + unit.getManagerName() + ")";
                if (!itemCodeNameList.contains(str)) {
                    itemCodeNameList.add(str);
                }
            }
        }
        StringBuffer itemCodeStr = new StringBuffer();
        for (String itemCodeName : itemCodeNameList) {
            if (0 < itemCodeStr.length()) {
                itemCodeStr.append(", ");
            }
            itemCodeStr.append(HinemosMessage.replace(itemCodeName));
        }
        if (itemCodeStr.length() > 256) {
            itemCodeStr = new StringBuffer(itemCodeStr.substring(0, 256));
            itemCodeStr.append("...");
        }
        settingLabel.setText(
                Messages.getString("collection.summary.type") + " : " + SummaryTypeMessage.typeToString(summaryType)
                        + ",   " + Messages.getString("collection.display.name") + " : " + itemCodeStr.toString());
    }

    /**
     * ????????
     */
    public void deleteGraphs() {
        String param = CONTROL_CLASS_NAME_LINESTACK + ".delDiv();";
        executeScript(param, m_browserGraph);
        param = CONTROL_CLASS_NAME_PIE + ".delDiv();";
        executeScript(param, m_browserGraph);
        param = CONTROL_CLASS_NAME_SCATTER + ".delDiv();";
        executeScript(param, m_browserGraph);
        param = CONTROL_CLASS_NAME_BARSTACK + ".delDiv();";
        executeScript(param, m_browserGraph);
        // ????????drawGraphs????
    }

    /**
     * ?????
     * 
     * 
     * @param collectKeyInfoList
     * @param summaryCode
     * @param treeItemList
     * @param returnFlg ?
     * @throws InvalidRole_Exception 
     * @throws HinemosUnknown_Exception 
     * @throws InvalidUserPass_Exception 
     * @throws Exception 
     */
    public void drawGraphs(List<CollectKeyInfoPK> collectKeyInfoList, String selectInfoStr, int summaryType,
            List<FacilityTreeItem> treeItemList, boolean returnFlg, boolean returnKindFlg, boolean totalFlg,
            boolean stackflg, boolean appflg, boolean threflg, boolean pieflg, boolean scatterflg,
            boolean legendFlg, boolean barFlg)
            throws InvalidUserPass_Exception, HinemosUnknown_Exception, InvalidRole_Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
        dateFormat.setTimeZone(TimezoneUtil.getTimeZone());

        m_log.info("drawGraphs() START time:" + dateFormat.format(new Date()) + ", selectInfoStr:" + selectInfoStr
                + ", summaryType:" + summaryType);

        setSettingLabel(summaryType, collectKeyInfoList);

        if (!completed || !slider_completed) {
            m_log.info("uncompleted!!");
            return;
        }
        CollectGraphUtil.init(totalFlg, stackflg, collectKeyInfoList, pieflg, scatterflg, barFlg, selectInfoStr);

        // ????
        setGraphMessages();

        // ?????
        boolean booleanArr[] = { returnFlg, returnKindFlg, totalFlg, stackflg, appflg, threflg, pieflg, scatterflg,
                legendFlg, barFlg, ClusterControlPlugin.isRAP() };
        String setting = getBooleanString(booleanArr);
        m_log.info(
                "setting boolean[return, returnkind, total, stack, applox, thre, pie, scatter, legend, bar, rap]:"
                        + setting);

        // ??????div?
        deleteGraphs();

        int facilitySize = 0;
        int graphSize = 0;
        int count = 0;
        for (FacilityTreeItem treeItem : treeItemList) {
            // ?????????
            facilitySize = CollectGraphUtil.sortManagerNameFacilityIdMap(treeItem, count);
            count++;
        }
        graphSize = facilitySize * collectKeyInfoList.size();

        int managercount = CollectGraphUtil.getSelectManagerCount();
        m_log.info("drawGraphs() graphSize:" + graphSize + ", itemCodeList.size:" + collectKeyInfoList.size()
                + ", facilityLength:" + facilitySize + ", managerCount:" + managercount);
        if (threflg && managercount != 1 && (!stackflg && !pieflg && !scatterflg && !barFlg)) {
            MessageDialog.openError(null, Messages.getString("error"), // ??????????
                    Messages.getString(
                            "message.collection.graph.do.not.display.upperandlowerlimits.in.multiplemanager"));
            return;
        }
        int preferenceCount = ClusterControlPlugin.getDefault().getPreferenceStore()
                .getInt(PerformancePreferencePage.P_GRAPH_MAX);
        if (graphSize > preferenceCount) {
            // Preference?????????
            String args[] = { String.valueOf(graphSize), String.valueOf(preferenceCount) };
            if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"),
                    Messages.getString("message.collection.graph.limitsize", args))) {
                return;
            }
            m_log.info("???????? " + preferenceCount + "/"
                    + graphSize);
        }

        // ?????????
        CollectGraphUtil.addManagerDummyName();

        // ??
        String createGraphJson = CollectGraphUtil.drawGraphSheets(summaryType);
        // ????
        String params = getHeadControlClassName() + ".addGraphAtOnce(" + createGraphJson + ", " + facilitySize
                + ", " + preferenceCount + ", '" + setting + "');";
        Long start = System.currentTimeMillis();
        m_log.info("start base_graph Draw");
        executeScript(params, m_browserGraph);
        m_log.info("end base_graph Draw time:" + (System.currentTimeMillis() - start) + "ms");

        // ???????100%??
        // ?????????????????initZoom?
        String preferenceZoom = ClusterControlPlugin.getDefault().getPreferenceStore()
                .getString(CollectSettingComposite.P_COLLECT_GRAPH_ZOOM_LEVEL);
        CollectGraphUtil.setGraphZoomSize(preferenceZoom);
        params = "initZoom(\'" + CollectGraphUtil.getGraphZoomSize() + "\', " + returnFlg + ", "
                + CollectGraphUtil.getM_screenWidth() + ");";
        executeScript(params, m_browserGraph);

        // ? -> ?
        int totalGraphSize = graphSize;
        if (graphSize > preferenceCount) {
            totalGraphSize = preferenceCount;
        }
        params = "ControlBrushLine.delCreateBrush(" + CollectGraphUtil.getSliderStart() + ","
                + CollectGraphUtil.getSliderEnd() + "," + CollectGraphUtil.getTargetConditionStartDate() + ","
                + CollectGraphUtil.getTargetConditionEndDate() + "," + totalGraphSize + ");";
        executeScript(params, m_browserSlider);

        // collectId??
        CollectGraphUtil.collectCollectIdInfo(summaryType);

        // ?????
        addGraphPlot(CollectGraphUtil.getTargetConditionStartDate(), CollectGraphUtil.getTargetConditionEndDate(),
                CollectGraphUtil.getTargetConditionStartDate(), CollectGraphUtil.getTargetConditionEndDate());

        // y?????
        String yaxisParam = getHeadControlClassName() + ".trimBranch();";
        executeScript(yaxisParam, m_browserGraph);

        m_log.info("drawGraphs() END time:" + dateFormat.format(new Date()));
    }

    /** 
     * ??????????
     * ?????????????browser?
     */
    private void setGraphMessages() {
        String param = "setGraphMessages({" + "\'autoadjust\':\'" + Messages.getString("collect.autoadjust")
                + "\', " // 
                + "\'autoupdate\':\'" + Messages.getString("collect.autoupdate") + "\', " // 
                + "\'bulkpng\':\'" + Messages.getString("collect.bulkpng") + "\', " // PNG
                + "\'nodes\':\'" + Messages.getString("collect.nodes") + "\', " // 
                + "\'total\':\'" + Messages.getString("collect.total") + "\', " // 
                + "\'time\':\'" + Messages.getString("time") + "\', " // 
                + "\'priority\':\'" + Messages.getString("priority") + "\', " // ??
                + "\'message\':\'" + Messages.getString("message") + "\', " // 
                + "\'total\':\'" + Messages.getString("collect.total") + "\', " // 
                + "\'information\':\'" + Messages.getString("info") + "\', " + "\'warning\':\'"
                + Messages.getString("warning") + "\', " + "\'critical\':\'" + Messages.getString("critical")
                + "\', " + "\'unknown\':\'" + Messages.getString("unknown") + "\', " + "\'detail\':\'"
                + Messages.getString("detail") + "\', "// 
                + "\'timezoneoffset\':" + TimezoneUtil.getTimeZoneOffset() / (1000 * 60) + ", "// ()
                + "\'captureerror\':\'" + Messages.getString("message.collection.graph.capture.morethan.displayed")
                + "\', "// ??100?????????
                + "\'unexpectederror\':\'" + Messages.getString("message.collection.graph.unexpected.error")
                + "\', "// ????????
                + "\'datainsufficient\':\'" + Messages.getString("message.collection.6") + "\'" // ????????
                + "});";
        executeScript(param, m_browserGraph);
        executeScript(param, m_browserSlider);
    }

    /**
     * ???(?)
     */
    @Override
    public void update() {
        super.update();
    }

    public String getZoomLevel() {
        return CollectGraphUtil.getGraphZoomSize();
    }

    /**
     * ???????????????
     */
    public void removeGraphSliderDisp() {
        m_log.debug("removeGraphSliderDisp()");
        String delSlider = "ControlBrushLine.delBrush()";
        executeScript(delSlider, m_browserSlider);
        deleteGraphs();
        String delGraphZoom = "removeZoomArea()";
        executeScript(delGraphZoom, m_browserGraph);
    }

    /**
     * ??script(Javascript)execBrowser??????
     * 
     * @param script
     * @param execBrowser
     * @return
     */
    private Object executeScript(String script, Browser execBrowser) {
        this.lastScript = script;
        m_log.debug("script:" + this.lastScript);
        Object retObj = execBrowser.evaluate(this.lastScript);
        return retObj;
    }

    /**
     * boolean?????????<br>
     * true  -> 1<br>
     * false -> 0<br>
     * @param booleanArr
     * @return
     */
    private static String getBooleanString(boolean[] booleanArr) {
        StringBuffer booleanBuffer = new StringBuffer();
        for (boolean bool : booleanArr) {
            int str = BooleanUtils.toInteger(bool);
            booleanBuffer.append(str);
        }
        String retStr = booleanBuffer.toString();
        return retStr;
    }

    /**
     * ????????????
     * @return
     */
    private static String getHeadControlClassName() {
        String headClassName = CONTROL_CLASS_NAME_LINESTACK;
        if (CollectGraphUtil.getPieFlg()) {
            headClassName = CONTROL_CLASS_NAME_PIE;
        } else if (CollectGraphUtil.getScatterFlg()) {
            headClassName = CONTROL_CLASS_NAME_SCATTER;
        } else if (CollectGraphUtil.getBarFlg()) {
            headClassName = CONTROL_CLASS_NAME_BARSTACK;
        }
        return headClassName;
    }

    /**
     * ????????????
     * @return
     */
    private static String getHeadGraphClassName() {
        String headClassName = GRAPH_CLASS_NAME_LINESTACK;
        if (CollectGraphUtil.getPieFlg()) {
            headClassName = GRAPH_CLASS_NAME_PIE;
        } else if (CollectGraphUtil.getScatterFlg()) {
            headClassName = GRAPH_CLASS_NAME_SCATTER;
        } else if (CollectGraphUtil.getBarFlg()) {
            headClassName = GRAPH_CLASS_NAME_BARSTACK;
        }
        return headClassName;
    }
}