1 14 package org.compiere.model; 15 16 import java.io.*; 17 import java.sql.*; 18 import java.util.*; 19 import javax.swing.*; 20 21 import org.compiere.util.*; 22 23 29 public class MWorkbench implements Serializable 30 { 31 34 public MWorkbench (Properties ctx) 35 { 36 m_ctx = ctx; 37 } 39 42 public MWorkbench (Properties ctx, int AD_Window_ID) 43 { 44 m_ctx = ctx; 45 m_windows.add (new WBWindow(TYPE_WINDOW, AD_Window_ID)); 46 } 48 49 private Properties m_ctx; 50 51 52 private ArrayList m_windows = new ArrayList(); 53 54 private int AD_Workbench_ID = 0; 55 private String Name = ""; 56 private String Description = ""; 57 private String Help = ""; 58 private int AD_Column_ID = 0; 59 private int AD_Image_ID = 0; 60 private int AD_Color_ID = 0; 61 private int PA_Goal_ID = 0; 62 private String ColumnName = ""; 63 64 67 public boolean initWorkbench (int ad_Workbench_ID) 68 { 69 AD_Workbench_ID = ad_Workbench_ID; 70 String sql = null; 72 if (Env.isBaseLanguage(m_ctx, "AD_Workbench")) 73 sql = "SELECT w.Name,w.Description,w.Help," + " w.AD_Column_ID,w.AD_Image_ID,w.AD_Color_ID,w.PA_Goal_ID," + " c.ColumnName " + "FROM AD_Workbench w, AD_Column c " 77 + "WHERE w.AD_Workbench_ID=?" + " AND w.IsActive='Y'" 79 + " AND w.AD_Column_ID=c.AD_Column_ID"; 80 else 81 sql = "SELECT t.Name,t.Description,t.Help," 82 + " w.AD_Column_ID,w.AD_Image_ID,w.AD_Color_ID,w.PA_Goal_ID," 83 + " c.ColumnName " 84 + "FROM AD_Workbench w, AD_Workbench_Trl t, AD_Column c " 85 + "WHERE w.AD_Workbench_ID=?" + " AND w.IsActive='Y'" 87 + " AND w.AD_Workbench_ID=t.AD_Workbench_ID" 88 + " AND t.AD_Language='" + Env.getAD_Language(m_ctx) + "'" 89 + " AND w.AD_Column_ID=c.AD_Column_ID"; 90 try 91 { 92 PreparedStatement pstmt = DB.prepareStatement(sql); 93 pstmt.setInt(1, AD_Workbench_ID); 94 ResultSet rs = pstmt.executeQuery(); 95 if (rs.next()) 96 { 97 Name = rs.getString(1); 98 Description = rs.getString(2); 99 if (Description == null) 100 Description = ""; 101 Help = rs.getString(3); 102 if (Help == null) 103 Help = ""; 104 AD_Column_ID = rs.getInt(4); 106 AD_Image_ID = rs.getInt(5); 107 AD_Color_ID = rs.getInt(6); 108 PA_Goal_ID = rs.getInt(7); 109 ColumnName = rs.getString(8); 110 } 111 else 112 AD_Workbench_ID = 0; 113 rs.close(); 114 pstmt.close(); 115 } 116 catch (SQLException e) 117 { 118 Log.error("MWorkbench.initWorkbench", e); 119 } 120 121 if (AD_Workbench_ID == 0) 122 return false; 123 return initWorkbenchWindows(); 124 } 126 129 public String toString() 130 { 131 return "MWorkbench ID=" + AD_Workbench_ID + " " + Name 132 + ", windows=" + m_windows.size() + ", LinkColumn=" + ColumnName; 133 } 135 138 public void dispose() 139 { 140 for (int i = 0; i < m_windows.size(); i++) 141 { 142 dispose(i); 143 } 144 m_windows.clear(); 145 m_windows = null; 146 } 148 152 public MQuery getQuery() 153 { 154 return MQuery.getEqualQuery(ColumnName, "@#" + ColumnName + "@"); 155 } 157 158 159 public int getAD_Workbench_ID() 160 { 161 return AD_Workbench_ID; 162 } 163 public String getName() 164 { 165 return Name; 166 } 167 public String getDescription() 168 { 169 return Description; 170 } 171 public String getHelp() 172 { 173 return Help; 174 } 175 public int getAD_Column_ID() 176 { 177 return AD_Column_ID; 178 } 179 public int getAD_Image_ID() 180 { 181 return AD_Image_ID; 182 } 183 public int getAD_Color_ID() 184 { 185 return AD_Color_ID; 186 } 187 public int getPA_Goal_ID() 188 { 189 return PA_Goal_ID; 190 } 191 192 193 194 195 public static final int TYPE_WINDOW = 1; 196 197 public static final int TYPE_FORM = 2; 198 199 public static final int TYPE_PROCESS = 3; 200 201 public static final int TYPE_TASK = 4; 202 203 206 private boolean initWorkbenchWindows() 207 { 208 String sql = "SELECT AD_Window_ID, AD_Form_ID, AD_Process_ID, AD_Task_ID " 209 + "FROM AD_WorkbenchWindow " 210 + "WHERE AD_Workbench_ID=? AND IsActive='Y'" 211 + "ORDER BY SeqNo"; 212 try 213 { 214 PreparedStatement pstmt = DB.prepareStatement(sql); 215 pstmt.setInt(1, AD_Workbench_ID); 216 ResultSet rs = pstmt.executeQuery(); 217 while (rs.next()) 218 { 219 int AD_Window_ID = rs.getInt(1); 220 int AD_Form_ID = rs.getInt(2); 221 int AD_Process_ID = rs.getInt(3); 222 int AD_Task_ID = rs.getInt(4); 223 if (AD_Window_ID > 0) 225 m_windows.add (new WBWindow(TYPE_WINDOW, AD_Window_ID)); 226 else if (AD_Form_ID > 0) 227 m_windows.add (new WBWindow(TYPE_FORM, AD_Form_ID)); 228 else if (AD_Process_ID > 0) 229 m_windows.add (new WBWindow(TYPE_PROCESS, AD_Process_ID)); 230 else if (AD_Task_ID > 0) 231 m_windows.add (new WBWindow(TYPE_TASK, AD_Task_ID)); 232 } 233 rs.close(); 234 pstmt.close(); 235 } 236 catch (SQLException e) 237 { 238 Log.error("MWorkbench.initWorkbenchWindows", e); 239 return false; 240 } 241 return true; 242 } 244 247 public int getWindowCount() 248 { 249 return m_windows.size(); 250 } 252 256 public int getWindowType (int index) 257 { 258 if (index < 0 || index > m_windows.size()) 259 return -1; 260 WBWindow win = (WBWindow)m_windows.get(index); 261 return win.Type; 262 } 264 268 public int getWindowID (int index) 269 { 270 if (index < 0 || index > m_windows.size()) 271 return -1; 272 WBWindow win = (WBWindow)m_windows.get(index); 273 return win.ID; 274 } 276 277 278 281 public void setMWindow (int index, MWindow mw) 282 { 283 if (index < 0 || index > m_windows.size()) 284 throw new IllegalArgumentException ("MWorkbench.setMWindow - Index invalid: " + index); 285 WBWindow win = (WBWindow)m_windows.get(index); 286 if (win.Type != TYPE_WINDOW) 287 throw new IllegalArgumentException ("MWorkbench.setMWindow - Not a MWindow: " + index); 288 win.mWindow = mw; 289 } 291 294 public MWindow getMWindow (int index) 295 { 296 if (index < 0 || index > m_windows.size()) 297 throw new IllegalArgumentException ("MWorkbench.getMWindow - Index invalid: " + index); 298 WBWindow win = (WBWindow)m_windows.get(index); 299 if (win.Type != TYPE_WINDOW) 300 throw new IllegalArgumentException ("MWorkbench.getMWindow - Not a MWindow: " + index); 301 return win.mWindow; 302 } 304 308 public String getName (int index) 309 { 310 if (index < 0 || index > m_windows.size()) 311 throw new IllegalArgumentException ("MWorkbench.getName - Index invalid: " + index); 312 WBWindow win = (WBWindow)m_windows.get(index); 313 if (win.mWindow != null && win.Type == TYPE_WINDOW) 314 return win.mWindow.getName(); 315 return null; 316 } 318 322 public String getDescription (int index) 323 { 324 if (index < 0 || index > m_windows.size()) 325 throw new IllegalArgumentException ("MWorkbench.getDescription - Index invalid: " + index); 326 WBWindow win = (WBWindow)m_windows.get(index); 327 if (win.mWindow != null && win.Type == TYPE_WINDOW) 328 return win.mWindow.getDescription(); 329 return null; 330 } 332 336 public String getHelp (int index) 337 { 338 if (index < 0 || index > m_windows.size()) 339 throw new IllegalArgumentException ("MWorkbench.getHelp - Index invalid: " + index); 340 WBWindow win = (WBWindow)m_windows.get(index); 341 if (win.mWindow != null && win.Type == TYPE_WINDOW) 342 return win.mWindow.getHelp(); 343 return null; 344 } 346 350 public Icon getIcon (int index) 351 { 352 if (index < 0 || index > m_windows.size()) 353 throw new IllegalArgumentException ("MWorkbench.getIcon - Index invalid: " + index); 354 WBWindow win = (WBWindow)m_windows.get(index); 355 if (win.mWindow != null && win.Type == TYPE_WINDOW) 356 return win.mWindow.getIcon(); 357 return null; 358 } 360 364 public int getAD_Color_ID (int index) 365 { 366 if (index < 0 || index > m_windows.size()) 367 throw new IllegalArgumentException ("MWorkbench.getAD_Color_ID - Index invalid: " + index); 368 WBWindow win = (WBWindow)m_windows.get(index); 369 int retValue = -1; 370 if (retValue == -1) 373 return getAD_Color_ID(); 374 return retValue; 375 } 377 380 public void setWindowNo (int index, int windowNo) 381 { 382 if (index < 0 || index > m_windows.size()) 383 throw new IllegalArgumentException ("MWorkbench.setWindowNo - Index invalid: " + index); 384 WBWindow win = (WBWindow)m_windows.get(index); 385 win.WindowNo = windowNo; 386 } 388 392 public int getWindowNo (int index) 393 { 394 if (index < 0 || index > m_windows.size()) 395 throw new IllegalArgumentException ("MWorkbench.getWindowNo - Index invalid: " + index); 396 WBWindow win = (WBWindow)m_windows.get(index); 397 return win.WindowNo; 398 } 400 403 public void dispose (int index) 404 { 405 if (index < 0 || index > m_windows.size()) 406 throw new IllegalArgumentException ("MWorkbench.getWindowNo - Index invalid: " + index); 407 WBWindow win = (WBWindow)m_windows.get(index); 408 if (win.mWindow != null) 409 win.mWindow.dispose(); 410 win.mWindow = null; 411 } 413 414 415 418 class WBWindow 419 { 420 public WBWindow (int type, int id) 421 { 422 Type = type; 423 ID = id; 424 } 425 public int Type = 0; 426 public int ID = 0; 427 public int WindowNo = -1; 428 public MWindow mWindow = null; 430 } } | Popular Tags |