}
@Nullable
protected T performElementAddition() {
final DomElement parent = getParentDomElement();
final DomManager domManager = parent.getManager();
final TypeChooser[] oldChoosers = new TypeChooser[]{null};
final Type[] aClass = new Type[]{null};
final StableElement<T> result = new WriteCommandAction<StableElement<T>>(domManager.getProject(), parent.getRoot().getFile()) {
protected void run(Result<StableElement<T>> result) throws Throwable {
final DomElement parentDomElement = getParentDomElement();
final T t = (T)getDomCollectionChildDescription().addValue(parentDomElement, getElementType());
tuneNewValue(t);
aClass[0] = parent.getGenericInfo().getCollectionChildDescription(t.getXmlElementName()).getType();
oldChoosers[0] = domManager.getTypeChooserManager().getTypeChooser(aClass[0]);
final SmartPsiElementPointer pointer =
SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(t.getXmlTag());
domManager.getTypeChooserManager().registerTypeChooser(aClass[0], new TypeChooser() {
public Type chooseType(final XmlTag tag) {
if (tag == pointer.getElement()) {
return getElementType();
}
return oldChoosers[0].chooseType(tag);
}
public void distinguishTag(final XmlTag tag, final Type aClass) throws IncorrectOperationException {
oldChoosers[0].distinguishTag(tag, aClass);
}
public Type[] getChooserTypes() {
return oldChoosers[0].getChooserTypes();
}
});
result.setResult((StableElement<T>)t.createStableCopy());
}
}.execute().getResultObject();
if (result != null) {
domManager.getTypeChooserManager().registerTypeChooser(aClass[0], oldChoosers[0]);
return result.getWrappedElement();
}
return null;
}