1 14 package org.compiere.apps.search; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import javax.swing.event.*; 20 import java.sql.*; 21 import java.util.*; 22 23 import org.compiere.apps.*; 24 import org.compiere.grid.ed.*; 25 import org.compiere.util.*; 26 import org.compiere.model.*; 27 import org.compiere.plaf.*; 28 29 30 36 public class InfoSchedule extends JDialog 37 implements ActionListener, ChangeListener 38 { 39 45 public InfoSchedule (Frame frame, MAssignment mAssignment, boolean createNew) 46 { 47 super(frame, Msg.getMsg(Env.getCtx(), "InfoSchedule"), frame != null && createNew); 48 if (mAssignment == null) 49 m_mAssignment = new MAssignment(Env.getCtx(), 0); 50 else 51 m_mAssignment = mAssignment; 52 Log.trace(Log.l1_User, "InfoSchedule", mAssignment); 53 m_dateFrom = m_mAssignment.getAssignDateFrom(); 54 if (m_dateFrom == null) 55 m_dateFrom = new Timestamp(System.currentTimeMillis()); 56 m_createNew = createNew; 57 try 58 { 59 jbInit(); 60 dynInit(createNew); 61 } 62 catch(Exception ex) 63 { 64 Log.error("InfoSchedule", ex); 65 } 66 AEnv.showCenterWindow(frame, this); 67 } 69 72 public InfoSchedule() 73 { 74 this (null, null, false); 75 } 77 78 private MAssignment m_mAssignment; 79 80 private Timestamp m_dateFrom = null; 81 82 private boolean m_loading = false; 83 84 private boolean m_createNew; 85 86 private JPanel mainPanel = new JPanel(); 87 private BorderLayout mainLayout = new BorderLayout(); 88 private JPanel parameterPanel = new JPanel(); 89 private GridBagLayout parameterLayout = new GridBagLayout(); 90 private JLabel labelResourceType = new JLabel(); 91 private JComboBox fieldResourceType = new JComboBox(); 92 private JLabel labelResource = new JLabel(); 93 private JComboBox fieldResource = new JComboBox(); 94 private JButton bPrevious = new JButton(); 95 private JLabel labelDate = new JLabel(); 96 private VDate fieldDate = new VDate(); 97 private JButton bNext = new JButton(); 98 private JTabbedPane timePane = new JTabbedPane(); 99 private VSchedule daySchedule = new VSchedule(this, VSchedule.TYPE_DAY); 100 private VSchedule weekSchedule = new VSchedule(this, VSchedule.TYPE_WEEK); 101 private VSchedule monthSchedule = new VSchedule(this, VSchedule.TYPE_MONTH); 102 private StatusBar statusBar = new StatusBar(); 103 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 104 105 109 private void jbInit() throws Exception 110 { 111 CompiereColor.setBackground(this); 112 mainPanel.setLayout(mainLayout); 113 parameterPanel.setLayout(parameterLayout); 114 labelResourceType.setHorizontalTextPosition(SwingConstants.LEADING); 115 labelResourceType.setText(Msg.translate(Env.getCtx(), "S_ResourceType_ID")); 116 labelResource.setHorizontalTextPosition(SwingConstants.LEADING); 117 labelResource.setText(Msg.translate(Env.getCtx(), "S_Resource_ID")); 118 bPrevious.setMargin(new Insets(0, 0, 0, 0)); 119 bPrevious.setText("<"); 120 labelDate.setText(Msg.translate(Env.getCtx(), "Date")); 121 bNext.setMargin(new Insets(0, 0, 0, 0)); 122 bNext.setText(">"); 123 getContentPane().add(mainPanel, BorderLayout.CENTER); 124 mainPanel.add(parameterPanel, BorderLayout.NORTH); 125 parameterPanel.add(labelResourceType, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 126 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 8, 0, 0), 0, 0)); 127 parameterPanel.add(fieldResourceType, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 128 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0)); 129 parameterPanel.add(labelResource, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 130 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 4, 0, 4), 0, 0)); 131 parameterPanel.add(fieldResource, new GridBagConstraints(1, 1, 1, 1, 0.5, 0.0 132 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 4), 0, 0)); 133 parameterPanel.add(bPrevious, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 134 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 8, 8, 0), 0, 0)); 135 parameterPanel.add(labelDate, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 136 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0)); 137 parameterPanel.add(fieldDate, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 138 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 8, 0), 0, 0)); 139 parameterPanel.add(bNext, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0 140 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 8, 8), 0, 0)); 141 mainPanel.add(timePane, BorderLayout.CENTER); 143 timePane.add(daySchedule, Msg.getMsg(Env.getCtx(), "Day")); 144 timePane.add(weekSchedule, Msg.getMsg(Env.getCtx(), "Week")); 145 timePane.add(monthSchedule, Msg.getMsg(Env.getCtx(), "Month")); 146 timePane.addChangeListener(this); 150 mainPanel.add(confirmPanel, BorderLayout.SOUTH); 152 this.getContentPane().add(statusBar, BorderLayout.SOUTH); 154 } 156 160 private void dynInit (boolean createNew) 161 { 162 fillResourceType(); 164 fillResource(); 165 fieldResourceType.addActionListener(this); 166 fieldResource.addActionListener(this); 167 168 fieldDate.setValue(m_dateFrom); 170 fieldDate.addActionListener(this); 171 bPrevious.addActionListener(this); 172 bNext.addActionListener(this); 173 174 daySchedule.setCreateNew(createNew); 176 weekSchedule.setCreateNew(createNew); 177 monthSchedule.setCreateNew(createNew); 178 confirmPanel.addActionListener(this); 180 displayCalendar(); 181 } 183 186 private void fillResourceType() 187 { 188 int S_ResourceType_ID = 0; 190 if (m_mAssignment.getS_Resource_ID() != 0) 191 { 192 String sql = "SELECT S_ResourceType_ID FROM S_Resource WHERE S_Resource_ID=?"; 193 try 194 { 195 PreparedStatement pstmt = DB.prepareStatement(sql); 196 pstmt.setInt(1, m_mAssignment.getS_Resource_ID()); 197 ResultSet rs = pstmt.executeQuery(); 198 if (rs.next()) 199 S_ResourceType_ID = rs.getInt(1); 200 rs.close(); 201 pstmt.close(); 202 } 203 catch (SQLException e) 204 { 205 Log.error("InfoSchedule.fillResourceType-1", e); 206 } 207 } 208 209 String sql = MRole.getDefault().addAccessSQL( 211 "SELECT S_ResourceType_ID, Name FROM S_ResourceType WHERE IsActive='Y' ORDER BY 2", 212 "S_ResourceType", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); 213 KeyNamePair defaultValue = null; 214 try 215 { 216 PreparedStatement pstmt = DB.prepareStatement(sql); 217 ResultSet rs = pstmt.executeQuery(); 218 while (rs.next()) 219 { 220 KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); 221 if (S_ResourceType_ID == pp.getKey()) 222 defaultValue = pp; 223 fieldResourceType.addItem(pp); 224 } 225 rs.close(); 226 pstmt.close(); 227 } 228 catch (SQLException e) 229 { 230 Log.error("InfoSchedule.fillResourceType-2", e); 231 } 232 if (defaultValue != null) 233 fieldResourceType.setSelectedItem(defaultValue); 234 } 236 239 private void fillResource() 240 { 241 KeyNamePair pp = (KeyNamePair)fieldResourceType.getSelectedItem(); 243 if (pp == null) 244 return; 245 int S_ResourceType_ID = pp.getKey(); 246 247 KeyNamePair defaultValue = null; 248 249 m_loading = true; 251 fieldResource.removeAllItems(); 252 String sql = "SELECT S_Resource_ID, Name FROM S_Resource WHERE S_ResourceType_ID=? ORDER BY 2"; 253 try 254 { 255 PreparedStatement pstmt = DB.prepareStatement(sql); 256 pstmt.setInt(1, S_ResourceType_ID); 257 ResultSet rs = pstmt.executeQuery(); 258 while (rs.next()) 259 { 260 pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); 261 if (m_mAssignment.getS_Resource_ID() == pp.getKey()) 262 defaultValue = pp; 263 fieldResource.addItem(pp); 264 } 265 rs.close(); 266 pstmt.close(); 267 } 268 catch (SQLException e) 269 { 270 Log.error("InfoSchedule.fillResource", e); 271 } 272 if (defaultValue != null) 273 fieldResource.setSelectedItem(defaultValue); 274 275 m_loading = false; 276 } 278 281 private void displayCalendar () 282 { 283 KeyNamePair pp = (KeyNamePair)fieldResource.getSelectedItem(); 285 if (pp == null) 286 return; 287 int S_Resource_ID = pp.getKey(); 288 m_mAssignment.setS_Resource_ID(S_Resource_ID); 289 Timestamp date = fieldDate.getTimestamp(); 290 int index = timePane.getSelectedIndex(); 291 Log.trace(Log.l3_Util, "InfoSchedule.displayCalendar " + index + ", ID=" + S_Resource_ID, date); 292 293 m_loading = true; 295 if (index == 0) 296 daySchedule.recreate (S_Resource_ID, date); 297 else if (index == 1) 298 weekSchedule.recreate (S_Resource_ID, date); 299 else 300 monthSchedule.recreate (S_Resource_ID, date); 301 m_loading = false; 302 repaint(); 303 } 305 306 307 310 public void dispose() 311 { 312 daySchedule.dispose(); 313 weekSchedule.dispose(); 314 monthSchedule.dispose(); 315 this.removeAll(); 316 super.dispose(); 317 } 319 323 public void actionPerformed(ActionEvent e) 324 { 325 if (m_loading) 326 return; 327 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 328 329 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 330 dispose(); 331 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 332 dispose(); 333 else if (e.getSource() == fieldResourceType) 335 fillResource(); 336 else if (e.getSource() == fieldResource || e.getSource() == fieldDate) 338 displayCalendar(); 339 else if (e.getSource() == bPrevious) 341 adjustDate(-1); 342 else if (e.getSource() == bNext) 343 adjustDate(+1); 344 this.setCursor(Cursor.getDefaultCursor()); 346 } 348 352 public void stateChanged (ChangeEvent e) 353 { 354 displayCalendar(); 355 } 357 361 private void adjustDate (int diff) 362 { 363 Timestamp date = fieldDate.getTimestamp(); 364 GregorianCalendar cal = new GregorianCalendar(); 365 cal.setTime(date); 366 if (timePane.getSelectedIndex() == 0) 367 cal.add(java.util.Calendar.DAY_OF_YEAR, diff); 368 else if (timePane.getSelectedIndex() == 1) 369 cal.add(java.util.Calendar.WEEK_OF_YEAR, diff); 370 else 371 cal.add(java.util.Calendar.MONTH, diff); 372 fieldDate.setValue(new Timestamp(cal.getTimeInMillis())); 374 displayCalendar (); 375 } 377 378 379 384 public void mAssignmentCallback (MAssignment assignment) 385 { 386 m_mAssignment = assignment; 387 if (m_createNew) 388 dispose(); 389 else 390 displayCalendar(); 391 } 393 397 public MAssignment getMAssignment() 398 { 399 return m_mAssignment; 400 } 402 403 404 420 } | Popular Tags |