1 package hero.client.manager; 2 3 24 25 26 import hero.interfaces.Constants; 27 import hero.util.BonitaClient; 28 29 import java.awt.BorderLayout ; 30 import java.awt.Color ; 31 import java.awt.Dimension ; 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 42 import javax.swing.DefaultListModel ; 43 import javax.swing.JLabel ; 44 import javax.swing.JList ; 45 import javax.swing.JMenuItem ; 46 import javax.swing.JOptionPane ; 47 import javax.swing.JPanel ; 48 import javax.swing.JPopupMenu ; 49 import javax.swing.JScrollPane ; 50 import javax.swing.ImageIcon ; 51 52 53 public class JActivityList extends JPanel implements PropertyChangeListener , MouseListener , Constants.Nd { 54 55 static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction"); 56 57 private BonitaClient soapclient; 58 private JList activityList = null; 59 private DefaultListModel model; 60 String project = null; 61 public final static String imageBase = "images/"; 62 public final static ImageIcon icon = new ImageIcon (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 (); 71 activityList = new JList (model); 72 activityList.setCellRenderer(new ManagerCellRenderer()); 73 74 JScrollPane jspact=new JScrollPane (activityList); 75 jspact.setBackground(new Color (177,177,251)); 76 this.setBackground(new Color (177,177,251)); 77 this.setLayout(new BorderLayout ()); 78 this.add(new JLabel (resource.getString("jactivitylist.activity")),BorderLayout.NORTH); 79 this.add(jspact,BorderLayout.CENTER); 80 activityList.addMouseListener(this); 81 }catch(Exception e){JOptionPane.showMessageDialog(null,resource.getString("jactivitylist.error"),resource.getString("jactivitylist.interror"),JOptionPane.INFORMATION_MESSAGE,icon);} 82 } 83 84 public void mouseReleased(MouseEvent e){ 85 try { 86 if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK) != 0) { 88 if (activityList.getSelectedValue() != null) 89 { 90 JPopupMenu menu = new JPopupMenu (); 91 PopupMenu(menu); 92 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 93 Dimension size = menu.getPreferredSize(); 94 95 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 ex){}; 106 } 107 108 public void PopupMenu(JPopupMenu menu) 109 { 110 JMenuItem mi; 111 ClassLoader cl = this.getClass().getClassLoader(); 112 113 mi = (JMenuItem ) menu.add(new JMenuItem (resource.getString("jactivitylist.terminate"))); 114 mi.addActionListener(new ActionListener () { 115 public void actionPerformed(ActionEvent e) { 116 terminate(); 117 } 118 }); 119 120 mi = (JMenuItem ) menu.add(new JMenuItem (resource.getString("jactivitylist.cancel"))); 121 mi.addActionListener(new ActionListener () { 122 public void actionPerformed(ActionEvent e) { 123 cancel(); 124 } 125 }); 126 127 mi = (JMenuItem ) menu.add(new JMenuItem (resource.getString("jactivitylist.details"))); 128 mi.addActionListener(new ActionListener () { 129 public void actionPerformed(ActionEvent 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 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 cancel){JOptionPane.showMessageDialog(null,resource.getString("jactivitylist.acterror")+cancel.getMessage(),"Cancel Activity",JOptionPane.INFORMATION_MESSAGE,icon);} 154 } 155 156 public void propertyChange(PropertyChangeEvent e) 157 { 158 try { 159 if (e.getPropertyName().equals(JProjectList.SELECTED)) 160 { 161 model.clear(); 162 project = (String )e.getNewValue(); 163 164 Collection activity = soapclient.getActivityList(project); 165 Iterator i = activity.iterator(); 166 167 while (i.hasNext()) 168 { 169 String node = (String )i.next(); 170 ListItem li = new ListItem(getColor(node),node); 171 model.addElement(li); 172 } 173 } 174 }catch(Exception e1){} 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 EXECUTING: return (Color.red); 182 case ANTICIPATING: return (Color.magenta); 183 } 184 return(Color.white); 185 } 186 187 public void changeEvent(Object [] e, String 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 e1){} 201 } 202 203 public void mousePressed(MouseEvent e) { } 205 public void mouseEntered(MouseEvent e) { } 206 public void mouseExited(MouseEvent e) { } 207 public void mouseClicked(MouseEvent e) { } 208 209 210 } 211 212 213 | Popular Tags |