01: package org.columba.addressbook.facade;
02:
03: import java.net.URI;
04:
05: import org.columba.addressbook.folder.AbstractFolder;
06: import org.columba.addressbook.folder.GroupFolder;
07: import org.columba.addressbook.folder.IContactFolder;
08: import org.columba.addressbook.gui.dialog.contact.ContactEditorDialog;
09: import org.columba.addressbook.gui.tree.AddressbookTreeModel;
10: import org.columba.addressbook.model.IContactModel;
11: import org.columba.api.gui.frame.IContainer;
12: import org.columba.api.gui.frame.IFrameMediator;
13: import org.columba.core.gui.dialog.ErrorDialog;
14: import org.columba.core.gui.frame.FrameManager;
15: import org.columba.core.logging.Logging;
16:
17: public class DialogFacade implements IDialogFacade {
18:
19: /**
20: * @see org.columba.addressbook.facade.IDialogFacade#openContactDialog(java.net.URI)
21: */
22: public void openContactDialog(URI location) {
23: // example: "columba://org.columba.contact/<folder-id>/<contact-id>"
24: String s = location.toString();
25:
26: // TODO: @author fdietz replace with regular expression
27: int index = s.lastIndexOf('/');
28: String contactId = s.substring(index + 1, s.length());
29: String folderId = s.substring(
30: s.lastIndexOf('/', index - 1) + 1, index);
31:
32: IContainer[] container = FrameManager.getInstance()
33: .getOpenFrames();
34: if (container == null || container.length == 0)
35: throw new RuntimeException("No frames available");
36:
37: IFrameMediator frameMediator = container[0].getFrameMediator();
38:
39: IContactFolder folder = (IContactFolder) AddressbookTreeModel
40: .getInstance().getFolder(folderId);
41:
42: IContactModel card = null;
43: try {
44: card = (IContactModel) folder.get(contactId);
45: } catch (Exception e) {
46: if (Logging.DEBUG)
47: e.printStackTrace();
48: ErrorDialog.createDialog(e.getMessage(), e);
49: }
50:
51: //
52: ContactEditorDialog dialog = new ContactEditorDialog(
53: frameMediator.getView().getFrame(), card);
54:
55: if (dialog.getResult()) {
56:
57: try {
58: // modify card properties in folder
59: folder.modify(contactId, dialog.getDestModel());
60: } catch (Exception e1) {
61: if (Logging.DEBUG)
62: e1.printStackTrace();
63:
64: ErrorDialog.createDialog(e1.getMessage(), e1);
65: }
66:
67: }
68: }
69: }
|