001: package hero.client.manager;
002:
003: /*
004: *
005: * JActivityList.java -
006: * Copyright (C) 2003 Ecoo Team
007: * valdes@loria.fr
008: *
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
023: */
024:
025: import hero.interfaces.Constants;
026: import hero.util.BonitaClient;
027:
028: import java.awt.BorderLayout;
029: import java.awt.Color;
030: import java.awt.Dimension;
031: import java.awt.Toolkit;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.awt.event.MouseEvent;
035: import java.awt.event.MouseListener;
036: import java.beans.PropertyChangeEvent;
037: import java.beans.PropertyChangeListener;
038: import java.util.Iterator;
039: import java.util.Collection;
040:
041: import javax.swing.DefaultListModel;
042: import javax.swing.JLabel;
043: import javax.swing.JList;
044: import javax.swing.JMenuItem;
045: import javax.swing.JOptionPane;
046: import javax.swing.JPanel;
047: import javax.swing.JPopupMenu;
048: import javax.swing.JScrollPane;
049: import javax.swing.ImageIcon;
050:
051: public class JActivityList extends JPanel implements
052: PropertyChangeListener, MouseListener, Constants.Nd {
053:
054: static java.util.ResourceBundle resource = java.util.ResourceBundle
055: .getBundle("resources.Traduction")/*#BundleType=List*/;
056:
057: private BonitaClient soapclient;
058: private JList activityList = null;
059: private DefaultListModel model;
060: String project = null;
061: public final static String imageBase = "images/";
062: public final static ImageIcon icon = new ImageIcon(Thread
063: .currentThread().getContextClassLoader().getResource(
064: imageBase + "icon.png"));
065:
066: public JActivityList(BonitaClient soapclient, MListener ml) {
067: try {
068: this .soapclient = soapclient;
069: ml.addEventActivityListener(this );
070:
071: model = new DefaultListModel();
072: activityList = new JList(model);
073: activityList.setCellRenderer(new ManagerCellRenderer());
074:
075: JScrollPane jspact = new JScrollPane(activityList);
076: jspact.setBackground(new Color(177, 177, 251));
077: this .setBackground(new Color(177, 177, 251));
078: this .setLayout(new BorderLayout());
079: this .add(new JLabel(resource
080: .getString("jactivitylist.activity")),
081: BorderLayout.NORTH);
082: this .add(jspact, BorderLayout.CENTER);
083: activityList.addMouseListener(this );
084: } catch (Exception e) {
085: JOptionPane.showMessageDialog(null, resource
086: .getString("jactivitylist.error"), resource
087: .getString("jactivitylist.interror"),
088: JOptionPane.INFORMATION_MESSAGE, icon);
089: }
090: }
091:
092: public void mouseReleased(MouseEvent e) {
093: try {
094: // Popup Menu
095: if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK) != 0) {
096: if (activityList.getSelectedValue() != null) {
097: JPopupMenu menu = new JPopupMenu();
098: PopupMenu(menu);
099: Dimension screen = Toolkit.getDefaultToolkit()
100: .getScreenSize();
101: Dimension size = menu.getPreferredSize();
102:
103: // Flip along screen
104: int x = e.getX();
105: int y = e.getY();
106:
107: menu.show(this , x, y);
108: }
109: } else if (e.getClickCount() == 2)
110: BrowserControl.displayURL(java.lang.System
111: .getProperty("bonita.host")
112: + "/bonita/protected/Action.jsp?projectname="
113: + project
114: + "&nodename="
115: + ((ListItem) activityList.getSelectedValue())
116: .getValue());
117:
118: } catch (Exception ex) {
119: }
120: ;
121: }
122:
123: public void PopupMenu(JPopupMenu menu) {
124: JMenuItem mi;
125: ClassLoader cl = this .getClass().getClassLoader();
126:
127: mi = (JMenuItem) menu.add(new JMenuItem(resource
128: .getString("jactivitylist.terminate")));
129: mi.addActionListener(new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: terminate();
132: }
133: });
134:
135: mi = (JMenuItem) menu.add(new JMenuItem(resource
136: .getString("jactivitylist.cancel")));
137: mi.addActionListener(new ActionListener() {
138: public void actionPerformed(ActionEvent e) {
139: cancel();
140: }
141: });
142:
143: mi = (JMenuItem) menu.add(new JMenuItem(resource
144: .getString("jactivitylist.details")));
145: mi.addActionListener(new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: BrowserControl.displayURL(java.lang.System
148: .getProperty("bonita.host")
149: + "/bonita/protected/Action.jsp?projectname="
150: + project
151: + "&nodename="
152: + ((ListItem) activityList.getSelectedValue())
153: .getValue());
154: }
155: });
156: }
157:
158: void terminate() {
159: try {
160: if (project != null)
161: soapclient.terminateActivity(project,
162: ((ListItem) activityList.getSelectedValue())
163: .getValue());
164: } catch (Exception term) {
165: if (term.getMessage().matches(
166: "(?i).*You have to terminate subProcess.*"))
167: JOptionPane.showMessageDialog(null, resource
168: .getString("jactivitylist.subnofinish"),
169: resource.getString("jactivitylist.terminate"),
170: JOptionPane.INFORMATION_MESSAGE, icon);
171: else
172: JOptionPane.showMessageDialog(null, resource
173: .getString("jactivitylist.terminateerror")
174: + term.getMessage(), resource
175: .getString("jactivitylist.terminate"),
176: JOptionPane.INFORMATION_MESSAGE, icon);
177: }
178: }
179:
180: void cancel() {
181: try {
182: if (project != null)
183: soapclient.cancelActivity(project,
184: ((ListItem) activityList.getSelectedValue())
185: .getValue());
186:
187: } catch (Exception cancel) {
188: JOptionPane.showMessageDialog(null, resource
189: .getString("jactivitylist.acterror")
190: + cancel.getMessage(), "Cancel Activity",
191: JOptionPane.INFORMATION_MESSAGE, icon);
192: }
193: }
194:
195: public void propertyChange(PropertyChangeEvent e) {
196: try {
197: if (e.getPropertyName().equals(JProjectList.SELECTED)) {
198: model.clear();
199: project = (String) e.getNewValue();
200:
201: Collection activity = soapclient
202: .getActivityList(project);
203: Iterator i = activity.iterator();
204:
205: while (i.hasNext()) {
206: String node = (String) i.next();
207: ListItem li = new ListItem(getColor(node), node);
208: model.addElement(li);
209: }
210: }
211: } catch (Exception e1) {
212: }
213: }
214:
215: public Color getColor(String name) throws Exception {
216: soapclient.openProject(project);
217: int state = soapclient.getNodeState(name);
218: switch (state) {
219: case EXECUTING:
220: return (Color.red);
221: case ANTICIPATING:
222: return (Color.magenta);
223: }
224: return (Color.white);
225: }
226:
227: public void changeEvent(Object[] e, String projectName) {
228: try {
229: if (projectName.equals(project)) {
230: model.clear();
231: int i = 0;
232: for (i = 0; i < e.length; i++) {
233: ListItem li = new ListItem(
234: getColor(e[i].toString()), e[i].toString());
235: model.add(i, li);
236: }
237: }
238: } catch (Exception e1) {
239: }
240: }
241:
242: // Rest of mouse listener is empty
243: public void mousePressed(MouseEvent e) {
244: }
245:
246: public void mouseEntered(MouseEvent e) {
247: }
248:
249: public void mouseExited(MouseEvent e) {
250: }
251:
252: public void mouseClicked(MouseEvent e) {
253: }
254:
255: }
|