Ejemplo n.º 1
0
  private void openAndWait(VirtualFile file, @Nullable String relativePath)
      throws InterruptedException, IOException {
    semaphore.down();

    DesignerApplicationManager.getInstance()
        .renderDocument(myModule, Tests.virtualToPsi(myProject, file));
    await();
  }
Ejemplo n.º 2
0
 @Override
 protected void tearDown() throws Exception {
   try {
     super.tearDown();
     if (getName().equals("testCloseAndOpenProject")) {
       callClientAssert("close");
     }
   } finally {
     DesignerApplicationManager.getInstance().disposeApplication();
     StringRegistry.getInstance().reset();
   }
 }
Ejemplo n.º 3
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 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();
                  }
                });
          }
        });
  }