| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view.menu.items; |
| 5 | |
|
| 6 | |
import java.awt.event.ActionEvent; |
| 7 | |
import java.util.List; |
| 8 | |
import java.util.logging.Logger; |
| 9 | |
|
| 10 | |
import org.homeunix.thecave.buddi.i18n.keys.MenuKeys; |
| 11 | |
import org.homeunix.thecave.buddi.model.BudgetCategory; |
| 12 | |
import org.homeunix.thecave.buddi.model.Document; |
| 13 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 14 | |
import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException; |
| 15 | |
import org.homeunix.thecave.buddi.plugin.api.exception.ModelException; |
| 16 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
| 17 | |
|
| 18 | |
import ca.digitalcave.moss.swing.MossMenuItem; |
| 19 | |
|
| 20 | |
public class EditDeleteBudgetCategory extends MossMenuItem{ |
| 21 | |
public static final long serialVersionUID = 0; |
| 22 | |
|
| 23 | |
public EditDeleteBudgetCategory(MainFrame frame) { |
| 24 | 256 | super(frame, PrefsModel.getInstance().getTranslator().get(MenuKeys.MENU_EDIT_DELETE_BUDGET_CATEGORIES)); |
| 25 | 256 | } |
| 26 | |
|
| 27 | |
@Override |
| 28 | |
public void actionPerformed(ActionEvent e) { |
| 29 | 0 | if (!(getFrame() instanceof MainFrame)) |
| 30 | 0 | throw new RuntimeException("Calling frame not instance of BudgetFrame"); |
| 31 | |
|
| 32 | 0 | ((MainFrame) getFrame()).getDocument().startBatchChange(); |
| 33 | 0 | List<BudgetCategory> bcs = ((MainFrame) getFrame()).getSelectedBudgetCategories(); |
| 34 | 0 | for (BudgetCategory bc : bcs) { |
| 35 | |
try { |
| 36 | 0 | ((Document) ((MainFrame) getFrame()).getDocument()).removeBudgetCategory(bc); |
| 37 | |
} |
| 38 | 0 | catch (ModelException me){ |
| 39 | |
try { |
| 40 | 0 | bc.setDeleted(true); |
| 41 | |
} |
| 42 | 0 | catch (InvalidValueException ive){ |
| 43 | 0 | Logger.getLogger(this.getClass().getName()).warning("Error setting deleted flag on budget category"); |
| 44 | 0 | } |
| 45 | 0 | } |
| 46 | |
} |
| 47 | |
|
| 48 | 0 | ((MainFrame) getFrame()).updateContent(); |
| 49 | 0 | ((MainFrame) getFrame()).fireStructureChanged(); |
| 50 | 0 | ((MainFrame) getFrame()).getDocument().finishBatchChange(); |
| 51 | |
|
| 52 | 0 | } |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public void updateMenus() { |
| 56 | 420 | super.updateMenus(); |
| 57 | |
|
| 58 | 420 | this.setEnabled(((MainFrame) getFrame()).getSelectedBudgetCategories().size() > 0); |
| 59 | 420 | } |
| 60 | |
} |