private void load() {
    final ArrayList<Pack> values = new ArrayList<Pack>();
    TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
    try {
      MapPack param = new MapPack();
      param.put("sDate", sDate);
      param.put("eDate", eDate);
      param.put("objType", objType);
      param.put("counter", counter);

      tcp.process(
          RequestCmd.COUNTER_PAST_LONGDATE_ALL,
          param,
          new INetReader() {
            public void process(DataInputX in) throws IOException {
              Pack pack = in.readPack();
              values.add(pack);
            };
          });

    } catch (Throwable t) {
      ConsoleProxy.errorSafe(t.toString());
    } finally {
      TcpProxy.putTcpProxy(tcp);
    }

    final Map<Long, Double> valueMap =
        ScouterUtil.getLoadTotalMap(counter, values, mode, TimeTypeEnum.FIVE_MIN);

    ExUtil.exec(
        this.canvas,
        new Runnable() {
          public void run() {
            try {
              traceDataProvider.clearTrace();
              Set<Long> timeSet = valueMap.keySet();
              for (long time : timeSet) {
                traceDataProvider.addSample(
                    new Sample(CastUtil.cdouble(time), CastUtil.cdouble(valueMap.get(time))));
              }
            } catch (Throwable t) {
              ConsoleProxy.error(t.toString());
            }
            if (CounterUtil.isPercentValue(objType, counter)) {
              xyGraph.primaryYAxis.setRange(0, 100);
            } else {
              double max = ChartUtil.getMax(traceDataProvider.iterator());
              xyGraph.primaryYAxis.setRange(0, max);
            }
            redraw();
            applyBtn.setEnabled(true);
          }
        });
  }
  private void getYesterdayData(String date) {
    final ArrayList<Pack> values = new ArrayList<Pack>();
    TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
    try {
      MapPack param = new MapPack();
      param.put("date", date);
      param.put("objType", objType);
      param.put("counter", counter);

      tcp.process(
          RequestCmd.COUNTER_PAST_DATE_ALL,
          param,
          new INetReader() {
            public void process(DataInputX in) throws IOException {
              Pack p = in.readPack();
              values.add(p);
            };
          });
    } catch (Throwable t) {
      t.printStackTrace();
    } finally {
      TcpProxy.putTcpProxy(tcp);
    }

    final Map<Long, Double> valueMap =
        ScouterUtil.getLoadTotalMap(counter, values, mode, TimeTypeEnum.FIVE_MIN);

    ExUtil.exec(
        this.canvas,
        new Runnable() {
          public void run() {
            yesterdayDataProvider.clearTrace();
            Set<Long> timeSet = valueMap.keySet();
            for (long time : timeSet) {
              yesterdayDataProvider.addSample(
                  new Sample(
                      CastUtil.cdouble(time + DateUtil.MILLIS_PER_DAY),
                      CastUtil.cdouble(valueMap.get(time))));
            }
            yesterdayMax = ChartUtil.getMax(yesterdayDataProvider.iterator());
          }
        });
  }
 public String getColumnText(Object element, int columnIndex) {
   if (element instanceof DirObject) {
     DirObject obj = (DirObject) element;
     switch (columnIndex) {
       case 0:
         int lastIndex = obj.name.lastIndexOf("/");
         if (lastIndex < 0) {
           lastIndex = obj.name.lastIndexOf("\\");
         }
         if (lastIndex > -1) {
           return obj.name.substring(lastIndex + 1);
         } else {
           return obj.name;
         }
       case 1:
         return ScouterUtil.humanReadableByteCount(obj.size, true);
       case 2:
         return DateUtil.format(obj.lastModified, "yyyy-MM-dd HH:mm:ss");
     }
   }
   return null;
 }
 public void refresh() {
   ScouterUtil.collectGroupObjcts(grpName, serverObjMap);
   isActive = false;
   Iterator<Integer> serverIds = serverObjMap.keySet().iterator();
   final List<Pack> result = new ArrayList<Pack>();
   while (serverIds.hasNext()) {
     int serverId = serverIds.next();
     TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
     try {
       MapPack param = new MapPack();
       param.put("counter", counter);
       param.put("objHash", serverObjMap.get(serverId));
       tcp.process(
           RequestCmd.COUNTER_TODAY_GROUP,
           param,
           new INetReader() {
             public void process(DataInputX in) throws IOException {
               Pack p = in.readPack();
               if (p != null) {
                 result.add(p);
               }
             }
           });
     } catch (Exception e) {
       e.printStackTrace();
     } finally {
       TcpProxy.putTcpProxy(tcp);
     }
   }
   final long[] values = new long[(int) (DateUtil.MILLIS_PER_DAY / DateUtil.MILLIS_PER_HOUR)];
   if (result.size() > 0) {
     Map<Long, Double> valueMap =
         ScouterUtil.getLoadTotalMap(counter, result, mode, TimeTypeEnum.FIVE_MIN);
     Iterator<Long> itr = valueMap.keySet().iterator();
     while (itr.hasNext()) {
       long time = itr.next();
       int index = (int) (DateUtil.getDateMillis(time) / DateUtil.MILLIS_PER_HOUR);
       values[index] += valueMap.get(time);
     }
     isActive = true;
   }
   ExUtil.exec(
       this.canvas,
       new Runnable() {
         public void run() {
           if (isActive == true) {
             setActive();
           } else {
             setInactive();
             return;
           }
           double max = 0;
           traceDataProvider.clearTrace();
           for (int i = 0; i < values.length; i++) {
             traceDataProvider.addSample(
                 new Sample(CastUtil.cdouble(i) + 0.5d, CastUtil.cdouble(values[i])));
           }
           max = Math.max(ChartUtil.getMax(traceDataProvider.iterator()), max);
           if (CounterUtil.isPercentValue(objType, counter)) {
             xyGraph.primaryYAxis.setRange(0, 100);
           } else {
             xyGraph.primaryYAxis.setRange(0, max);
           }
           canvas.redraw();
           xyGraph.repaint();
         }
       });
 }
  public void createPartControl(Composite parent) {
    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gLayout = new GridLayout(1, true);
    gLayout.horizontalSpacing = 0;
    gLayout.marginHeight = 0;
    gLayout.marginWidth = 0;
    composite.setLayout(gLayout);
    createUpperMenu(composite);

    Composite chartComposite = new Composite(composite, SWT.NONE);
    chartComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    chartComposite.setLayout(UIUtil.formLayout(0, 0));
    this.marginTargetComposite = chartComposite;
    chartComposite.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));

    canvas = new FigureCanvas(chartComposite);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));

    canvas.setLayoutData(UIUtil.formData(0, leftMargin, 0, 0, 100, 0, 100, 0));

    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterPastLongDateTotalView.this.setContentDescription(desc);
              } else {
                CounterPastLongDateTotalView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            xyGraph.setSize(r.width, r.height);
          }

          public void controlMoved(ControlEvent e) {}
        });
    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    traceDataProvider = new CircularBufferDataProvider(true);
    //		traceDataProvider.setBufferSize(buffer);
    traceDataProvider.setCurrentXDataArray(new double[] {});
    traceDataProvider.setCurrentYDataArray(new double[] {});

    // create the trace
    trace = new Trace("TOTAL", xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);

    // set trace property
    trace.setPointStyle(PointStyle.NONE);
    trace.getXAxis().setFormatPattern("yyyy-MM-dd\n  HH:mm:ss");
    trace.getYAxis().setFormatPattern("#,##0");

    trace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    trace.setTraceType(TraceType.AREA);
    trace.setTraceColor(ColorUtil.getInstance().TOTAL_CHART_COLOR);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    ChartUtil.addSolidLine(xyGraph, traceDataProvider, ColorUtil.getInstance().TOTAL_CHART_COLOR);

    ScouterUtil.addShowTotalValueListener(canvas, xyGraph);

    man = getViewSite().getActionBars().getToolBarManager();

    canvas.addKeyListener(
        new KeyListener() {
          public void keyReleased(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F5) {
              ExUtil.asyncRun(
                  new Runnable() {
                    public void run() {
                      try {
                        setInput(sDate, eDate, objType, counter, serverId);
                      } catch (Exception e) {
                        e.printStackTrace();
                      }
                    }
                  });
            }
          }
        });

    man.add(
        new Action("Reload", ImageUtil.getImageDescriptor(Images.refresh)) {
          public void run() {
            ExUtil.exec(
                new Runnable() {
                  public void run() {
                    try {
                      setInput(sDate, eDate, objType, counter, serverId);
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                });
          }
        });

    man.add(new Separator());
    man.add(
        new Action("Duplicate", ImageUtil.getImageDescriptor(Images.copy)) {
          public void run() {
            ExUtil.exec(
                new Runnable() {
                  public void run() {
                    duplicateView();
                  }
                });
          }
        });

    restoreState();
  }
  public void refresh() {
    String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId) - DateUtil.MILLIS_PER_DAY);
    if (date.equals(yesterday) == false) {
      yesterday = date;
      getYesterdayData(date);
    }
    final ArrayList<Pack> packs = new ArrayList<Pack>();
    TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
    try {
      MapPack param = new MapPack();
      param.put("objType", objType);
      param.put("counter", counter);
      param.put("mode", CounterUtil.getTotalMode(objType, counter));
      isActive = false;
      tcp.process(
          RequestCmd.COUNTER_TODAY_ALL,
          param,
          new INetReader() {
            public void process(DataInputX in) throws IOException {
              packs.add(in.readPack());
            }
          });
    } catch (Throwable t) {
      ConsoleProxy.errorSafe(t.toString());
    } finally {
      TcpProxy.putTcpProxy(tcp);
    }

    final Map<Long, Double> valueMap =
        ScouterUtil.getLoadTotalMap(counter, packs, mode, TimeTypeEnum.FIVE_MIN);
    if (valueMap.size() > 0) {
      isActive = true;
    }

    ExUtil.exec(
        this.canvas,
        new Runnable() {
          public void run() {
            if (isActive) {
              setActive();
            } else {
              setInactive();
            }
            String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId));
            try {
              long stime = DateUtil.getTime(date, "yyyyMMdd");
              long etime = stime + DateUtil.MILLIS_PER_DAY;
              xyGraph.primaryXAxis.setRange(stime, etime);
              traceDataProvider.clearTrace();
              Set<Long> timeSet = valueMap.keySet();
              for (long time : timeSet) {
                traceDataProvider.addSample(
                    new Sample(CastUtil.cdouble(time), CastUtil.cdouble(valueMap.get(time))));
              }
              if (CounterUtil.isPercentValue(objType, counter)) {
                xyGraph.primaryYAxis.setRange(0, 100);
              } else {
                double max = ChartUtil.getMax(traceDataProvider.iterator());
                max = Math.max(max, yesterdayMax);
                xyGraph.primaryYAxis.setRange(0, max);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
            canvas.redraw();
            xyGraph.repaint();
          }
        });
  }
  public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);

    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    man = getViewSite().getActionBars().getToolBarManager();

    man.add(
        new Action("Reload", ImageUtil.getImageDescriptor(Images.refresh)) {
          public void run() {
            yesterday = null;
            yesterdayDataProvider.clearTrace();
            traceDataProvider.clearTrace();
            thread.interrupt();
          }
        });

    canvas = new FigureCanvas(parent);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));

    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterTodayTotalView.this.setContentDescription(desc);
              } else {
                CounterTodayTotalView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            xyGraph.setSize(r.width, r.height);
          }

          public void controlMoved(ControlEvent e) {}
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);
    // xyGraph.setShowTitle(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    ScouterUtil.addShowTotalValueListener(canvas, xyGraph);

    createDataProvider();
    createYesterdayProvider();

    canvas.addKeyListener(
        new KeyListener() {
          public void keyReleased(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F5) {
              yesterday = null;
              yesterdayDataProvider.clearTrace();
              traceDataProvider.clearTrace();
              thread.interrupt();
            }
          }
        });

    String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId));

    Server server = ServerManager.getInstance().getServer(serverId);
    String svrName = "";
    String counterDisplay = "";
    String counterUnit = "";
    if (server != null) {
      svrName = server.getName();
      counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter);
      counterUnit = server.getCounterEngine().getCounterUnit(objType, counter);
    }
    desc =
        "ⓢ"
            + svrName
            + " | (Today) ["
            + date.substring(0, 4)
            + "-"
            + date.substring(4, 6)
            + "-"
            + date.substring(6, 8)
            + "] Total "
            + counterDisplay
            + (!"".equals(counterUnit) ? " (" + counterUnit + ")" : "");
    try {
      setViewTab(objType, counter, serverId);
    } catch (Exception e1) {
      e1.printStackTrace();
    }

    thread = new RefreshThread(this, 10000);
    thread.setName(
        this.toString()
            + " - "
            + "objType:"
            + objType
            + ", counter:"
            + counter
            + ", serverId:"
            + serverId);
    thread.start();
  }
  public void createPartControl(Composite parent) {
    Server server = ServerManager.getInstance().getServer(serverId);
    this.setPartName("DB Activity[" + server.getName() + "]");
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    canvas = new FigureCanvas(parent);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.addControlListener(
        new ControlListener() {
          public void controlMoved(ControlEvent arg0) {}

          public void controlResized(ControlEvent arg0) {
            Rectangle r = canvas.getClientArea();
            xyGraph.setSize(r.width, r.height);
          }
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(true);
    xyGraph.setShowTitle(false);
    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);
    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);
    xyGraph.primaryXAxis.setFormatPattern("HH:mm:ss");
    xyGraph.primaryYAxis.setFormatPattern("#,##0");

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    CircularBufferDataProvider callProvider = new CircularBufferDataProvider(true);
    callProvider.setBufferSize(BUFFER_SIZE);
    callProvider.setCurrentXDataArray(new double[] {});
    callProvider.setCurrentYDataArray(new double[] {});
    callTrace = new Trace("Call (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, callProvider);
    callTrace.setPointStyle(PointStyle.NONE);
    callTrace.setTraceType(TraceType.AREA);
    callTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    callTrace.setAreaAlpha(255);
    callTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_BLUE));
    xyGraph.addTrace(callTrace);

    CircularBufferDataProvider selectProvider = new CircularBufferDataProvider(true);
    selectProvider.setBufferSize(BUFFER_SIZE);
    selectProvider.setCurrentXDataArray(new double[] {});
    selectProvider.setCurrentYDataArray(new double[] {});
    selectTrace =
        new Trace("Select (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, selectProvider);
    selectTrace.setPointStyle(PointStyle.NONE);
    selectTrace.setTraceType(TraceType.AREA);
    selectTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    selectTrace.setAreaAlpha(255);
    selectTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_CYAN));
    xyGraph.addTrace(selectTrace);

    CircularBufferDataProvider insertProvider = new CircularBufferDataProvider(true);
    insertProvider.setBufferSize(BUFFER_SIZE);
    insertProvider.setCurrentXDataArray(new double[] {});
    insertProvider.setCurrentYDataArray(new double[] {});
    insertTrace =
        new Trace("Insert (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, insertProvider);
    insertTrace.setPointStyle(PointStyle.NONE);
    insertTrace.setTraceType(TraceType.AREA);
    insertTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    insertTrace.setAreaAlpha(255);
    insertTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_GRAY));
    xyGraph.addTrace(insertTrace);

    CircularBufferDataProvider updateProvider = new CircularBufferDataProvider(true);
    updateProvider.setBufferSize(BUFFER_SIZE);
    updateProvider.setCurrentXDataArray(new double[] {});
    updateProvider.setCurrentYDataArray(new double[] {});
    updateTrace =
        new Trace("Update (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, updateProvider);
    updateTrace.setPointStyle(PointStyle.NONE);
    updateTrace.setTraceType(TraceType.AREA);
    updateTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    updateTrace.setAreaAlpha(255);
    updateTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_GREEN));
    xyGraph.addTrace(updateTrace);

    CircularBufferDataProvider deleteProvider = new CircularBufferDataProvider(true);
    deleteProvider.setBufferSize(BUFFER_SIZE);
    deleteProvider.setCurrentXDataArray(new double[] {});
    deleteProvider.setCurrentYDataArray(new double[] {});
    deleteTrace =
        new Trace("Delete (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, deleteProvider);
    deleteTrace.setPointStyle(PointStyle.NONE);
    deleteTrace.setTraceType(TraceType.AREA);
    deleteTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    deleteTrace.setAreaAlpha(255);
    deleteTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_MAGENTA));
    xyGraph.addTrace(deleteTrace);

    ScouterUtil.addHorizontalRangeListener(
        xyGraph.getPlotArea(), new OpenDigestTableAction(serverId), true);

    IToolBarManager man = getViewSite().getActionBars().getToolBarManager();
    Action fixRangeAct =
        new Action("Pin Range", IAction.AS_CHECK_BOX) {
          public void run() {
            fixRange = isChecked();
          }
        };
    fixRangeAct.setImageDescriptor(ImageUtil.getImageDescriptor(Images.pin));
    man.add(fixRangeAct);

    thread = new RefreshThread(this, REFRESH_INTERVAL);
    thread.start();
  }