Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5bebb72ccac0ab8be4d8b3fec9dbf34ff4c44024 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2004, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xml.ui.internal.tabletree;

import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;


public class DOMPropertyDescriptorFactory {

	protected static final String HACK = "hack"; //$NON-NLS-1$

	public DOMPropertyDescriptorFactory() {
	}

	public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) {
		IPropertyDescriptor result = null;

		String attributeName = attr.getName();

		ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument());

		if (mq != null) {
			CMAttributeDeclaration ad = mq.getCMAttributeDeclaration(attr);
			if (ad != null) {
				String[] valuesArray = mq.getPossibleDataTypeValues(attr.getOwnerElement(), ad);
				if ((valuesArray != null) && (valuesArray.length > 0)) {
					result = new EnumeratedStringPropertyDescriptor(attributeName, attributeName, valuesArray);
				}
			}
		}

		if (result == null) {
			result = createDefaultPropertyDescriptor(attributeName);
		}
		return result;
	}

	public IPropertyDescriptor createCDATASectionPropertyDescriptor(CDATASection cdataSection) {
		return createDefaultPropertyDescriptor(HACK);
	}

	public IPropertyDescriptor createCommentPropertyDescriptor(Comment comment) {
		return createDefaultPropertyDescriptor(HACK);
	}

	protected IPropertyDescriptor createDefaultPropertyDescriptor(String attributeName) {
		TextPropertyDescriptor descriptor = new TextPropertyDescriptor(attributeName, attributeName);
		return descriptor;
	}

	public IPropertyDescriptor createDocumentTypePropertyDescriptor(DocumentType documentType) {
		return null; // new TextPropertyDescriptor(HACK, HACK);
	}

	public IPropertyDescriptor createElementPropertyDescriptor(Element element) {
		return createDefaultPropertyDescriptor(HACK);
	}

	public IPropertyDescriptor createEntityReferencePropertyDescriptor(EntityReference entityReference) {
		return createDefaultPropertyDescriptor(HACK);
	}

	public IPropertyDescriptor createProcessingInstructionPropertyDescriptor(ProcessingInstruction pi) {
		return createDefaultPropertyDescriptor(HACK);
	}

	public IPropertyDescriptor createPropertyDescriptor(Object object) {
		IPropertyDescriptor result = null;
		if (object instanceof Node) {
			Node node = (Node) object;
			int nodeType = node.getNodeType();
			switch (nodeType) {
				case Node.ATTRIBUTE_NODE : {
					result = createAttributePropertyDescriptor((Attr) node);
					break;
				}
				case Node.CDATA_SECTION_NODE : {
					result = createCDATASectionPropertyDescriptor((CDATASection) node);
					break;
				}
				case Node.COMMENT_NODE : {
					result = createCommentPropertyDescriptor((Comment) node);
					break;
				}
				case Node.DOCUMENT_TYPE_NODE : {
					result = createDocumentTypePropertyDescriptor((DocumentType) node);
					break;
				}
				case Node.ELEMENT_NODE : {
					result = createElementPropertyDescriptor((Element) node);
					break;
				}
				case Node.ENTITY_REFERENCE_NODE : {
					result = createEntityReferencePropertyDescriptor((EntityReference) node);
					break;
				}
				case Node.PROCESSING_INSTRUCTION_NODE : {
					result = createProcessingInstructionPropertyDescriptor((ProcessingInstruction) node);
					break;
				}
				case Node.TEXT_NODE : {
					result = createTextPropertyDescriptor((Text) node);
					break;
				}
			}
		}
		return result;
	}

	public IPropertyDescriptor createTextPropertyDescriptor(Text text) {
		return createDefaultPropertyDescriptor(HACK);
	}
}

Back to the top