diff --git a/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/SetupSDKNotificationProvider.java b/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/SetupSDKNotificationProvider.java new file mode 100644 index 000000000000..b4abfb99cc60 --- /dev/null +++ b/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/SetupSDKNotificationProvider.java @@ -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 { + private static final Key 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 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; + } +} diff --git a/platform/projectModel-impl/src/messages/ProjectBundle.properties b/platform/projectModel-impl/src/messages/ProjectBundle.properties index 6e08ca5d3c41..cee4e41dc4c3 100644 --- a/platform/projectModel-impl/src/messages/ProjectBundle.properties +++ b/platform/projectModel-impl/src/messages/ProjectBundle.properties @@ -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} diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 72ef62dedb26..6f614bddea9a 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -267,6 +267,7 @@ +