| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view.menu.items; |
| 5 | |
|
| 6 | |
import java.awt.Toolkit; |
| 7 | |
import java.awt.event.ActionEvent; |
| 8 | |
import java.awt.event.KeyEvent; |
| 9 | |
import java.util.Date; |
| 10 | |
import java.util.logging.Level; |
| 11 | |
import java.util.logging.Logger; |
| 12 | |
|
| 13 | |
import javax.swing.KeyStroke; |
| 14 | |
|
| 15 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
| 16 | |
import org.homeunix.thecave.buddi.i18n.keys.MenuKeys; |
| 17 | |
import org.homeunix.thecave.buddi.model.BudgetCategory; |
| 18 | |
import org.homeunix.thecave.buddi.model.swing.MyBudgetTreeTableModel; |
| 19 | |
import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException; |
| 20 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
| 21 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
| 22 | |
|
| 23 | |
import ca.digitalcave.moss.swing.MossMenuItem; |
| 24 | |
|
| 25 | |
public class EditCopyBudgetCategoryValuesToNext extends MossMenuItem{ |
| 26 | |
public static final long serialVersionUID = 0; |
| 27 | |
|
| 28 | |
public EditCopyBudgetCategoryValuesToNext(MainFrame frame) { |
| 29 | 256 | super(frame, TextFormatter.getTranslation(MenuKeys.MENU_EDIT_COPY_VALUES_TO_NEXT_BUDGET_PERIOD), |
| 30 | |
KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + KeyEvent.SHIFT_DOWN_MASK)); |
| 31 | 256 | } |
| 32 | |
|
| 33 | |
@Override |
| 34 | |
public void actionPerformed(ActionEvent e) { |
| 35 | 0 | Date currentlySelectedDate = ((MainFrame) getFrame()).getMyBudgetPanel().getTreeTableModel().getSelectedDate(); |
| 36 | 0 | for (BudgetCategory bc : ((MainFrame) getFrame()).getBudgetCategoriesInSelectedPeriod()) { |
| 37 | 0 | long amount = bc.getAmount(currentlySelectedDate); |
| 38 | |
try { |
| 39 | 0 | if (bc.getAmount(bc.getBudgetPeriodType().getBudgetPeriodOffset(currentlySelectedDate, 1)) == 0) |
| 40 | 0 | bc.setAmount(bc.getBudgetPeriodType().getBudgetPeriodOffset(currentlySelectedDate, 1), amount); |
| 41 | |
} |
| 42 | 0 | catch (InvalidValueException ive){ |
| 43 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Invalid Value Exception", ive); |
| 44 | 0 | } |
| 45 | 0 | } |
| 46 | |
|
| 47 | 0 | ((MainFrame) getFrame()).fireStructureChanged(); |
| 48 | 0 | ((MainFrame) getFrame()).updateContent(); |
| 49 | 0 | } |
| 50 | |
|
| 51 | |
@Override |
| 52 | |
public void updateMenus() { |
| 53 | 420 | super.updateMenus(); |
| 54 | |
|
| 55 | 420 | MyBudgetTreeTableModel treeTableModel = ((MainFrame) getFrame()).getMyBudgetPanel().getTreeTableModel(); |
| 56 | 420 | this.setText(TextFormatter.getTranslation(MenuKeys.MENU_EDIT_COPY_VALUES_TO_NEXT_BUDGET_PERIOD) |
| 57 | |
+ " (" + treeTableModel.getColumnName(2) + " " |
| 58 | |
+ TextFormatter.getTranslation(BuddiKeys.TO) |
| 59 | |
+ " " + treeTableModel.getColumnName(3) + ")"); |
| 60 | |
|
| 61 | 420 | this.setEnabled(((MainFrame) getFrame()).getBudgetCategoriesInSelectedPeriod().size() > 0); |
| 62 | 420 | } |
| 63 | |
} |