mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[grails] delegate creations of configure actions to MvcFramework, since we want to allow extend this behaviour
This commit is contained in:
@@ -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<String, Runnable> action : framework.createConfigureActions(module).entrySet()) {
|
||||
panel.createActionLabel(action.getKey(), action.getValue());
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, Runnable> createConfigureActions(final @NotNull Module module) {
|
||||
return Collections.<String, Runnable>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());
|
||||
}
|
||||
|
||||
+35
-23
@@ -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<Module, MvcFramework> pair = findModuleWithoutLibrary(project);
|
||||
if (pair == null) return;
|
||||
|
||||
Pair<Module, MvcFramework> pair = findModuleWithoutLibrary(project);
|
||||
final MvcFramework framework = pair.second;
|
||||
final Module module = pair.first;
|
||||
final String name = framework.getFrameworkName();
|
||||
final Map<String, Runnable> actions = framework.createConfigureActions(module);
|
||||
|
||||
if (pair != null) {
|
||||
final MvcFramework framework = pair.second;
|
||||
final Module module = pair.first;
|
||||
final StringBuilder content = new StringBuilder()
|
||||
.append("<html><body>")
|
||||
.append("Module").append('\'').append(module.getName()).append('\'')
|
||||
.append(" has no ").append(name).append(" SDK.");
|
||||
if (!actions.isEmpty()) content.append("<br/>");
|
||||
content.append(StringUtil.join(actions.keySet(), new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String actionName) {
|
||||
return String.format("<a href='%s'>%s</a>", actionName, actionName);
|
||||
}
|
||||
}, " "));
|
||||
content.append("</body></html>");
|
||||
|
||||
String name = framework.getFrameworkName();
|
||||
String content = "<html><body>Module '" + module.getName() + "' has no " + name + " SDK. <a href='create'>Configure SDK</a></body></html>";
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user