From 88dbbba7726672c1cf90c9d958e478db4178e545 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 22 Sep 2015 13:17:53 +0300 Subject: [PATCH] [grails] delegate creations of configure actions to MvcFramework, since we want to allow extend this behaviour --- .../groovy/mvc/MvcConfigureNotification.java | 25 ++------ .../plugins/groovy/mvc/MvcFramework.java | 18 ++++++ .../MvcProjectWithoutLibraryNotificator.java | 58 +++++++++++-------- 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConfigureNotification.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConfigureNotification.java index 18b554c4eabd..653e0747e617 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConfigureNotification.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConfigureNotification.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,11 +16,11 @@ package org.jetbrains.plugins.groovy.mvc; import com.intellij.openapi.module.Module; -import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDialog; import com.intellij.ui.EditorNotificationPanel; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.annotator.GroovyFrameworkConfigNotification; -import org.jetbrains.plugins.groovy.config.GroovyLibraryDescription; + +import java.util.Map.Entry; /** * @author sergey.evdokimov @@ -43,26 +43,13 @@ public class MvcConfigureNotification extends GroovyFrameworkConfigNotification return framework.hasFrameworkJar(module); } - public static void configure(@NotNull MvcFramework framework, @NotNull Module module) { - final GroovyLibraryDescription description = framework.createLibraryDescription(); - final AddCustomLibraryDialog dialog = AddCustomLibraryDialog.createDialog(description, module, null); - dialog.setTitle("Change " + framework.getDisplayName() + " SDK version"); - if (dialog.showAndGet()) { - module.putUserData(MvcFramework.UPGRADE, Boolean.TRUE); - } - } - @Override public EditorNotificationPanel createConfigureNotificationPanel(@NotNull final Module module) { final EditorNotificationPanel panel = new EditorNotificationPanel(); panel.setText(framework.getFrameworkName() + " SDK is not configured for module '" + module.getName() + '\''); - panel.createActionLabel("Configure " + framework.getFrameworkName() + " SDK", new Runnable() { - @Override - public void run() { - configure(framework, module); - } - }); - + for (Entry action : framework.createConfigureActions(module).entrySet()) { + panel.createActionLabel(action.getKey(), action.getValue()); + } return panel; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java index 1ec30d6e9fb1..2da1ef5c1764 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java @@ -35,6 +35,7 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryKind; import com.intellij.openapi.roots.ui.configuration.ClasspathEditor; import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; +import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDialog; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.ModificationTracker; @@ -102,6 +103,23 @@ public abstract class MvcFramework { return JavaPsiFacade.getInstance(module.getProject()).findClass(getSomeFrameworkClass(), scope) != null; } + @NotNull + public Map createConfigureActions(final @NotNull Module module) { + return Collections.singletonMap("Configure " + getFrameworkName() + " SDK", new Runnable() { + @Override + public void run() { + configureAsLibraryDependency(module); + } + }); + } + + protected void configureAsLibraryDependency(@NotNull Module module) { + final GroovyLibraryDescription description = createLibraryDescription(); + final AddCustomLibraryDialog dialog = AddCustomLibraryDialog.createDialog(description, module, null); + dialog.setTitle("Change " + getDisplayName() + " SDK version"); + if (dialog.showAndGet()) module.putUserData(UPGRADE, Boolean.TRUE); + } + public boolean isCommonPluginsModule(@NotNull Module module) { return module.getName().endsWith(getCommonPluginSuffix()); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectWithoutLibraryNotificator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectWithoutLibraryNotificator.java index d0bb2a0fbc4d..cfe20fc4f89e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectWithoutLibraryNotificator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectWithoutLibraryNotificator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -27,10 +27,13 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupActivity; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.event.HyperlinkEvent; +import java.util.Map; /** * @author Sergey Evdokimov @@ -41,31 +44,40 @@ public class MvcProjectWithoutLibraryNotificator implements StartupActivity, Dum ProgressIndicatorUtils.scheduleWithWriteActionPriority(new ReadTask() { @Override public void computeInReadAction(@NotNull ProgressIndicator indicator) { - if (project.isDisposed()) { - return; - } + if (project.isDisposed()) return; + final Pair pair = findModuleWithoutLibrary(project); + if (pair == null) return; - Pair pair = findModuleWithoutLibrary(project); + final MvcFramework framework = pair.second; + final Module module = pair.first; + final String name = framework.getFrameworkName(); + final Map actions = framework.createConfigureActions(module); - if (pair != null) { - final MvcFramework framework = pair.second; - final Module module = pair.first; + final StringBuilder content = new StringBuilder() + .append("") + .append("Module").append('\'').append(module.getName()).append('\'') + .append(" has no ").append(name).append(" SDK."); + if (!actions.isEmpty()) content.append("
"); + content.append(StringUtil.join(actions.keySet(), new Function() { + @Override + public String fun(String actionName) { + return String.format("%s", actionName, actionName); + } + }, " ")); + content.append(""); - String name = framework.getFrameworkName(); - String content = "Module '" + module.getName() + "' has no " + name + " SDK. Configure SDK"; - new Notification(name + ".Configure", - name + " SDK not found", - content, NotificationType.INFORMATION, - new NotificationListener.Adapter() { - @Override - protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) { - if (!module.isDisposed()) { - MvcConfigureNotification.configure(framework, module); - } - } - } - ).notify(project); - } + new Notification( + name + ".Configure", name + " SDK not found", content.toString(), NotificationType.INFORMATION, + new NotificationListener.Adapter() { + @Override + protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) { + if (module.isDisposed()) return; + final Runnable runnable = actions.get(e.getDescription()); + assert runnable != null; + runnable.run(); + } + } + ).notify(project); } @Override