public static void printToConsole(
      @NotNull final LanguageConsoleImpl console,
      @NotNull final ConsoleViewContentType mainType,
      @NotNull final List<Pair<String, ConsoleViewContentType>> textToPrint) {
    final List<Pair<String, TextAttributes>> attributedText =
        ContainerUtil.map(
            textToPrint,
            new Function<Pair<String, ConsoleViewContentType>, Pair<String, TextAttributes>>() {
              @Override
              public Pair<String, TextAttributes> fun(Pair<String, ConsoleViewContentType> input) {
                final TextAttributes mainAttributes = mainType.getAttributes();
                final TextAttributes attributes;
                if (input.getSecond() == null) {
                  attributes = mainAttributes;
                } else {
                  attributes = input.getSecond().getAttributes().clone();
                  attributes.setBackgroundColor(mainAttributes.getBackgroundColor());
                }
                return Pair.create(input.getFirst(), attributes);
              }
            });

    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
      console.printToHistory(attributedText);
    } else {
      application.invokeLater(
          new Runnable() {
            public void run() {
              console.printToHistory(attributedText);
            }
          },
          ModalityState.stateForComponent(console.getComponent()));
    }
  }
  public static void printToConsole(
      @NotNull final LanguageConsoleImpl console,
      @NotNull final String string,
      @NotNull final ConsoleViewContentType mainType,
      @Nullable ConsoleViewContentType additionalType) {
    final TextAttributes mainAttributes = mainType.getAttributes();
    final TextAttributes attributes;
    if (additionalType == null) {
      attributes = mainAttributes;
    } else {
      attributes = additionalType.getAttributes().clone();
      attributes.setBackgroundColor(mainAttributes.getBackgroundColor());
    }

    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
      console.printToHistory(string, attributes);
    } else {
      application.invokeLater(
          new Runnable() {
            public void run() {
              console.printToHistory(string, attributes);
            }
          },
          ModalityState.stateForComponent(console.getComponent()));
    }
  }
Exemplo n.º 3
0
  public void addMessage(final CompilerMessage message) {
    prepareMessageView();

    final CompilerMessageCategory messageCategory = message.getCategory();
    if (CompilerMessageCategory.WARNING.equals(messageCategory)) {
      myWarningCount += 1;
    } else if (CompilerMessageCategory.ERROR.equals(messageCategory)) {
      myErrorCount += 1;
      informWolf(message);
    }

    if (ApplicationManager.getApplication().isDispatchThread()) {
      openMessageView();
      doAddMessage(message);
    } else {
      final Window window = getWindow();
      final ModalityState modalityState =
          window != null ? ModalityState.stateForComponent(window) : ModalityState.NON_MODAL;
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                public void run() {
                  if (!myProject.isDisposed()) {
                    openMessageView();
                    doAddMessage(message);
                  }
                }
              },
              modalityState);
    }
  }
  public MoveClassesOrPackagesDialog(
      Project project,
      boolean searchTextOccurences,
      PsiElement[] elementsToMove,
      final PsiElement initialTargetElement,
      MoveCallback moveCallback) {
    super(project, true);
    myElementsToMove = elementsToMove;
    myMoveCallback = moveCallback;
    myManager = PsiManager.getInstance(myProject);
    setTitle(MoveHandler.REFACTORING_NAME);
    mySearchTextOccurencesEnabled = searchTextOccurences;

    selectInitialCard();

    init();

    if (initialTargetElement instanceof PsiClass) {
      myMakeInnerClassOfRadioButton.setSelected(true);

      myInnerClassChooser.setText(((PsiClass) initialTargetElement).getQualifiedName());

      ApplicationManager.getApplication()
          .invokeLater(
              () -> myInnerClassChooser.requestFocus(),
              ModalityState.stateForComponent(myMainPanel));
    } else if (initialTargetElement instanceof PsiPackage) {
      myClassPackageChooser.setText(((PsiPackage) initialTargetElement).getQualifiedName());
    }

    updateControlsEnabled();
    myToPackageRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateControlsEnabled();
            myClassPackageChooser.requestFocus();
          }
        });
    myMakeInnerClassOfRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateControlsEnabled();
            myInnerClassChooser.requestFocus();
          }
        });

    for (PsiElement element : elementsToMove) {
      if (element.getContainingFile() != null) {
        myOpenInEditorPanel.add(initOpenInEditorCb(), BorderLayout.EAST);
        break;
      }
    }
  }
 private void addAlarmRequest() {
   Runnable request =
       () -> {
         if (!myDisposed && !myProject.isDisposed()) {
           PsiDocumentManager.getInstance(myProject)
               .performLaterWhenAllCommitted(
                   () ->
                       DumbService.getInstance(myProject)
                           .withAlternativeResolveEnabled(this::updateComponent));
         }
       };
   myAlarm.addRequest(request, DELAY, ModalityState.stateForComponent(myEditor.getComponent()));
 }
 private void updateFileIconLater(VirtualFile file) {
   myFilesToUpdateIconsFor.add(file);
   myIconUpdaterAlarm.cancelAllRequests();
   myIconUpdaterAlarm.addRequest(
       () -> {
         if (myManager.getProject().isDisposed()) return;
         for (VirtualFile file1 : myFilesToUpdateIconsFor) {
           updateFileIconImmediately(file1);
         }
         myFilesToUpdateIconsFor.clear();
       },
       200,
       ModalityState.stateForComponent(this));
 }
 private void updateListsInChooser() {
   Runnable runnable =
       new Runnable() {
         public void run() {
           if (myChangeListChooser != null && myShowingAllChangeLists) {
             myChangeListChooser.updateLists(
                 ChangeListManager.getInstance(myProject).getChangeListsCopy());
           }
         }
       };
   if (SwingUtilities.isEventDispatchThread()) {
     runnable.run();
   } else {
     ApplicationManager.getApplication()
         .invokeLater(runnable, ModalityState.stateForComponent(this));
   }
 }
  private void updateChangesForDocument(@NotNull final Document document) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (DaemonListeners.isUnderIgnoredAction(null) || myProject.isDisposed()) return;
    List<Pair<PsiElement, Boolean>> toUpdate = changedElements.get(document);
    if (toUpdate == null) {
      // The document has been changed, but psi hasn't
      // We may still need to rehighlight the file if there were changes inside highlighted ranges.
      if (UpdateHighlightersUtil.isWhitespaceOptimizationAllowed(document)) return;

      // don't create PSI for files in other projects
      PsiElement file = PsiDocumentManager.getInstance(myProject).getCachedPsiFile(document);
      if (file == null) return;

      toUpdate = Collections.singletonList(Pair.create(file, true));
    }
    Application application = ApplicationManager.getApplication();
    final Editor editor = FileEditorManager.getInstance(myProject).getSelectedTextEditor();
    if (editor != null && !application.isUnitTestMode()) {
      application.invokeLater(
          () -> {
            if (!editor.isDisposed()) {
              EditorMarkupModel markupModel = (EditorMarkupModel) editor.getMarkupModel();
              PsiFile file =
                  PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
              TrafficLightRenderer.setOrRefreshErrorStripeRenderer(
                  markupModel, myProject, editor.getDocument(), file);
            }
          },
          ModalityState.stateForComponent(editor.getComponent()),
          myProject.getDisposed());
    }

    for (Pair<PsiElement, Boolean> changedElement : toUpdate) {
      PsiElement element = changedElement.getFirst();
      Boolean whiteSpaceOptimizationAllowed = changedElement.getSecond();
      updateByChange(element, document, whiteSpaceOptimizationAllowed);
    }
    changedElements.remove(document);
  }
Exemplo n.º 9
0
  void updateTable() {
    IDevice[] devices = myBridge != null ? getFilteredDevices(myBridge) : EMPTY_DEVICE_ARRAY;
    if (devices.length > 1) {
      // sort by API level
      Arrays.sort(
          devices,
          new Comparator<IDevice>() {
            @Override
            public int compare(IDevice device1, IDevice device2) {
              int apiLevel1 = safeGetApiLevel(device1);
              int apiLevel2 = safeGetApiLevel(device2);
              return apiLevel2 - apiLevel1;
            }

            private int safeGetApiLevel(IDevice device) {
              try {
                String s = device.getProperty(IDevice.PROP_BUILD_API_LEVEL);
                return StringUtil.isNotEmpty(s) ? Integer.parseInt(s) : 0;
              } catch (Exception e) {
                return 0;
              }
            }
          });
    }

    if (!Arrays.equals(myDisplayedDevices, devices)) {
      myDetectedDevicesRef.set(devices);
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  refreshTable();
                }
              },
              ModalityState.stateForComponent(myDeviceTable));
    }
  }
Exemplo n.º 10
0
 private void closeUI() {
   if (isHeadlessMode()) {
     return;
   }
   Window window = getWindow();
   ModalityState modalityState =
       window != null ? ModalityState.stateForComponent(window) : ModalityState.NON_MODAL;
   final Application application = ApplicationManager.getApplication();
   application.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           synchronized (myMessageViewLock) {
             if (myErrorTreeView != null) {
               final boolean shouldRetainView =
                   myErrorCount > 0 || myWarningCount > 0 && !myErrorTreeView.isHideWarnings();
               if (shouldRetainView) {
                 addMessage(
                     new CompilerMessageImpl(
                         myProject,
                         CompilerMessageCategory.STATISTICS,
                         CompilerBundle.message("statistics.error.count", myErrorCount)));
                 addMessage(
                     new CompilerMessageImpl(
                         myProject,
                         CompilerMessageCategory.STATISTICS,
                         CompilerBundle.message("statistics.warnings.count", myWarningCount)));
                 // activateMessageView();
                 myErrorTreeView.selectFirstMessage();
               } else {
                 removeAllContents(myProject, null);
               }
             }
           }
         }
       },
       modalityState);
 }
 private void applyInformationToEditorsLater(
     @NotNull final FileEditor fileEditor,
     @NotNull final TextEditorHighlightingPass pass,
     @NotNull final DaemonProgressIndicator updateProgress,
     @NotNull final AtomicInteger threadsToStartCountdown) {
   ApplicationManager.getApplication()
       .invokeLater(
           (DumbAwareRunnable)
               () -> {
                 if (isDisposed() || myProject.isDisposed()) {
                   updateProgress.cancel();
                 }
                 if (updateProgress.isCanceled()) {
                   log(updateProgress, pass, " is canceled during apply, sorry");
                   return;
                 }
                 Document document = pass.getDocument();
                 try {
                   if (fileEditor.getComponent().isDisplayable()
                       || ApplicationManager.getApplication().isUnitTestMode()) {
                     pass.applyInformationToEditor();
                     FileStatusMap fileStatusMap =
                         DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap();
                     if (document != null) {
                       fileStatusMap.markFileUpToDate(document, pass.getId());
                     }
                     log(updateProgress, pass, " Applied");
                   }
                 } catch (ProcessCanceledException e) {
                   log(updateProgress, pass, "Error " + e);
                   throw e;
                 } catch (RuntimeException e) {
                   VirtualFile file =
                       document == null
                           ? null
                           : FileDocumentManager.getInstance().getFile(document);
                   FileType fileType = file == null ? null : file.getFileType();
                   String message =
                       "Exception while applying information to "
                           + fileEditor
                           + "("
                           + fileType
                           + ")";
                   log(updateProgress, pass, message + e);
                   throw new RuntimeException(message, e);
                 }
                 if (threadsToStartCountdown.decrementAndGet() == 0) {
                   log(updateProgress, pass, "Stopping ");
                   updateProgress.stopIfRunning();
                 } else {
                   log(
                       updateProgress,
                       pass,
                       "Finished but there are passes in the queue: "
                           + threadsToStartCountdown.get());
                 }
               },
           Registry.is("ide.perProjectModality")
               ? ModalityState.defaultModalityState()
               : ModalityState.stateForComponent(fileEditor.getComponent()));
 }
 private ModalityState getModalityState() {
   return ModalityState.stateForComponent(getRootPane());
 }
Exemplo n.º 13
0
 public void addComponentRequest(@NotNull Runnable request, long delayMillis) {
   assert myActivationComponent != null;
   _addRequest(request, delayMillis, ModalityState.stateForComponent(myActivationComponent));
 }
Exemplo n.º 14
0
 public void addComponentRequest(Runnable request, int delay) {
   assert myActivationComponent != null;
   _addRequest(request, delay, ModalityState.stateForComponent(myActivationComponent));
 }
  public void findUsages(final Set<PsiFile> searchIn, final Set<PsiFile> searchFor) {
    cancelCurrentFindRequest();

    myAlarm.cancelAllRequests();
    myAlarm.addRequest(
        () ->
            ApplicationManager.getApplication()
                .executeOnPooledThread(
                    () -> {
                      final ProgressIndicator progress =
                          new PanelProgressIndicator(component -> setToComponent(component));
                      myCurrentProgress = progress;
                      ProgressManager.getInstance()
                          .runProcess(
                              () -> {
                                ApplicationManager.getApplication()
                                    .runReadAction(
                                        () -> {
                                          UsageInfo[] usages = new UsageInfo[0];
                                          Set<PsiFile> elementsToSearch = null;

                                          try {
                                            if (myBuilders.get(0).isBackward()) {
                                              elementsToSearch = searchIn;
                                              usages =
                                                  FindDependencyUtil.findBackwardDependencies(
                                                      myBuilders, searchFor, searchIn);
                                            } else {
                                              elementsToSearch = searchFor;
                                              usages =
                                                  FindDependencyUtil.findDependencies(
                                                      myBuilders, searchIn, searchFor);
                                            }
                                            assert !new HashSet<PsiFile>(elementsToSearch)
                                                .contains(null);
                                          } catch (ProcessCanceledException e) {
                                          } catch (Exception e) {
                                            LOG.error(e);
                                          }

                                          if (!progress.isCanceled()) {
                                            final UsageInfo[] finalUsages = usages;
                                            final PsiElement[] _elementsToSearch =
                                                elementsToSearch != null
                                                    ? PsiUtilCore.toPsiElementArray(
                                                        elementsToSearch)
                                                    : PsiElement.EMPTY_ARRAY;
                                            ApplicationManager.getApplication()
                                                .invokeLater(
                                                    () ->
                                                        showUsages(_elementsToSearch, finalUsages),
                                                    ModalityState.stateForComponent(
                                                        DependenciesUsagesPanel.this));
                                          }
                                        });
                                myCurrentProgress = null;
                              },
                              progress);
                    }),
        300);
  }