added extension points to Project Structure which allow a plugin to add new configurable or hide existing

This commit is contained in:
nik
2013-08-20 13:43:48 +04:00
parent 9b08ac29b4
commit dd19635642
5 changed files with 117 additions and 10 deletions
@@ -146,7 +146,11 @@ public class BuildElementsEditor extends ModuleElementsEditor {
private void updateOutputPathPresentation() {
if (getCompilerExtension().isCompilerOutputPathInherited()) {
final String baseUrl = ProjectStructureConfigurable.getInstance(myProject).getProjectConfig().getCompilerOutputUrl();
ProjectConfigurable projectConfig = ProjectStructureConfigurable.getInstance(myProject).getProjectConfig();
if (projectConfig == null) {
return;
}
final String baseUrl = projectConfig.getCompilerOutputUrl();
moduleCompileOutputChanged(baseUrl, getModel().getModule().getName());
} else {
final VirtualFile compilerOutputPath = getCompilerExtension().getCompilerOutputPath();
@@ -60,6 +60,8 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurableFilter.ConfigurableId;
public class ProjectStructureConfigurable extends BaseConfigurable implements SearchableConfigurable, Place.Navigator {
public static final DataKey<ProjectStructureConfigurable> KEY = DataKey.create("ProjectStructureConfiguration");
@@ -220,13 +222,40 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
addFacetsConfig();
addArtifactsConfig();
}
ProjectStructureConfigurableAdder[] adders = ProjectStructureConfigurableAdder.EP_NAME.getExtensions();
for (ProjectStructureConfigurableAdder adder : adders) {
for (Configurable configurable : adder.getExtraProjectConfigurables(myProject, myContext)) {
addConfigurable(configurable, true);
}
}
mySidePanel.addSeparator("Platform Settings");
addJdkListConfig();
addGlobalLibrariesConfig();
for (ProjectStructureConfigurableAdder adder : adders) {
for (Configurable configurable : adder.getExtraPlatformConfigurables(myProject, myContext)) {
addConfigurable(configurable, true);
}
}
}
private void addArtifactsConfig() {
addConfigurable(myArtifactsStructureConfigurable);
addConfigurable(myArtifactsStructureConfigurable, ConfigurableId.ARTIFACTS);
}
private void addConfigurable(final Configurable configurable, final ConfigurableId configurableId) {
addConfigurable(configurable, isAvailable(configurableId));
}
private boolean isAvailable(ConfigurableId id) {
for (ProjectStructureConfigurableFilter filter : ProjectStructureConfigurableFilter.EP_NAME.getExtensions()) {
if (!filter.isAvailable(id, myProject)) {
return false;
}
}
return true;
}
public ArtifactsStructureConfigurable getArtifactsStructureConfigurable() {
@@ -235,7 +264,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
private void addFacetsConfig() {
if (myFacetStructureConfigurable.isVisible()) {
addConfigurable(myFacetStructureConfigurable);
addConfigurable(myFacetStructureConfigurable, ConfigurableId.FACETS);
}
}
@@ -244,25 +273,25 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
myJdkListConfig = JdkListConfigurable.getInstance(myProject);
myJdkListConfig.init(myContext);
}
addConfigurable(myJdkListConfig);
addConfigurable(myJdkListConfig, ConfigurableId.JDK_LIST);
}
private void addProjectConfig() {
myProjectConfig = new ProjectConfigurable(myProject, myContext, myModuleConfigurator, myProjectJdksModel);
addConfigurable(myProjectConfig);
addConfigurable(myProjectConfig, ConfigurableId.PROJECT);
}
private void addProjectLibrariesConfig() {
addConfigurable(myProjectLibrariesConfig);
addConfigurable(myProjectLibrariesConfig, ConfigurableId.PROJECT_LIBRARIES);
}
private void addGlobalLibrariesConfig() {
addConfigurable(myGlobalLibrariesConfig);
addConfigurable(myGlobalLibrariesConfig, ConfigurableId.GLOBAL_LIBRARIES);
}
private void addModulesConfig() {
myModulesConfig = ModuleStructureConfigurable.getInstance(myProject);
addConfigurable(myModulesConfig);
addConfigurable(myModulesConfig, ConfigurableId.MODULES);
}
@Override
@@ -579,10 +608,12 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
return myProjectConfig;
}
private void addConfigurable(Configurable configurable) {
private void addConfigurable(Configurable configurable, boolean addToSidePanel) {
myName2Config.add(configurable);
mySidePanel.addPlace(createPlaceFor(configurable), new Presentation(configurable.getDisplayName()));
if (addToSidePanel) {
mySidePanel.addPlace(createPlaceFor(configurable), new Presentation(configurable.getDisplayName()));
}
}
private static Place createPlaceFor(final Configurable configurable) {
@@ -0,0 +1,40 @@
/*
* Copyright 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.roots.ui.configuration;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public abstract class ProjectStructureConfigurableAdder {
public static final ExtensionPointName<ProjectStructureConfigurableAdder> EP_NAME = ExtensionPointName.create("com.intellij.projectStructureConfigurableAdder");
@NotNull
public List<? extends Configurable> getExtraProjectConfigurables(@NotNull Project project, @NotNull StructureConfigurableContext context) {
return Collections.emptyList();
}
@NotNull
public List<? extends Configurable> getExtraPlatformConfigurables(@NotNull Project project, @NotNull StructureConfigurableContext context) {
return Collections.emptyList();
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 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.roots.ui.configuration;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
public abstract class ProjectStructureConfigurableFilter {
public static final ExtensionPointName<ProjectStructureConfigurableFilter> EP_NAME = ExtensionPointName.create("com.intellij.projectStructureConfigurableFilter");
public enum ConfigurableId {
PROJECT, MODULES, PROJECT_LIBRARIES, FACETS, ARTIFACTS, JDK_LIST, GLOBAL_LIBRARIES
}
public abstract boolean isAvailable(@NotNull ConfigurableId id, @NotNull Project project);
}
@@ -78,6 +78,8 @@
<extensionPoint name="codeInsight.wordCompletionFilter" beanClass="com.intellij.lang.LanguageExtensionPoint"/>
<extensionPoint name="projectStructureConfigurableFilter" interface="com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurableFilter"/>
<extensionPoint name="projectStructureConfigurableAdder" interface="com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurableAdder"/>
<extensionPoint name="compiler" area="IDEA_PROJECT" interface="com.intellij.openapi.compiler.Compiler"/>
<extensionPoint name="compilerFactory" area="IDEA_PROJECT" interface="com.intellij.openapi.compiler.CompilerFactory"/>