KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > gui > AttendeePanel


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.applications.calendar.gui;
21
22 import java.awt.*;
23 import java.awt.event.*;
24 import java.util.*;
25
26 import javax.swing.*;
27
28 import org.lucane.client.Client;
29 import org.lucane.client.widgets.DialogBox;
30 import org.lucane.client.widgets.UserSelector;
31 import org.lucane.common.concepts.*;
32 import org.lucane.applications.calendar.*;
33 import org.lucane.applications.calendar.Event;
34
35 public class AttendeePanel extends JPanel
36 implements ActionListener
37 {
38     private transient CalendarPlugin plugin;
39     private Event event;
40     private EventDescriptionPanel description;
41     
42     private AttendeeTable attendees;
43     private JButton btnAddMandatory;
44     private JButton btnAddOptional;
45     private JButton btnRemove;
46     private JButton btnFindFreeTime;
47     
48     public AttendeePanel(CalendarPlugin plugin, Event event, EventDescriptionPanel description)
49     {
50         super(new BorderLayout());
51         this.plugin = plugin;
52         this.event = event;
53         this.description = description;
54         
55         this.attendees = new AttendeeTable(plugin, tr("event.attendees"), event.getAttendeeList());
56         this.btnAddMandatory = new JButton(tr("btn.addMandatoryAttendee"));
57         this.btnAddOptional = new JButton(tr("btn.addOptionalAttendee"));
58         this.btnRemove = new JButton(tr("btn.removeAttendee"));
59         this.btnFindFreeTime = new JButton(tr("btn.findFreeTime"), plugin.getImageIcon("search.png"));
60         this.btnAddMandatory.addActionListener(this);
61         this.btnAddOptional.addActionListener(this);
62         this.btnRemove.addActionListener(this);
63         this.btnFindFreeTime.addActionListener(this);
64         
65         JPanel buttons = new JPanel(new GridLayout(4, 1));
66         buttons.add(this.btnAddMandatory);
67         buttons.add(this.btnAddOptional);
68         buttons.add(this.btnRemove);
69         buttons.add(this.btnFindFreeTime);
70         JPanel container = new JPanel(new BorderLayout());
71         container.add(buttons, BorderLayout.NORTH);
72         
73         this.add(new JScrollPane(attendees), BorderLayout.CENTER);
74         
75         String JavaDoc userName = Client.getInstance().getMyInfos().getName();
76         boolean isOrganizer = event.getOrganizer().equals(userName);
77         boolean isEditable = isOrganizer || (event.isEditable() && event.hasAttendee(userName));
78         if(isEditable)
79             this.add(container, BorderLayout.EAST);
80     }
81     
82     public ArrayList getAttendees()
83     {
84         return attendees.getAttendeeList();
85     }
86     
87     public void refreshAttendees()
88     {
89         attendees.setAttendees(event.getAttendeeList());
90     }
91     
92     public void actionPerformed(ActionEvent ae)
93     {
94         if(ae.getSource() == btnAddMandatory || ae.getSource() == btnAddOptional)
95         {
96             try {
97                 ArrayList groups = plugin.getGroups();
98                                 
99                                 //remove organizer
100
UserConcept user = new UserConcept(event.getOrganizer(), null, null, null, null, false, null);
101                                 for(int i=0;i<groups.size();i++)
102                                 {
103                                     GroupConcept group = (GroupConcept)groups.get(i);
104                                     group.removeUser(user);
105                                 }
106                                 
107                                 //and already selected users
108
Iterator attendees = getAttendees().iterator();
109                                 while(attendees.hasNext())
110                                 {
111                                     Attendee a = (Attendee)attendees.next();
112                                     user = new UserConcept(a.getUser(), null, null, null, null, false, null);
113                                     for(int i=0;i<groups.size();i++)
114                                     {
115                                         GroupConcept group = (GroupConcept)groups.get(i);
116                                         group.removeUser(user);
117                                     }
118                                 }
119
120                 UserSelector select = new UserSelector(null, tr("msg.selectUser"));
121                 select.setRecursive(true);
122                 select.setGroups(groups);
123
124                 Object JavaDoc[] users = select.selectItems();
125                 if(users == null)
126                     return;
127                 
128                 boolean isMandatory = (ae.getSource() == btnAddMandatory);
129                 for(int i=0;i<users.length;i++)
130                 {
131                     user = (UserConcept)users[i];
132                     this.attendees.addAttendee(new Attendee(user.getName(), isMandatory));
133                 }
134             } catch(Exception JavaDoc e) {
135                 DialogBox.error(tr("err.unableToFetchUserList"));
136                 e.printStackTrace();
137             }
138         }
139         else if(ae.getSource() == btnRemove)
140             attendees.removeSelected();
141         else if(ae.getSource() == btnFindFreeTime)
142             findFreeTime();
143     }
144     
145     private void findFreeTime()
146     {
147         event.setAttendees(getAttendees());
148         FreeBusyDialog freebusy = new FreeBusyDialog(plugin, event, description);
149         freebusy.show();
150     }
151     
152     private String JavaDoc tr(String JavaDoc s)
153     {
154         return plugin.tr(s);
155     }
156 }
Popular Tags