mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-85568 feature request: complain if there is no valid SDK implemented
This commit is contained in:
+98
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.ide.highlighter.JavaClassFileType;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotifications;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class SetupSDKNotificationProvider implements EditorNotifications.Provider<EditorNotificationPanel> {
|
||||
private static final Key<EditorNotificationPanel> KEY = Key.create("Setup SDK");
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
public SetupSDKNotificationProvider(Project project, final EditorNotifications notifications) {
|
||||
myProject = project;
|
||||
myProject.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
|
||||
public void rootsChanged(ModuleRootEvent event) {
|
||||
notifications.updateAllNotifications();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key<EditorNotificationPanel> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditorNotificationPanel createNotificationPanel(VirtualFile file) {
|
||||
if (file.getFileType() == JavaClassFileType.INSTANCE) return null;
|
||||
|
||||
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ProjectRootManager.getInstance(myProject).getProjectSdk() != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createPanel(myProject, psiFile);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static EditorNotificationPanel createPanel(final @NotNull Project project, final @NotNull PsiFile file) {
|
||||
final EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||
panel.setText(ProjectBundle.message("project.sdk.not.defined"));
|
||||
panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Sdk projectSdk = ProjectSettingsService.getInstance(project).chooseAndSetSdk();
|
||||
if (projectSdk == null) return;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(file);
|
||||
if (module != null) {
|
||||
ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
modifiableModel.inheritSdk();
|
||||
modifiableModel.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,9 @@ library.attach.sources.action=Attach Sources
|
||||
library.attach.sources.action.busy.text=Attaching...
|
||||
library.attach.sources.description=Select jar/zip files or directories in which library sources are located
|
||||
|
||||
project.sdk.not.defined=Project SDK is not defined
|
||||
project.sdk.setup=Setup SDK
|
||||
|
||||
module.module.language.level=&Language level:
|
||||
module.module.language.level.comment=(effective on project reload)
|
||||
module.circular.dependency.warning.short=There is circular dependency between modules {0}
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
<applicationConfigurable instance="com.intellij.execution.console.ConsoleFoldingConfigurable"/>
|
||||
|
||||
<editorNotificationProvider implementation="com.intellij.codeInsight.daemon.impl.AttachSourcesNotificationProvider"/>
|
||||
<editorNotificationProvider implementation="com.intellij.codeInsight.daemon.impl.SetupSDKNotificationProvider"/>
|
||||
|
||||
<checkoutListener implementation="com.intellij.openapi.vcs.checkout.ProjectCheckoutListener"/>
|
||||
<checkoutListener implementation="com.intellij.openapi.vcs.checkout.ProjectDirCheckoutListener"/>
|
||||
|
||||
Reference in New Issue
Block a user