FieldSelection extends Selection { public void applyStyle(OdfStyleBase style) throws InvalidNavigationException { if (spanContainer == null) { textSelection.applyStyle(style); } else { spanContainer.setProperties(style.getStyleProperties()); } } FieldSelection(TextSelection selection); Field replaceWithSimpleField(Field.FieldType fieldType); void replaceWithReferenceField(ReferenceField field, ReferenceField.DisplayType type); void replaceWithVariableField(VariableField field); ConditionField replaceWithConditionField(String condition, String trueText, String falseText); ConditionField replaceWithHiddenTextField(String condition, String text); void applyStyle(OdfStyleBase style); @Override void cut(); void replaceWith(String newText); @Override void pasteAtEndOf(Selection positionItem); @Override void pasteAtFrontOf(Selection positionItem);  }
@Test public void testApplyStyle() { search = null; search = new TextNavigation("delete", doc); OdfOfficeAutomaticStyles autoStyles = null; try { autoStyles = doc.getContentDom().getAutomaticStyles(); } catch (Exception e1) { Assert.fail("Failed with " + e1.getClass().getName() + ": '" + e1.getMessage() + "'"); } OdfStyleBase style = autoStyles.getStyle("T4", OdfStyleFamily.Text); Assert.assertNotNull(style); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); try { item.applyStyle(style); } catch (InvalidNavigationException e) { Assert.fail(e.getMessage()); } } try { doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_STYLE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }