⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modeltree.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        Element imageElement = UtilXml.firstChildElement(nodeElement, "image");            if (imageElement != null) {                this.image = new Image(imageElement);            }                /* there are situations in which nothing should be displayed            if (screenElement == null && labelElement == null && linkElement == null) {                throw new IllegalArgumentException("Neither 'screen' nor 'label' nor 'link' found for the node definition with name: " + this.name);            }            */        Element conditionElement = UtilXml.firstChildElement(nodeElement, "condition");        if (conditionElement != null) {            this.condition = new ModelTreeCondition(modelTree, conditionElement);        }            List subNodeElements = UtilXml.childElementList(nodeElement, "sub-node");            Iterator subNodeElementIter = subNodeElements.iterator();            while (subNodeElementIter.hasNext()) {                Element subNodeElementEntry = (Element) subNodeElementIter.next();                ModelSubNode subNode = new ModelSubNode(subNodeElementEntry, this);                subNodeList.add(subNode);            }                        }            public void renderNodeString(Writer writer, Map context,                TreeStringRenderer treeStringRenderer, int depth, boolean isLast)                throws IOException, GeneralException {            boolean passed = true;            if (this.condition != null) {                if (!this.condition.eval(context)) {                    passed = false;                }            }            //Debug.logInfo("in ModelMenu, name:" + this.getName(), module);            if (passed) {                //this.subNodeValues = new ArrayList();                //context.put("subNodeValues", new ArrayList());                //if (Debug.infoOn()) Debug .logInfo(" renderNodeString, " + modelTree.getdefaultPkName() + " :" + context.get(modelTree.getdefaultPkName()), module);                context.put("processChildren", new Boolean(true));                // this action will usually obtain the "current" entity                ModelTreeAction.runSubActions(this.actions, context);                String pkName = getPkName();                String id = null;                if (UtilValidate.isNotEmpty(this.entryName)) {                    Map map = (Map)context.get(this.entryName);                    id = (String)map.get(pkName);                } else {                    id = (String) context.get(pkName);                }                if (id != null) {                     modelTree.currentNodeTrail.add(id);                }                context.put("currentNodeTrail", modelTree.currentNodeTrail);                String currentNodeTrailPiped = StringUtil.join(modelTree.currentNodeTrail, "|");                context.put("currentNodeTrailPiped", currentNodeTrailPiped);                treeStringRenderer.renderNodeBegin(writer, context, this, depth, isLast);                //if (Debug.infoOn()) Debug.logInfo(" context:" +                // context.entrySet(), module);                try {                    String screenName = null;                    if (screenNameExdr != null)                        screenName = screenNameExdr.expandString(context);                    String screenLocation = null;                    if (screenLocationExdr != null)                        screenLocation = screenLocationExdr.expandString(context);                    if (screenName != null && screenLocation != null) {                        ScreenStringRenderer screenStringRenderer = treeStringRenderer .getScreenStringRenderer(context);                        ModelScreen modelScreen = ScreenFactory .getScreenFromLocation(screenLocation, screenName);                        modelScreen.renderScreenString(writer, context, screenStringRenderer);                    }                    if (label != null) {                        label.renderLabelString(writer, context, treeStringRenderer);                    }                    if (link != null) {                        link.renderLinkString(writer, context, treeStringRenderer);                    }                    Boolean processChildren = (Boolean) context .get("processChildren");                    //if (Debug.infoOn()) Debug.logInfo(" processChildren:" + processChildren, module);                    if (processChildren.booleanValue()) {                        getChildren(context);                        Iterator nodeIter = this.subNodeValues.iterator();                        int nodeIndex = -1;                        int newDepth = depth + 1;                        while (nodeIter.hasNext()) {                            nodeIndex++;                            modelTree.setNodeIndexAtDepth(newDepth, nodeIndex);                            Object[] arr = (Object[]) nodeIter.next();                            ModelNode node = (ModelNode) arr[0];                            Map val = (Map) arr[1];                            //GenericPK pk = val.getPrimaryKey();                            //if (Debug.infoOn()) Debug.logInfo(" pk:" + pk,                            // module);                            String thisPkName = node.getPkName();                            String thisEntityId = (String) val.get(thisPkName);                            Map newContext = ((MapStack) context) .standAloneChildStack();                            String nodeEntryName = node.getEntryName();                            if (UtilValidate.isNotEmpty(nodeEntryName)) {                                newContext.put(nodeEntryName, val);                                                    } else {                                newContext.putAll(val);                            }                            newContext.put("currentNodeIndex", new Integer(nodeIndex));                            String targetEntityId = null;                            List targetNodeTrail = this.modelTree .getTrailList();                            if (newDepth < targetNodeTrail.size()) {                                targetEntityId = (String) targetNodeTrail .get(newDepth);                            }                            if ((targetEntityId != null && targetEntityId .equals(thisEntityId)) || this.showPeers(newDepth)) {                                boolean lastNode = !nodeIter.hasNext();                                newContext.put("lastNode", new Boolean(lastNode));                                node.renderNodeString(writer, newContext, treeStringRenderer, newDepth, lastNode);                            }                        }                    }                } catch (SAXException e) {                    String errMsg = "Error rendering included label with name ["                            + name + "] : " + e.toString();                    Debug.logError(e, errMsg, module);                    throw new RuntimeException(errMsg);                } catch (ParserConfigurationException e3) {                    String errMsg = "Error rendering included label with name ["                            + name + "] : " + e3.toString();                    Debug.logError(e3, errMsg, module);                    throw new RuntimeException(errMsg);                } catch (IOException e2) {                    String errMsg = "Error rendering included label with name ["                            + name + "] : " + e2.toString();                    Debug.logError(e2, errMsg, module);                    throw new RuntimeException(errMsg);                }                treeStringRenderer.renderNodeEnd(writer, context, this);                int removeIdx = modelTree.currentNodeTrail.size() - 1;                if (removeIdx >= 0) modelTree.currentNodeTrail.remove(removeIdx);            }        }        public boolean hasChildren(Map context) {             boolean hasChildren = false;             Long nodeCount = null;             String countFieldName = "childBranchCount";               Object obj = null;             if (UtilValidate.isNotEmpty(this.entryName)) {                    Map map = (Map)context.get(this.entryName);                    if (map instanceof GenericValue) {                    	ModelEntity modelEntity = ((GenericValue)map).getModelEntity();                    	if (modelEntity.isField(countFieldName)) {                    		obj = map.get(countFieldName);                    	}                    }             } else {                   obj = context.get(countFieldName);             }             if (obj != null) {                nodeCount = (Long)obj;             }             String entName = this.getEntityName();             GenericDelegator delegator = modelTree.getDelegator();             ModelEntity modelEntity = delegator.getModelEntity(entName);             ModelField modelField = null;         	 if (modelEntity.isField(countFieldName)) {                 modelField = modelEntity.getField(countFieldName);         	 }             if (nodeCount == null && modelField != null || this.modelTree.forceChildCheck) {                 getChildren(context);                 /*                 String id = (String)context.get(modelTree.getPkName());                 if (UtilValidate.isNotEmpty(id)) {                     try {                         int leafCount = ContentManagementWorker.updateStatsTopDown(delegator, id, UtilMisc.toList("SUB_CONTENT", "PUBLISH_LINK"));                         GenericValue entity = delegator.findByPrimaryKeyCache(entName, UtilMisc.toMap(modelTree.getPkName(), id));                         obj = entity.get("childBranchCount");                        if (obj != null)                            nodeCount = (Long)obj;                     } catch(GenericEntityException e) {                         Debug.logError(e, module);                         throw new RuntimeException(e.getMessage());                     }                 }                 */                 nodeCount = new Long(this.subNodeValues.size());                String pkName = this.getPkName();                String id = null;                if (UtilValidate.isNotEmpty(this.entryName)) {                    Map map = (Map)context.get(this.entryName);                    id = (String)map.get(pkName);                } else {                    id = (String) context.get(pkName);                }                 try {                	 if (id != null && modelEntity.getPksSize() == 1) {                		 GenericValue entity = delegator.findByPrimaryKey(entName, UtilMisc.toMap(pkName, id));                         if (modelEntity.isField("childBranchCount")) {                    		 entity.put("childBranchCount", nodeCount);                         }                		 entity.store();                	 }                 } catch(GenericEntityException e) {                     Debug.logError(e, module);                     throw new RuntimeException(e.getMessage());                 }             } else if (nodeCount == null) {                 getChildren(context);                if (subNodeValues != null)                    nodeCount = new Long(subNodeValues.size());             }                          if (nodeCount != null && nodeCount.intValue() > 0)                  hasChildren = true;                                          return hasChildren;        }        public void getChildren(Map context) {             this.subNodeValues = new ArrayList();             Iterator nodeIter = subNodeList.iterator();             while (nodeIter.hasNext()) {                 ModelSubNode subNode = (ModelSubNode)nodeIter.next();                 String nodeName = subNode.getNodeName(context);                 ModelNode node = (ModelNode)modelTree.nodeMap.get(nodeName);                 List subNodeActions = subNode.getActions();                 //if (Debug.infoOn()) Debug.logInfo(" context.currentValue:" + context.get("currentValue"), module);                 ModelTreeAction.runSubActions(subNodeActions, context);                 // List dataFound = (List)context.get("dataFound");                 ListIterator dataIter =  subNode.getListIterator();                 if (dataIter instanceof EntityListIterator) {                     EntityListIterator eli = (EntityListIterator) dataIter;                     Map val = null;                     while ((val = (Map) eli.next()) != null) {                         Object [] arr = {node, val};                         this.subNodeValues.add(arr);                     }                     try {                         eli.close();                     } catch(GenericEntityException e) {                         Debug.logError(e, module);                         throw new RuntimeException(e.getMessage());                     }                 } else if (dataIter != null) {                     while (dataIter.hasNext()) {                         Map val = (Map) dataIter.next();                         Object [] arr = {node, val};                         this.subNodeValues.add(arr);                     }                 }             }             return;        }        public String getName() {            return name;        }        public String getEntryName() {            return this.entryName;        }        public String getRenderStyle() {            String rStyle = this.renderStyle;            if (UtilValidate.isEmpty(rStyle))                rStyle = modelTree.getRenderStyle();            return rStyle;        }            public boolean isExpandCollapse() {            boolean isExpCollapse = false;            String rStyle = getRenderStyle();            if (rStyle != null && rStyle.equals("expand-collapse"))                isExpCollapse = true;                        return isExpCollapse;        }                public boolean isFollowTrail() {            boolean isFollowTrail = false;            String rStyle = getRenderStyle();            if (rStyle != null && (rStyle.equals("follow-trail") || rStyle.equals("show-peers") || rStyle.equals("follow-trail"))) {                isFollowTrail = true;            }                        return isFollowTrail;        }            public boolean showPeers(int currentDepth) {            int trailSize = 0;            List trail = modelTree.getTrailList();            int openDepth = modelTree.getOpenDepth();            int postTrailOpenDepth = modelTree.getPostTrailOpenDepth();            if (trail != null) trailSize = trail.size();                            boolean showPeers = false;            String rStyle = getRenderStyle();            if (rStyle == null) {                showPeers = true;            } else if (!isFollowTrail()) {                showPeers = true;            } else if ((currentDepth < trailSize) && (rStyle != null) &&  (rStyle.equals("show-peers") || rStyle.equals("expand-collapse"))) {                showPeers = true;            } else if (openDepth >= currentDepth) {                showPeers = true;            } else {                int depthAfterTrail = currentDepth - trailSize;                if (depthAfterTrail >= 0 && depthAfterTrail <= postTrailOpenDepth) showPeers = true;            }                        return showPeers;        }            public String getExpandCollapseStyle() {            return expandCollapseStyle;        }        public String getWrapStyle(Map context) {            String val = this.wrapStyleExdr.expandString(context);            if (UtilValidate.isEmpty(val)) {                val = this.modelTree.getWrapStyle(context);            }            return val;        }            public ModelTree getModelTree() {            return this.modelTree;        }                public void setEntityName(String name) {            this.entityName = name;            if (UtilValidate.isNotEmpty(this.entityName)) {                ModelEntity modelEntity = modelTree.delegator.getModelEntity(this.entityName);                if (modelEntity.getPksSize() == 1) {                    ModelField modelField = modelEntity.getOnlyPk();                    this.pkName = modelField.getName();                } else {                    // TODO: what to do here?                }            }        }                public String getEntityName() {            if (UtilValidate.isNotEmpty(this.entityName)) {                return this.entityName;            } else {                return this.modelTree.getDefaultEntityName();            }        }            public String getPkName() {            if (UtilValidate.isNotEmpty(this.pkName)) {                return this.pkName;            } else {                return this.modelTree.getDefaultPkName();            }        }            public void setPkName(String pkName) {        	this.pkName = pkName;        }                public static class ModelSubNode {                protected ModelNode rootNode;            protected FlexibleStringExpander nodeNameExdr;            protected List actions = new ArrayList();            protected List outFieldMaps;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -