Insert cascade dependencies

Post here questions and problems related to oXygen frameworks/document types.
damarislc
Posts: 9
Joined: Tue Sep 11, 2018 9:23 pm

Insert cascade dependencies

Post by damarislc »

Hi,

I'm trying to insert various element levels, for example, if I enter the element <glossentry> it automatically should be fill like this:

Code: Select all


<glossentry>
<glossterm></glossterm>
<glossdef>
<p></p>
</glossdef>
</glossentry>
I'm using SchemaManagerFilter for doing this, I can insert the <glossterm> and <glossdef> sucessfuly, but due glossdef its auto inserted, the <p> element is not been added.

Here is my code:

Code: Select all


private static final List<String> ELEMENTS_WITH_MANDATORY_P_CHILD =
Arrays.asList(new String[] {"section", "note", "li", "context", "info", "stepresult", "entry", "stentry", "choice", "result", "glossdef"});

@Override
public List<CIElement> filterElements(final List<CIElement> elements,
final WhatElementsCanGoHereContext context) {

final List<CIElement> filteredElements = super.filterElements(elements, context);

if ((context != null) && (filteredElements != null)) {
for (final CIElement element : filteredElements) {
final String elementName = element.getQName();

//is the current element a glossentry?
if(elementName.equals("glossentry")) {
addGlossentryChilds(element);
}

// is the current element included in the list of elements with mandatory child p?
if (ELEMENTS_WITH_MANDATORY_P_CHILD.contains(elementName)) {
addChildPElement(element);
}

//here is where the glossdef subelement should be add the child <p>
final List<CIElement> childElements = element.getGuessElements();
// Verify in the child Elements if there are more elements that
// will be "auto" completed.
getSubElements(childElements);
}
}
return filteredElements;
}

void addGlossentryChilds(final CIElement parent) {
final CIElement glosstermElement = new GlosstermElement();
final CIElement glossdefElement = new GlossdefElement();

parent.addGuessElement(glosstermElement);
parent.addGuessElement(glossdefElement);
}
How can I do to insert also the <p> automatically when added the <glossdef> ?
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Insert cascade dependencies

Post by alex_jitianu »

Hello,

In our SDK sample project, inside the oxygen-sample-framework module, thre is an implementation of an ro.sync.contentcompletion.xml.CIElement named simple.documentation.framework.SDFElement. After you copy this impllementation into your own project all you have to do is build the hierarchy:

Code: Select all

  
glossterm.setName("glossterm");
glossentry.addGuessElement(glossterm);

CIElement glossdef = new SDFElement();
glossdef.setName("glossdef");
glossentry.addGuessElement(glossdef);

CIElement p = new SDFElement();
p.setName("p");
glossdef.addGuessElement(p);
As an alternative, you can configure content completion through a configuration file. You can obtain the same result by adding these lines inside such a configuration file:

Code: Select all

	<elementProposals path="glossentry" insertElements="glossterm glossdef"/>
<elementProposals path="glossdef" insertElements="p"/>
<elementProposals path="p" insertElements="b"/>
Best regards,
Alex
damarislc
Posts: 9
Joined: Tue Sep 11, 2018 9:23 pm

Re: Insert cascade dependencies

Post by damarislc »

Awesome, the first solution worked perfectly.

Thanks!
Post Reply