Configuring Content Completion Proposals
You can filter or contribute to proposals offered for content completion by implementing the ro.sync.contentcompletion.xml.SchemaManagerFilter interface.
import java.util.List;
import ro.sync.contentcompletion.xml.CIAttribute;
import ro.sync.contentcompletion.xml.CIElement;
import ro.sync.contentcompletion.xml.CIValue;
import ro.sync.contentcompletion.xml.Context;
import ro.sync.contentcompletion.xml.SchemaManagerFilter;
import ro.sync.contentcompletion.xml.WhatAttributesCanGoHereContext;
import ro.sync.contentcompletion.xml.WhatElementsCanGoHereContext;
import ro.sync.contentcompletion.xml.WhatPossibleValuesHasAttributeContext;
public class SDFSchemaManagerFilter implements SchemaManagerFilter {
You can implement the various callbacks of the interface either by returning the default
values given by Oxygen XML Author or by contributing to the list of proposals. The filter
can be applied on elements, attributes or on their values. Attributes filtering can be
implemented using the filterAttributes method and changing the default content
completion list of ro.sync.contentcompletion.xml.CIAttribute for
the element provided by the current ro.sync.contentcompletion.xml.WhatAttributesCanGoHereContext context. For
example, the SDFSchemaManagerFilter
checks if the element from the current
context is the table
element and adds the frame
attribute to
the table
list of attributes.
/**
* Filter attributes of the "table" element.
*/
public List<CIAttribute> filterAttributes(List<CIAttribute> attributes,
WhatAttributesCanGoHereContext context) {
// If the element from the current context is the 'table' element add the
// attribute named 'frame' to the list of default content completion proposals
if (context != null) {
ContextElement contextElement = context.getParentElement();
if ("table".equals(contextElement.getQName())) {
CIAttribute frameAttribute = new CIAttribute();
frameAttribute.setName("frame");
frameAttribute.setRequired(false);
frameAttribute.setFixed(false);
frameAttribute.setDefaultValue("void");
if (attributes == null) {
attributes = new ArrayList<CIAttribute>();
}
attributes.add(frameAttribute);
}
}
return attributes;
}
The elements that can be inserted in a specific context can be filtered using the
filterElements method. The SDFSchemaManagerFilter
uses this method
to replace the td
child element with the th
element when
header
is the current context element.
public List<CIElement> filterElements(List<CIElement> elements,
WhatElementsCanGoHereContext context) {
// If the element from the current context is the 'header' element remove the
// 'td' element from the list of content completion proposals and add the
// 'th' element.
if (context != null) {
Stack<ContextElement> elementStack = context.getElementStack();
if (elementStack != null) {
ContextElement contextElement = context.getElementStack().peek();
if ("header".equals(contextElement.getQName())) {
if (elements != null) {
for (Iterator<CIElement> iterator =
elements.iterator(); iterator.hasNext();) {
CIElement element = iterator.next();
// Remove the 'td' element
if ("td".equals(element.getQName())) {
elements.remove(element);
break;
}
}
} else {
elements = new ArrayList<CIElement>();
}
// Insert the 'th' element in the list of content completion proposals
CIElement thElement = new SDFElement();
thElement.setName("th");
elements.add(thElement);
}
}
} else {
// If the given context is null then the given list of content completion
// elements contains global elements.
}
return elements;
}
The elements or attributes values can be filtered using the filterElementValues or filterAttributeValues methods.