public static DatePeriodUnit fromString(String text) {
   if (text != null) {
     for (DatePeriodUnit b : DatePeriodUnit.values()) {
       if (text.equalsIgnoreCase(b.label)) {
         return b;
       }
     }
   }
   return null;
 }
  private void createUpperMenu(Composite composite) {
    headerComp = new Composite(composite, SWT.NONE);
    headerComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    headerComp.setLayout(UIUtil.formLayout(0, 0));

    long initialTime = TimeUtil.getCurrentTime(serverId) - DatePeriodUnit.A_DAY.getTime();

    applyBtn = new Button(headerComp, SWT.PUSH);
    applyBtn.setLayoutData(UIUtil.formData(null, -1, 0, 2, 100, -5, null, -1));
    applyBtn.setText("Apply");
    applyBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                ((Button) event.widget).setEnabled(false);
                try {
                  setInput(sDate, eDate, objType, counter, serverId);
                } catch (Exception e) {
                  e.printStackTrace();
                }
                break;
            }
          }
        });

    Button manualBtn = new Button(headerComp, SWT.PUSH);
    manualBtn.setImage(Images.CTXMENU_RDC);
    manualBtn.setText("Manual");
    manualBtn.setLayoutData(UIUtil.formData(null, -1, 0, 2, applyBtn, -5, null, -1));
    manualBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                Display display = Display.getCurrent();
                if (display == null) {
                  display = Display.getDefault();
                }

                calDialog = new LoadDualCalendarDialog(display, CounterPastLongDateTotalView.this);
                calDialog.show(UIUtil.getMousePosition());

                break;
            }
          }
        });

    periodCombo = new Combo(headerComp, SWT.VERTICAL | SWT.BORDER | SWT.READ_ONLY);
    periodCombo.setLayoutData(UIUtil.formData(null, -1, 0, 3, manualBtn, -5, null, -1));
    ArrayList<String> periodStrList = new ArrayList<String>();
    for (DatePeriodUnit minute : DatePeriodUnit.values()) {
      periodStrList.add(minute.getLabel());
    }
    periodCombo.setItems(periodStrList.toArray(new String[DatePeriodUnit.values().length]));
    periodCombo.select(2);
    periodCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            if (((Combo) e.widget).getSelectionIndex() == 0) {
              setStartEndDate(30);
            } else if (((Combo) e.widget).getSelectionIndex() == 1) {
              setStartEndDate(7);
            } else {
              setStartEndDate(1);
            }
          }

          private void setStartEndDate(int i) {
            long yesterday = TimeUtil.getCurrentTime(serverId) - DatePeriodUnit.A_DAY.getTime();
            long startDate =
                TimeUtil.getCurrentTime(serverId) - (DatePeriodUnit.A_DAY.getTime() * i);
            sDateText.setText(DateUtil.format(startDate, "yyyy-MM-dd"));
            eDateText.setText(DateUtil.format(yesterday, "yyyy-MM-dd"));

            sDate = DateUtil.format(startDate, "yyyyMMdd");
            eDate = DateUtil.format(yesterday, "yyyyMMdd");

            stime = DateUtil.getTime(sDate, "yyyyMMdd");
            etime = DateUtil.getTime(eDate, "yyyyMMdd") + DateUtil.MILLIS_PER_DAY;
          }
        });

    eDateText = new Label(headerComp, SWT.NONE);
    eDateText.setLayoutData(UIUtil.formData(null, -1, 0, 7, periodCombo, -5, null, -1));
    eDateText.setText(DateUtil.format(initialTime - 1, "yyyy-MM-dd"));

    Label windbarLabel = new Label(headerComp, SWT.NONE);
    windbarLabel.setLayoutData(UIUtil.formData(null, -1, 0, 7, eDateText, -5, null, -1));
    windbarLabel.setText("~");

    sDateText = new Label(headerComp, SWT.NONE);
    sDateText.setLayoutData(UIUtil.formData(null, -1, 0, 7, windbarLabel, -5, null, -1));
    sDateText.setText(DateUtil.format(initialTime, "yyyy-MM-dd"));

    serverText = new Label(headerComp, SWT.NONE | SWT.RIGHT);
    serverText.setLayoutData(UIUtil.formData(0, 0, 0, 7, sDateText, -5, null, -1));
    serverText.setText("ⓢ");
  }