Search in sources :

Example 11 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class TreeSearchPanel method refreshSearchList.

private void refreshSearchList() {
    treeNodeItemMap.clear();
    if (tree.getModel() == null) {
        TreeUtils.traverse(tree, new TreeItemAction() {

            public void run(Treeitem treeItem) {
                addTreeItem(treeItem);
            }
        });
    } else {
        TreeUtils.traverse(tree.getModel(), new TreeNodeAction() {

            public void run(DefaultTreeNode<?> treeNode) {
                addTreeItem(treeNode);
            }
        });
    }
    treeValues = new String[treeNodeItemMap.size()];
    treeDescription = new String[treeNodeItemMap.size()];
    int i = -1;
    for (Object value : treeNodeItemMap.values()) {
        i++;
        if (value instanceof Treeitem) {
            Treeitem treeItem = (Treeitem) value;
            treeValues[i] = treeItem.getLabel();
            treeDescription[i] = treeItem.getTooltiptext();
        } else if (value instanceof DefaultTreeNode) {
            DefaultTreeNode<?> sNode = (DefaultTreeNode<?>) value;
            MTreeNode mNode = (MTreeNode) sNode.getData();
            treeValues[i] = mNode.getName();
            treeDescription[i] = mNode.getDescription();
        }
    }
    cmbSearch.setDescription(treeDescription);
    cmbSearch.setDict(treeValues);
}
Also used : MTreeNode(org.compiere.model.MTreeNode) TreeItemAction(org.adempiere.webui.util.TreeItemAction) Treeitem(org.zkoss.zul.Treeitem) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) TreeNodeAction(org.adempiere.webui.util.TreeNodeAction)

Example 12 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class WMenu method createPage.

//  checkLogin
/**
	 * 	Create Menu Page
	 *	@param request request 
	 *	@param wsc context
	 *	@param AD_Role_ID role
	 *	@return document
	 */
private WebDoc createPage(HttpServletRequest request, WebSessionCtx wsc, int AD_Role_ID, int AD_User_ID, int AD_Client_ID, int AD_Org_ID) {
    //	Document
    //Modified by Rob Klein 4/29/07
    //String windowTitle = Msg.getMsg(wsc.ctx, "Menu");
    String windowTitle = "Menu";
    WebDoc doc = WebDoc.create(windowTitle);
    head head = doc.getHead();
    //  Target
    head.addElement(new base().setTarget(WebEnv.TARGET_WINDOW));
    //  Specific Menu Script/Stylesheet
    head.addElement(new link(WebEnv.getBaseDirectory("/css/menu.css"), link.REL_STYLESHEET, link.TYPE_CSS));
    head.addElement(new script((Element) null, WebEnv.getBaseDirectory("/js/menu.js")));
    head.addElement(new script((Element) null, WebEnv.getBaseDirectory("/js/window.js")));
    //Modified by Rob Klein 4/29/07
    //head.addElement(new script((Element)null, WebEnv.getBaseDirectory("/js/mktree.js")));
    //head.addElement(new link(WebEnv.getBaseDirectory("/css/mktree.css"), link.REL_STYLESHEET, link.TYPE_CSS));
    //	Scripts
    String statusMessage = Msg.getMsg(wsc.ctx, "SelectMenuItem");
    String scriptTxt = "top.document.title='" + windowTitle + " - " + wsc.loginInfo + "'; " + "var defaultStatus='" + statusMessage + "';";
    //Rob 12-16-2006 head.addElement(new script(scriptTxt));
    //	Body
    body body = doc.getBody();
    body.setTitle(statusMessage);
    //  Clear Window Frame
    //Rob 12-16-2006 body.addElement(WebUtil.getClearFrame(WebEnv.TARGET_WINDOW));
    //  Header
    table table = doc.getTable();
    doc.setClasses("menuTable", "menuHeader");
    //Rob 12-16-2006 doc.getTopLeft().addElement(new cite(wsc.loginInfo));
    input txtSearch = new input(input.TYPE_TEXT, "txtSearch", "");
    txtSearch.setOnKeyDown("searchMenu('main',this.value,event,'" + WebEnv.TARGET_WINDOW + "')");
    doc.getTopLeft().addElement("Find: ");
    doc.getTopLeft().addElement(txtSearch);
    //  Load Menu Structure     ----------------------
    int AD_Tree_ID = DB.getSQLValue(null, "SELECT COALESCE(r.AD_Tree_Menu_ID, ci.AD_Tree_Menu_ID)" + "FROM AD_ClientInfo ci" + " INNER JOIN AD_Role r ON (ci.AD_Client_ID=r.AD_Client_ID) " + "WHERE AD_Role_ID=?", AD_Role_ID);
    if (AD_Tree_ID <= 0)
        //	Menu
        AD_Tree_ID = 10;
    log.fine("doPost - AD_Tree_ID=" + AD_Tree_ID + " - " + Env.getAD_Language(wsc.ctx));
    // Language set in WLogin
    MTree tree = new MTree(wsc.ctx, AD_Tree_ID, false, false, null);
    //	Trim tree
    MTreeNode root = tree.getRoot();
    Enumeration en = root.preorderEnumeration();
    /*while (en.hasMoreElements())
		{
			MTreeNode nd = (MTreeNode)en.nextElement();
			if (nd.isTask() 
				|| nd.isWorkbench() 
				|| nd.isWorkFlow()
				|| nd.getNode_ID() == 383	//	Reset Cache - kills the server
			)
			{
				MTreeNode parent = (MTreeNode)nd.getParent();
				parent.remove(nd);
			}
		}*/
    tree.trimTree();
    //	Print tree
    StringBuffer buf = new StringBuffer();
    StringBuffer buffav = new StringBuffer();
    en = root.preorderEnumeration();
    int oldLevel = 0;
    while (en.hasMoreElements()) {
        MTreeNode nd = (MTreeNode) en.nextElement();
        //  Level
        //	0 == root
        int level = nd.getLevel();
        if (level == 0)
            continue;
        //
        while (oldLevel < level) {
            if (level == 1)
                //  start first level
                buf.append("<ul class=\"mktree\"  id=\"main\">\n");
            else
                //  start next level
                buf.append("<ul style=\"display:none\">\n");
            oldLevel++;
        }
        while (oldLevel > level) {
            oldLevel--;
            if (oldLevel == 1)
                //  finish last level
                buf.append("</ul>\n");
            else
                //  finish next level
                buf.append("</ul></li>\n");
        }
        //	Print Node
        buf.append(printNode(nd, wsc.ctx));
        //Modified by Rob Klein 4/29/07
        if (nd.isOnBar())
            buffav.append(printNode(nd, wsc.ctx));
    }
    //	Final
    while (oldLevel > 0) {
        oldLevel--;
        if (oldLevel == 1)
            //  finish last level
            buf.append("</ul>\n");
        else
            //  finish next level
            buf.append("</ul></li>\n");
    }
    //Modified by Rob Klein 4/29/07
    //  Set Favorites		
    buf.append("<ul><li class=\"menuSummary\" id=\"218\" onClick=\"changeMenu(event);\">Favorites<ul style=\"display:none\">\n");
    buf.append(buffav);
    buf.append("</ul></li></ul>\n");
    td td = new td().setColSpan(2).setNoWrap(true);
    td.setClass("menuCenter");
    td.addElement(buf.toString());
    table.addElement(new tr().addElement(td));
    //	  Expand/Collapse Info
    td = new td().setColSpan(2);
    td.setClass("menuFooter");
    //	Modified by Rob Klein 4/29/07
    /**td.addElement(new a("javascript:expandTree('main');", "Expand Menu"));
		td.addElement(" | ");		
		td.addElement( new a("javascript:collapseTree('main');", "Contract Menu"));
		table.addElement(new tr().addElement(td));
		**/
    //  Exit Info
    td = new td().setColSpan(2);
    td.setClass("menuFooter");
    String url = request.getRequestURI() + "?Exit=true";
    td.addElement(new a(url, Msg.getMsg(wsc.ctx, "Exit")));
    table.addElement(new tr().addElement(td));
    //	System.out.println(doc);
    return doc;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) Enumeration(java.util.Enumeration) Element(org.apache.ecs.Element) org.apache.ecs.xhtml.link(org.apache.ecs.xhtml.link) org.apache.ecs.xhtml.body(org.apache.ecs.xhtml.body) org.apache.ecs.xhtml.script(org.apache.ecs.xhtml.script) MTree(org.compiere.model.MTree) org.apache.ecs.xhtml.head(org.apache.ecs.xhtml.head) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) WebDoc(org.compiere.util.WebDoc) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.base(org.apache.ecs.xhtml.base)

Example 13 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class ADTreePanel method nodeChanged.

//
/**************************************************************************
	 *  Node Changed - synchronize Node
	 *
	 *  @param  save    true the node was saved (changed/added), false if the row was deleted
	 *  @param  keyID   the ID of the row changed
	 *  @param  name	name
	 *  @param  description	description
	 *  @param  isSummary	summary node
	 *  @param  imageIndicator image indicator
	 */
@SuppressWarnings("unchecked")
public void nodeChanged(boolean save, int keyID, String name, String description, boolean isSummary, String imageIndicator) {
    if (tree == null)
        return;
    //	if ID==0=root - don't update it
    if (keyID == 0)
        return;
    //  try to find the node
    TreeModel<Object> model = tree.getModel();
    DefaultTreeNode<Object> root = (DefaultTreeNode<Object>) model.getRoot();
    SimpleTreeModel sModel = new SimpleTreeModel(root);
    DefaultTreeNode<Object> node = sModel.find(null, keyID);
    //  Node not found and saved -> new
    if (node == null && save) {
        MTreeNode rootData = (MTreeNode) root.getData();
        MTreeNode mTreeNode = new MTreeNode(keyID, 0, name, description, rootData.getNode_ID(), isSummary, imageIndicator, false, null);
        DefaultTreeNode<Object> newNode = new DefaultTreeNode<Object>(mTreeNode);
        sModel.addNode(root, newNode, 0);
        int[] path = sModel.getPath(newNode);
        Treeitem ti = tree.renderItemByPath(path);
        tree.setSelectedItem(ti);
    } else //  Node found and saved -> change
    if (node != null && save) {
        MTreeNode mTreeNode = (MTreeNode) node.getData();
        mTreeNode.setName(name);
        mTreeNode.setAllowsChildren(isSummary);
        int[] path = sModel.getPath(node);
        Treeitem ti = tree.renderItemByPath(path);
        tree.setSelectedItem(ti);
    } else //  Node found and not saved -> delete
    if (node != null && !save) {
        sModel.removeNode(node);
    } else //  Error
    {
        node = null;
    }
    //  Nothing to display
    if (node == null)
        return;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) SimpleTreeModel(org.adempiere.webui.component.SimpleTreeModel) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode)

Example 14 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class DPFavourites method createFavouritesPanel.

private Box createFavouritesPanel() {
    bxFav = new Vbox();
    int AD_Role_ID = Env.getAD_Role_ID(Env.getCtx());
    int AD_Tree_ID = DB.getSQLValue(null, "SELECT COALESCE(r.AD_Tree_Menu_ID, ci.AD_Tree_Menu_ID)" + "FROM AD_ClientInfo ci" + " INNER JOIN AD_Role r ON (ci.AD_Client_ID=r.AD_Client_ID) " + "WHERE AD_Role_ID=?", AD_Role_ID);
    if (AD_Tree_ID <= 0)
        //	Menu
        AD_Tree_ID = 10;
    m_AD_Tree_ID = AD_Tree_ID;
    MTree vTree = new MTree(Env.getCtx(), AD_Tree_ID, false, true, null);
    MTreeNode m_root = vTree.getRoot();
    Enumeration<?> enTop = m_root.children();
    while (enTop.hasMoreElements()) {
        MTreeNode ndTop = (MTreeNode) enTop.nextElement();
        Enumeration<?> en = ndTop.preorderEnumeration();
        while (en.hasMoreElements()) {
            MTreeNode nd = (MTreeNode) en.nextElement();
            if (nd.isOnBar()) {
                String label = nd.toString().trim();
                Button btnFavItem = new Button(String.valueOf(nd.getNode_ID()));
                btnFavItem.setLabel(label);
                btnFavItem.setImage(getIconFile(nd));
                btnFavItem.setIconSclass("dp-favorite-button-image");
                btnFavItem.setDraggable(DELETE_FAV_DROPPABLE);
                btnFavItem.addEventListener(Events.ON_CLICK, this);
                btnFavItem.addEventListener(Events.ON_DROP, this);
                bxFav.appendChild(btnFavItem);
            }
        }
    }
    lblMsg = new Label("(Drag and drop menu item here)");
    if (bxFav.getChildren().isEmpty())
        bxFav.appendChild(lblMsg);
    return bxFav;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Button(org.adempiere.webui.component.Button) Label(org.zkoss.zul.Label) Vbox(org.zkoss.zul.Vbox) MTree(org.compiere.model.MTree)

Example 15 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class AMenu method propertyChange.

//	setBusy
/**
	 * 	Selection in tree - launch Application
	 *  @param e PropertyChangeEvent
	 */
public void propertyChange(PropertyChangeEvent e) {
    MTreeNode nd = (MTreeNode) e.getNewValue();
    log.info(nd.getNode_ID() + " - " + nd.toString());
    //	ignore summary items & when loading
    if (m_startingItem || nd.isSummary())
        return;
    String sta = nd.toString();
    progressBar.setString(sta);
    int cmd = nd.getNode_ID();
    //	async load
    (new AMenuStartItem(cmd, true, sta, this)).start();
//hengsin, updateInfo is call again in AMenuStartItem
//updateInfo();
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Point(java.awt.Point)

Aggregations

MTreeNode (org.compiere.model.MTreeNode)38 MTree (org.compiere.model.MTree)9 DefaultTreeNode (org.zkoss.zul.DefaultTreeNode)8 Treeitem (org.zkoss.zul.Treeitem)7 JTree (javax.swing.JTree)5 ArrayList (java.util.ArrayList)4 Enumeration (java.util.Enumeration)4 TreePath (javax.swing.tree.TreePath)4 MContainer (org.compiere.model.MContainer)3 BorderLayout (java.awt.BorderLayout)2 JButton (javax.swing.JButton)2 JToolBar (javax.swing.JToolBar)2 AdempiereTaskPaneUI (org.adempiere.plaf.AdempiereTaskPaneUI)2 SimpleTreeModel (org.adempiere.webui.component.SimpleTreeModel)2 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)2 org.apache.ecs.xhtml.body (org.apache.ecs.xhtml.body)2 org.apache.ecs.xhtml.head (org.apache.ecs.xhtml.head)2 org.apache.ecs.xhtml.link (org.apache.ecs.xhtml.link)2 MCStage (org.compiere.model.MCStage)2 JXTaskPane (org.jdesktop.swingx.JXTaskPane)2