private boolean isRelevant(PsiTreeChangeEvent event) { if (myToolWindowForm == null || !myToolWindowReady || myToolWindowDisposed) { return false; } final PsiFile fileInPreview = myToolWindowForm.getFile(); final PsiFile file = event.getFile(); if (fileInPreview == null || file == null || fileInPreview != file) { return false; } PsiElement child = event.getChild(); PsiElement parent = event.getParent(); // We can ignore edits in whitespace, and in XML error nodes, and in comments // (Note that editing text in an attribute value, including whitespace characters, // is not a PsiWhiteSpace element; it's an XmlToken of token type XML_ATTRIBUTE_VALUE_TOKEN if (child instanceof PsiWhiteSpace || child instanceof PsiErrorElement || child instanceof XmlComment || parent instanceof XmlComment) { return false; } return true; }
public boolean render() { ApplicationManager.getApplication().assertIsDispatchThread(); if (myToolWindow == null || !myToolWindow.isVisible()) { return false; } final PsiFile psiFile = myToolWindowForm.getFile(); if (psiFile == null) { return false; } final AndroidFacet facet = AndroidFacet.getInstance(psiFile); if (facet == null) { return false; } getRenderingQueue() .queue( new Update("render") { @Override public void run() { ProgressManager.getInstance() .runProcess( new Runnable() { @Override public void run() { DumbService.getInstance(myProject).waitForSmartMode(); try { doRender(facet, psiFile); } catch (Throwable e) { LOG.error(e); } synchronized (PROGRESS_LOCK) { if (myCurrentIndicator != null) { myCurrentIndicator.stop(); myCurrentIndicator = null; } } } }, new AndroidPreviewProgressIndicator(myToolWindowForm, 100)); } @Override public boolean canEat(Update update) { return true; } }); return true; }