1 14 package org.compiere.grid.ed; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import java.sql.*; 20 import java.util.*; 21 22 import org.compiere.util.*; 23 import org.compiere.model.*; 24 import org.compiere.apps.*; 25 import org.compiere.plaf.*; 26 import org.compiere.swing.*; 27 28 34 public class VDocAction extends JDialog implements ActionListener 35 { 36 43 public VDocAction(int WindowNo, MTab mTab, VButton button) 44 { 45 super(Env.getWindow(WindowNo), Msg.translate(Env.getCtx(), "DocAction"), true); 46 Log.trace(Log.l3_Util, "VDocAction"); 47 m_WindowNo = WindowNo; 48 m_mTab = mTab; 49 try 51 { 52 jbInit(); 53 } 54 catch(Exception ex) 55 { 56 Log.error("VDocAction", ex); 57 } 58 59 m_AD_Table_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "BaseTable_ID"); 61 if (s_value == null) 62 readReference(); 63 dynInit(); 65 AEnv.positionCenterWindow(Env.getWindow(WindowNo), this); 67 } 69 private int m_WindowNo = 0; 71 private int m_AD_Table_ID; 72 private boolean m_OKpressed = false; 73 private MTab m_mTab; 74 private static String [] s_value = null; 76 private static String [] s_name; 77 private static String [] s_description; 78 private CPanel mainPanel = new CPanel(); 80 private BorderLayout mainLayout = new BorderLayout(); 81 private CPanel northPanel = new CPanel(); 82 private CComboBox actionCombo = new CComboBox(); 83 private JLabel actionLabel = new JLabel(); 84 private JScrollPane centerPane = new JScrollPane(); 85 private JTextArea message = new JTextArea(); 86 private FlowLayout northLayout = new FlowLayout(); 87 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 88 89 93 void jbInit() throws Exception 94 { 95 CompiereColor.setBackground(this); 96 mainPanel.setLayout(mainLayout); 97 actionLabel.setText(Msg.translate(Env.getCtx(), "DocAction")); 98 actionCombo.addActionListener(this); 99 message.setLineWrap(true); 100 message.setPreferredSize(new Dimension(350, 35)); 101 message.setWrapStyleWord(true); 102 message.setBackground(CompierePLAF.getFieldBackground_Inactive()); 103 message.setEditable(false); 104 northPanel.setLayout(northLayout); 105 northLayout.setAlignment(FlowLayout.RIGHT); 106 getContentPane().add(mainPanel); 107 mainPanel.add(northPanel, BorderLayout.NORTH); 108 northPanel.add(actionLabel, null); 109 northPanel.add(actionCombo, null); 110 mainPanel.add(centerPane, BorderLayout.CENTER); 111 centerPane.getViewport().add(message, null); 112 mainPanel.add(confirmPanel, BorderLayout.SOUTH); 114 confirmPanel.addActionListener(this); 115 } 117 154 private void dynInit() 155 { 156 String DocStatus = (String )m_mTab.getValue("DocStatus"); 157 String DocAction = (String )m_mTab.getValue("DocAction"); 158 String Processing = (String )m_mTab.getValue("Processing"); 159 String OrderType = Env.getContext(Env.getCtx(), m_WindowNo, "OrderType"); 160 String IsSOTrx = Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx"); 161 162 if (DocStatus == null) 163 { 164 message.setText("*** ERROR ***"); 165 return; 166 } 167 168 Log.trace(Log.l5_DData, "DocStatus=" + DocStatus + ", DocAction=" 169 + DocAction + ", OrderType=" + OrderType + ", IsSOTrx=" + IsSOTrx 170 + ", Processing=" + Processing + ", AD_Table_ID=" + m_AD_Table_ID); 171 172 173 String [] options = new String [s_value.length]; 174 int index = 0; 175 177 180 181 if (Processing != null && Processing.equals("Y")) 183 { 184 options[index++] = "XL"; } 186 187 else if (DocStatus.equals("NA")) 189 { 190 options[index++] = "AP"; options[index++] = "RJ"; options[index++] = "VO"; } 194 else if (DocStatus.equals("DR")) 196 { 197 options[index++] = "CO"; options[index++] = "VO"; } 200 else if (DocStatus.equals("IP")) 202 { 203 options[index++] = "CO"; options[index++] = "VO"; } 206 else if (DocStatus.equals("CO")) 208 { 209 options[index++] = "CL"; } 211 else if (DocStatus.equals("CL") || DocStatus.equals("VO") || DocStatus.equals("RE")) 213 return; 214 215 216 219 if (m_AD_Table_ID == 259) 220 { 221 if (DocStatus.equals("DR")) 223 { 224 options[index++] = "PR"; if ("Y".equals(IsSOTrx) 227 && ("OB".equals(OrderType) || "ON".equals(OrderType))) 228 DocAction = "PR"; 229 } 230 else if (DocStatus.equals("CO")) 232 options[index++] = "RE"; } 234 237 else if (m_AD_Table_ID == 318) 238 { 239 if (DocStatus.equals("CO")) 241 options[index++] = "RC"; } 243 246 else if (m_AD_Table_ID == 335) 247 { 248 if (DocStatus.equals("CO")) 250 options[index++] = "RC"; } 252 253 254 257 for (int i = 0; i < index; i++) 258 { 259 boolean added = false; 261 for (int j = 0; j < s_value.length && !added; j++) 262 if (options[i].equals(s_value[j])) 263 { 264 actionCombo.addItem(s_name[j]); 265 added = true; 266 } 267 } 268 269 if (DocAction.equals("--")) DocAction = "CL"; 272 String defaultV = ""; 273 for (int i = 0; i < s_value.length && defaultV.equals(""); i++) 274 if (DocAction.equals(s_value[i])) 275 defaultV = s_name[i]; 276 if (!defaultV.equals("")) 277 actionCombo.setSelectedItem(defaultV); 278 } 280 284 public int getNumberOfOptions() 285 { 286 return actionCombo.getItemCount(); 287 } 289 293 public boolean getStartProcess() 294 { 295 return m_OKpressed; 296 } 298 299 302 private void readReference() 303 { 304 String SQL; 305 if (Env.isBaseLanguage(Env.getCtx(), "AD_Ref_List")) 306 SQL = "SELECT Value, Name, Description FROM AD_Ref_List " 307 + "WHERE AD_Reference_ID=135 ORDER BY Name"; 308 else 309 SQL = "SELECT l.Value, t.Name, t.Description " 310 + "FROM AD_Ref_List l, AD_Ref_List_Trl t " 311 + "WHERE l.AD_Ref_List_ID=t.AD_Ref_List_ID" 312 + " AND t.AD_Language='" + Env.getAD_Language(Env.getCtx()) + "'" 313 + " AND l.AD_Reference_ID=135 ORDER BY t.Name"; 314 315 ArrayList v_value = new ArrayList(); 316 ArrayList v_name = new ArrayList(); 317 ArrayList v_description = new ArrayList(); 318 try 319 { 320 PreparedStatement pstmt = DB.prepareStatement(SQL); 321 ResultSet rs = pstmt.executeQuery(); 322 while (rs.next()) 323 { 324 String value = rs.getString(1); 325 String name = rs.getString(2); 326 String description = rs.getString(3); 327 if (description == null) 328 description = ""; 329 v_value.add(value); 331 v_name.add(name); 332 v_description.add(description); 333 } 334 rs.close(); 335 pstmt.close(); 336 } 337 catch (SQLException e) 338 { 339 Log.error("VDocAction.readReference", e); 340 } 341 342 int size = v_value.size(); 344 s_value = new String [size]; 345 s_name = new String [size]; 346 s_description = new String [size]; 347 for (int i = 0; i < size; i++) 348 { 349 s_value[i] = (String )v_value.get(i); 350 s_name[i] = (String )v_name.get(i); 351 s_description[i] = (String )v_description.get(i); 352 } 353 } 355 359 public void actionPerformed(ActionEvent e) 360 { 361 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 362 { 363 if (save()) 364 { 365 dispose(); 366 m_OKpressed = true; 367 } 368 } 369 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 370 dispose(); 371 else if (e.getSource() != actionCombo) 372 return; 373 374 377 int index = getSelectedIndex(); 378 if (index != -1) 380 message.setText(s_description[index]); 381 } 383 384 388 private int getSelectedIndex() 389 { 390 int index = -1; 391 392 String sel = (String )actionCombo.getSelectedItem(); 394 if (sel == null) 395 return index; 396 397 for (int i = 0; i < s_name.length && index == -1; i++) 399 if (sel.equals(s_name[i])) 400 index = i; 401 return index; 403 } 405 409 private boolean save() 410 { 411 int index = getSelectedIndex(); 412 if (index == -1) 413 return false; 414 415 m_mTab.setValue("DocAction", s_value[index]); 417 return true; 418 } 420 } | Popular Tags |