Source Code Cross Referenced for CollaboratorsUI.java in  » Project-Management » Activity-Manager » jfb » tools » activitymgr » ui » 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 » Project Management » Activity Manager » jfb.tools.activitymgr.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2004-2006, Jean-François Brazeau. All rights reserved.
003:         * 
004:         * Redistribution and use in source and binary forms, with or without 
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         *  1. Redistributions of source code must retain the above copyright notice,
008:         *     this list of conditions and the following disclaimer.
009:         * 
010:         *  2. Redistributions in binary form must reproduce the above copyright
011:         *     notice, this list of conditions and the following disclaimer in the
012:         *     documentation and/or other materials provided with the distribution.
013:         * 
014:         *  3. The name of the author may not be used to endorse or promote products
015:         *     derived from this software without specific prior written permission.
016:         *
017:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
018:         * IMPLIEDWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
019:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
020:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
021:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
022:         * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
023:         * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
024:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
025:         * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
026:         * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027:         */
028:        package jfb.tools.activitymgr.ui;
029:
030:        import java.util.ArrayList;
031:        import java.util.Arrays;
032:        import java.util.Iterator;
033:
034:        import jfb.tools.activitymgr.core.ModelMgr;
035:        import jfb.tools.activitymgr.core.beans.Collaborator;
036:        import jfb.tools.activitymgr.ui.DatabaseUI.IDbStatusListener;
037:        import jfb.tools.activitymgr.ui.dialogs.ContributionsViewerDialog;
038:        import jfb.tools.activitymgr.ui.images.ImagesDatas;
039:        import jfb.tools.activitymgr.ui.util.AbstractTableMgr;
040:        import jfb.tools.activitymgr.ui.util.SWTHelper;
041:        import jfb.tools.activitymgr.ui.util.SafeRunner;
042:        import jfb.tools.activitymgr.ui.util.TableOrTreeColumnsMgr;
043:        import jfb.tools.activitymgr.ui.util.UITechException;
044:
045:        import org.apache.log4j.Logger;
046:        import org.eclipse.jface.viewers.CellEditor;
047:        import org.eclipse.jface.viewers.CheckboxCellEditor;
048:        import org.eclipse.jface.viewers.IBaseLabelProvider;
049:        import org.eclipse.jface.viewers.ICellModifier;
050:        import org.eclipse.jface.viewers.LabelProviderChangedEvent;
051:        import org.eclipse.jface.viewers.StructuredSelection;
052:        import org.eclipse.jface.viewers.TableViewer;
053:        import org.eclipse.jface.viewers.TextCellEditor;
054:        import org.eclipse.swt.SWT;
055:        import org.eclipse.swt.events.MenuEvent;
056:        import org.eclipse.swt.events.MenuListener;
057:        import org.eclipse.swt.events.SelectionEvent;
058:        import org.eclipse.swt.events.SelectionListener;
059:        import org.eclipse.swt.graphics.Image;
060:        import org.eclipse.swt.layout.GridData;
061:        import org.eclipse.swt.layout.GridLayout;
062:        import org.eclipse.swt.widgets.Composite;
063:        import org.eclipse.swt.widgets.Event;
064:        import org.eclipse.swt.widgets.Listener;
065:        import org.eclipse.swt.widgets.Menu;
066:        import org.eclipse.swt.widgets.MenuItem;
067:        import org.eclipse.swt.widgets.TabItem;
068:        import org.eclipse.swt.widgets.Table;
069:        import org.eclipse.swt.widgets.TableColumn;
070:        import org.eclipse.swt.widgets.TableItem;
071:
072:        /**
073:         * IHM de gestion des collaborateurs.
074:         */
075:        public class CollaboratorsUI extends AbstractTableMgr implements 
076:                IDbStatusListener, ICellModifier, SelectionListener,
077:                MenuListener {
078:
079:            /** Logger */
080:            private static Logger log = Logger.getLogger(CollaboratorsUI.class);
081:
082:            /** Constantes associées aux colonnes */
083:            public static final int IS_ACTIVE_COLUMN_IDX = 0;
084:            public static final int IDENTIFIER_COLUMN_IDX = 1;
085:            public static final int FIRST_NAME_COLUMN_IDX = 2;
086:            public static final int LAST_NAME_COLUMN_IDX = 3;
087:            private static TableOrTreeColumnsMgr tableColsMgr;
088:
089:            /**
090:             * Interface utilisée pour permettre l'écoute de la suppression ou de
091:             * l'ajout de collaborateurs.
092:             */
093:            public static interface ICollaboratorListener {
094:
095:                /**
096:                 * Indique qu'un collaborateur a été ajouté au référentiel.
097:                 * @param collaborator le collaborateur ajouté.
098:                 */
099:                public void collaboratorAdded(Collaborator collaborator);
100:
101:                /**
102:                 * Indique qu'un collaborateur a été supprimé du référentiel.
103:                 * @param collaborator le collaborateur supprimé.
104:                 */
105:                public void collaboratorRemoved(Collaborator collaborator);
106:
107:                /**
108:                 * Indique qu'un collaborateur a été modifié du référentiel.
109:                 * @param collaborator le collaborateur modifié.
110:                 */
111:                public void collaboratorUpdated(Collaborator collaborator);
112:
113:                /**
114:                 * Indique que l'état d'activation d'un collaborateur a été désactivé dans le référentiel.
115:                 * @param collaborator le collaborateur modifié.
116:                 */
117:                public void collaboratorActivationStatusChanged(
118:                        Collaborator collaborator);
119:
120:            }
121:
122:            /** Listeners */
123:            private ArrayList listeners = new ArrayList();
124:
125:            /** Viewer */
126:            private TableViewer tableViewer;
127:
128:            /** Items de menu */
129:            private MenuItem newItem;
130:            private MenuItem removeItem;
131:            private MenuItem listTaskContributionsItem;
132:            private MenuItem exportItem;
133:
134:            /** Composant parent */
135:            private Composite parent;
136:
137:            /** Popup permettant de lister les contributions d'une tache */
138:            private ContributionsViewerDialog contribsViewerDialog;
139:
140:            /** Index de la colonne utilisé pour trier les collaborateurs */
141:            private int sortColumnIndex = LAST_NAME_COLUMN_IDX;
142:
143:            /** Icone utilisé pour marquer le collaborateur actifs */
144:            private Image checkedIcon;
145:
146:            /** Icone utilisé pour les collaborateurs non actifs */
147:            private Image uncheckedIcon;
148:
149:            /**
150:             * Constructeur permettant de placer l'IHM dans un onglet.
151:             * @param tabItem item parent.
152:             */
153:            public CollaboratorsUI(TabItem tabItem) {
154:                this (tabItem.getParent());
155:                tabItem.setControl(parent);
156:            }
157:
158:            /**
159:             * Constructeur par défaut.
160:             * @param parentComposite composant parent.
161:             */
162:            public CollaboratorsUI(Composite parentComposite) {
163:                // Création du composite parent
164:                parent = new Composite(parentComposite, SWT.NONE);
165:                parent.setLayout(new GridLayout(1, false));
166:
167:                // Table
168:                final Table table = new Table(parent, SWT.MULTI
169:                        | SWT.FULL_SELECTION | SWT.BORDER | SWT.HIDE_SELECTION);
170:                GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
171:                gridData.heightHint = 75;
172:                table.setLayoutData(gridData);
173:                table.setLinesVisible(true);
174:                table.setHeaderVisible(true);
175:                table.setEnabled(true);
176:                table
177:                        .setToolTipText("Use the first column to activate or disactivate the collaborators\n"
178:                                + "(disactivated collaborators are not deleted from the database but are hidden\n"
179:                                + "in the contributions tab)");
180:
181:                // Création du viewer
182:                tableViewer = new TableViewer(table);
183:                tableViewer.setCellModifier(this );
184:                tableViewer.setContentProvider(this );
185:                tableViewer.setLabelProvider(this );
186:
187:                // Configuration des colonnes
188:                tableColsMgr = new TableOrTreeColumnsMgr();
189:                tableColsMgr.addColumn("IS_ACTIVE", "!", 20, SWT.CENTER);
190:                tableColsMgr.addColumn("IDENTIFIER", "Identifier", 100,
191:                        SWT.LEFT);
192:                tableColsMgr.addColumn("FIRST_NAME", "First name", 100,
193:                        SWT.LEFT);
194:                tableColsMgr.addColumn("LAST_NAME", "Last name", 100, SWT.LEFT);
195:                tableColsMgr.configureTable(tableViewer);
196:
197:                // Ajout du listener de gestion du tri des colonnes
198:                // Add sort indicator and sort data when column selected
199:                Listener sortListener = new Listener() {
200:                    public void handleEvent(Event e) {
201:                        log.debug("handleEvent(" + e + ")");
202:                        TableColumn previousSortColumn = table.getSortColumn();
203:                        TableColumn newSortColumn = (TableColumn) e.widget;
204:                        int dir = table.getSortDirection();
205:                        if (previousSortColumn == newSortColumn) {
206:                            dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
207:                        } else {
208:                            table.setSortColumn(newSortColumn);
209:                            dir = SWT.UP;
210:                        }
211:                        table.setSortDirection(dir);
212:                        sortColumnIndex = Arrays.asList(table.getColumns())
213:                                .indexOf(newSortColumn);
214:                        // Rafraichissement des données
215:                        tableViewer.refresh();
216:                    }
217:                };
218:                table.getColumns()[IS_ACTIVE_COLUMN_IDX].addListener(
219:                        SWT.Selection, sortListener);
220:                table.getColumns()[IDENTIFIER_COLUMN_IDX].addListener(
221:                        SWT.Selection, sortListener);
222:                table.getColumns()[FIRST_NAME_COLUMN_IDX].addListener(
223:                        SWT.Selection, sortListener);
224:                table.getColumns()[LAST_NAME_COLUMN_IDX].addListener(
225:                        SWT.Selection, sortListener);
226:                table.setSortColumn(table.getColumns()[sortColumnIndex]);
227:                table.setSortDirection(SWT.UP);
228:
229:                // Configuration des éditeurs de cellules
230:                CellEditor[] editors = new CellEditor[9];
231:                editors[IS_ACTIVE_COLUMN_IDX] = new CheckboxCellEditor(table);
232:                editors[IDENTIFIER_COLUMN_IDX] = new TextCellEditor(table);
233:                editors[FIRST_NAME_COLUMN_IDX] = new TextCellEditor(table);
234:                editors[LAST_NAME_COLUMN_IDX] = new TextCellEditor(table);
235:                tableViewer.setCellEditors(editors);
236:
237:                // Initialisation des popups
238:                contribsViewerDialog = new ContributionsViewerDialog(parent
239:                        .getShell());
240:
241:                // Configuration du menu popup
242:                final Menu menu = new Menu(table);
243:                menu.addMenuListener(this );
244:                newItem = new MenuItem(menu, SWT.CASCADE);
245:                newItem.setText("New collaborator");
246:                newItem.addSelectionListener(this );
247:                removeItem = new MenuItem(menu, SWT.CASCADE);
248:                removeItem.setText("Remove");
249:                removeItem.addSelectionListener(this );
250:                listTaskContributionsItem = new MenuItem(menu, SWT.CASCADE);
251:                listTaskContributionsItem.setText("List contrib.");
252:                listTaskContributionsItem.addSelectionListener(this );
253:                exportItem = new MenuItem(menu, SWT.CASCADE);
254:                exportItem.setText("Export");
255:                exportItem.addSelectionListener(this );
256:                table.setMenu(menu);
257:
258:                // Chargement des icones
259:                checkedIcon = new Image(parentComposite.getDisplay(),
260:                        ImagesDatas.CHECKED_ICON);
261:                uncheckedIcon = new Image(parentComposite.getDisplay(),
262:                        ImagesDatas.UNCHECKED_ICON);
263:            }
264:
265:            /* (non-Javadoc)
266:             * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
267:             */
268:            public Object[] getElements(Object inputElement) {
269:                // Chargement des données
270:                SafeRunner safeRunner = new SafeRunner() {
271:                    public Object runUnsafe() throws Exception {
272:                        // Recherche des collaborateurs 
273:                        int orderByFieldIndex = -1;
274:                        switch (sortColumnIndex) {
275:                        case IS_ACTIVE_COLUMN_IDX:
276:                            orderByFieldIndex = Collaborator.IS_ACTIVE_FIELD_IDX;
277:                            break;
278:                        case IDENTIFIER_COLUMN_IDX:
279:                            orderByFieldIndex = Collaborator.LOGIN_FIELD_IDX;
280:                            break;
281:                        case FIRST_NAME_COLUMN_IDX:
282:                            orderByFieldIndex = Collaborator.FIRST_NAME_FIELD_IDX;
283:                            break;
284:                        case LAST_NAME_COLUMN_IDX:
285:                        default:
286:                            orderByFieldIndex = Collaborator.LAST_NAME_FIELD_IDX;
287:                            break;
288:                        }
289:                        // Récupération
290:                        return ModelMgr
291:                                .getCollaborators(orderByFieldIndex,
292:                                        tableViewer.getTable()
293:                                                .getSortDirection() == SWT.UP);
294:                    }
295:                };
296:                // Exécution
297:                Object result = (Object) safeRunner.run(parent.getShell());
298:                return (Collaborator[]) (result != null ? result
299:                        : new Collaborator[] {});
300:            }
301:
302:            /* (non-Javadoc)
303:             * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
304:             */
305:            public boolean canModify(Object element, String property) {
306:                log.debug("ICellModifier.canModify(" + element + ", "
307:                        + property + ")");
308:                return true;
309:            }
310:
311:            /* (non-Javadoc)
312:             * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
313:             */
314:            public Object getValue(final Object element, final String property) {
315:                log.debug("ICellModifier.getValue(" + element + ", " + property
316:                        + ")");
317:                SafeRunner safeRunner = new SafeRunner() {
318:                    public Object runUnsafe() throws Exception {
319:                        Collaborator collaborator = (Collaborator) element;
320:                        Object value = null;
321:                        int columnIndex = tableColsMgr.getColumnIndex(property);
322:                        switch (columnIndex) {
323:                        case (IS_ACTIVE_COLUMN_IDX):
324:                            value = collaborator.getIsActive() ? Boolean.TRUE
325:                                    : Boolean.FALSE;
326:                            break;
327:                        case (IDENTIFIER_COLUMN_IDX):
328:                            value = collaborator.getLogin();
329:                            break;
330:                        case (FIRST_NAME_COLUMN_IDX):
331:                            value = collaborator.getFirstName();
332:                            break;
333:                        case (LAST_NAME_COLUMN_IDX):
334:                            value = collaborator.getLastName();
335:                            break;
336:                        default:
337:                            throw new Error("Colonne inconnue");
338:                        }
339:                        return value;
340:                    }
341:                };
342:                // Exécution
343:                return safeRunner.run(parent.getShell(), "");
344:            }
345:
346:            /* (non-Javadoc)
347:             * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
348:             */
349:            public void modify(final Object element, final String property,
350:                    final Object value) {
351:                log.debug("ICellModifier.modify(" + element + ", " + property
352:                        + ", " + value + ")");
353:                TableItem item = (TableItem) element;
354:                final Collaborator collaborator = (Collaborator) item.getData();
355:                final IBaseLabelProvider labelProvider = this ;
356:                final int columnIndex = tableColsMgr.getColumnIndex(property);
357:                SafeRunner safeRunner = new SafeRunner() {
358:                    public Object runUnsafe() throws Exception {
359:                        boolean mustNotifyUpdateEvent = false;
360:                        boolean mustNotifyActivationStatusChangeEvent = false;
361:                        switch (columnIndex) {
362:                        case (IS_ACTIVE_COLUMN_IDX):
363:                            Boolean isActive = (Boolean) value;
364:                            collaborator.setIsActive(isActive.booleanValue());
365:                            mustNotifyActivationStatusChangeEvent = true;
366:                            break;
367:                        case (IDENTIFIER_COLUMN_IDX):
368:                            String newIdentifier = (String) value;
369:                            if (!collaborator.getLogin().equals(newIdentifier)) {
370:                                collaborator.setLogin(newIdentifier);
371:                            }
372:                            mustNotifyUpdateEvent = true;
373:                            break;
374:                        case (FIRST_NAME_COLUMN_IDX):
375:                            collaborator.setFirstName((String) value);
376:                            mustNotifyUpdateEvent = true;
377:                            break;
378:                        case (LAST_NAME_COLUMN_IDX):
379:                            collaborator.setLastName((String) value);
380:                            mustNotifyUpdateEvent = true;
381:                            break;
382:                        default:
383:                            throw new UITechException("Colonne inconnue");
384:                        }
385:                        // Mise à jour en base
386:                        ModelMgr.updateCollaborator(collaborator);
387:                        // Notification des listeners
388:                        notifyLabelProviderListener(new LabelProviderChangedEvent(
389:                                labelProvider, collaborator));
390:                        if (mustNotifyUpdateEvent)
391:                            notifyCollaboratorUpdated(collaborator);
392:                        if (mustNotifyActivationStatusChangeEvent)
393:                            notifyCollaboratorActivationStatusChanged(collaborator);
394:                        return null;
395:                    }
396:                };
397:                // Exécution
398:                safeRunner.run(parent.getShell());
399:            }
400:
401:            /* (non-Javadoc)
402:             * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
403:             */
404:            public String getColumnText(final Object element,
405:                    final int columnIndex) {
406:                log.debug("ITableLabelProvider.getColumnText(" + element + ", "
407:                        + columnIndex + ")");
408:                SafeRunner safeRunner = new SafeRunner() {
409:                    public Object runUnsafe() throws Exception {
410:                        Collaborator collaborator = (Collaborator) element;
411:                        String text = null;
412:                        switch (columnIndex) {
413:                        case (IS_ACTIVE_COLUMN_IDX):
414:                            text = ""; // La colonne est renseignée par une icone
415:                            break;
416:                        case (IDENTIFIER_COLUMN_IDX):
417:                            text = collaborator.getLogin();
418:                            break;
419:                        case (FIRST_NAME_COLUMN_IDX):
420:                            text = collaborator.getFirstName();
421:                            break;
422:                        case (LAST_NAME_COLUMN_IDX):
423:                            text = collaborator.getLastName();
424:                            break;
425:                        default:
426:                            throw new Error("Colonne inconnue");
427:                        }
428:                        return text;
429:                    }
430:                };
431:                // Exécution
432:                return (String) safeRunner.run(parent.getShell(), "");
433:            }
434:
435:            /* (non-Javadoc)
436:             * @see jfb.tools.activitymgr.ui.util.AbstractTableMgr#getColumnImage(java.lang.Object, int)
437:             */
438:            public Image getColumnImage(final Object element,
439:                    final int columnIndex) {
440:                log.debug("ITableLabelProvider.getColumnImage(" + element
441:                        + ", " + columnIndex + ")");
442:                SafeRunner safeRunner = new SafeRunner() {
443:                    public Object runUnsafe() throws Exception {
444:                        Collaborator collaborator = (Collaborator) element;
445:                        Image image = null;
446:                        switch (columnIndex) {
447:                        case (IS_ACTIVE_COLUMN_IDX):
448:                            image = collaborator.getIsActive() ? checkedIcon
449:                                    : uncheckedIcon;
450:                            break;
451:                        case (IDENTIFIER_COLUMN_IDX):
452:                        case (FIRST_NAME_COLUMN_IDX):
453:                        case (LAST_NAME_COLUMN_IDX):
454:                            image = null;
455:                            break;
456:                        default:
457:                            throw new Error("Colonne inconnue");
458:                        }
459:                        return image;
460:                    }
461:                };
462:                // Exécution
463:                return (Image) safeRunner.run(parent.getShell());
464:            }
465:
466:            /* (non-Javadoc)
467:             * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
468:             */
469:            public void widgetSelected(final SelectionEvent e) {
470:                log.debug("SelectionListener.widgetSelected(" + e + ")");
471:                log.debug("   e.source=" + e.getSource() + ")");
472:                final Object source = e.getSource();
473:                SafeRunner safeRunner = new SafeRunner() {
474:                    public Object runUnsafe() throws Exception {
475:                        TableItem[] selection = tableViewer.getTable()
476:                                .getSelection();
477:                        // Cas d'une création
478:                        if (newItem.equals(source)) {
479:                            Collaborator newCollaborator = ModelMgr
480:                                    .createNewCollaborator();
481:                            newLine(newCollaborator);
482:                            // Notification des listeners
483:                            notifyCollaboratorAdded(newCollaborator);
484:                        }
485:                        // Cas d'une suppression
486:                        else if (removeItem.equals(source)) {
487:                            TableItem[] items = tableViewer.getTable()
488:                                    .getSelection();
489:                            for (int i = 0; i < items.length; i++) {
490:                                TableItem item = items[i];
491:                                Collaborator collaborator = (Collaborator) item
492:                                        .getData();
493:                                ModelMgr.removeCollaborator(collaborator);
494:                                item.dispose();
495:                                // Notification des listeners
496:                                notifyCollaboratorRemoved(collaborator);
497:                            }
498:                        }
499:                        // Cas d'une demande de liste des contributions
500:                        else if (listTaskContributionsItem.equals(source)) {
501:                            Collaborator selectedCollaborator = (Collaborator) selection[0]
502:                                    .getData();
503:                            contribsViewerDialog.setFilter(null,
504:                                    selectedCollaborator, null, null, null);
505:                            // Ouverture du dialogue
506:                            contribsViewerDialog.open();
507:                        }
508:                        // Cas d'une demande d'export
509:                        else if (exportItem.equals(source)) {
510:                            SWTHelper.exportToWorkBook(tableViewer.getTable());
511:                        }
512:                        return null;
513:                    }
514:                };
515:                // Exécution
516:                safeRunner.run(parent.getShell());
517:            }
518:
519:            /**
520:             * Ajoute une ligne dans le tableau.
521:             * @param collaborator le collaborateur associé à la nouvelle ligne.
522:             */
523:            private void newLine(Collaborator collaborator) {
524:                // Ajout dans l'arbre
525:                tableViewer.add(collaborator);
526:                tableViewer.setSelection(new StructuredSelection(collaborator),
527:                        true);
528:            }
529:
530:            /* (non-Javadoc)
531:             * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
532:             */
533:            public void widgetDefaultSelected(SelectionEvent e) {
534:                widgetSelected(e);
535:            }
536:
537:            /* (non-Javadoc)
538:             * @see org.eclipse.swt.events.MenuListener#menuShown(org.eclipse.swt.events.MenuEvent)
539:             */
540:            public void menuShown(MenuEvent e) {
541:                log.debug("menuShown(" + e + ")");
542:                TableItem[] selection = tableViewer.getTable().getSelection();
543:                boolean emptySelection = selection.length == 0;
544:                boolean singleSelection = selection.length == 1;
545:                newItem.setEnabled(emptySelection || singleSelection);
546:                removeItem.setEnabled(!emptySelection);
547:                listTaskContributionsItem.setEnabled(singleSelection);
548:                exportItem.setEnabled(true);
549:            }
550:
551:            /* (non-Javadoc)
552:             * @see org.eclipse.swt.events.MenuListener#menuHidden(org.eclipse.swt.events.MenuEvent)
553:             */
554:            public void menuHidden(MenuEvent e) {
555:                // Do nothing...
556:            }
557:
558:            /**
559:             * Ajoute un listener.
560:             * @param listener le nouveau listener.
561:             */
562:            public void addCollaboratorListener(ICollaboratorListener listener) {
563:                listeners.add(listener);
564:            }
565:
566:            /**
567:             * Ajoute un listener.
568:             * @param listener le nouveau listener.
569:             */
570:            public void removeCollaboratorListener(
571:                    ICollaboratorListener listener) {
572:                listeners.remove(listener);
573:            }
574:
575:            /**
576:             * Notifie les listeners qu'un collaborateur a été ajouté.
577:             * @param newCollaborator le collaborateur ajouté.
578:             */
579:            private void notifyCollaboratorAdded(Collaborator newCollaborator) {
580:                Iterator it = listeners.iterator();
581:                while (it.hasNext()) {
582:                    ICollaboratorListener listener = (ICollaboratorListener) it
583:                            .next();
584:                    listener.collaboratorAdded(newCollaborator);
585:                }
586:            }
587:
588:            /**
589:             * Notifie les listeners qu'un collaborateur a été supprimé.
590:             * @param collaborator le collaborateur supprimé.
591:             */
592:            private void notifyCollaboratorRemoved(Collaborator collaborator) {
593:                Iterator it = listeners.iterator();
594:                while (it.hasNext()) {
595:                    ICollaboratorListener listener = (ICollaboratorListener) it
596:                            .next();
597:                    listener.collaboratorRemoved(collaborator);
598:                }
599:            }
600:
601:            /**
602:             * Notifie les listeners qu'un collaborateur a été modifié.
603:             * @param collaborator le collaborateur modifié.
604:             */
605:            private void notifyCollaboratorUpdated(Collaborator collaborator) {
606:                Iterator it = listeners.iterator();
607:                while (it.hasNext()) {
608:                    ICollaboratorListener listener = (ICollaboratorListener) it
609:                            .next();
610:                    listener.collaboratorUpdated(collaborator);
611:                }
612:            }
613:
614:            /**
615:             * Notifie les listeners que l'état d'activation d'un collaborateur a été modifié.
616:             * @param collaborator le collaborateur modifié.
617:             */
618:            private void notifyCollaboratorActivationStatusChanged(
619:                    Collaborator collaborator) {
620:                Iterator it = listeners.iterator();
621:                while (it.hasNext()) {
622:                    ICollaboratorListener listener = (ICollaboratorListener) it
623:                            .next();
624:                    listener.collaboratorActivationStatusChanged(collaborator);
625:                }
626:            }
627:
628:            /* (non-Javadoc)
629:             * @see jfb.tools.activitymgr.ui.DatabaseUI.DbStatusListener#databaseOpened()
630:             */
631:            public void databaseOpened() {
632:                // Création d'une racine fictive
633:                tableViewer.setInput(ROOT_NODE);
634:            }
635:
636:            /* (non-Javadoc)
637:             * @see jfb.tools.activitymgr.ui.DatabaseUI.DbStatusListener#databaseClosed()
638:             */
639:            public void databaseClosed() {
640:                Table table = tableViewer.getTable();
641:                TableItem[] items = table.getItems();
642:                for (int i = 0; i < items.length; i++) {
643:                    items[i].dispose();
644:                }
645:            }
646:
647:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.