use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class DocumentImpl method getCMAttributes.
/**
* Provides an element's attribute declarations
* @param element the element to retrieve the attribute map of
* @return a <code>CMNamedNodeMap</code> of attributes if the declaration exists; null otherwise.
*/
CMNamedNodeMap getCMAttributes(Element element) {
CMNamedNodeMap map = (CMNamedNodeMap) fCMCache.get(element);
if (map == null) {
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(this);
CMElementDeclaration decl = modelQuery != null ? modelQuery.getCMElementDeclaration(element) : null;
if (decl != null) {
map = decl.getAttributes();
fCMCache.put(element, map);
}
}
return map;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method getPossibleDataTypeValues.
/**
* Retrieves all of the possible valid values for this attribute
* declaration
*/
protected List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) {
List list = null;
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String[] dataTypeValues = null;
// The ModelQuery may not be available if the corresponding
// adapter
// is absent
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if (modelQuery != null) {
dataTypeValues = modelQuery.getPossibleDataTypeValues(element, ad);
} else {
if (ad.getAttrType() != null) {
dataTypeValues = ad.getAttrType().getEnumeratedValues();
}
}
if (dataTypeValues != null) {
list = new ArrayList(dataTypeValues.length);
for (int i = 0; i < dataTypeValues.length; i++) {
list.add(dataTypeValues[i]);
}
}
}
if (list == null) {
list = new ArrayList(0);
}
return list;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method getAvailableChildrenAtIndex.
// returns a list of ModelQueryActions
protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) {
List list = new ArrayList();
CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
if (parentDecl != null) {
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
// taken from ActionManagers
// int editMode = modelQuery.getEditMode();
int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : ModelQuery.INCLUDE_CHILD_NODES;
modelQuery.getInsertActions(parent, parentDecl, index, ic, validityChecking, list);
}
return list;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLQuickAssistProcessor method getRequiredAttrs.
private List getRequiredAttrs(Node node) {
List result = new ArrayList();
ModelQuery modelQuery = getModelQuery(node);
if (modelQuery != null) {
CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);
if (elementDecl != null) {
CMNamedNodeMap attrMap = elementDecl.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap);
List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
attrMap = allAttributes;
Iterator it = attrMap.iterator();
CMAttributeDeclaration attr = null;
while (it.hasNext()) {
attr = (CMAttributeDeclaration) it.next();
if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
result.add(attr);
}
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class ContentModelWorkbenchAdapter method getChildren.
public Object[] getChildren(Object o) {
if (o instanceof Element) {
Element node = (Element) o;
ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
if (mq != null) {
CMElementDeclaration decl = mq.getCMElementDeclaration(node);
CMListWorkbenchAdapter adapter = new CMListWorkbenchAdapter(decl);
return new Object[] { adapter };
}
}
return EMPTY;
}
Aggregations