|
| 1 | +package com.oxygenxml.samples.legaldocml; |
| 2 | + |
| 3 | +import static java.util.stream.Collectors.toList; |
| 4 | + |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import ro.sync.contentcompletion.xml.CIAttribute; |
| 9 | +import ro.sync.contentcompletion.xml.CIElement; |
| 10 | +import ro.sync.contentcompletion.xml.CIValue; |
| 11 | +import ro.sync.contentcompletion.xml.Context; |
| 12 | +import ro.sync.contentcompletion.xml.SchemaManagerFilter; |
| 13 | +import ro.sync.contentcompletion.xml.WhatAttributesCanGoHereContext; |
| 14 | +import ro.sync.contentcompletion.xml.WhatElementsCanGoHereContext; |
| 15 | +import ro.sync.contentcompletion.xml.WhatPossibleValuesHasAttributeContext; |
| 16 | +import ro.sync.ecss.extensions.api.AuthorAccess; |
| 17 | +import ro.sync.ecss.extensions.api.AuthorAccessProvider; |
| 18 | +import ro.sync.ecss.extensions.api.node.AuthorNode; |
| 19 | + |
| 20 | +/** |
| 21 | + * Schema Manager filter. |
| 22 | + * |
| 23 | + * @author cristi_talau |
| 24 | + */ |
| 25 | +public class LegalDocMLSchemaManagerFilter implements SchemaManagerFilter { |
| 26 | + |
| 27 | + /** |
| 28 | + * Access provider. |
| 29 | + */ |
| 30 | + private final AuthorAccessProvider accessProvider; |
| 31 | + |
| 32 | + public LegalDocMLSchemaManagerFilter(AuthorAccessProvider accessProvider) { |
| 33 | + this.accessProvider = accessProvider; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Do not propose these elements to surround a paragraph. |
| 38 | + */ |
| 39 | + private final List<String> invalidParagraphParents = Arrays.asList("p", "table"); |
| 40 | + |
| 41 | + public List<CIElement> filterElements(List<CIElement> elements, WhatElementsCanGoHereContext context) { |
| 42 | + List<CIElement> toReturn = elements; |
| 43 | + AuthorAccess authorAccess = this.accessProvider.getAuthorAccess(); |
| 44 | + if (authorAccess != null) { |
| 45 | + AuthorNode fullySelectedNode = authorAccess.getEditorAccess().getFullySelectedNode(); |
| 46 | + if (fullySelectedNode != null && fullySelectedNode.getName().equals("p")) { |
| 47 | + toReturn = elements.stream() |
| 48 | + .filter(elem -> !invalidParagraphParents.contains(elem.getName())) |
| 49 | + .collect(toList()); |
| 50 | + } |
| 51 | + } |
| 52 | + return toReturn; |
| 53 | + } |
| 54 | + |
| 55 | + public String getDescription() { |
| 56 | + return "Used to filter content completion items"; |
| 57 | + } |
| 58 | + |
| 59 | + public List<CIValue> filterAttributeValues(List<CIValue> values, WhatPossibleValuesHasAttributeContext context) { |
| 60 | + return values; |
| 61 | + } |
| 62 | + |
| 63 | + public List<CIAttribute> filterAttributes(List<CIAttribute> attributes, WhatAttributesCanGoHereContext context) { |
| 64 | + return attributes; |
| 65 | + } |
| 66 | + |
| 67 | + public List<CIValue> filterElementValues(List<CIValue> values, Context context) { |
| 68 | + return values; |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments