/** Load the data of the selected parameter into the table */ private void list_selected() { String key; try { key = getCurrentKey(); } catch (Exception e1) { return; } MeasurementHistoryController hist = master.getHistoryController(); MeasurementHistory data; try { if (getCurrentTimeBase().equals("hours")) data = hist.getDataHours().get(key); else data = hist.getDataDays().get(key); } catch (Exception ex) { return; } Vector<MeasurementHistoryEntry> newData = new Vector<MeasurementHistoryEntry>(data.getValues().size()); newData.addAll(data.getValues()); Collections.sort(newData); Collections.reverse(newData); dataTable.removeAll(); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); for (MeasurementHistoryEntry e : newData) { TableItem item = new TableItem(dataTable, SWT.NONE); item.setText(new String[] {sdf.format(e.getTimestamp()), "" + e.getValue()}); } }
/** * 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(); }