KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > manager > JActivityList


1 package hero.client.manager;
2
3 /*
4 *
5 * JActivityList.java -
6 * Copyright (C) 2003 Ecoo Team
7 * valdes@loria.fr
8 *
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */

24
25
26 import hero.interfaces.Constants;
27 import hero.util.BonitaClient;
28
29 import java.awt.BorderLayout JavaDoc;
30 import java.awt.Color JavaDoc;
31 import java.awt.Dimension JavaDoc;
32 import java.awt.Toolkit JavaDoc;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.awt.event.ActionListener JavaDoc;
35 import java.awt.event.MouseEvent JavaDoc;
36 import java.awt.event.MouseListener JavaDoc;
37 import java.beans.PropertyChangeEvent JavaDoc;
38 import java.beans.PropertyChangeListener JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.Collection JavaDoc;
41
42 import javax.swing.DefaultListModel JavaDoc;
43 import javax.swing.JLabel JavaDoc;
44 import javax.swing.JList JavaDoc;
45 import javax.swing.JMenuItem JavaDoc;
46 import javax.swing.JOptionPane JavaDoc;
47 import javax.swing.JPanel JavaDoc;
48 import javax.swing.JPopupMenu JavaDoc;
49 import javax.swing.JScrollPane JavaDoc;
50 import javax.swing.ImageIcon JavaDoc;
51
52
53 public class JActivityList extends JPanel JavaDoc implements PropertyChangeListener JavaDoc, MouseListener JavaDoc, Constants.Nd {
54
55 static java.util.ResourceBundle JavaDoc resource = java.util.ResourceBundle.getBundle("resources.Traduction")/*#BundleType=List*/;
56
57     private BonitaClient soapclient;
58     private JList JavaDoc activityList = null;
59     private DefaultListModel JavaDoc model;
60     String JavaDoc project = null;
61     public final static String JavaDoc imageBase = "images/";
62     public final static ImageIcon JavaDoc icon = new ImageIcon JavaDoc(Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png"));
63
64     public JActivityList(BonitaClient soapclient, MListener ml)
65     {
66       try{
67       this.soapclient = soapclient;
68       ml.addEventActivityListener(this);
69       
70       model = new DefaultListModel JavaDoc();
71       activityList = new JList JavaDoc(model);
72       activityList.setCellRenderer(new ManagerCellRenderer());
73       
74       JScrollPane JavaDoc jspact=new JScrollPane JavaDoc(activityList);
75       jspact.setBackground(new Color JavaDoc(177,177,251));
76       this.setBackground(new Color JavaDoc(177,177,251));
77       this.setLayout(new BorderLayout JavaDoc());
78       this.add(new JLabel JavaDoc(resource.getString("jactivitylist.activity")),BorderLayout.NORTH);
79       this.add(jspact,BorderLayout.CENTER);
80       activityList.addMouseListener(this);
81       }catch(Exception JavaDoc e){JOptionPane.showMessageDialog(null,resource.getString("jactivitylist.error"),resource.getString("jactivitylist.interror"),JOptionPane.INFORMATION_MESSAGE,icon);}
82     }
83
84     public void mouseReleased(MouseEvent JavaDoc e){
85     try {
86         // Popup Menu
87
if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK) != 0) {
88         if (activityList.getSelectedValue() != null)
89         {
90             JPopupMenu JavaDoc menu = new JPopupMenu JavaDoc();
91             PopupMenu(menu);
92             Dimension JavaDoc screen = Toolkit.getDefaultToolkit().getScreenSize();
93             Dimension JavaDoc size = menu.getPreferredSize();
94             
95             // Flip along screen
96
int x = e.getX();
97             int y = e.getY();
98             
99             menu.show(this, x, y);
100         }
101         }
102         else if (e.getClickCount() == 2)
103             BrowserControl.displayURL(java.lang.System.getProperty("bonita.host")+"/bonita/protected/Action.jsp?projectname="+project+"&nodename="+((ListItem)activityList.getSelectedValue()).getValue());
104
105     }catch (Exception JavaDoc ex){};
106       }
107
108     public void PopupMenu(JPopupMenu JavaDoc menu)
109     {
110     JMenuItem JavaDoc mi;
111     ClassLoader JavaDoc cl = this.getClass().getClassLoader();
112     
113     mi = (JMenuItem JavaDoc) menu.add(new JMenuItem JavaDoc(resource.getString("jactivitylist.terminate")));
114     mi.addActionListener(new ActionListener JavaDoc() {
115         public void actionPerformed(ActionEvent JavaDoc e) {
116             terminate();
117         }
118         });
119
120     mi = (JMenuItem JavaDoc) menu.add(new JMenuItem JavaDoc(resource.getString("jactivitylist.cancel")));
121     mi.addActionListener(new ActionListener JavaDoc() {
122         public void actionPerformed(ActionEvent JavaDoc e) {
123             cancel();
124         }
125         });
126     
127     mi = (JMenuItem JavaDoc) menu.add(new JMenuItem JavaDoc(resource.getString("jactivitylist.details")));
128     mi.addActionListener(new ActionListener JavaDoc() {
129         public void actionPerformed(ActionEvent JavaDoc e) {
130             BrowserControl.displayURL(java.lang.System.getProperty("bonita.host")+"/bonita/protected/Action.jsp?projectname="+project+"&nodename="+((ListItem)activityList.getSelectedValue()).getValue());
131         }
132         });
133     }
134     
135     void terminate()
136     {
137     try {
138         if (project != null)
139         soapclient.terminateActivity(project, ((ListItem)activityList.getSelectedValue()).getValue());
140     }catch(Exception JavaDoc term){
141         if (term.getMessage().matches("(?i).*You have to terminate subProcess.*"))
142             JOptionPane.showMessageDialog(null,resource.getString("jactivitylist.subnofinish"),resource.getString("jactivitylist.terminate"),JOptionPane.INFORMATION_MESSAGE,icon);
143         else
144             JOptionPane.showMessageDialog(null,resource.getString("jactivitylist.terminateerror")+term.getMessage(),resource.getString("jactivitylist.terminate"),JOptionPane.INFORMATION_MESSAGE,icon);}
145     }
146
147     void cancel()
148     {
149     try {
150         if (project != null)
151         soapclient.cancelActivity(project, ((ListItem)activityList.getSelectedValue()).getValue());
152
153     }catch(Exception JavaDoc cancel){JOptionPane.showMessageDialog(null,resource.getString("jactivitylist.acterror")+cancel.getMessage(),"Cancel Activity",JOptionPane.INFORMATION_MESSAGE,icon);}
154     }
155
156     public void propertyChange(PropertyChangeEvent JavaDoc e)
157     {
158        try {
159        if (e.getPropertyName().equals(JProjectList.SELECTED))
160        {
161            model.clear();
162            project = (String JavaDoc)e.getNewValue();
163            
164            Collection JavaDoc activity = soapclient.getActivityList(project);
165            Iterator JavaDoc i = activity.iterator();
166
167            while (i.hasNext())
168            {
169            String JavaDoc node = (String JavaDoc)i.next();
170            ListItem li = new ListItem(getColor(node),node);
171            model.addElement(li);
172            }
173        }
174        }catch(Exception JavaDoc e1){}
175     }
176
177     public Color JavaDoc getColor(String JavaDoc name) throws Exception JavaDoc{
178     soapclient.openProject(project);
179     int state = soapclient.getNodeState(name);
180     switch (state) {
181     case EXECUTING: return (Color.red);
182     case ANTICIPATING: return (Color.magenta);
183     }
184     return(Color.white);
185     }
186
187     public void changeEvent(Object JavaDoc[] e, String JavaDoc projectName)
188     {
189       try{
190     if (projectName.equals(project))
191     {
192         model.clear();
193         int i=0;
194         for (i=0;i<e.length;i++)
195         {
196         ListItem li = new ListItem(getColor(e[i].toString()),e[i].toString());
197         model.add(i,li);
198         }
199     }
200       }catch(Exception JavaDoc e1){}
201     }
202
203     // Rest of mouse listener is empty
204
public void mousePressed(MouseEvent JavaDoc e) { }
205     public void mouseEntered(MouseEvent JavaDoc e) { }
206     public void mouseExited(MouseEvent JavaDoc e) { }
207     public void mouseClicked(MouseEvent JavaDoc e) { }
208
209
210 }
211
212
213
Popular Tags