Source Code Cross Referenced for TableController.java in  » Mail-Clients » columba-1.4 » org » columba » addressbook » gui » table » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » columba 1.4 » org.columba.addressbook.gui.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        package org.columba.addressbook.gui.table;
019:
020:        import java.awt.event.MouseAdapter;
021:        import java.awt.event.MouseEvent;
022:
023:        import javax.swing.JComponent;
024:        import javax.swing.JTable;
025:        import javax.swing.event.TreeSelectionEvent;
026:        import javax.swing.event.TreeSelectionListener;
027:        import javax.swing.table.JTableHeader;
028:        import javax.swing.table.TableColumnModel;
029:
030:        import org.columba.addressbook.facade.IContactItem;
031:        import org.columba.addressbook.folder.AbstractFolder;
032:        import org.columba.addressbook.folder.AddressbookTreeNode;
033:        import org.columba.addressbook.folder.FolderListener;
034:        import org.columba.addressbook.folder.IContactStorage;
035:        import org.columba.addressbook.folder.IFolderEvent;
036:        import org.columba.addressbook.gui.focus.FocusManager;
037:        import org.columba.addressbook.gui.focus.FocusOwner;
038:        import org.columba.addressbook.gui.frame.AddressbookFrameMediator;
039:        import org.columba.addressbook.gui.table.model.AddressbookTableModel;
040:        import org.columba.addressbook.gui.table.model.FilterDecorator;
041:        import org.columba.addressbook.gui.table.model.SortDecorator;
042:        import org.columba.addressbook.model.IContactModelPartial;
043:        import org.columba.core.gui.dialog.ErrorDialog;
044:        import org.columba.core.logging.Logging;
045:
046:        /**
047:         * @author fdietz
048:         */
049:        public class TableController implements  TreeSelectionListener,
050:                FolderListener, FocusOwner {
051:
052:            private TableView view;
053:
054:            private AddressbookFrameMediator mediator;
055:
056:            private AddressbookTableModel addressbookModel;
057:
058:            private SortDecorator sortDecorator;
059:
060:            private FilterDecorator filterDecorator;
061:
062:            private AddressbookTreeNode selectedFolder;
063:
064:            /**
065:             * 
066:             */
067:            public TableController(AddressbookFrameMediator mediator) {
068:                super ();
069:
070:                this .mediator = mediator;
071:
072:                addressbookModel = new AddressbookTableModel();
073:
074:                sortDecorator = new SortDecorator(addressbookModel);
075:
076:                filterDecorator = new FilterDecorator(sortDecorator);
077:
078:                view = new TableView(this , filterDecorator);
079:
080:                addMouseListenerToHeaderInTable();
081:
082:                view.addMouseListener(new TableMouseListener(this ));
083:
084:                // register as focus owner
085:                FocusManager.getInstance().registerComponent(this );
086:
087:            }
088:
089:            /**
090:             * Add MouseListener to JTableHeader to sort table based on clicked column
091:             * header.
092:             * 
093:             */
094:            protected void addMouseListenerToHeaderInTable() {
095:                final JTable tableView = getView();
096:
097:                tableView.setColumnSelectionAllowed(false);
098:
099:                MouseAdapter listMouseListener = new MouseAdapter() {
100:                    public void mouseClicked(MouseEvent e) {
101:                        TableColumnModel columnModel = tableView
102:                                .getColumnModel();
103:                        int viewColumn = columnModel
104:                                .getColumnIndexAtX(e.getX());
105:                        int column = tableView
106:                                .convertColumnIndexToModel(viewColumn);
107:
108:                        if ((e.getClickCount() == 1) && (column != -1)) {
109:
110:                            if (sortDecorator.getSelectedColumn() == column)
111:                                sortDecorator.setSortOrder(!sortDecorator
112:                                        .isSortOrder());
113:
114:                            sortDecorator.sort(column);
115:
116:                        }
117:                    }
118:                };
119:
120:                JTableHeader th = tableView.getTableHeader();
121:                th.addMouseListener(listMouseListener);
122:            }
123:
124:            /**
125:             * @return AddressbookFrameController
126:             */
127:            public AddressbookFrameMediator getMediator() {
128:                return mediator;
129:            }
130:
131:            /**
132:             * @return TableView
133:             */
134:            public TableView getView() {
135:                return view;
136:            }
137:
138:            public void setSelectedFolder(IContactStorage store) {
139:                filterDecorator.setContactItemMap(((AbstractFolder) store)
140:                        .getContactItemMap());
141:            }
142:
143:            /**
144:             * Update table on tree selection changes.
145:             */
146:            public void valueChanged(TreeSelectionEvent e) {
147:                AddressbookTreeNode node = (AddressbookTreeNode) e.getPath()
148:                        .getLastPathComponent();
149:
150:                if (node == null) {
151:                    return;
152:                }
153:
154:                if (node instanceof  IContactStorage) {
155:                    try {
156:
157:                        ((AbstractFolder) node).removeFolderListener(this );
158:
159:                        selectedFolder = node;
160:                        ((AbstractFolder) node).addFolderListener(this );
161:
162:                        filterDecorator
163:                                .setContactItemMap(((AbstractFolder) selectedFolder)
164:                                        .getContactItemMap());
165:                    } catch (Exception e1) {
166:                        if (Logging.DEBUG)
167:                            e1.printStackTrace();
168:
169:                        ErrorDialog.createDialog(e1.getMessage(), e1);
170:                    }
171:                } else {
172:                    filterDecorator.setContactItemMap(null);
173:                }
174:            }
175:
176:            /**
177:             * Get selected uids.
178:             * 
179:             * @return
180:             */
181:            public String[] getUids() {
182:                int[] rows = getView().getSelectedRows();
183:                String[] uids = new String[rows.length];
184:
185:                IContactModelPartial item;
186:
187:                for (int i = 0; i < rows.length; i++) {
188:                    item = (IContactModelPartial) filterDecorator
189:                            .getContactItem(rows[i]);
190:                    uids[i] = item.getId();
191:                }
192:
193:                return uids;
194:            }
195:
196:            /**
197:             * @return Returns the addressbookModel.
198:             */
199:            public AddressbookTableModel getAddressbookModel() {
200:                return addressbookModel;
201:            }
202:
203:            public IContactItem getSelectedItem() {
204:                int row = getView().getSelectedRow();
205:                if (row == -1)
206:                    return null;
207:
208:                // we use the SortDecorator, because the indices are sorted
209:                IContactItem item = (IContactItem) sortDecorator
210:                        .getContactItem(row);
211:
212:                return item;
213:            }
214:
215:            /** ********************** FolderListener ***************** */
216:
217:            /**
218:             * @see org.columba.addressbook.folder.FolderListener#itemAdded(org.columba.addressbook.folder.FolderEvent)
219:             */
220:            public void itemAdded(IFolderEvent e) {
221:                getAddressbookModel().update();
222:
223:            }
224:
225:            /**
226:             * @see org.columba.addressbook.folder.FolderListener#itemChanged(org.columba.addressbook.folder.FolderEvent)
227:             */
228:            public void itemChanged(IFolderEvent e) {
229:                getAddressbookModel().update();
230:
231:            }
232:
233:            /**
234:             * @see org.columba.addressbook.folder.FolderListener#itemRemoved(org.columba.addressbook.folder.FolderEvent)
235:             */
236:            public void itemRemoved(IFolderEvent e) {
237:                getAddressbookModel().update();
238:
239:            }
240:
241:            /** ************* FocusOwner Implementation ****************** */
242:
243:            /**
244:             * @see org.columba.addressbook.gui.focus.FocusOwner#copy()
245:             */
246:            public void copy() {
247:
248:            }
249:
250:            /**
251:             * @see org.columba.addressbook.gui.focus.FocusOwner#cut()
252:             */
253:            public void cut() {
254:
255:            }
256:
257:            /**
258:             * @see org.columba.addressbook.gui.focus.FocusOwner#delete()
259:             */
260:            public void delete() {
261:
262:            }
263:
264:            /**
265:             * @see org.columba.addressbook.gui.focus.FocusOwner#getComponent()
266:             */
267:            public JComponent getComponent() {
268:                return getView();
269:            }
270:
271:            /**
272:             * @see org.columba.addressbook.gui.focus.FocusOwner#isCopyActionEnabled()
273:             */
274:            public boolean isCopyActionEnabled() {
275:
276:                return false;
277:            }
278:
279:            /**
280:             * @see org.columba.addressbook.gui.focus.FocusOwner#isCutActionEnabled()
281:             */
282:            public boolean isCutActionEnabled() {
283:
284:                return false;
285:            }
286:
287:            /**
288:             * @see org.columba.addressbook.gui.focus.FocusOwner#isDeleteActionEnabled()
289:             */
290:            public boolean isDeleteActionEnabled() {
291:
292:                return false;
293:            }
294:
295:            /**
296:             * @see org.columba.addressbook.gui.focus.FocusOwner#isPasteActionEnabled()
297:             */
298:            public boolean isPasteActionEnabled() {
299:
300:                return false;
301:            }
302:
303:            /**
304:             * @see org.columba.addressbook.gui.focus.FocusOwner#isRedoActionEnabled()
305:             */
306:            public boolean isRedoActionEnabled() {
307:
308:                return false;
309:            }
310:
311:            /**
312:             * @see org.columba.addressbook.gui.focus.FocusOwner#isSelectAllActionEnabled()
313:             */
314:            public boolean isSelectAllActionEnabled() {
315:                if (getView().getRowCount() > 0) {
316:                    return true;
317:                }
318:
319:                return false;
320:            }
321:
322:            /**
323:             * @see org.columba.addressbook.gui.focus.FocusOwner#isUndoActionEnabled()
324:             */
325:            public boolean isUndoActionEnabled() {
326:
327:                return false;
328:            }
329:
330:            /**
331:             * @see org.columba.addressbook.gui.focus.FocusOwner#paste()
332:             */
333:            public void paste() {
334:
335:            }
336:
337:            /**
338:             * @see org.columba.addressbook.gui.focus.FocusOwner#redo()
339:             */
340:            public void redo() {
341:
342:            }
343:
344:            /**
345:             * @see org.columba.addressbook.gui.focus.FocusOwner#selectAll()
346:             */
347:            public void selectAll() {
348:                getView().selectAll();
349:            }
350:
351:            /**
352:             * @see org.columba.addressbook.gui.focus.FocusOwner#undo()
353:             */
354:            public void undo() {
355:
356:            }
357:
358:            /**
359:             * @return Returns the sortDecorator.
360:             */
361:            public SortDecorator getSortDecorator() {
362:                return sortDecorator;
363:            }
364:
365:            /**
366:             * @return Returns the filterDecorator.
367:             */
368:            public FilterDecorator getFilterDecorator() {
369:                return filterDecorator;
370:            }
371:
372:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.