public static boolean checkSourceRootsConfigured(
      final Module module, final boolean askUserToSetupSourceRoots) {
    List<VirtualFile> sourceRoots =
        ModuleRootManager.getInstance(module).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
    if (sourceRoots.isEmpty()) {
      if (!askUserToSetupSourceRoots) {
        return false;
      }

      Project project = module.getProject();
      Messages.showErrorDialog(
          project,
          ProjectBundle.message("module.source.roots.not.configured.error", module.getName()),
          ProjectBundle.message("module.source.roots.not.configured.title"));

      ProjectSettingsService.getInstance(project)
          .showModuleConfigurationDialog(module.getName(), CommonContentEntriesEditor.NAME);

      sourceRoots =
          ModuleRootManager.getInstance(module).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
      if (sourceRoots.isEmpty()) {
        return false;
      }
    }
    return true;
  }
Esempio n. 2
0
 private boolean isNavigatableLibraryRoot() {
   VirtualFile jarRoot = getJarRoot();
   final Project project = getProject();
   if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
     final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
     return orderEntry != null
         && ProjectSettingsService.getInstance(project).canOpenLibraryOrSdkSettings(orderEntry);
   }
   return false;
 }
 @Override
 public void doFix(@NotNull Project project, @NotNull VirtualFile file) {
   final String javaErrorMessage =
       JavaProjectSdkSetupValidator.INSTANCE.getErrorMessage(project, file);
   if (javaErrorMessage != null) {
     JavaProjectSdkSetupValidator.INSTANCE.doFix(project, file);
     return;
   }
   final Module module = ModuleUtilCore.findModuleForFile(file, project);
   final String moduleName = module != null && !module.isDisposed() ? module.getName() : null;
   ProjectSettingsService.getInstance(project)
       .showModuleConfigurationDialog(moduleName, ClasspathEditor.NAME);
 }
Esempio n. 4
0
  @Override
  public void navigate(boolean requestFocus) {
    final VirtualFile jarRoot = getJarRoot();
    final Project project = getProject();
    if (requestFocus && jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
      final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
      if (orderEntry != null) {
        ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry);
        return;
      }
    }

    super.navigate(requestFocus);
  }
Esempio n. 5
0
  public void createApplicationIfNeeded(@NotNull final Module module) {
    if (findAppRoot(module) == null && module.getUserData(CREATE_APP_STRUCTURE) == Boolean.TRUE) {
      while (ModuleUtilCore.getSdk(module, JavaModuleExtensionImpl.class) == null) {
        if (Messages.showYesNoDialog(
                module.getProject(),
                "Cannot generate "
                    + getDisplayName()
                    + " project structure because JDK is not specified for module \""
                    + module.getName()
                    + "\".\n"
                    + getDisplayName()
                    + " project will not be created if you don't specify JDK.\nDo you want to specify JDK?",
                "Error",
                Messages.getErrorIcon())
            == 1) {
          return;
        }
        ProjectSettingsService.getInstance(module.getProject())
            .showModuleConfigurationDialog(module.getName(), ClasspathEditor.NAME);
      }
      module.putUserData(CREATE_APP_STRUCTURE, null);
      final GeneralCommandLine commandLine = getCreationCommandLine(module);
      if (commandLine == null) return;

      MvcConsole.executeProcess(
          module,
          commandLine,
          new Runnable() {
            public void run() {
              VirtualFile root = findAppRoot(module);
              if (root == null) return;

              PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(root);
              IdeView ide =
                  LangDataKeys.IDE_VIEW.getData(DataManager.getInstance().getDataContext());
              if (ide != null) ide.selectElement(psiDir);

              // also here comes fileCreated(application.properties) which manages roots and run
              // configuration
            }
          },
          true);
    }
  }
 @Override
 public void invoke(@NotNull Project project, Editor editor, final PsiFile file) {
   Sdk projectJdk = ProjectSettingsService.getInstance(project).chooseAndSetSdk();
   if (projectJdk == null) return;
   ApplicationManager.getApplication()
       .runWriteAction(
           new Runnable() {
             @Override
             public void run() {
               Module module = ModuleUtil.findModuleForPsiElement(file);
               if (module != null) {
                 ModifiableRootModel modifiableModel =
                     ModuleRootManager.getInstance(module).getModifiableModel();
                 modifiableModel.inheritSdk();
                 modifiableModel.commit();
               }
             }
           });
 }
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;

      ProjectSettingsService.getInstance(myProject).openProjectSettings();
    }
Esempio n. 8
0
 @Override
 public void navigate(final boolean requestFocus) {
   Module module = getValue().getModule();
   ProjectSettingsService.getInstance(myProject).openModuleLibrarySettings(module);
 }
Esempio n. 9
0
 @Override
 public boolean canNavigate() {
   return ProjectSettingsService.getInstance(myProject).canOpenModuleLibrarySettings();
 }