KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > frame > AddressbookFrameController


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18

19 package org.columba.addressbook.gui.frame;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JScrollPane JavaDoc;
30 import javax.swing.event.ListSelectionEvent JavaDoc;
31 import javax.swing.event.ListSelectionListener JavaDoc;
32 import javax.swing.event.TreeSelectionEvent JavaDoc;
33 import javax.swing.event.TreeSelectionListener JavaDoc;
34
35 import org.columba.addressbook.config.AddressbookConfig;
36 import org.columba.addressbook.folder.AddressbookTreeNode;
37 import org.columba.addressbook.folder.IContactStorage;
38 import org.columba.addressbook.gui.table.FilterToolbar;
39 import org.columba.addressbook.gui.table.TableController;
40 import org.columba.addressbook.gui.tagging.ContactTagList;
41 import org.columba.addressbook.gui.tree.TreeController;
42 import org.columba.addressbook.model.IContactModel;
43 import org.columba.addressbook.util.AddressbookResourceLoader;
44 import org.columba.api.gui.frame.IContainer;
45 import org.columba.api.gui.frame.IDock;
46 import org.columba.api.gui.frame.IDockable;
47 import org.columba.core.config.ViewItem;
48 import org.columba.core.context.base.api.IStructureValue;
49 import org.columba.core.context.semantic.api.ISemanticContext;
50 import org.columba.core.gui.frame.DockFrameController;
51 import org.columba.core.gui.tagging.TagList;
52 import org.columba.core.gui.tagging.TagPopupMenu;
53 import org.columba.core.io.DiskIO;
54
55 /**
56  *
57  *
58  * @author fdietz
59  */

60 public class AddressbookFrameController extends DockFrameController implements
61         AddressbookFrameMediator, TreeSelectionListener JavaDoc, ListSelectionListener JavaDoc {
62
63     protected TreeController tree;
64
65     protected TableController table;
66
67     protected FilterToolbar filterToolbar;
68
69     private IDockable contactListPanel;
70
71     private IDockable treePanel;
72
73     private IDockable tagListDockable;
74
75     /**
76      * Constructor for AddressbookController.
77      */

78     public AddressbookFrameController(ViewItem viewItem) {
79         super(viewItem);
80
81         tree = new TreeController(this);
82         table = new TableController(this);
83         filterToolbar = new FilterToolbar(table);
84
85         // table should be updated when tree selection changes
86
tree.getView().addTreeSelectionListener(table);
87
88         // this is needed to update the titlebar
89
tree.getView().addTreeSelectionListener(this);
90
91         // getContainer().setContentPane(this);
92

93         registerDockables();
94
95         table.getView().getSelectionModel().addListSelectionListener(this);
96
97         // initPerspective(this.perspective);
98
}
99
100     private void registerDockables() {
101
102         JScrollPane JavaDoc treeScrollPane = new JScrollPane JavaDoc(tree.getView());
103         treeScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
104
105         treePanel = registerDockable("addressbook_foldertree",
106                 AddressbookResourceLoader.getString("global",
107                         "dockable_foldertree"), treeScrollPane, null);
108
109         JPanel JavaDoc p = new JPanel JavaDoc();
110         p.setLayout(new BorderLayout JavaDoc());
111         JScrollPane JavaDoc tableScrollPane = new JScrollPane JavaDoc(table.getView());
112         tableScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
113         p.add(tableScrollPane, BorderLayout.CENTER);
114         p.add(filterToolbar, BorderLayout.NORTH);
115
116         contactListPanel = registerDockable("addressbook_contactlist",
117                 AddressbookResourceLoader.getString("global",
118                         "dockable_contactlist"), p, null);
119
120 // TagList tagList = new ContactTagList(this);
121
// JScrollPane tagListScrollPane = new JScrollPane(tagList);
122
// tagListScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
123
// tagListScrollPane
124
// .setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
125

126 // tagListDockable = registerDockable("addressbook_taglist",
127
// AddressbookResourceLoader.getString("global",
128
// "dockable_taglist"), tagListScrollPane,
129
// new TagPopupMenu(this, tagList));
130
// tagList.setPopupMenu(new TagPopupMenu(this, tagList));
131

132     }
133
134     /**
135      * @return AddressbookTableController
136      */

137     public TableController getTable() {
138         return table;
139     }
140
141     /**
142      * @return AddressbookTreeController
143      */

144     public TreeController getTree() {
145         return tree;
146     }
147
148     /**
149      * @see org.columba.addressbook.gui.frame.AddressbookFrameMediator#addTableSelectionListener(javax.swing.event.ListSelectionListener)
150      */

151     public void addTableSelectionListener(ListSelectionListener JavaDoc listener) {
152         getTable().getView().getSelectionModel().addListSelectionListener(
153                 listener);
154     }
155
156     /**
157      * @see org.columba.addressbook.gui.frame.AddressbookFrameMediator#addTreeSelectionListener(javax.swing.event.TreeSelectionListener)
158      */

159     public void addTreeSelectionListener(TreeSelectionListener JavaDoc listener) {
160         getTree().getView().addTreeSelectionListener(listener);
161     }
162
163     /**
164      * @see org.columba.api.gui.frame.IFrameMediator#getString(java.lang.String,
165      * java.lang.String, java.lang.String)
166      */

167     public String JavaDoc getString(String JavaDoc sPath, String JavaDoc sName, String JavaDoc sID) {
168         return AddressbookResourceLoader.getString(sPath, sName, sID);
169     }
170
171     /**
172      * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
173      */

174     public void valueChanged(TreeSelectionEvent JavaDoc arg0) {
175         AddressbookTreeNode selectedFolder = (AddressbookTreeNode) arg0
176                 .getPath().getLastPathComponent();
177
178         if (selectedFolder != null) {
179             fireTitleChanged(selectedFolder.getName());
180         }
181     }
182
183     public void loadDefaultPosition() {
184         super.dock(contactListPanel, IDock.REGION.CENTER);
185         super.dock(treePanel, contactListPanel, IDock.REGION.WEST, 0.3f);
186
187         super.setSplitProportion(treePanel, 0.3f);
188         super.setSplitProportion(contactListPanel, 0.35f);
189     }
190
191     /** *********************** container callbacks ************* */
192
193     public void extendMenu(IContainer container) {
194         try {
195             InputStream JavaDoc is = DiskIO
196                     .getResourceStream("org/columba/addressbook/action/menu.xml");
197             container.extendMenu(this, is);
198
199         } catch (IOException JavaDoc e) {
200             e.printStackTrace();
201         }
202     }
203
204     public void extendToolBar(IContainer container) {
205         try {
206             File JavaDoc configDirectory = AddressbookConfig.getInstance()
207                     .getConfigDirectory();
208             InputStream JavaDoc is2 = new FileInputStream JavaDoc(new File JavaDoc(configDirectory,
209                     "main_toolbar.xml"));
210             container.extendToolbar(this, is2);
211         } catch (IOException JavaDoc e) {
212             e.printStackTrace();
213         }
214     }
215
216     public void valueChanged(ListSelectionEvent JavaDoc event) {
217         // return if selection change is in flux
218
if (event.getValueIsAdjusting()) {
219             return;
220         }
221
222         Object JavaDoc[] uids = getTable().getUids();
223
224         if (uids.length == 1) {
225             String JavaDoc id = (String JavaDoc) uids[0];
226
227             // get selected folder
228
IContactStorage store = getTree().getSelectedFolder();
229             if (store == null)
230                 return;
231             // retrieve contact model from folder
232
IContactModel model = store.get(id);
233             if (model == null)
234                 return;
235
236             String JavaDoc lastname = model.getFamilyName();
237             String JavaDoc firstname = model.getGivenName();
238             String JavaDoc displayname = model.getSortString();
239             String JavaDoc email = model.getPreferredEmail();
240
241             // create empty value
242
IStructureValue value = getSemanticContext().createValue();
243
244             // create identity value
245
IStructureValue identity = value.addChild(
246                     ISemanticContext.CONTEXT_NODE_IDENTITY,
247                     ISemanticContext.CONTEXT_NAMESPACE_CORE);
248             if (displayname.toString() != null)
249                 identity.setString(ISemanticContext.CONTEXT_ATTR_DISPLAY_NAME,
250                         ISemanticContext.CONTEXT_NAMESPACE_CORE, displayname);
251             if (email != null)
252                 identity.setString(ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
253                         ISemanticContext.CONTEXT_NAMESPACE_CORE, email);
254             if (firstname != null)
255                 identity.setString(ISemanticContext.CONTEXT_ATTR_FIRST_NAME,
256                         ISemanticContext.CONTEXT_NAMESPACE_CORE, firstname);
257             if (lastname != null)
258                 identity.setString(ISemanticContext.CONTEXT_ATTR_LAST_NAME,
259                         ISemanticContext.CONTEXT_NAMESPACE_CORE, lastname);
260         }
261     }
262
263 }
Popular Tags