001: package hero.client.manager;
002:
003: /*
004: *
005: * JTodoList.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.FlowLayout;
032: import java.awt.Toolkit;
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035: import java.awt.event.MouseEvent;
036: import java.awt.event.MouseListener;
037: import java.beans.PropertyChangeEvent;
038: import java.beans.PropertyChangeListener;
039: import java.util.Iterator;
040: import java.util.Collection;
041: import java.util.Enumeration;
042: import java.util.ArrayList;
043:
044: import javax.swing.DefaultListModel;
045: import javax.swing.JLabel;
046: import javax.swing.JList;
047: import javax.swing.JMenuItem;
048: import javax.swing.JOptionPane;
049: import javax.swing.JPanel;
050: import javax.swing.JPopupMenu;
051: import javax.swing.JScrollPane;
052: import javax.swing.ImageIcon;
053:
054: public class JTodoList extends JPanel implements
055: PropertyChangeListener, MouseListener, Constants.Nd {
056:
057: static java.util.ResourceBundle resource = java.util.ResourceBundle
058: .getBundle("resources.Traduction")/*#BundleType=List*/;
059:
060: private BonitaClient soapclient;
061: private DefaultListModel model;
062: private JList todoList;
063: private String project = null;
064: MListener ml;
065: public final static String imageBase = "images/";
066: public final static ImageIcon icon = new ImageIcon(Thread
067: .currentThread().getContextClassLoader().getResource(
068: imageBase + "icon.png"));
069:
070: public JTodoList(BonitaClient soapclient, MListener ml) {
071: try {
072: this .soapclient = soapclient;
073: ml.addEventTodoListener(this );
074:
075: model = new DefaultListModel();
076: todoList = new JList(model);
077: todoList.setCellRenderer(new ManagerCellRenderer());
078:
079: JScrollPane jsptdl = new JScrollPane(todoList);
080:
081: JPanel p = new JPanel();
082: p.setLayout(new FlowLayout());
083: p.setBackground(new Color(177, 177, 251));
084:
085: this .setLayout(new BorderLayout());
086: this .setBackground(new Color(177, 177, 251));
087: this .add(new JLabel(resource.getString("jtodolist.todo")),
088: BorderLayout.NORTH);
089: this .add(jsptdl, BorderLayout.CENTER);
090: this .add(p, BorderLayout.SOUTH);
091:
092: todoList.addMouseListener(this );
093: } catch (Exception e) {
094: JOptionPane.showMessageDialog(null, resource
095: .getString("jtodolist.error"), resource
096: .getString("jtodolist.inerror"),
097: JOptionPane.INFORMATION_MESSAGE, icon);
098: }
099: }
100:
101: public void mouseReleased(MouseEvent e) {
102: try {
103: // Popup Menu
104: if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK) != 0) {
105: // if (todoList.getSelectedValue() != null)
106: // {
107: JPopupMenu menu = new JPopupMenu();
108: PopupMenu(menu);
109:
110: Dimension screen = Toolkit.getDefaultToolkit()
111: .getScreenSize();
112: Dimension size = menu.getPreferredSize();
113:
114: // Flip along screen
115: int x = e.getX();
116: int y = e.getY();
117:
118: menu.show(this , x, y);
119: //}
120: } else if (e.getClickCount() == 2)
121: try {
122: BrowserControl
123: .displayURL(java.lang.System
124: .getProperty("bonita.host")
125: + "/bonita/protected/Action.jsp?projectname="
126: + project
127: + "&nodename="
128: + ((ListItem) todoList
129: .getSelectedValue())
130: .getValue());
131: } catch (Exception ex) {
132: }
133: } catch (Exception ex) {
134: }
135: ;
136: }
137:
138: public void PopupMenu(JPopupMenu menu) {
139: JMenuItem mi;
140: ClassLoader cl = this .getClass().getClassLoader();
141:
142: if (todoList.getSelectedIndex() != -1) {
143: mi = (JMenuItem) menu.add(new JMenuItem(resource
144: .getString("jtodolist.start")));
145: mi.addActionListener(new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: start();
148: }
149: });
150:
151: mi = (JMenuItem) menu.add(new JMenuItem(resource
152: .getString("jtodolist.details")));
153: mi.addActionListener(new ActionListener() {
154: public void actionPerformed(ActionEvent e) {
155: BrowserControl
156: .displayURL(java.lang.System
157: .getProperty("bonita.host")
158: + "/bonita/protected/Action.jsp?projectname="
159: + project
160: + "&nodename="
161: + ((ListItem) todoList
162: .getSelectedValue())
163: .getValue());
164: }
165: });
166: }
167: }
168:
169: void start() {
170: try {
171: if (project != null)
172: soapclient.startActivity(project, ((ListItem) todoList
173: .getSelectedValue()).getValue());
174: } catch (Exception start) {
175: JOptionPane.showMessageDialog(null, resource
176: .getString("jtodolist.starterror")
177: + start.getMessage(), resource
178: .getString("jtodolist.start"),
179: JOptionPane.INFORMATION_MESSAGE, icon);
180: }
181: }
182:
183: public void propertyChange(PropertyChangeEvent e) {
184: try {
185: if (e.getPropertyName().equals(JProjectList.SELECTED)) {
186: model.clear();
187: this .project = (String) e.getNewValue();
188:
189: Collection toDo = soapclient.getToDoList(project);
190: Iterator i = toDo.iterator();
191:
192: while (i.hasNext()) {
193: String node = (String) i.next();
194: ListItem li = new ListItem(getColor(node), node);
195: model.addElement(li);
196: }
197: }
198: } catch (Exception e1) {
199: e1.printStackTrace();
200: }
201: }
202:
203: public Color getColor(String name) throws Exception {
204: soapclient.openProject(project);
205: int state = soapclient.getNodeState(name);
206: switch (state) {
207: case READY:
208: return (Color.yellow);
209: case ANTICIPABLE:
210: return (Color.green);
211: }
212: return (Color.white);
213: }
214:
215: public void changeEvent(Object[] e, String projectName) {
216: try {
217: if (projectName.equals(project)) {
218: model.clear();
219: int i = 0;
220: for (i = 0; i < e.length; i++) {
221: ListItem li = new ListItem(
222: getColor(e[i].toString()), e[i].toString());
223: model.addElement(li);
224: }
225: }
226:
227: } catch (Exception ex) {
228: }
229: }
230:
231: public boolean isChanged(Object[] elements) {
232: Collection listElements = new ArrayList();
233:
234: for (Enumeration e = model.elements(); e.hasMoreElements();) {
235: ListItem li = (ListItem) e.nextElement();
236: listElements.add(li.getValue());
237: }
238: Collection newElements = java.util.Arrays.asList(elements);
239: if (listElements.containsAll(newElements))
240: return false;
241: return true;
242: }
243:
244: // Rest of mouse listener is empty
245: public void mousePressed(MouseEvent e) {
246: }
247:
248: public void mouseEntered(MouseEvent e) {
249: }
250:
251: public void mouseExited(MouseEvent e) {
252: }
253:
254: public void mouseClicked(MouseEvent e) {
255: }
256:
257: }
|