1 package hero.client.manager; 2 3 24 25 import hero.interfaces.Constants; 26 import hero.util.BonitaClient; 27 28 import java.awt.BorderLayout ; 29 import java.awt.Color ; 30 import java.awt.Dimension ; 31 import java.awt.FlowLayout ; 32 import java.awt.Toolkit ; 33 import java.awt.event.ActionEvent ; 34 import java.awt.event.ActionListener ; 35 import java.awt.event.MouseEvent ; 36 import java.awt.event.MouseListener ; 37 import java.beans.PropertyChangeEvent ; 38 import java.beans.PropertyChangeListener ; 39 import java.util.Iterator ; 40 import java.util.Collection ; 41 import java.util.Enumeration ; 42 import java.util.ArrayList ; 43 44 import javax.swing.DefaultListModel ; 45 import javax.swing.JLabel ; 46 import javax.swing.JList ; 47 import javax.swing.JMenuItem ; 48 import javax.swing.JOptionPane ; 49 import javax.swing.JPanel ; 50 import javax.swing.JPopupMenu ; 51 import javax.swing.JScrollPane ; 52 import javax.swing.ImageIcon ; 53 54 public class JTodoList extends JPanel implements PropertyChangeListener , MouseListener , Constants.Nd { 55 56 static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction"); 57 58 private BonitaClient soapclient; 59 private DefaultListModel model; 60 private JList todoList; 61 private String project = null; 62 MListener ml; 63 public final static String imageBase = "images/"; 64 public final static ImageIcon icon = new ImageIcon (Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png")); 65 66 public JTodoList(BonitaClient soapclient, MListener ml) { 67 try { 68 this.soapclient = soapclient; 69 ml.addEventTodoListener(this); 70 71 model = new DefaultListModel (); 72 todoList = new JList (model); 73 todoList.setCellRenderer(new ManagerCellRenderer()); 74 75 JScrollPane jsptdl = new JScrollPane (todoList); 76 77 JPanel p = new JPanel (); 78 p.setLayout(new FlowLayout ()); 79 p.setBackground(new Color (177,177,251)); 80 81 this.setLayout(new BorderLayout ()); 82 this.setBackground(new Color (177,177,251)); 83 this.add(new JLabel (resource.getString("jtodolist.todo")), BorderLayout.NORTH); 84 this.add(jsptdl, BorderLayout.CENTER); 85 this.add(p, BorderLayout.SOUTH); 86 87 todoList.addMouseListener(this); 88 } catch (Exception e) { 89 JOptionPane.showMessageDialog(null,resource.getString("jtodolist.error"),resource.getString("jtodolist.inerror"),JOptionPane.INFORMATION_MESSAGE,icon); 90 } 91 } 92 93 public void mouseReleased(MouseEvent e) { 94 try { 95 if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK) != 0) { 97 JPopupMenu menu = new JPopupMenu (); 100 PopupMenu(menu); 101 102 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 103 Dimension size = menu.getPreferredSize(); 104 105 int x = e.getX(); 107 int y = e.getY(); 108 109 menu.show(this, x, y); 110 } else if (e.getClickCount() == 2) 112 try { 113 BrowserControl.displayURL(java.lang.System.getProperty("bonita.host")+ "/bonita/protected/Action.jsp?projectname=" 114 + project 115 + "&nodename=" 116 + ((ListItem) todoList.getSelectedValue()).getValue()); 117 } catch (Exception ex) { 118 } 119 } catch (Exception ex) { 120 }; 121 } 122 123 public void PopupMenu(JPopupMenu menu) { 124 JMenuItem mi; 125 ClassLoader cl = this.getClass().getClassLoader(); 126 127 if (todoList.getSelectedIndex() != -1) { 128 mi = (JMenuItem ) menu.add(new JMenuItem (resource.getString("jtodolist.start"))); 129 mi.addActionListener(new ActionListener () { 130 public void actionPerformed(ActionEvent e) { 131 start(); 132 } 133 }); 134 135 mi = (JMenuItem ) menu.add(new JMenuItem (resource.getString("jtodolist.details"))); 136 mi.addActionListener(new ActionListener () { 137 public void actionPerformed(ActionEvent e) { 138 BrowserControl.displayURL(java.lang.System.getProperty("bonita.host") 139 + "/bonita/protected/Action.jsp?projectname=" 140 + project 141 + "&nodename=" 142 + ((ListItem) todoList.getSelectedValue()).getValue()); 143 } 144 }); 145 } 146 } 147 148 void start() { 149 try { 150 if (project != null) 151 soapclient.startActivity(project, ((ListItem) todoList.getSelectedValue()).getValue()); 152 } catch (Exception start) { 153 JOptionPane.showMessageDialog(null,resource.getString("jtodolist.starterror")+start.getMessage(),resource.getString("jtodolist.start"),JOptionPane.INFORMATION_MESSAGE,icon); 154 } 155 } 156 157 public void propertyChange(PropertyChangeEvent e) { 158 try { 159 if (e.getPropertyName().equals(JProjectList.SELECTED)) { 160 model.clear(); 161 this.project = (String ) e.getNewValue(); 162 163 Collection toDo = soapclient.getToDoList(project); 164 Iterator i = toDo.iterator(); 165 166 while (i.hasNext()) { 167 String node = (String ) i.next(); 168 ListItem li = new ListItem(getColor(node), node); 169 model.addElement(li); 170 } 171 } 172 } catch (Exception e1) { 173 e1.printStackTrace(); 174 } 175 } 176 177 public Color getColor(String name) throws Exception { 178 soapclient.openProject(project); 179 int state = soapclient.getNodeState(name); 180 switch (state) { 181 case READY : 182 return (Color.yellow); 183 case ANTICIPABLE : 184 return (Color.green); 185 } 186 return (Color.white); 187 } 188 189 public void changeEvent(Object [] e, String projectName) { 190 try { 191 if (projectName.equals(project)) { 192 model.clear(); 193 int i = 0; 194 for (i = 0; i < e.length; i++) { 195 ListItem li = new ListItem(getColor(e[i].toString()), e[i].toString()); 196 model.addElement(li); 197 } 198 } 199 200 } catch (Exception ex) { 201 } 202 } 203 204 public boolean isChanged(Object [] elements) { 205 Collection listElements = new ArrayList (); 206 207 for (Enumeration e = model.elements() ; e.hasMoreElements() ;) { 208 ListItem li = (ListItem)e.nextElement(); 209 listElements.add(li.getValue()); 210 } 211 Collection newElements = java.util.Arrays.asList(elements); 212 if (listElements.containsAll(newElements)) 213 return false; 214 return true; 215 } 216 217 public void mousePressed(MouseEvent e) { 219 } 220 public void mouseEntered(MouseEvent e) { 221 } 222 public void mouseExited(MouseEvent e) { 223 } 224 public void mouseClicked(MouseEvent e) { 225 } 226 227 } 228 229 230 | Popular Tags |