1 14 package org.compiere.apps; 15 16 import javax.swing.*; 17 import java.text.*; 18 import java.awt.*; 19 import java.awt.event.*; 20 import java.sql.*; 21 22 import org.compiere.util.*; 23 import org.compiere.plaf.*; 24 import org.compiere.swing.*; 25 26 32 public class StatusBar extends CPanel 33 { 34 37 public StatusBar() 38 { 39 this(false); 40 } 42 46 public StatusBar (boolean withInfo) 47 { 48 super(); 49 try 50 { 51 jbInit(); 52 } 53 catch (Exception e) 54 {} 55 this.setName("statusBar"); 56 if (!withInfo) 57 infoLine.setVisible(false); 58 } 60 private BorderLayout mainLayout = new BorderLayout(); 61 private JLabel statusLine = new JLabel(); 62 private JLabel statusDB = new JLabel(); 63 private JLabel infoLine = new JLabel(); 64 private boolean mt_error; 66 private String mt_text; 67 private String m_text; 69 private Timestamp m_created; 70 private Object m_createdBy; 71 private Timestamp m_updated; 72 private Object m_updatedBy; 73 private String m_info; 74 75 79 private void jbInit() throws Exception 80 { 81 statusLine.setBorder(BorderFactory.createEtchedBorder()); 82 statusLine.setText("statusLine"); 83 statusLine.setOpaque(false); 84 statusDB.setForeground(Color.blue); 85 statusDB.setBorder(BorderFactory.createEtchedBorder()); 86 statusDB.setText("#"); 87 statusDB.setOpaque(false); 88 statusDB.addMouseListener(new StatusBar_mouseAdapter(this)); 89 this.setLayout(mainLayout); 90 infoLine.setFont(CompierePLAF.getFont_Label()); 91 infoLine.setBorder(BorderFactory.createRaisedBevelBorder()); 92 infoLine.setHorizontalAlignment(SwingConstants.CENTER); 93 infoLine.setHorizontalTextPosition(SwingConstants.CENTER); 94 infoLine.setText("info"); 95 mainLayout.setHgap(2); 96 mainLayout.setVgap(2); 97 this.add(statusLine, BorderLayout.CENTER); 98 this.add(statusDB, BorderLayout.EAST); 99 this.add(infoLine, BorderLayout.NORTH); 100 } 102 103 104 108 public void setStatusLine (String text) 109 { 110 if (text == null) 111 setStatusLine("", false); 112 else 113 setStatusLine(text, false); 114 } 116 121 public void setStatusLine (String text, boolean error) 122 { 123 mt_error = error; 124 mt_text = text; 125 if (mt_error) 126 statusLine.setForeground(CompierePLAF.getTextColor_Issue()); 127 else 128 statusLine.setForeground(CompierePLAF.getTextColor_OK()); 129 statusLine.setText(" " + mt_text); 130 Thread.yield(); 132 } 134 138 public String getStatusLine () 139 { 140 return statusLine.getText().trim(); 141 } 143 147 public void setStatusToolTip (String tip) 148 { 149 statusLine.setToolTipText(tip); 150 } 152 161 public void setStatusDB (String text, Timestamp created, 162 Object createdBy, Timestamp updated, Object updatedBy, String info) 163 { 164 if (text == null || text.length() == 0) 166 { 167 statusDB.setText(""); 168 statusDB.setVisible(false); 169 } 170 else 171 { 172 StringBuffer sb = new StringBuffer (" "); 173 sb.append(text).append(" "); 174 statusDB.setText(sb.toString()); 175 if (!statusDB.isVisible()) 176 statusDB.setVisible(true); 177 } 178 179 m_text = text; 181 m_created = created; 182 m_createdBy = createdBy; 183 m_updated = updated; 184 m_updatedBy = updatedBy; 185 m_info = info; 186 } 188 192 public void setStatusDB (String text) 193 { 194 setStatusDB (text, null, null, null, null, null); 195 } 197 201 public void setStatusDB (int no) 202 { 203 setStatusDB (String.valueOf(no), null, null, null, null, null); 204 } 206 210 public void setInfo (String text) 211 { 212 if (!infoLine.isVisible()) 213 infoLine.setVisible(true); 214 infoLine.setText(text); 215 } 217 221 public void addStatusComponent (JComponent component) 222 { 223 this.add(component, BorderLayout.EAST); 224 } 226 230 void mouseClicked(MouseEvent e) 231 { 232 Log.trace(Log.l2_Sub, "StatusBar.mouseClicked - WHO"); 233 if (m_created == null && m_updated == null) 234 return; 235 236 String createdBy = null; 238 String updatedBy = null; 239 int createdByint = 0; 240 if (m_createdBy != null) 241 createdByint = Integer.parseInt(m_createdBy.toString()); 242 int updatedByint = 0; 243 if (m_updatedBy != null) 244 updatedByint = Integer.parseInt(m_updatedBy.toString()); 245 String SQL = "SELECT AD_User_ID, Name FROM AD_User WHERE AD_User_ID=? OR AD_User_ID=?"; 246 try 247 { 248 PreparedStatement pstmt = DB.prepareStatement(SQL); 249 pstmt.setInt(1, createdByint); 250 pstmt.setInt(2, updatedByint); 251 ResultSet rs = pstmt.executeQuery(); 252 while (rs.next()) 253 { 254 if (rs.getInt(1) == createdByint) 255 createdBy = rs.getString(2); 256 else 257 updatedBy = rs.getString(2); 258 } 259 rs.close(); 260 pstmt.close(); 261 } 262 catch (SQLException e1) 263 { 264 Log.error ("StatusBar.mouseClicked", e1); 265 } 266 267 if (createdByint == updatedByint) 268 updatedBy = createdBy; 269 270 StringBuffer msg = new StringBuffer (); 272 SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime); 273 msg.append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(createdBy); 274 msg.append(" - ").append(format.format(m_created)).append("\n"); 275 if (!m_created.equals(m_updated) || createdByint != updatedByint) 276 { 277 msg.append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(updatedBy); 278 msg.append(" - ").append(format.format(m_updated)).append("\n"); 279 } 280 if (m_info != null && m_info.length() > 0) 281 msg.append("\n(").append(m_info).append(")\n"); 282 283 JOptionPane.showMessageDialog(null, 285 msg.toString(), Msg.getMsg(Env.getCtx(), "Who") + m_text, JOptionPane.INFORMATION_MESSAGE); 288 } 290 } 292 293 294 295 298 class StatusBar_mouseAdapter extends java.awt.event.MouseAdapter 299 { 300 private StatusBar adaptee; 301 302 306 StatusBar_mouseAdapter(StatusBar adaptee) 307 { 308 this.adaptee = adaptee; 309 } 310 311 315 public void mouseClicked(MouseEvent e) 316 { 317 adaptee.mouseClicked(e); 318 } 319 } | Popular Tags |