001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018:
019: package org.columba.addressbook.gui.frame;
020:
021: import java.awt.BorderLayout;
022: import java.io.File;
023: import java.io.FileInputStream;
024: import java.io.IOException;
025: import java.io.InputStream;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.JPanel;
029: import javax.swing.JScrollPane;
030: import javax.swing.event.ListSelectionEvent;
031: import javax.swing.event.ListSelectionListener;
032: import javax.swing.event.TreeSelectionEvent;
033: import javax.swing.event.TreeSelectionListener;
034:
035: import org.columba.addressbook.config.AddressbookConfig;
036: import org.columba.addressbook.folder.AddressbookTreeNode;
037: import org.columba.addressbook.folder.IContactStorage;
038: import org.columba.addressbook.gui.table.FilterToolbar;
039: import org.columba.addressbook.gui.table.TableController;
040: import org.columba.addressbook.gui.tagging.ContactTagList;
041: import org.columba.addressbook.gui.tree.TreeController;
042: import org.columba.addressbook.model.IContactModel;
043: import org.columba.addressbook.util.AddressbookResourceLoader;
044: import org.columba.api.gui.frame.IContainer;
045: import org.columba.api.gui.frame.IDock;
046: import org.columba.api.gui.frame.IDockable;
047: import org.columba.core.config.ViewItem;
048: import org.columba.core.context.base.api.IStructureValue;
049: import org.columba.core.context.semantic.api.ISemanticContext;
050: import org.columba.core.gui.frame.DockFrameController;
051: import org.columba.core.gui.tagging.TagList;
052: import org.columba.core.gui.tagging.TagPopupMenu;
053: import org.columba.core.io.DiskIO;
054:
055: /**
056: *
057: *
058: * @author fdietz
059: */
060: public class AddressbookFrameController extends DockFrameController
061: implements AddressbookFrameMediator, TreeSelectionListener,
062: ListSelectionListener {
063:
064: protected TreeController tree;
065:
066: protected TableController table;
067:
068: protected FilterToolbar filterToolbar;
069:
070: private IDockable contactListPanel;
071:
072: private IDockable treePanel;
073:
074: private IDockable tagListDockable;
075:
076: /**
077: * Constructor for AddressbookController.
078: */
079: public AddressbookFrameController(ViewItem viewItem) {
080: super (viewItem);
081:
082: tree = new TreeController(this );
083: table = new TableController(this );
084: filterToolbar = new FilterToolbar(table);
085:
086: // table should be updated when tree selection changes
087: tree.getView().addTreeSelectionListener(table);
088:
089: // this is needed to update the titlebar
090: tree.getView().addTreeSelectionListener(this );
091:
092: // getContainer().setContentPane(this);
093:
094: registerDockables();
095:
096: table.getView().getSelectionModel().addListSelectionListener(
097: this );
098:
099: // initPerspective(this.perspective);
100: }
101:
102: private void registerDockables() {
103:
104: JScrollPane treeScrollPane = new JScrollPane(tree.getView());
105: treeScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0,
106: 0, 0));
107:
108: treePanel = registerDockable("addressbook_foldertree",
109: AddressbookResourceLoader.getString("global",
110: "dockable_foldertree"), treeScrollPane, null);
111:
112: JPanel p = new JPanel();
113: p.setLayout(new BorderLayout());
114: JScrollPane tableScrollPane = new JScrollPane(table.getView());
115: tableScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0,
116: 0, 0));
117: p.add(tableScrollPane, BorderLayout.CENTER);
118: p.add(filterToolbar, BorderLayout.NORTH);
119:
120: contactListPanel = registerDockable("addressbook_contactlist",
121: AddressbookResourceLoader.getString("global",
122: "dockable_contactlist"), p, null);
123:
124: // TagList tagList = new ContactTagList(this);
125: // JScrollPane tagListScrollPane = new JScrollPane(tagList);
126: // tagListScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
127: // tagListScrollPane
128: // .setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
129:
130: // tagListDockable = registerDockable("addressbook_taglist",
131: // AddressbookResourceLoader.getString("global",
132: // "dockable_taglist"), tagListScrollPane,
133: // new TagPopupMenu(this, tagList));
134: // tagList.setPopupMenu(new TagPopupMenu(this, tagList));
135:
136: }
137:
138: /**
139: * @return AddressbookTableController
140: */
141: public TableController getTable() {
142: return table;
143: }
144:
145: /**
146: * @return AddressbookTreeController
147: */
148: public TreeController getTree() {
149: return tree;
150: }
151:
152: /**
153: * @see org.columba.addressbook.gui.frame.AddressbookFrameMediator#addTableSelectionListener(javax.swing.event.ListSelectionListener)
154: */
155: public void addTableSelectionListener(ListSelectionListener listener) {
156: getTable().getView().getSelectionModel()
157: .addListSelectionListener(listener);
158: }
159:
160: /**
161: * @see org.columba.addressbook.gui.frame.AddressbookFrameMediator#addTreeSelectionListener(javax.swing.event.TreeSelectionListener)
162: */
163: public void addTreeSelectionListener(TreeSelectionListener listener) {
164: getTree().getView().addTreeSelectionListener(listener);
165: }
166:
167: /**
168: * @see org.columba.api.gui.frame.IFrameMediator#getString(java.lang.String,
169: * java.lang.String, java.lang.String)
170: */
171: public String getString(String sPath, String sName, String sID) {
172: return AddressbookResourceLoader.getString(sPath, sName, sID);
173: }
174:
175: /**
176: * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
177: */
178: public void valueChanged(TreeSelectionEvent arg0) {
179: AddressbookTreeNode selectedFolder = (AddressbookTreeNode) arg0
180: .getPath().getLastPathComponent();
181:
182: if (selectedFolder != null) {
183: fireTitleChanged(selectedFolder.getName());
184: }
185: }
186:
187: public void loadDefaultPosition() {
188: super .dock(contactListPanel, IDock.REGION.CENTER);
189: super
190: .dock(treePanel, contactListPanel, IDock.REGION.WEST,
191: 0.3f);
192:
193: super .setSplitProportion(treePanel, 0.3f);
194: super .setSplitProportion(contactListPanel, 0.35f);
195: }
196:
197: /** *********************** container callbacks ************* */
198:
199: public void extendMenu(IContainer container) {
200: try {
201: InputStream is = DiskIO
202: .getResourceStream("org/columba/addressbook/action/menu.xml");
203: container.extendMenu(this , is);
204:
205: } catch (IOException e) {
206: e.printStackTrace();
207: }
208: }
209:
210: public void extendToolBar(IContainer container) {
211: try {
212: File configDirectory = AddressbookConfig.getInstance()
213: .getConfigDirectory();
214: InputStream is2 = new FileInputStream(new File(
215: configDirectory, "main_toolbar.xml"));
216: container.extendToolbar(this , is2);
217: } catch (IOException e) {
218: e.printStackTrace();
219: }
220: }
221:
222: public void valueChanged(ListSelectionEvent event) {
223: // return if selection change is in flux
224: if (event.getValueIsAdjusting()) {
225: return;
226: }
227:
228: Object[] uids = getTable().getUids();
229:
230: if (uids.length == 1) {
231: String id = (String) uids[0];
232:
233: // get selected folder
234: IContactStorage store = getTree().getSelectedFolder();
235: if (store == null)
236: return;
237: // retrieve contact model from folder
238: IContactModel model = store.get(id);
239: if (model == null)
240: return;
241:
242: String lastname = model.getFamilyName();
243: String firstname = model.getGivenName();
244: String displayname = model.getSortString();
245: String email = model.getPreferredEmail();
246:
247: // create empty value
248: IStructureValue value = getSemanticContext().createValue();
249:
250: // create identity value
251: IStructureValue identity = value.addChild(
252: ISemanticContext.CONTEXT_NODE_IDENTITY,
253: ISemanticContext.CONTEXT_NAMESPACE_CORE);
254: if (displayname.toString() != null)
255: identity.setString(
256: ISemanticContext.CONTEXT_ATTR_DISPLAY_NAME,
257: ISemanticContext.CONTEXT_NAMESPACE_CORE,
258: displayname);
259: if (email != null)
260: identity.setString(
261: ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
262: ISemanticContext.CONTEXT_NAMESPACE_CORE, email);
263: if (firstname != null)
264: identity.setString(
265: ISemanticContext.CONTEXT_ATTR_FIRST_NAME,
266: ISemanticContext.CONTEXT_NAMESPACE_CORE,
267: firstname);
268: if (lastname != null)
269: identity.setString(
270: ISemanticContext.CONTEXT_ATTR_LAST_NAME,
271: ISemanticContext.CONTEXT_NAMESPACE_CORE,
272: lastname);
273: }
274: }
275:
276: }
|