01: package org.columba.mail.gui.config.account;
02:
03: import java.awt.event.ActionEvent;
04: import java.awt.event.ItemEvent;
05: import java.awt.event.ItemListener;
06: import java.io.File;
07: import java.util.Observable;
08: import java.util.Observer;
09:
10: import org.columba.api.gui.frame.IFrameMediator;
11: import org.columba.core.desktop.ColumbaDesktop;
12: import org.columba.core.gui.action.AbstractColumbaAction;
13: import org.columba.mail.config.AccountItem;
14: import org.columba.mail.config.Identity;
15: import org.columba.mail.gui.composer.ComposerController;
16: import org.columba.mail.util.MailResourceLoader;
17:
18: public class EditSignatureAction extends AbstractColumbaAction
19: implements Observer, ItemListener {
20:
21: private Identity identity;
22: private ComposerController composerController;
23:
24: public EditSignatureAction(IFrameMediator frameMediator) {
25: super (frameMediator, MailResourceLoader.getString("dialog",
26: "account", "editsignature"));
27:
28: composerController = (ComposerController) getFrameMediator();
29:
30: composerController.getAccountController().getView()
31: .addItemListener(this );
32:
33: identity = composerController.getModel().getAccountItem()
34: .getIdentity();
35:
36: setEnabled(identity.getSignature() != null
37: && ColumbaDesktop.getInstance().supportsOpen());
38: identity.addObserver(this );
39: }
40:
41: public EditSignatureAction(IFrameMediator frameMediator,
42: AccountItem item) {
43: super (frameMediator, MailResourceLoader.getString("dialog",
44: "account", "editsignature"));
45:
46: identity = item.getIdentity();
47: }
48:
49: public void actionPerformed(ActionEvent e) {
50: File signature = identity.getSignature();
51: if (signature == null) {
52: //Create the file
53: signature = new File(System.getProperty("user.home"),
54: ".signature");
55: }
56:
57: ColumbaDesktop.getInstance().openAndWait(signature);
58:
59: // update signature -> will notify all listeners that signature changed
60: identity.setSignature(signature);
61: }
62:
63: public void update(Observable o, Object arg) {
64: setEnabled(arg != null
65: && ColumbaDesktop.getInstance().supportsOpen());
66: }
67:
68: public void itemStateChanged(ItemEvent e) {
69: identity.removeObserver(this );
70:
71: if (e.getStateChange() == ItemEvent.SELECTED) {
72: AccountItem item = (AccountItem) composerController
73: .getAccountController().getView().getSelectedItem();
74: identity = item.getIdentity();
75:
76: setEnabled(identity.getSignature() != null
77: && ColumbaDesktop.getInstance().supportsOpen());
78: identity.addObserver(this);
79: }
80:
81: }
82:
83: }
|