Author: vsalaun Date: 2011-05-30 10:55:09 +0200 (Mon, 30 May 2011) New Revision: 3150 Url: http://chorem.org/repositories/revision/lima/3150 Log: shortcut for dates Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java 2011-05-27 12:29:39 UTC (rev 3149) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java 2011-05-30 08:55:09 UTC (rev 3150) @@ -25,6 +25,7 @@ package org.chorem.lima.ui.celleditor; +import org.apache.commons.lang.time.DateUtils; import org.chorem.lima.LimaContext; import org.jdesktop.swingx.JXDatePicker; @@ -53,6 +54,7 @@ private static final long serialVersionUID = 1L; private static DateTableCellEditor editor; private boolean keyPressed; + private Date date; /** * constructor @@ -69,12 +71,34 @@ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value instanceof Date) { datePicker.setDate((Date) value); + date = (Date) value; } return datePicker; } @Override public Object getCellEditorValue() { + if (!datePicker.getEditor().getText().isEmpty()) { + String[] str = datePicker.getEditor().getText().split("/"); + //day + if (str.length > 0) { + if (str[0].contains(" ")) { + String[] string = str[0].split(" "); + date = DateUtils.setDays(date, Integer.valueOf(string[1])); + } else { + date = DateUtils.setDays(date, Integer.valueOf(str[0])); + } + } + //month + if (str.length > 1) { + date = DateUtils.setMonths(date, Integer.valueOf(str[1])-1); + } + //year + if (str.length > 2) { + date = DateUtils.setYears(date, Integer.valueOf(str[2])); + } + } + datePicker.setDate(date); return datePicker.getDate(); } @@ -139,7 +163,6 @@ keyPressed = true; } else if (e.getKeyChar() == KeyEvent.VK_BACK_SPACE){ - datePicker.getEditor().setText(""); keyPressed = true; } }