📄 wmenu.java
字号:
//
return loginInfo;
} // checkLogin
/*************************************************************************/
/**
* Load Tree and return root node
* @param AD_Client_ID client
* @param AD_Role_ID role
* @param AD_User_ID user
* @param AD_Language language
* @return node
*/
private MNode loadTree (int AD_Client_ID, int AD_Role_ID, int AD_User_ID, String AD_Language)
{
// Get Tree info with start node
int AD_Tree_ID;
String Name;
String TreeType;
String Description;
int startID;
//
MNode root = null;
// Get Root Node
String SQL = "SELECT t.AD_Tree_ID, t.Name, t.Description, t.TreeType, tn.Node_ID "
+ "FROM AD_Tree t, AD_ClientInfo c, AD_TreeNode tn "
+ "WHERE t.AD_Tree_ID=tn.AD_Tree_ID"
+ " AND tn.Parent_ID IS NULL"
+ " AND t.AD_Tree_ID=c.AD_Tree_Menu_ID"
+ " AND c.AD_Client_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery();
if (!rs.next())
{
rs.close();
pstmt.close();
return null;
}
AD_Tree_ID = rs.getInt(1);
Name = rs.getString(2);
Description = rs.getString(3);
TreeType = rs.getString(4);
startID = rs.getInt(5);
// create root node
root = new MNode (startID, Name, Description, true, "");
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("WMenu.loadTree -1", e);
return null;
}
// SQL for TreeNodes
StringBuffer cmd = new StringBuffer("SELECT tn.Node_ID,tn.Parent_ID,tn.SeqNo, "
+ "(SELECT 'Y' FROM AD_TreeBar tb WHERE tb.AD_Tree_ID=tn.AD_Tree_ID AND tb.AD_User_ID=")
.append(AD_User_ID).append(" AND tb.Node_ID=tn.Node_ID) "
+ "FROM AD_TreeNode tn ")
.append("WHERE tn.IsActive='Y' "
+ "START WITH Parent_ID IS NULL AND AD_Tree_ID=? "
+ "CONNECT BY Parent_ID=PRIOR Node_ID AND AD_Tree_ID=? "
+ "ORDER BY LEVEL, SeqNo");
// SQL for Node Info
StringBuffer cmdNode = new StringBuffer();
boolean base = Env.isBaseLanguage(Env.getCtx(), "AD_Menu");
if (base)
cmdNode.append("SELECT m.Name,m.Description,m.IsSummary,m.Action "
+ "FROM AD_Menu m");
else
cmdNode.append("SELECT t.Name,t.Description,m.IsSummary,m.Action "
+ "FROM AD_Menu m, AD_Menu_Trl t");
cmdNode.append(", (SELECT ").append(AD_Role_ID).append(" AS XRole FROM DUAL)");
cmdNode.append(" WHERE m.AD_Menu_ID=?");
if (!base)
cmdNode.append(" AND m.AD_Menu_ID=t.AD_Menu_ID AND t.AD_Language='")
.append(Env.getAD_Language(Env.getCtx())).append("'");
cmdNode.append(" AND m.IsActive='Y' "
+ "AND (m.IsSummary='Y' OR m.Action='B'"
+ " OR EXISTS (SELECT * FROM AD_Window_Access wa WHERE wa.AD_Window_ID=m.AD_Window_ID AND wa.AD_Role_ID=XRole)"
+ " OR EXISTS (SELECT * FROM AD_Process_Access wa WHERE wa.AD_Process_ID=m.AD_Process_ID AND wa.AD_Role_ID=XRole)"
+ " OR EXISTS (SELECT * FROM AD_Form_Access wa WHERE wa.AD_Form_ID=m.AD_Form_ID AND wa.AD_Role_ID=XRole)"
+ " OR EXISTS (SELECT * FROM AD_Task_Access wa WHERE wa.AD_Task_ID=m.AD_Task_ID AND wa.AD_Role_ID=XRole)"
+ " OR EXISTS (SELECT * FROM AD_Workflow_Access wa WHERE wa.AD_Workflow_ID=m.AD_Workflow_ID AND wa.AD_Role_ID=XRole)"
+ ")");
// Log.trace(Log.l6_Database, "SQL Tree", cmd.toString());
// Log.trace(Log.l6_Database, "SQL Node", cmdNode.toString());
// The Node Loop
try
{
PreparedStatement pstmtNode = DB.prepareStatement(cmdNode.toString());
//
PreparedStatement pstmt = DB.prepareStatement(cmd.toString());
pstmt.setInt(1, AD_Tree_ID);
pstmt.setInt(2, AD_Tree_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
int Node_ID = rs.getInt(1);
int Parent_ID = rs.getInt(2);
int SeqNo = rs.getInt(3);
boolean onBar = (rs.getString(4) != null);
loadNode (pstmtNode, root, Node_ID, Parent_ID, SeqNo, onBar);
}
rs.close();
pstmt.close();
pstmtNode.close();
}
catch (SQLException e)
{
Log.error("WMenu.loadTree -2", e);
}
// Clean Menu tree
root.clean(root);
return root;
} // loadTree
/**
* Load Node using prepared statement
* @param pstmt Prepared Statement requiring to set Node_ID and returning
* Name,Description,IsSummary,ImageIndiactor
* @param root root node
* @param Node_ID Key of the record
* @param Parent_ID Parent ID of the record
* @param SeqNo Sort index
* @param onBar Node also on Shortcut bar
*/
private void loadNode (PreparedStatement pstmt, MNode root,
int Node_ID, int Parent_ID, int SeqNo, boolean onBar)
{
try
{
pstmt.setInt(1, Node_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
String Name = rs.getString(1);
String Description = rs.getString(2);
boolean IsSummary = rs.getString(3).equals("Y");
String ImageIndicator = rs.getString(4);
if (Name != null)
{
MNode child = new MNode (Node_ID, Name, Description, IsSummary, ImageIndicator);
child.add(root, Parent_ID, child);
}
}
// else
// Log.trace(Log.l6_Database,"Not added", "Node_ID=" + Node_ID);
rs.close();
}
catch (SQLException e)
{
Log.error("WMenu.loadNode", e);
}
} // loadNode
/**************************************************************************
* Web Menu Tree Node
*/
class MNode
{
/**
* Constructor
* @param ID id
* @param Name name
* @param Description description
* @param isSummary summary
* @param Type type
*/
public MNode (int ID, String Name, String Description, boolean isSummary, String Type)
{
this.ID = ID;
this.Name = Name;
this.Description = Description;
if (this.Description == null)
this.Description = "";
this.isSummary = isSummary;
this.Type = Type;
if (this.Type == null)
this.Type = "";
}
public int ID;
public String Name;
public String Description;
public boolean isSummary;
public String Type;
public ArrayList children = new ArrayList();
/**
* Add to list of children
* @param child child
* @return true
*/
public boolean add (MNode child)
{
children.add(child);
return true;
} // add
/*********************************************************************/
/**
* Traverse Tree starting at root to add child to parent with parentID
* @param root root
* @param parentID parent
* @param child child
* @returns false if not added
*/
public boolean add (MNode root, int parentID, MNode child)
{
// is this root the parent?
if (root.ID == parentID)
return root.add(child);
// do we have children to check?
else if (root.children.size() == 0)
return false;
// check children
for (int i = 0; i < root.children.size(); i++)
{
MNode cc = (MNode)root.children.get(i);
if (root.add(cc, parentID, child))
return true;
}
// nothing found
return false;
} // add
/**
* Traverse Tree and print it
* @param root root
* @param buf buffer
*/
public void print (MNode root, StringBuffer buf)
{
// Leaf
if (root.children.size() == 0)
{
/**
* <li id="menuXXXXX"><a href="...." onMouseOver="status='Menu Description';return true;">Menu Entry</a></li>
*/
String item = "";
String servletName = "";
if (root.Type.equals("W"))
{
item = "menuWindow";
servletName = "WWindow";
}
else if (root.Type.equals("X"))
{
item = "menuWindow";
servletName = "WForm";
}
else if (root.Type.equals("R"))
{
item = "menuReport";
servletName = "WReport";
}
else if (root.Type.equals("P"))
{
item = "menuProcess";
servletName = "WProcess";
}
else if (root.Type.equals("F"))
{
item = "menuWorkflow";
servletName = "WWorkflow";
}
else if (root.Type.equals("T"))
{
item = "menuProcess";
servletName = "WTask";
}
else
servletName = "WError";
String description = root.Description.replace('\'',' ').replace('"',' ');
buf.append("<li id=\"" + item + "\"><a href=\"");
// url - /appl/servletName?AD_Menu_ID=x
buf.append(WEnv.getBaseDirectory(servletName))
.append("?AD_Menu_ID=")
.append(root.ID);
//
buf.append("\" onMouseOver=\"status='" + description + "';return true;\" onclick=showLoadingWindow(\"" + WEnv.getBaseDirectory("") + "\")>");
buf.append(root.Name);
buf.append("</a></li>\n");
}
else
{
/**
* <li id="foldHeader">MenuEntry</li>
* <ul style="display:none">
* ....
* </ul>
*/
buf.append("\n<li id=\"menuHeader\">"); // summary node
buf.append(root.Name);
buf.append("</li>\n");
// Next Level
buf.append("<ul style=\"display:none\">\n"); // start next level
for (int i = 0; i < root.children.size(); i++)
{
MNode cc = (MNode)root.children.get(i);
root.print(cc, buf);
}
buf.append("</ul>"); // finish next level
}
} // print
/**
* Clean tree of parents without children
* @param root root node
*/
public void clean (MNode root)
{
int size = root.children.size();
if (size == 0)
return;
//
ArrayList temp = new ArrayList(size);
boolean changed = false;
for (int i = 0; i < size; i++)
{
MNode cc = (MNode)root.children.get(i);
int ccSize = cc.children.size();
if (cc.isSummary && ccSize == 0)
changed = true;
else
temp.add(cc);
if (ccSize != 0)
cc.clean(cc);
}
if (changed)
root.children = temp;
} // clean
} // MNode
} // WMenu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -