Configuring a Content completion handler

You can filter or contribute to items 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/> 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 add the frame attribute to the table list of attributes.

	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
	  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");
	    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.
	  ContextElement contextElement = context.getElementStack().peek();
	  if ("header".equals(contextElement.getQName())) {
	    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;
          }
        }
	    // Insert the 'th' element in the list of content completion proposals
	    CIElement thElement = new SDFElement();
	    thElement.setName("th");
	    elements.add(thElement);
	  }
		return elements;
	}

The elements or attributes values can be filtered using the filterElementValues or filterAttributeValues methods.

The complete source code of the SDFSchemaManagerFilter implementation is found in the Example Files Listings, the Java Files section.