@Override
    public void selectionChanged(@NotNull FileEditorManagerEvent event) {
      final FileEditor newFileEditor = event.getNewEditor();
      Editor mxmlEditor = null;
      if (newFileEditor instanceof TextEditor) {
        final Editor editor = ((TextEditor) newFileEditor).getEditor();
        if (DesignerApplicationManager.dumbAwareIsApplicable(
            project, PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()))) {
          mxmlEditor = editor;
        }
      }

      if (mxmlEditor == null) {
        processFileEditorChange(null);
        return;
      }

      final DumbService dumbService = DumbService.getInstance(project);
      if (dumbService.isDumb()) {
        openWhenSmart(dumbService);
      } else {
        if (!isApplicableEditor(mxmlEditor)) {
          mxmlEditor = null;
        }

        processFileEditorChange(mxmlEditor);
      }
    }
 private boolean isApplicableEditor(Editor editor) {
   final Document document = editor.getDocument();
   return DesignerApplicationManager.isApplicable(
       project, PsiDocumentManager.getInstance(project).getPsiFile(document));
 }
  private void render(final boolean isSlow, final boolean clearPreviousOnError) {
    if (!toolWindowVisible) {
      return;
    }

    final VirtualFile file = toolWindowForm.getFile();
    if (file == null) {
      return;
    }

    toolWindowForm.getPreviewPanel().clearCannotRender();

    if (isSlow) {
      toolWindowForm.getPreviewPanel().getLoadingDecorator().startLoading(false);
      loadingDecoratorStarted++;
    }

    toolWindowForm.waitingForGetDocument = true;
    XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(file);
    LogMessageUtil.LOG.assertTrue(xmlFile != null);
    AsyncResult<BufferedImage> result =
        DesignerApplicationManager.getInstance().getDocumentImage(xmlFile);
    result.doWhenDone(
        new QueuedAsyncResultHandler<BufferedImage>() {
          @Override
          protected boolean isExpired() {
            return toolWindowForm == null || !file.equals(toolWindowForm.getFile());
          }

          @Override
          public void process(final BufferedImage image) {
            UIUtil.invokeLaterIfNeeded(
                new Runnable() {
                  @Override
                  public void run() {
                    toolWindowForm.getPreviewPanel().setImage(image);
                  }
                });
          }
        });

    result.doWhenProcessed(
        new Runnable() {
          @Override
          public void run() {
            toolWindowForm.waitingForGetDocument = false;
            if (isSlow && --loadingDecoratorStarted == 0 && toolWindowForm != null) {
              toolWindowForm.getPreviewPanel().getLoadingDecorator().stopLoading();
            }
          }
        });

    result.doWhenRejected(
        new Runnable() {
          @Override
          public void run() {
            if (clearPreviousOnError) {
              toolWindowForm.getPreviewPanel().setImage(null);
            }
            UIUtil.invokeLaterIfNeeded(
                new Runnable() {
                  @Override
                  public void run() {
                    toolWindowForm.getPreviewPanel().showCannotRender();
                  }
                });
          }
        });
  }