@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);
      }
    }
예제 #2
0
  private void openAndWait(VirtualFile file, @Nullable String relativePath)
      throws InterruptedException, IOException {
    semaphore.down();

    DesignerApplicationManager.getInstance()
        .renderDocument(myModule, Tests.virtualToPsi(myProject, file));
    await();
  }
예제 #3
0
 @Override
 protected void tearDown() throws Exception {
   try {
     super.tearDown();
     if (getName().equals("testCloseAndOpenProject")) {
       callClientAssert("close");
     }
   } finally {
     DesignerApplicationManager.getInstance().disposeApplication();
     StringRegistry.getInstance().reset();
   }
 }
예제 #4
0
  private void renderAndWait(VirtualFile file) throws InterruptedException {
    semaphore.down();
    AsyncResult<DocumentInfo> result =
        DesignerApplicationManager.getInstance()
            .renderDocument(myModule, Tests.virtualToPsi(myProject, file));

    result.doWhenProcessed(
        new Runnable() {
          @Override
          public void run() {
            semaphore.up();
          }
        });

    await();
  }
 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();
                  }
                });
          }
        });
  }