*/
public Field replaceWithSimpleField(Field.FieldType fieldType) {
int leftLength = textSelection.getText().length();
int index = textSelection.getIndex();
prepareSpanContainer(leftLength, index);
Field field = null;
switch (fieldType) {
case DATE_FIELD:
field = Fields.createDateField(spanContainer);
break;
case FIXED_DATE_FIELD:
field = Fields.createFixedDateField(spanContainer);
break;
case TIME_FIELD:
field = Fields.createTimeField(spanContainer);
break;
case FIXED_TIME_FIELD:
field = Fields.createFixedTimeField(spanContainer);
break;
case PREVIOUS_PAGE_NUMBER_FIELD:
field = Fields.createPreviousPageNumberField(spanContainer);
break;
case CURRENT_PAGE_NUMBER_FIELD:
field = Fields.createCurrentPageNumberField(spanContainer);
break;
case NEXT_PAGE_NUMBER_FIELD:
field = Fields.createNextPageNumberField(spanContainer);
break;
case PAGE_COUNT_FIELD:
field = Fields.createPageCountField(spanContainer);
break;
case TITLE_FIELD:
field = Fields.createTitleField(spanContainer);
break;
case SUBJECT_FIELD:
field = Fields.createSubjectField(spanContainer);
break;
case AUTHOR_NAME_FIELD:
field = Fields.createAuthorNameField(spanContainer);
break;
case AUTHOR_INITIALS_FIELD:
field = Fields.createAuthorInitialsField(spanContainer);
break;
case CHAPTER_FIELD:
field = Fields.createChapterField(spanContainer);
break;
case REFERENCE_FIELD:
case SIMPLE_VARIABLE_FIELD:
case USER_VARIABLE_FIELD:
case CONDITION_FIELD:
case HIDDEN_TEXT_FIELD:
throw new IllegalArgumentException("this is not a vaild simple field type.");
}
textSelection.mMatchedText = field.getOdfElement().getTextContent();
int textLength = textSelection.mMatchedText.length();
int offset = textLength - leftLength;
SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength);
return field;
}