예제 #1
0
파일: ViewData.java 프로젝트: schugabe/FWS
  /**
   * Delete Values from the history
   *
   * @param all when true the whole history of the selected parameter is deleted
   */
  private void delete(boolean all) {

    MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    messageBox.setMessage("Are you shure you want to delete these entries?");
    messageBox.setText("Delete History?");

    if (messageBox.open() == SWT.NO) return;

    String key, timebase;
    try {
      key = getCurrentKey();
      timebase = getCurrentTimeBase();
    } catch (Exception e) {
      return;
    }
    MeasurementHistoryController hist = master.getHistoryController();
    MeasurementHistory measurements;

    if (timebase.equals("hours")) measurements = hist.getDataHours().get(key);
    else measurements = hist.getDataDays().get(key);

    if (all) {
      measurements.removeAll();
    } else {
      for (TableItem item : this.dataTable.getSelection()) {
        String date = item.getText(0);
        String value = item.getText(1);

        SimpleDateFormat bla = new SimpleDateFormat(DATE_FORMAT);
        Date tmpdate;
        try {
          tmpdate = bla.parse(date);
        } catch (ParseException e) {
          e.printStackTrace();
          continue;
        }

        MeasurementHistoryEntry tmp =
            new MeasurementHistoryEntry(Double.parseDouble(value), tmpdate);
        measurements.removeEntry(tmp);
      }
    }
    this.list_selected();
  }