001: package org.columba.mail.facade;
002:
003: import java.net.URI;
004:
005: import org.columba.api.gui.frame.IContainer;
006: import org.columba.api.gui.frame.IFrameMediator;
007: import org.columba.core.command.CommandProcessor;
008: import org.columba.core.gui.frame.DefaultContainer;
009: import org.columba.core.gui.frame.FrameManager;
010: import org.columba.mail.command.IMailFolderCommandReference;
011: import org.columba.mail.command.MailFolderCommandReference;
012: import org.columba.mail.folder.IMailbox;
013: import org.columba.mail.gui.composer.ComposerController;
014: import org.columba.mail.gui.composer.ComposerModel;
015: import org.columba.mail.gui.frame.ThreePaneMailFrameController;
016: import org.columba.mail.gui.message.command.ViewMessageCommand;
017: import org.columba.mail.gui.messageframe.MessageFrameController;
018: import org.columba.mail.gui.tree.FolderTreeModel;
019: import org.columba.ristretto.message.Address;
020:
021: public class DialogFacade implements IDialogFacade {
022:
023: public DialogFacade() {
024: super ();
025: }
026:
027: /**
028: * @see org.columba.mail.facade.IDialogFacade#openComposer()
029: */
030: public void openComposer() {
031: // Choice btw. text and html will be based on stored option
032: ComposerController controller = new ComposerController();
033: new DefaultContainer(controller);
034:
035: // model -> view
036: controller.updateComponents(true);
037: }
038:
039: /**
040: * @see org.columba.mail.facade.IDialogFacade#openMessage(java.net.URI)
041: */
042: public void openMessage(URI location) {
043: // example: "columba://org.columba.mail/<folder-id>/<message-id>"
044: String s = location.toString();
045:
046: // TODO: @author fdietz replace with regular expression
047: int index = s.lastIndexOf('/');
048: String messageId = s.substring(index + 1, s.length());
049: String folderId = s.substring(
050: s.lastIndexOf('/', index - 1) + 1, index);
051:
052: IContainer[] container = FrameManager.getInstance()
053: .getOpenFrames();
054: if (container == null || container.length == 0)
055: throw new RuntimeException("No frames available");
056:
057: IFrameMediator mailFrameMediator = null;
058: for (int i = 0; i < container.length; i++) {
059: IFrameMediator mediator = container[i].getFrameMediator();
060: if (mediator.getId().equals("ThreePaneMail")) {
061: // found mail component frame
062: mailFrameMediator = mediator;
063: }
064: }
065:
066: if (mailFrameMediator == null)
067: throw new RuntimeException("No mail frame mediator found");
068:
069: // type-cast here is safe
070: MessageFrameController c = new MessageFrameController(
071: (ThreePaneMailFrameController) mailFrameMediator);
072: new DefaultContainer(c);
073:
074: IMailbox folder = (IMailbox) FolderTreeModel.getInstance()
075: .getFolder(folderId);
076: IMailFolderCommandReference r = new MailFolderCommandReference(
077: folder, new Object[] { Integer.parseInt(messageId) });
078:
079: c.setTreeSelection(r);
080:
081: c.setTableSelection(r);
082:
083: CommandProcessor.getInstance().addOp(
084: new ViewMessageCommand(c, r));
085: }
086:
087: public void openComposer(String contact) {
088: // Choice btw. text and html will be based on stored option
089: ComposerController controller = new ComposerController();
090: new DefaultContainer(controller);
091: ComposerModel model = controller.getModel();
092: Address adr = new Address(contact);
093: model.setTo(new Address[] { adr });
094: // model -> view
095: controller.updateComponents(true);
096: }
097:
098: public void openComposer(String[] recipients) {
099: // Choice btw. text and html will be based on stored option
100: ComposerController controller = new ComposerController();
101: new DefaultContainer(controller);
102: ComposerModel model = controller.getModel();
103: Address[] adr = new Address[recipients.length];
104: for (int i = 0; i < recipients.length; i++) {
105: adr[i] = new Address(recipients[i]);
106: }
107:
108: model.setTo(adr);
109: // model -> view
110: controller.updateComponents(true);
111: }
112:
113: }
|