public static boolean showAcceptDialog(
     final @NotNull Callable<? extends DialogWrapper> dialogFactory) {
   Application app = ApplicationManager.getApplication();
   final CountDownLatch proceeded = new CountDownLatch(1);
   final AtomicBoolean accepted = new AtomicBoolean();
   app.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           try {
             DialogWrapper dialog = dialogFactory.call();
             accepted.set(dialog.showAndGet());
           } catch (Exception e) {
             LOG.error("Unexpected error", e);
           } finally {
             proceeded.countDown();
           }
         }
       },
       ModalityState.any());
   try {
     proceeded.await();
   } catch (InterruptedException e) {
     LOG.error("Interrupted", e);
   }
   return accepted.get();
 }
  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()));
    }
  }
  private static void showDialog(ApplicationImpl app) {
    DialogWrapper dialog =
        new DialogWrapper(null) {
          {
            setTitle("Some Modal Dialog");
            init();
          }

          @Nullable
          @Override
          protected JComponent createCenterPanel() {
            return new JTextField("Waiting for the progress...");
          }
        };
    EdtExecutorService.getScheduledExecutorInstance()
        .schedule(
            () -> {
              app.runWriteActionWithProgress(
                  "Progress in modal dialog",
                  null,
                  dialog.getRootPane(),
                  TestWriteActionUnderProgress::runDeterminateProgress);
              dialog.close(0);
            },
            2500,
            TimeUnit.MILLISECONDS);
    app.invokeLater(
        () -> {
          dialog.setSize(100, 100);
          dialog.setLocation(100, 100);
        },
        ModalityState.any());
    dialog.show();
  }
 @Nullable
 public CvsTabbedWindow openTabbedWindow(final CvsHandler output) {
   if (ApplicationManager.getApplication().isUnitTestMode()) return null;
   if (myProject != null && myProject.isDefault()) return null;
   if (myProject != null) {
     if (myConfiguration != null && myConfiguration.SHOW_OUTPUT && !myIsQuietOperation) {
       if (ApplicationManager.getApplication().isDispatchThread()) {
         connectToOutput(output);
       } else {
         ApplicationManager.getApplication()
             .invokeAndWait(
                 new Runnable() {
                   public void run() {
                     connectToOutput(output);
                   }
                 },
                 ModalityState.defaultModalityState());
       }
     }
     if (!myProject.isDisposed()) {
       return CvsTabbedWindow.getInstance(myProject);
     }
   }
   return null;
 }
Exemplo n.º 5
0
  public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
    try {
      FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.rootNode");

      Project project = event.getData(PlatformDataKeys.PROJECT);
      assert project != null;

      RootChooseModel chooseSNodeResult = new RootChooseModel(project, new RootNodeNameIndex());
      ChooseByNamePopup popup =
          MpsPopupFactory.createNodePopupWithParentAction(
              project, chooseSNodeResult, GoToRootNode_Action.this);

      popup.invoke(
          new ChooseByNamePopupComponent.Callback() {
            @Override
            public void onClose() {}

            @Override
            public void elementChosen(Object element) {
              ((NavigationItem) element).navigate(true);
            }
          },
          ModalityState.current(),
          true);
    } catch (Throwable t) {
      if (LOG.isEnabledFor(Level.ERROR)) {
        LOG.error("User's action execute method failed. Action:" + "GoToRootNode", t);
      }
    }
  }
Exemplo n.º 6
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 boolean confirmUndeploy() {
    final Ref<Boolean> confirmed = new Ref<Boolean>(false);
    ApplicationManager.getApplication()
        .invokeAndWait(
            new Runnable() {

              @Override
              public void run() {
                String title = CloudBundle.getText("cloud.undeploy.confirm.title");
                while (true) {
                  String password =
                      Messages.showPasswordDialog(
                          CloudBundle.getText("cloud.undeploy.confirm.message", myPresentableName),
                          title);
                  if (password == null) {
                    return;
                  }
                  if (password.equals(myConfiguration.getPassword())) {
                    confirmed.set(true);
                    return;
                  }
                  Messages.showErrorDialog(
                      CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title);
                }
              }
            },
            ModalityState.defaultModalityState());
    return confirmed.get();
  }
  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()));
    }
  }
 private void awaitTermination(@NotNull Runnable request, long delayMillis) {
   if (ApplicationManager.getApplication().isUnitTestMode()) {
     ApplicationManager.getApplication().invokeLater(request, ModalityState.any());
   } else {
     myAwaitingTerminationAlarm.addRequest(request, delayMillis);
   }
 }
    @Override
    public void processTerminated(ProcessEvent event) {
      if (myProject.isDisposed()) return;
      if (!myTerminateNotified.compareAndSet(false, true)) return;

      ApplicationManager.getApplication()
          .invokeLater(
              () -> {
                RunnerLayoutUi ui = myDescriptor.getRunnerLayoutUi();
                if (ui != null && !ui.isDisposed()) {
                  ui.updateActionsNow();
                }
              },
              ModalityState.any());

      myProject
          .getMessageBus()
          .syncPublisher(EXECUTION_TOPIC)
          .processTerminated(myExecutorId, myEnvironment, myProcessHandler, event.getExitCode());

      SaveAndSyncHandler saveAndSyncHandler = SaveAndSyncHandler.getInstance();
      if (saveAndSyncHandler != null) {
        saveAndSyncHandler.scheduleRefresh();
      }
    }
  @Override
  public void runWhenProjectIsInitialized(@NotNull final Runnable action) {
    final Application application = ApplicationManager.getApplication();
    if (application == null) return;

    //noinspection SynchronizeOnThis
    synchronized (this) {
      // in tests which simulate project opening, post-startup activities could have been run
      // already.
      // Then we should act as if the project was initialized
      boolean initialized =
          myProject.isInitialized()
              || application.isUnitTestMode() && myPostStartupActivitiesPassed;
      if (!initialized) {
        registerPostStartupActivity(action);
        return;
      }
    }

    Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            if (!myProject.isDisposed()) {
              action.run();
            }
          }
        };
    if (application.isDispatchThread() && ModalityState.current() == ModalityState.NON_MODAL) {
      runnable.run();
    } else {
      application.invokeLater(runnable, ModalityState.NON_MODAL);
    }
  }
  @Override
  public void addMessageToConsoleWindow(final String message, final TextAttributes attributes) {
    if (!Registry.is("vcs.showConsole")) {
      return;
    }
    if (StringUtil.isEmptyOrSpaces(message)) {
      return;
    }

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                // for default and disposed projects the ContentManager is not available.
                if (myProject.isDisposed() || myProject.isDefault()) return;
                final ContentManager contentManager = getContentManager();
                if (contentManager == null) {
                  myPendingOutput.add(Pair.create(message, attributes));
                } else {
                  getOrCreateConsoleContent(contentManager);
                  myEditorAdapter.appendString(message, attributes);
                }
              }
            },
            ModalityState.defaultModalityState());
  }
 @Override
 protected byte[] key(@Nullable final Project project) throws PasswordSafeException {
   ApplicationEx application = (ApplicationEx) ApplicationManager.getApplication();
   if (!isTestMode() && application.isHeadlessEnvironment()) {
     throw new MasterPasswordUnavailableException(
         "The provider is not available in headless environment");
   }
   if (key.get() == null) {
     if (isPasswordEncrypted()) {
       try {
         String s = decryptPassword(database.getPasswordInfo());
         setMasterPassword(s);
       } catch (PasswordSafeException e) {
         // ignore exception and ask password
       }
     }
     if (key.get() == null) {
       final Ref<PasswordSafeException> ex = new Ref<PasswordSafeException>();
       if (application.holdsReadLock()) {
         throw new IllegalStateException(
             "Access from read action is not allowed, because it might lead to a deadlock.");
       }
       application.invokeAndWait(
           new Runnable() {
             public void run() {
               if (key.get() == null) {
                 try {
                   if (isTestMode()) {
                     throw new MasterPasswordUnavailableException(
                         "Master password must be specified in test mode.");
                   }
                   if (database.isEmpty()) {
                     if (!ResetPasswordDialog.newPassword(project, MasterKeyPasswordSafe.this)) {
                       throw new MasterPasswordUnavailableException(
                           "Master password is required to store passwords in the database.");
                     }
                   } else {
                     MasterPasswordDialog.askPassword(project, MasterKeyPasswordSafe.this);
                   }
                 } catch (PasswordSafeException e) {
                   ex.set(e);
                 } catch (Exception e) {
                   //noinspection ThrowableInstanceNeverThrown
                   ex.set(
                       new MasterPasswordUnavailableException(
                           "The problem with retrieving the password", e));
                 }
               }
             }
           },
           ModalityState.defaultModalityState());
       //noinspection ThrowableResultOfMethodCallIgnored
       if (ex.get() != null) {
         throw ex.get();
       }
     }
   }
   return this.key.get();
 }
Exemplo n.º 14
0
  public static void addModelImport(
      final Project project,
      final SModule module,
      final SModel model,
      @Nullable BaseAction parentAction) {
    BaseModelModel goToModelModel =
        new BaseModelModel(project) {
          @Override
          public NavigationItem doGetNavigationItem(final SModelReference modelReference) {
            return new AddModelItem(project, model, modelReference, module);
          }

          @Override
          public SModelReference[] find(SearchScope scope) {
            Condition<SModel> cond =
                new Condition<SModel>() {
                  @Override
                  public boolean met(SModel modelDescriptor) {
                    boolean rightStereotype =
                        SModelStereotype.isUserModel(modelDescriptor)
                            || SModelStereotype.isStubModelStereotype(
                                SModelStereotype.getStereotype(modelDescriptor));
                    boolean hasModule = modelDescriptor.getModule() != null;
                    return rightStereotype && hasModule;
                  }
                };
            ConditionalIterable<SModel> iter =
                new ConditionalIterable<SModel>(scope.getModels(), cond);
            List<SModelReference> filteredModelRefs = new ArrayList<SModelReference>();
            for (SModel md : iter) {
              filteredModelRefs.add(md.getReference());
            }
            return filteredModelRefs.toArray(new SModelReference[filteredModelRefs.size()]);
          }

          @Override
          @Nullable
          public String getPromptText() {
            return "Import model:";
          }
        };
    ChooseByNamePopup popup =
        MpsPopupFactory.createPackagePopup(project, goToModelModel, parentAction);

    popup.invoke(
        new ChooseByNamePopupComponent.Callback() {
          @Override
          public void onClose() {
            // if (GoToRootNodeAction.class.equals(myInAction)) myInAction = null;
          }

          @Override
          public void elementChosen(final Object element) {
            ((NavigationItem) element).navigate(true);
          }
        },
        ModalityState.current(),
        true);
  }
Exemplo n.º 15
0
  public static void addModelImportByRoot(
      final Project project,
      final SModule contextModule,
      final SModel model,
      String initialText,
      @Nullable BaseAction parentAction,
      final ModelImportByRootCallback callback) {
    BaseMPSChooseModel goToNodeModel =
        new RootChooseModel(project, new RootNodeNameIndex()) {
          @Override
          public NavigationItem doGetNavigationItem(final NavigationTarget object) {
            return new RootNodeElement(object) {
              @Override
              public void navigate(boolean requestFocus) {
                ModelAccess.assertLegalRead();
                new AddModelItem(
                        project,
                        model,
                        object.getNodeReference().getModelReference(),
                        contextModule)
                    .navigate(requestFocus);
              }
            };
          }

          @Override
          @Nullable
          public String getPromptText() {
            return "Import model that contains root:";
          }
        };
    ChooseByNamePopup popup =
        MpsPopupFactory.createNodePopup(project, goToNodeModel, initialText, parentAction);

    popup.invoke(
        new ChooseByNamePopupComponent.Callback() {
          @Override
          public void onClose() {
            // if (GoToRootNodeAction.class.equals(myInAction)) myInAction = null;
          }

          @Override
          public void elementChosen(final Object element) {
            ModelAccess.instance()
                .runWriteAction(
                    new Runnable() {
                      @Override
                      public void run() {
                        NavigationItem navigationItem = (NavigationItem) element;
                        navigationItem.navigate(true);
                        callback.importForRootAdded(
                            navigationItem.getPresentation().getPresentableText());
                      }
                    });
          }
        },
        ModalityState.current(),
        true);
  }
  @Nullable
  private static RunnableInfo getNextEvent(boolean remove) {
    synchronized (LOCK) {
      if (!ourForcedFlushQueue.isEmpty()) {
        final RunnableInfo toRun =
            remove ? ourForcedFlushQueue.remove(0) : ourForcedFlushQueue.get(0);
        if (!toRun.expired.value(null)) {
          return toRun;
        } else {
          toRun.callback.setDone();
        }
      }

      ModalityState currentModality;
      if (ourModalEntities.isEmpty()) {
        Application application = ApplicationManager.getApplication();
        currentModality =
            application == null ? ModalityState.NON_MODAL : application.getNoneModalityState();
      } else {
        currentModality = new ModalityStateEx(ourModalEntities.toArray());
      }

      while (ourQueueSkipCount < ourQueue.size()) {
        RunnableInfo info = ourQueue.get(ourQueueSkipCount);

        if (info.expired.value(null)) {
          ourQueue.remove(ourQueueSkipCount);
          info.callback.setDone();
          continue;
        }

        if (!currentModality.dominates(info.modalityState)) {
          if (remove) {
            ourQueue.remove(ourQueueSkipCount);
          }
          return info;
        }
        ourQueueSkipCount++;
      }

      return null;
    }
  }
 private void showMergeDialog(@NotNull final Collection<VirtualFile> initiallyUnmergedFiles) {
   ApplicationManager.getApplication()
       .invokeAndWait(
           () -> {
             MergeProvider mergeProvider = new GitMergeProvider(myProject, myParams.reverse);
             myVcsHelper.showMergeDialog(
                 new ArrayList<>(initiallyUnmergedFiles),
                 mergeProvider,
                 myParams.myMergeDialogCustomizer);
           },
           ModalityState.defaultModalityState());
 }
  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;
      }
    }
  }
Exemplo n.º 19
0
 private void queueChangesCheck() {
   if (myAlarm.isDisposed()) {
     return;
   }
   myAlarm.addRequest(
       () -> {
         checkChanges();
         queueChangesCheck();
       },
       CHANGES_CHECK_TIME,
       ModalityState.any());
 }
Exemplo n.º 20
0
  private void doInit(
      final List<SModelReference> options, @Nullable List<SModelReference> nonProjectModels) {
    setModal(true);
    myModels.addAll(options);
    if (nonProjectModels != null) {
      myNonProjectModels.addAll(nonProjectModels);
    }

    DataContext dataContext = DataManager.getInstance().getDataContext();
    final Project project = MPSDataKeys.PROJECT.getData(dataContext);

    BaseModelModel goToModelModel =
        new BaseModelModel(project) {
          public NavigationItem doGetNavigationItem(final SModelReference modelReference) {
            return new BaseModelItem(modelReference) {
              public void navigate(boolean requestFocus) {}
            };
          }

          @Override
          public SModelReference[] find(boolean checkboxState) {
            if (checkboxState) {
              return myNonProjectModels.toArray(new SModelReference[myNonProjectModels.size()]);
            } else {
              return myModels.toArray(new SModelReference[myModels.size()]);
            }
          }

          public SModelReference[] find(IScope scope) {
            throw new UnsupportedOperationException("must not be used");
          }

          @Override
          public boolean loadInitialCheckBoxState() {
            return false;
          }
        };

    myChooser =
        MpsPopupFactory.createPanelForPackage(goToModelModel, !myNonProjectModels.isEmpty());
    myChooser.invoke(
        new Callback() {
          public void elementChosen(Object element) {
            if (!myOkDone) {
              myOkDone = true;
              onOk();
            }
          }
        },
        ModalityState.current(),
        myIsMultipleSelection);
  }
 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 static void showDumbModeWarningLaterIfNobodyConsumesEvent(
      final InputEvent e, final AnActionEvent... actionEvents) {
    if (ModalityState.current() == ModalityState.NON_MODAL) {
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                public void run() {
                  if (e.isConsumed()) return;

                  ActionUtil.showDumbModeWarning(actionEvents);
                }
              });
    }
  }
 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));
 }
Exemplo n.º 24
0
  public static void addLanguageImport(
      final Project project,
      final SModule contextModule,
      final SModel model,
      @Nullable BaseAction parentAction,
      @Nullable final Runnable onClose) {
    BaseLanguageModel goToLanguageModel =
        new BaseLanguageModel(project) {
          @Override
          public NavigationItem doGetNavigationItem(SModuleReference ref) {
            return new AddLanguageItem(project, ref, contextModule, model);
          }

          @Override
          public SModuleReference[] find(SearchScope scope) {
            ArrayList<SModuleReference> res = new ArrayList<SModuleReference>();
            for (SModule m : scope.getModules()) {
              if (!(m instanceof Language)) continue;
              res.add(m.getModuleReference());
            }
            return res.toArray(new SModuleReference[res.size()]);
          }

          @Nullable
          @Override
          public String getPromptText() {
            return "Import language:";
          }
        };
    ChooseByNamePopup popup =
        MpsPopupFactory.createPackagePopup(project, goToLanguageModel, parentAction);

    popup.invoke(
        new ChooseByNamePopupComponent.Callback() {
          @Override
          public void onClose() {
            // if (GoToRootNodeAction.class.equals(myInAction)) myInAction = null;
            if (onClose != null) {
              onClose.run();
            }
          }

          @Override
          public void elementChosen(Object element) {
            ((NavigationItem) element).navigate(true);
          }
        },
        ModalityState.current(),
        true);
  }
 /**
  * Opens an error dialog with the specified title. Ensures that the error dialog is opened on the
  * UI thread.
  *
  * @param message The message to be displayed.
  * @param title The title of the error dialog to be displayed
  */
 public static void showErrorDialog(final String message, @NotNull final String title) {
   if (ApplicationManager.getApplication().isDispatchThread()) {
     Messages.showErrorDialog(message, title);
   } else {
     ApplicationManager.getApplication()
         .invokeLater(
             new Runnable() {
               @Override
               public void run() {
                 Messages.showErrorDialog(message, title);
               }
             },
             ModalityState.defaultModalityState());
   }
 }
  @CalledInAwt
  @NotNull
  public static ProgressIndicator executeOnPooledThread(
      @NotNull final Consumer<ProgressIndicator> task, @NotNull Disposable parent) {
    final ModalityState modalityState = ModalityState.current();
    final ProgressIndicator indicator =
        new EmptyProgressIndicator() {
          @NotNull
          @Override
          public ModalityState getModalityState() {
            return modalityState;
          }
        };
    indicator.start();

    final Disposable disposable =
        new Disposable() {
          @Override
          public void dispose() {
            if (indicator.isRunning()) indicator.cancel();
          }
        };
    Disposer.register(parent, disposable);

    ApplicationManager.getApplication()
        .executeOnPooledThread(
            new Runnable() {
              @Override
              public void run() {
                ProgressManager.getInstance()
                    .executeProcessUnderProgress(
                        new Runnable() {
                          @Override
                          public void run() {
                            try {
                              task.consume(indicator);
                            } finally {
                              indicator.stop();
                              Disposer.dispose(disposable);
                            }
                          }
                        },
                        indicator);
              }
            });

    return indicator;
  }
Exemplo n.º 27
0
 @Override
 protected void loadLibraries() {
   if (!ThreadUtils.isEventDispatchThread()) {
     ApplicationManager.getApplication()
         .invokeAndWait(
             new Runnable() {
               @Override
               public void run() {
                 ProjectLibraryManager.super.loadLibraries();
               }
             },
             ModalityState.defaultModalityState());
   } else {
     super.loadLibraries();
   }
 }
 @Nullable
 private AuthDialog showAuthDialog(final String url, final String login) {
   final Ref<AuthDialog> dialog = Ref.create();
   ApplicationManager.getApplication()
       .invokeAndWait(
           new Runnable() {
             @Override
             public void run() {
               dialog.set(
                   new AuthDialog(
                       myProject, myTitle, "Enter credentials for " + url, login, null, true));
               dialog.get().show();
             }
           },
           ModalityState.any());
   return dialog.get();
 }
 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));
   }
 }
Exemplo n.º 30
0
  public void doExecute(AnActionEvent e, Map<String, Object> _params) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    assert project != null;

    FeatureUsageTracker.getInstance().triggerFeatureUsed("goto.model");
    // PsiDocumentManager.getInstance(project).commitAllDocuments();

    BaseModelModel goToModelModel =
        new BaseModelModel(project) {
          public NavigationItem doGetNavigationItem(final SModelReference modelReference) {
            return new BaseModelItem(modelReference) {
              public void navigate(boolean requestFocus) {
                ProjectPane projectPane = ProjectPane.getInstance(project);
                SModelDescriptor md =
                    SModelRepository.getInstance().getModelDescriptor(modelReference);
                projectPane.selectModel(md, true);
              }
            };
          }

          public SModelReference[] find(IScope scope) {
            Condition<SModelDescriptor> cond =
                new Condition<SModelDescriptor>() {
                  public boolean met(SModelDescriptor modelDescriptor) {
                    boolean rightStereotype =
                        SModelStereotype.isUserModel(modelDescriptor)
                            || SModelStereotype.isStubModelStereotype(
                                modelDescriptor.getStereotype());
                    boolean hasModule = modelDescriptor.getModule() != null;
                    return rightStereotype && hasModule;
                  }
                };
            ConditionalIterable<SModelDescriptor> iter =
                new ConditionalIterable<SModelDescriptor>(scope.getModelDescriptors(), cond);
            List<SModelReference> result = new ArrayList<SModelReference>();
            for (SModelDescriptor md : iter) {
              result.add(md.getSModelReference());
            }
            return result.toArray(new SModelReference[result.size()]);
          }
        };
    ChooseByNamePopup popup = MpsPopupFactory.createPackagePopup(project, goToModelModel);
    popup.setShowListForEmptyPattern(true);
    popup.invoke(new NavigateCallback(), ModalityState.current(), true);
  }