| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view.menu.items; |
| 5 | |
|
| 6 | |
import java.awt.event.ActionEvent; |
| 7 | |
import java.util.logging.Logger; |
| 8 | |
|
| 9 | |
import org.homeunix.thecave.buddi.i18n.keys.MenuKeys; |
| 10 | |
import org.homeunix.thecave.buddi.model.Account; |
| 11 | |
import org.homeunix.thecave.buddi.model.Document; |
| 12 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 13 | |
import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException; |
| 14 | |
import org.homeunix.thecave.buddi.plugin.api.exception.ModelException; |
| 15 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
| 16 | |
|
| 17 | |
import ca.digitalcave.moss.swing.MossFrame; |
| 18 | |
import ca.digitalcave.moss.swing.MossMenuItem; |
| 19 | |
|
| 20 | |
public class EditDeleteAccount extends MossMenuItem { |
| 21 | |
public static final long serialVersionUID = 0; |
| 22 | |
|
| 23 | |
public EditDeleteAccount(MossFrame frame) { |
| 24 | 29974 | super(frame, PrefsModel.getInstance().getTranslator().get(MenuKeys.MENU_EDIT_DELETE_ACCOUNTS)); |
| 25 | 29974 | } |
| 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 AccountFrame"); |
| 31 | |
|
| 32 | 0 | for (Account a : ((MainFrame) getFrame()).getSelectedAccounts()) { |
| 33 | |
try { |
| 34 | 0 | ((Document) ((MainFrame) getFrame()).getDocument()).removeAccount(a); |
| 35 | |
} |
| 36 | 0 | catch (ModelException me){ |
| 37 | |
try { |
| 38 | 0 | a.setDeleted(true); |
| 39 | |
} |
| 40 | 0 | catch (InvalidValueException ive){ |
| 41 | 0 | Logger.getLogger(this.getClass().getName()).warning("Error setting deleted flag on account"); |
| 42 | 0 | } |
| 43 | 0 | } |
| 44 | |
} |
| 45 | |
|
| 46 | 0 | ((MainFrame) getFrame()).fireStructureChanged(); |
| 47 | 0 | ((MainFrame) getFrame()).updateContent(); |
| 48 | 0 | } |
| 49 | |
|
| 50 | |
@Override |
| 51 | |
public void updateMenus() { |
| 52 | 169470 | super.updateMenus(); |
| 53 | |
|
| 54 | 169470 | this.setEnabled(((MainFrame) getFrame()).getSelectedAccounts().size() > 0); |
| 55 | 169470 | } |
| 56 | |
} |