001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo
013: // Stich.
014: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
015: //
016: //All Rights Reserved.
017: package org.columba.addressbook.facade;
018:
019: import java.util.List;
020: import java.util.Vector;
021:
022: import org.columba.addressbook.folder.AbstractFolder;
023: import org.columba.addressbook.gui.tree.AddressbookTreeModel;
024:
025: /**
026: * Provides access to contact and group folders.
027: *
028: * @author fdietz
029: */
030: public class FolderFacade implements IFolderFacade {
031:
032: /**
033: * @see org.columba.addressbook.facade.IFolderFacade#getFolder(int)
034: */
035: public IFolder getFolder(String uid) {
036: return (IFolder) AddressbookTreeModel.getInstance().getFolder(
037: uid);
038: }
039:
040: /**
041: * @see org.columba.addressbook.facade.IFolderFacade#getCollectedAddresses()
042: */
043: public IFolder getCollectedAddresses() {
044: AddressbookTreeModel model = AddressbookTreeModel.getInstance();
045: if (model != null)
046: return (AbstractFolder) model.getFolder("102");
047:
048: return null;
049: }
050:
051: /**
052: * @see org.columba.addressbook.facade.IFolderFacade#getLocalAddressbook()
053: */
054: public IFolder getLocalAddressbook() {
055: AddressbookTreeModel model = AddressbookTreeModel.getInstance();
056: if (model != null)
057: return (AbstractFolder) model.getFolder("101");
058:
059: return null;
060: }
061:
062: /**
063: * @see org.columba.addressbook.facade.IFolderFacade#getFolderByName(java.lang.String)
064: */
065: public IFolder getFolderByName(String name) {
066: AddressbookTreeModel model = AddressbookTreeModel.getInstance();
067: if (model != null)
068: return (AbstractFolder) model.getFolderByName(name);
069:
070: return null;
071: }
072:
073: /**
074: * @see org.columba.addressbook.facade.IFolderFacade#getAllFolders()
075: */
076: public List<IFolder> getAllFolders() {
077: AddressbookTreeModel model = AddressbookTreeModel.getInstance();
078: Vector<IFolder> v = new Vector<IFolder>();
079:
080: Object parent = model.getRoot();
081:
082: getChildren(model, parent, v);
083:
084: return v;
085: }
086:
087: private void getChildren(AddressbookTreeModel model, Object parent,
088: Vector<IFolder> v) {
089: int childCount = model.getChildCount(parent);
090: for (int i = 0; i < childCount; i++) {
091: Object child = model.getChild(parent, i);
092: v.add((IFolder) child);
093:
094: getChildren(model, child, v);
095: }
096: }
097:
098: /**
099: * @see org.columba.addressbook.facade.IFolderFacade#getRootFolder()
100: */
101: public IFolder getRootFolder() {
102: AddressbookTreeModel model = AddressbookTreeModel.getInstance();
103: return (IFolder) model.getRoot();
104: }
105: }
|