david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This |
| 3 | * program and the accompanying materials are made available under the terms |
| 4 | * of the Eclipse Public License v1.0 which accompanies this distribution, and |
| 5 | * is available at http://www.eclipse.org/legal/epl-v10.html |
| 6 | * |
| 7 | * Contributors: IBM Corporation - initial API and implementation |
| 8 | ****************************************************************************/ |
| 9 | |
| 10 | |
| 11 | package org.eclipse.wst.xml.ui.internal.tabletree; |
| 12 | |
| 13 | import java.util.List; |
| 14 | |
| 15 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
| 16 | import org.eclipse.ui.views.properties.TextPropertyDescriptor; |
david_williams | c06c86f | 2005-03-18 18:23:41 +0000 | [diff] [blame] | 17 | import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; |
| 18 | import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; |
| 19 | import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; |
| 20 | import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 21 | import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; |
nitind | 1395066 | 2005-02-13 20:17:33 +0000 | [diff] [blame] | 22 | import org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 23 | import org.w3c.dom.Attr; |
| 24 | import org.w3c.dom.Element; |
| 25 | import org.w3c.dom.Node; |
| 26 | import org.w3c.dom.Text; |
| 27 | |
| 28 | |
| 29 | public class XMLTableTreePropertyDescriptorFactory extends DOMPropertyDescriptorFactory { |
| 30 | |
| 31 | protected TreeContentHelper treeContentHelper = new TreeContentHelper(); |
| 32 | |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 33 | public XMLTableTreePropertyDescriptorFactory() { |
| 34 | super(); |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | protected IPropertyDescriptor createPropertyDescriptorHelper(String name, Element element, CMNode cmNode) { |
| 38 | IPropertyDescriptor result = null; |
| 39 | |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 40 | ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); |
| 41 | String[] valuesArray = null; |
| 42 | if (mq != null) { |
| 43 | valuesArray = mq.getPossibleDataTypeValues(element, cmNode); |
| 44 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 45 | if (valuesArray != null && valuesArray.length > 0) { |
| 46 | result = new EnumeratedStringPropertyDescriptor(name, name, valuesArray); |
| 47 | } |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 48 | else { |
| 49 | result = createDefaultPropertyDescriptor(name); |
| 50 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 51 | |
| 52 | return result; |
| 53 | } |
| 54 | |
| 55 | public IPropertyDescriptor createTextPropertyDescriptor(Text text) { |
| 56 | IPropertyDescriptor result = null; |
| 57 | Node parentNode = text.getParentNode(); |
| 58 | if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) { |
| 59 | Element parentElement = (Element) parentNode; |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 60 | ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument()); |
| 61 | CMElementDeclaration ed = null; |
| 62 | if (mq != null) { |
| 63 | ed = mq.getCMElementDeclaration(parentElement); |
| 64 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 65 | if (ed != null) { |
| 66 | result = createPropertyDescriptorHelper(HACK, parentElement, ed); |
| 67 | } |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 68 | else { |
| 69 | result = createDefaultPropertyDescriptor(parentElement.getNodeName()); |
| 70 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | if (result == null) { |
| 74 | result = new TextPropertyDescriptor(HACK, HACK); |
| 75 | } |
| 76 | |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) { |
| 81 | IPropertyDescriptor result = null; |
| 82 | |
| 83 | String attributeName = attr.getName(); |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 84 | ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument()); |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 85 | |
nitind | a4e5778 | 2005-09-13 22:26:51 +0000 | [diff] [blame] | 86 | CMAttributeDeclaration ad = null; |
| 87 | if (mq != null) { |
| 88 | ad = mq.getCMAttributeDeclaration(attr); |
| 89 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 90 | if (ad != null) { |
| 91 | result = createPropertyDescriptorHelper(attributeName, attr.getOwnerElement(), ad); |
| 92 | } |
| 93 | |
| 94 | if (result == null) { |
| 95 | result = new TextPropertyDescriptor(attributeName, attributeName); |
| 96 | } |
| 97 | |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | public IPropertyDescriptor createElementPropertyDescriptor(Element element) { |
| 102 | IPropertyDescriptor result = null; |
| 103 | List list = treeContentHelper.getElementTextContent(element); |
| 104 | if (list != null) { |
| 105 | Text text = treeContentHelper.getEffectiveTextNodeForCombinedNodeList(list); |
| 106 | if (text != null) { |
| 107 | result = createTextPropertyDescriptor(text); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if (result == null) { |
| 112 | result = new TextPropertyDescriptor(HACK, HACK); |
| 113 | } |
| 114 | return result; |
| 115 | } |
| 116 | } |