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

📄 jdfframe.java

📁 java xml 应用开发
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			boolean bHasChildNodes = elem.hasChildElements() || elem.hasAttributes();
			
			m_xpandPopupItem.setEnabled(bHasChildNodes);
			m_collapsePopupItem.setEnabled(bHasChildNodes);
			
			m_requiredAttrPopupItem.setEnabled(true);
			m_requiredElemPopupItem.setEnabled(true);
			m_modifyAttrValuePopupItem.setEnabled(false);
		}
		else
		{
			m_requiredAttrPopupItem.setEnabled(false);
			m_requiredElemPopupItem.setEnabled(false);
			m_modifyAttrValuePopupItem.setEnabled(true);
			m_xpandPopupItem.setEnabled(false);
			m_collapsePopupItem.setEnabled(false);
		}
		
		m_pastePopupItem.setEnabled(m_copyNode != null);
		final Object parent = ((JDFTreeNode) node.getParent()).getUserObject();
		m_renamePopupItem.setEnabled(parent!=null);
		
	}
	/**
	 * Method createModel.
	 * create the treeModel
	 * @param doc
	 * @return TreeModel
	 */
	private TreeModel createModel(JDFDoc doc)
	{
		m_jdfDocument = doc;
		
		if (m_jdfDocument != null)
		{
			m_docNS = m_jdfDocument.getDocumentElement().getNamespaceURI();
			buildModel(m_jdfDocument.getRoot(), m_root);
		}
		m_model = new DefaultTreeModel(m_root);
		m_vStrangeElementsString.clear();
		m_vStrangeElements.clear();
		m_vInvalidResLinks.clear();
		m_vInvalidResLinksString.clear();
		m_model.addTreeModelListener(new MyTreeModelListener());
		return m_model;
	}
	/**
	 * Method buildModel.
	 * Creates the JDFTreeNodes
	 * @param node
	 * @param m_root
	 */
	private void buildModel(JDFElement node, JDFTreeNode my_Root)
	{
		JDFTreeNode childNode = null;
		final String xPath = node.buildXPath();
		if (node.getNodeName().equals("JDF"))
		{
			final JDFWrapper jdfW = new JDFWrapper(node);
			childNode = new JDFTreeNode(jdfW, jdfW.wrapperIsValid(), true, xPath);
			if (!childNode.isValid())
				setInvalidNode(node, KElement.EnumValidationLevel.Complete);
			
			setNSAndAttributes(node, childNode, my_Root);
		}
		else if (node instanceof JDFResourceLink && childNode == null)
		{
			final ResourceLinkWrapper resLinkW = new ResourceLinkWrapper(node);
			childNode = new JDFTreeNode(resLinkW, resLinkW.wrapperIsValid(), true, xPath);
			if (!childNode.isValid())
				setInvalidNode(node, KElement.EnumValidationLevel.Complete);
			
			setNSAndAttributes(node, childNode, my_Root);
			
			if (m_currentAutoVal)
			{
				final JDFElement jdfElement = node;
				hasInvalidResourceLinks(childNode, jdfElement);
			}
		}
		else if (node instanceof JDFRefElement && childNode == null)
		{
			final RefElementWrapper refElW = new RefElementWrapper(node);
			childNode = new JDFTreeNode(refElW, refElW.wrapperIsValid(), true, xPath);
			if (!childNode.isValid())
				setInvalidNode(node, KElement.EnumValidationLevel.Complete);
			
			setNSAndAttributes(node, childNode, my_Root);
			
		}
		else if (node.getParentNode().getNodeName().equals("ResourcePool")
				&& childNode == null)
		{
			final ResourceWrapper resW = new ResourceWrapper(node);
			childNode = new JDFTreeNode(resW, resW.wrapperIsValid(), true, xPath);
			if (!childNode.isValid())
				setInvalidNode(node, KElement.EnumValidationLevel.Complete);
			
			setNSAndAttributes(node, childNode, my_Root);
		}
		else if (node != null && childNode == null)
		{
			final Wrapper wrapper = new Wrapper(node);
			childNode = new JDFTreeNode(wrapper, wrapper.wrapperIsValid(), true, xPath);
			if (!childNode.isValid())
				setInvalidNode(node, KElement.EnumValidationLevel.Complete);
			
			setNSAndAttributes(node, childNode, my_Root);
			
			if (!node.hasAttributes())
				childNode.setAllowsChildren(true);
		}
		if (childNode != null)
		{
			if (m_currentAutoVal)
			{
				if (m_isJDF)
				{
					hasInvalidLinks(childNode);
					setErrorVector(childNode, node.buildXPath());
				}
				setMissingAndStrangeNodes(childNode);
				
				for (int n = 0; n < m_vStrangeElements.size(); n++)
				{
					final JDFElement jdfElement = node;
					
					if (jdfElement.equals(m_vStrangeElements.elementAt(n)))
					{
						childNode.setVVector(new MyListElement(
								childNode, (String) m_vStrangeElementsString.elementAt(n)));
						childNode.setValid(false);
					}
				}
				if (!childNode.isValid())
				{
					childNode.setInValidElementFirst("INVALID ELEMENT: " + childNode.toString());
					
					while (my_Root != null)
					{
						if (my_Root.isValid())
						{
							my_Root.setInValidElementFirst("INVALID ELEMENT: " + my_Root.toString());
							my_Root.setValid(false);
						}
						my_Root = (JDFTreeNode) my_Root.getParent();
					}
				}
				m_invalidNode = null;
				childNode.setInvalidNode(null);
			}
			final VElement nodeList = node.getChildElementVector("*", "", new JDFAttributeMap(), true, 0);
			if (nodeList != null)
			{
				for (int i = 0; i < nodeList.size(); i++)
				{
					buildModel((JDFElement) nodeList.elementAt(i), childNode);
				}
			}
		}
	}
	
	private void drawDevCapOutputTree (XMLDoc bugReport, VElement execNodes) 
	{
		if (bugReport==null && (execNodes==null|| execNodes.size()==0))
			return;
		
		m_reportRoot = new DefaultMutableTreeNode("Report");
		m_reportTree = new JTree(m_reportRoot);
		m_reportTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		m_reportTree.setExpandsSelectedPaths(true);
		m_reportTree.setEditable(false);
		
		DefaultMutableTreeNode bugReportRoot = null;
		
		if (bugReport!=null) 
		{
			KElement bugRoot = bugReport.getRoot();
			
			bugReportRoot = new DefaultMutableTreeNode(new DCOutputWrapper(bugRoot));
			m_reportRoot.add(bugReportRoot);
			
			setDevCapOutputTree(bugRoot, bugReportRoot);
			
		}
		
		if (execNodes!=null && execNodes.size()>0) 
		{
			m_execRoot = new DefaultMutableTreeNode("ExecutableNodes");
			m_reportRoot.add(m_execRoot);
			
			for (int i=0; i < execNodes.size(); i++)
			{
				KElement execNode = (KElement) execNodes.elementAt(i);
				m_execRoot.add(new DefaultMutableTreeNode(new JDFWrapper(execNode, execNode.buildXPath())));
			}
			
		}
		
		if (bugReportRoot != null)
		{
			m_reportTree.expandPath(new TreePath(bugReportRoot.getPath()));
		}
		if (m_execRoot != null)
		{
			m_reportTree.expandPath(new TreePath(m_execRoot.getPath()));
		}
		
		m_devCapTreeSelectionListener = new DevCapTreeSelectionListener();
		m_reportTree.addTreeSelectionListener(m_devCapTreeSelectionListener);
		
		final DevCapPopupListener popupListener = new DevCapPopupListener();
		m_reportTree.addMouseListener(popupListener);
		
		final DCOutputRenderer dcRenderer = new DCOutputRenderer(m_iniFile);
		m_reportTree.setCellRenderer(dcRenderer);
		m_devCapErrScroll.getViewport().setView(m_reportTree);
	}
	
	
	class DevCapTreeSelectionListener implements TreeSelectionListener
	{
		public void valueChanged(TreeSelectionEvent e) 
		{
			final DefaultMutableTreeNode node = (DefaultMutableTreeNode)
			m_reportTree.getLastSelectedPathComponent();
			
			if (node == null) 
				return;
			
			final Object object = node.getUserObject();
			
			if (object instanceof DCOutputWrapper) 
			{
				final DCOutputWrapper baseElem = (DCOutputWrapper) object;
				
				final String path = baseElem.getXPath();
				if (path != null) 
				{
					findInNode(path);
				}
			}
			else if (object instanceof JDFWrapper) 
			{
				final JDFWrapper baseElem = (JDFWrapper) object;
				
				final String path = baseElem.getXPath();
				if (path != null) 
				{
					findInNode(path);
				}
			}
			else  
			{
				findInNode("");
			}
			
		}
	}
	
	/**
	 * recursive adds to the tree new elements
	 * @param bugRoot
	 * @param bugReport
	 */
	private void setDevCapOutputTree(KElement bugRoot, DefaultMutableTreeNode bugReport)
	{
		Vector childVector = bugRoot.getChildElementVector(JDFConstants.WILDCARD, 
				JDFConstants.NONAMESPACE, 
				new JDFAttributeMap(), true, 0);
		for (int i=0; i< childVector.size(); i++)
		{
			KElement kEl = (KElement) childVector.elementAt(i);
			String n = kEl.getNodeName();
			DefaultMutableTreeNode next;
			if (n.equals("RejectedNode")||n.equals("RejectedChildNode"))
			{
				next = new DefaultMutableTreeNode(new RejectedNodeWrapper(kEl));
				setDevCapOutputTree(kEl,next);
			}
			else if (n.equals("InvalidAttribute")||n.equals("InvalidSpan")||n.equals("InvalidComment"))
			{
				next = new DefaultMutableTreeNode(new InvalidAttributeWrapper(kEl));
				setDevCapOutputTree(kEl,next);
			}
			else if (n.equals("InvalidSubelement")||n.equals("InvalidResource")||n.equals("InvalidPartitionLeaf"))
			{
				next = new DefaultMutableTreeNode(new InvalidElementWrapper(kEl));
				setDevCapOutputTree(kEl,next);
			}
			else if (n.equals("MissingAttribute")||n.equals("MissingSpan"))
			{
				next = new DefaultMutableTreeNode(new MissingAttributeWrapper(kEl));
				setDevCapOutputTree(kEl,next);
			}
			else if (n.equals("MissingSubelement")||n.equals("MissingResourceLink")
					||n.equals("MissingCustomerInfo")||n.equals("MissingNodeInfo"))
			{
				next = new DefaultMutableTreeNode(new MissingElementWrapper(kEl));
				setDevCapOutputTree(kEl,next);
			}
			else if (n.equals("MissingResources")||n.equals("InvalidResources")
					||n.equals("UnknownResources"))
			{
				KElement parent = kEl.getParentNode_KElement();
				if (parent.getNodeName().equals("RejectedNode")
						|| parent.getNodeName().equals("RejectedChildNode"))
				{
					String nodePath = parent.getAttribute("XPath");
					next = new DefaultMutableTreeNode(new ResourcePoolWrapper(kEl,nodePath));
				}
				else 
				{
					next = new DefaultMutableTreeNode(new DCOutputWrapper(kEl));
				}
				setDevCapOutputTree(kEl,next);
				
			}
			else if (kEl instanceof JDFStateBase) 
			{
				String parentCapPath = kEl.getParentNode_KElement().getAttribute("CapXPath");
				if ((parentCapPath!=null)&& !parentCapPath.equals(JDFConstants.EMPTYSTRING))
					parentCapPath = " [" + parentCapPath + "]";
				String valueList = ""; // __Lena__ temp. Until DevCap View will be realized
				if (kEl.hasAttribute("AllowedValueList"))
				{
					valueList = " AllowedValueList =" +
					kEl.getAttribute("AllowedValueList");
				}
				else 
				{
					VElement vEl = kEl.getChildrenWithAttribute(
							"Value","AllowedValue", 
							JDFConstants.NONAMESPACE, 
							JDFConstants.WILDCARD,true);
					int size = vEl.size();
					if (vEl!=null && size >0)
					{    
						valueList =  size > 1 ? " AllowedValues =" : " AllowedValue =";
						for (int k=0; k < size; k++)
						{
							valueList += " " + ((KElement)vEl.elementAt(k)).
							getAttribute("AllowedValue");
						}
					}
				}
				next = new DefaultMutableTreeNode(kEl.getNodeName() 
						+ parentCapPath 
						+ valueList);
			}
			else 
			{
				next = new DefaultMutableTreeNode(new DCOutputWrapper(kEl));
				setDevCapOutputTree(kEl,next);
			}	
			bugReport.add(next);
		}
	}
	
	/**
	 * Checks if the element belongs to a foreign namespace and
	 * adds the JDFTreeNode to the parent node
	 * if the element has attributes.
	 * @param node      - The JDFElement
	 * @param childNode - The JDFTreeNode
	 * @param m_root      - The Root
	 */
	private void setNSAndAttributes(JDFElement node, JDFTreeNode childNode, JDFTreeNode root)
	{
		if (node.getNamespaceURI() != null && !node.getNamespaceURI().equalsIgnoreCase(m_docNS)
				&& node.getPrefix() != null && !node.getPrefix().

⌨️ 快捷键说明

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