protected final DomFileEditor initFileEditor(final Project project, final VirtualFile virtualFile, final String name, final Factory<? extends BasicDomElementComponent> component) { myFileEditor = new DomFileEditor<BasicDomElementComponent>(project, virtualFile, name, component) { @Override public JComponent getPreferredFocusedComponent() { return null; } @Override @NotNull protected JComponent createCustomComponent() { final JComponent customComponent = super.createCustomComponent(); myContents = getDomComponent(); return customComponent; } @Override public void reset() { for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) { final DomElement newValue = entry.getKey().find(); final DomElement oldValue = entry.getValue(); if (newValue != null && !newValue.equals(oldValue) || newValue == null && !oldValue.getManager().isMockElement(oldValue)) { ((StableElement)oldValue).revalidate(); } } super.reset(); } @Override public void commit() { super.commit(); final List<EditedElementDescription> descriptions = new ArrayList<EditedElementDescription>(); final Set<PsiFile> changedFiles = new HashSet<PsiFile>(); for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) { final EditedElementDescription description = entry.getKey(); final DomElement editedElement = entry.getValue(); if (description.find() == null && editedElement.getXmlTag() != null) { descriptions.add(description); final XmlFile xmlFile = description.getEditedFile(); if (xmlFile != null) { changedFiles.add(xmlFile); } } } new WriteCommandAction(project, PsiUtilCore.toPsiFileArray(changedFiles)) { @Override protected void run(@NotNull Result result) throws Throwable { for (EditedElementDescription description : descriptions) { final DomElement editedElement = myDomElements.get(description); DomElement element = description.addElement(); element.copyFrom(editedElement); description.initialize(element); removeWatchedElement(editedElement); ((StableElement)editedElement).invalidate(); } } }.execute(); } }; final DomManager domManager = DomManager.getDomManager(project); for (final DomElement element : myDomElements.values()) { if (domManager.isMockElement(element)) { myFileEditor.addWatchedElement(element); } } return myFileEditor; }
protected final DomFileEditor initFileEditor(final Project project, final VirtualFile virtualFile, final String name, final Factory<? extends BasicDomElementComponent> component) { myFileEditor = new DomFileEditor<BasicDomElementComponent>(project, virtualFile, name, component) { public JComponent getPreferredFocusedComponent() { return null; } @NotNull protected JComponent createCustomComponent() { final JComponent customComponent = super.createCustomComponent(); myContents = getDomComponent(); return customComponent; } public void reset() { for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) { final DomElement newValue = entry.getKey().find(); final DomElement oldValue = entry.getValue(); if (newValue != null && !newValue.equals(oldValue) || newValue == null && !oldValue.getManager().isMockElement(oldValue)) { ((StableElement)oldValue).revalidate(); } } super.reset(); } public void commit() { super.commit(); final List<EditedElementDescription> descriptions = new ArrayList<EditedElementDescription>(); final Set<PsiFile> changedFiles = new HashSet<PsiFile>(); for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) { final EditedElementDescription description = entry.getKey(); final DomElement editedElement = entry.getValue(); if (description.find() == null && editedElement.getXmlTag() != null) { descriptions.add(description); final XmlFile xmlFile = description.getEditedFile(); if (xmlFile != null) { changedFiles.add(xmlFile); } } } new WriteCommandAction(project, PsiUtilCore.toPsiFileArray(changedFiles)) { protected void run(Result result) throws Throwable { for (EditedElementDescription description : descriptions) { final DomElement editedElement = myDomElements.get(description); DomElement element = description.addElement(); element.copyFrom(editedElement); description.initialize(element); removeWatchedElement(editedElement); ((StableElement)editedElement).invalidate(); } } }.execute(); } }; final DomManager domManager = DomManager.getDomManager(project); for (final DomElement element : myDomElements.values()) { if (domManager.isMockElement(element)) { myFileEditor.addWatchedElement(element); } } return myFileEditor; }