mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
added service to quickly find modules by module type; hide DevKit and J2ME run configurations if there are no corresponding modules (IDEA-116046)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.openapi.module;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class TypedModuleService {
|
||||
@NotNull
|
||||
public static TypedModuleService getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, TypedModuleService.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract Collection<Module> getModulesOfType(@NotNull ModuleType<?> moduleType);
|
||||
|
||||
public abstract boolean hasModulesOfType(@NotNull ModuleType<?> module);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.openapi.module.impl;
|
||||
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.TypedModuleService;
|
||||
import com.intellij.openapi.project.ModuleAdapter;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class TypedModuleServiceImpl extends TypedModuleService {
|
||||
private MultiMap<ModuleType<?>, Module> myCachedModules;
|
||||
private final ModuleManager myModuleManager;
|
||||
|
||||
public TypedModuleServiceImpl(ModuleManager moduleManager, MessageBus messageBus) {
|
||||
myModuleManager = moduleManager;
|
||||
messageBus.connect().subscribe(ProjectTopics.MODULES, new ModuleAdapter() {
|
||||
@Override
|
||||
public void moduleAdded(Project project, Module module) {
|
||||
myCachedModules = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moduleRemoved(Project project, Module module) {
|
||||
myCachedModules = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private MultiMap<ModuleType<?>, Module> getCachedModules() {
|
||||
if (myCachedModules == null) {
|
||||
myCachedModules = new MultiMap<ModuleType<?>, Module>();
|
||||
for (Module module : myModuleManager.getModules()) {
|
||||
myCachedModules.putValue(ModuleType.get(module), module);
|
||||
}
|
||||
}
|
||||
return myCachedModules;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Module> getModulesOfType(@NotNull ModuleType<?> moduleType) {
|
||||
return getCachedModules().get(moduleType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasModulesOfType(@NotNull ModuleType<?> module) {
|
||||
return !getModulesOfType(module).isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -248,6 +248,8 @@
|
||||
serviceImplementation="com.intellij.facet.impl.invalid.InvalidFacetManagerImpl"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.module.ProjectLoadingErrorsNotifier"
|
||||
serviceImplementation="com.intellij.openapi.module.impl.ProjectLoadingErrorsNotifierImpl"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.module.TypedModuleService"
|
||||
serviceImplementation="com.intellij.openapi.module.impl.TypedModuleServiceImpl"/>
|
||||
|
||||
<moduleService serviceInterface="com.intellij.facet.FacetModificationTrackingService"
|
||||
serviceImplementation="com.intellij.facet.impl.FacetModificationTrackingServiceImpl"/>
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.jetbrains.idea.devkit.module;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.module.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
@@ -123,15 +122,4 @@ public class PluginModuleType extends ModuleType<PluginModuleBuilder> {
|
||||
public boolean isValidSdk(@NotNull final Module module, final Sdk projectSdk) {
|
||||
return JavaModuleType.isValidJavaSdk(module);
|
||||
}
|
||||
|
||||
public static Module[] getAllPluginModules(final Project project) {
|
||||
List<Module> modules = new ArrayList<Module>();
|
||||
Module[] allModules = ModuleManager.getInstance(project).getModules();
|
||||
for (Module module : allModules) {
|
||||
if (get(module) == getInstance()) {
|
||||
modules.add(module);
|
||||
}
|
||||
}
|
||||
return modules.toArray(new Module[modules.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.TypedModuleService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.DevKitBundle;
|
||||
import org.jetbrains.idea.devkit.module.PluginModuleType;
|
||||
@@ -31,6 +33,7 @@ import org.jetbrains.idea.devkit.module.PluginModuleType;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
public class PluginConfigurationType implements ConfigurationType {
|
||||
private final ConfigurationFactory myFactory;
|
||||
@@ -48,6 +51,11 @@ public class PluginConfigurationType implements ConfigurationType {
|
||||
return runConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(@NotNull Project project) {
|
||||
return TypedModuleService.getInstance(project).hasModulesOfType(PluginModuleType.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSingletonByDefault() {
|
||||
return true;
|
||||
@@ -56,10 +64,8 @@ public class PluginConfigurationType implements ConfigurationType {
|
||||
public RunConfiguration createConfiguration(String name, RunConfiguration template) {
|
||||
final PluginRunConfiguration pluginRunConfiguration = (PluginRunConfiguration)template;
|
||||
if (pluginRunConfiguration.getModule() == null) {
|
||||
final Module[] modules = PluginModuleType.getAllPluginModules(pluginRunConfiguration.getProject());
|
||||
if (modules.length > 0){
|
||||
pluginRunConfiguration.setModule(modules[0]);
|
||||
}
|
||||
final Collection<Module> modules = TypedModuleService.getInstance(pluginRunConfiguration.getProject()).getModulesOfType(PluginModuleType.getInstance());
|
||||
pluginRunConfiguration.setModule(ContainerUtil.getFirstItem(modules));
|
||||
}
|
||||
return super.createConfiguration(name, pluginRunConfiguration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user