📄 mwindowvo.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.io.*;
import org.compiere.util.*;
/**
* Model Window Value Object
*
* @author Jorg Janke
* @version $Id: MWindowVO.java,v 1.9 2002/11/18 06:08:49 jjanke Exp $
*/
public class MWindowVO implements Serializable
{
/**
* Private Constructor
* @param ctx context
* @param WindowNo window no
*/
private MWindowVO (Properties ctx, int WindowNo)
{
this.ctx = ctx;
this.WindowNo = WindowNo;
} // MWindowVO
/** Properties */
public Properties ctx;
public int WindowNo;
// Database fields
public int AD_Window_ID = 0;
public String Name = "";
public String Description = "";
public String Help = "";
public String WindowType = "";
public int AD_Image_ID = 0;
public int AD_Color_ID = 0;
public String IsReadWrite = null;
/** Tabs contains MTabVO elements */
public ArrayList Tabs = null;
/**
* Set Context including contained elements
* @param newCtx context
*/
public void setCtx (Properties newCtx)
{
ctx = newCtx;
for (int i = 0; i < Tabs.size() ; i++)
{
MTabVO tab = (MTabVO)Tabs.get(i);
tab.setCtx(newCtx);
}
} // setCtx
/*************************************************************************/
/**
* Create Window Value Object
*
* @param ctx context
* @param WindowNo window no
* @param AD_Window_ID window id
* @return MWindowVO
*/
public static MWindowVO create (Properties ctx, int WindowNo, int AD_Window_ID)
{
return create (ctx, WindowNo, AD_Window_ID, 0);
} // create
/**
* Create Window Value Object
*
* @param ctx context
* @param WindowNo window no
* @param AD_Window_ID window id
* @param AD_Menu_ID menu id
* @return MWindowVO
*/
public static MWindowVO create (Properties ctx, int WindowNo, int AD_Window_ID, int AD_Menu_ID)
{
Log.trace(Log.l2_Sub, "MWindowVO.create #" + WindowNo,
"AD_Window_ID=" + AD_Window_ID + "; AD_Menu_ID=" + AD_Menu_ID);
MWindowVO vo = new MWindowVO (ctx, WindowNo);
vo.AD_Window_ID = AD_Window_ID;
// Get Window_ID if required
if (vo.AD_Window_ID == 0 && AD_Menu_ID != 0)
{
String sql = "SELECT AD_Window_ID FROM AD_Menu "
+ "WHERE AD_Menu_ID=? AND Action='W'";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, AD_Menu_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
vo.AD_Window_ID = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MWindowVO.create-Menu", e);
return null;
}
Log.trace(Log.l2_Sub, "AD_Window_ID=" + vo.AD_Window_ID);
}
// -- Get Window
StringBuffer sql = new StringBuffer("SELECT Name,Description,Help,WindowType, "
+ "AD_Color_ID,AD_Image_ID, a.IsReadWrite ");
if (Env.isBaseLanguage(vo.ctx, "AD_Window"))
sql.append("FROM AD_Window w, AD_Window_Access a "
+ "WHERE w.AD_Window_ID=?"
+ " AND w.AD_Window_ID=a.AD_Window_ID AND a.AD_Role_ID=?"
+ " AND w.IsActive='Y' AND a.IsActive='Y'");
else
sql.append("FROM AD_Window_vt w, AD_Window_Access a "
+ "WHERE w.AD_Window_ID=?"
+ " AND w.AD_Window_ID=a.AD_Window_ID AND a.AD_Role_ID=?"
+ " AND a.IsActive='Y'")
.append(" AND AD_Language='")
.append(Env.getAD_Language(vo.ctx)).append("'");
try
{
// create statement
PreparedStatement pstmt = DB.prepareStatement(sql.toString());
pstmt.setInt(1, vo.AD_Window_ID);
pstmt.setInt(2, Env.getContextAsInt(vo.ctx, "#AD_Role_ID"));
// get data
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
vo.Name = rs.getString(1);
vo.Description = rs.getString(2);
if (vo.Description == null)
vo.Description = "";
vo.Help = rs.getString(3);
if (vo.Help == null)
vo.Help = "";
vo.WindowType = rs.getString(4);
//
vo.AD_Color_ID = rs.getInt(5);
vo.AD_Image_ID = rs.getInt(6);
vo.IsReadWrite = rs.getString(7);
}
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
Log.error("MWindowVO.create - " + sql.toString(), ex);
return null;
}
if (vo.IsReadWrite == null)
{
Log.saveError("AccessTableNoView", "");
return null;
}
// Create Tabs
createTabs (vo);
if (vo.Tabs == null || vo.Tabs.size() == 0)
{
Log.error("MWindowVO.create - No Tabs");
return null;
}
return vo;
} // create
/**
* Create Window Tabs
* @param mWindowVO Window Value Object
* @return true if tabs were created
*/
private static boolean createTabs (MWindowVO mWindowVO)
{
mWindowVO.Tabs = new ArrayList ();
String sql = MTabVO.getSQL(mWindowVO);
int TabNo = 0;
int AD_Table_ID = 0;
try
{
// create statement
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, mWindowVO.AD_Window_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
if (AD_Table_ID == 0)
AD_Table_ID = rs.getInt("AD_Table_ID");
// Create TabVO
MTabVO mTabVO = MTabVO.create(mWindowVO, TabNo, rs,
mWindowVO.WindowType.equals(MWindow.WindowType_Query), // isRO
mWindowVO.WindowType.equals(MWindow.WindowType_Trx)); // onlyCurrentRows
if (mTabVO != null)
{
if (!mTabVO.IsReadOnly && "N".equals(mWindowVO.IsReadWrite))
mTabVO.IsReadOnly = true;
mWindowVO.Tabs.add(mTabVO);
TabNo++; // must be same as mWindow.getTab(x)
}
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MWindowVO.createTabs", e);
return false;
}
// No Tabs
if (TabNo == 0 || mWindowVO.Tabs.size() == 0)
return false;
// Put base table of window in ctx (for VDocAction)
Env.setContext(mWindowVO.ctx, mWindowVO.WindowNo, "BaseTable_ID", AD_Table_ID);
return true;
} // createTabs
} // MWindowVO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -