diff --git a/platform/platform-api/src/com/intellij/openapi/options/ConfigurableEP.java b/platform/platform-api/src/com/intellij/openapi/options/ConfigurableEP.java index 47e7ca64c26d..4146af6bb694 100644 --- a/platform/platform-api/src/com/intellij/openapi/options/ConfigurableEP.java +++ b/platform/platform-api/src/com/intellij/openapi/options/ConfigurableEP.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -236,28 +236,27 @@ public class ConfigurableEP extends AbstractExten protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) { myProject = project; myPicoContainer = picoContainer; - myProducer = new AtomicNotNullLazyValue() { - @NotNull - @Override - protected ObjectProducer compute() { - try { - if (providerClass != null) { - return new ProviderProducer(instantiate(providerClass, myPicoContainer)); - } - if (instanceClass != null) { - return new ClassProducer(myPicoContainer, findClass(instanceClass)); - } - if (implementationClass != null) { - return new ClassProducer(myPicoContainer, findClass(implementationClass)); - } - throw new RuntimeException("configurable class name is not set"); - } - catch (AssertionError | Exception | LinkageError error) { - LOG.error(error); - } - return new ObjectProducer(); + myProducer = AtomicNotNullLazyValue.createValue(this::createProducer); + } + + @NotNull + protected ObjectProducer createProducer() { + try { + if (providerClass != null) { + return new ProviderProducer(instantiate(providerClass, myPicoContainer)); } - }; + if (instanceClass != null) { + return new ClassProducer(myPicoContainer, findClass(instanceClass)); + } + if (implementationClass != null) { + return new ClassProducer(myPicoContainer, findClass(implementationClass)); + } + throw new RuntimeException("configurable class name is not set"); + } + catch (AssertionError | Exception | LinkageError error) { + LOG.error(error); + } + return new ObjectProducer(); } @Nullable @@ -295,16 +294,16 @@ public class ConfigurableEP extends AbstractExten return myProducer.getValue().getType(); } - private static class ObjectProducer { - Object createElement() { + protected static class ObjectProducer { + protected Object createElement() { return null; } - boolean canCreateElement() { + protected boolean canCreateElement() { return false; } - Class getType() { + protected Class getType() { return null; } } @@ -317,12 +316,12 @@ public class ConfigurableEP extends AbstractExten } @Override - Object createElement() { + protected Object createElement() { return myProvider == null ? null : myProvider.createConfigurable(); } @Override - boolean canCreateElement() { + protected boolean canCreateElement() { return myProvider != null && myProvider.canCreateConfigurable(); } } @@ -337,7 +336,7 @@ public class ConfigurableEP extends AbstractExten } @Override - Object createElement() { + protected Object createElement() { try { return instantiate(myType, myContainer, true); } @@ -351,11 +350,11 @@ public class ConfigurableEP extends AbstractExten } @Override - boolean canCreateElement() { + protected boolean canCreateElement() { return myType != null; } - Class getType() { + protected Class getType() { return myType; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java index 7d4b5336bb7c..1aacafadb396 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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,10 +16,10 @@ package com.intellij.openapi.vcs.configurable; import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.options.ConfigurableEP; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsConfigurableProvider; @@ -27,13 +27,14 @@ import com.intellij.openapi.vcs.changes.ChangeListManagerImpl; import com.intellij.openapi.vcs.changes.conflicts.ChangelistConflictConfigurable; import com.intellij.openapi.vcs.changes.ui.IgnoredSettingsPanel; import com.intellij.openapi.vcs.impl.VcsDescriptor; -import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.ArrayList; import java.util.List; +import static com.intellij.openapi.options.ex.ConfigurableWrapper.wrapConfigurable; + public class VcsManagerConfigurable extends SearchableConfigurable.Parent.Abstract implements Configurable.NoScroll { private final Project myProject; private VcsDirectoryConfigurationPanel myMappings; @@ -151,62 +152,39 @@ public class VcsManagerConfigurable extends SearchableConfigurable.Parent.Abstra return myMappings; } - private Configurable createVcsConfigurableWrapper(final VcsDescriptor vcs) { - final NotNullLazyValue delegate = new NotNullLazyValue() { - @NotNull - @Override - protected Configurable compute() { - return ProjectLevelVcsManager.getInstance(myProject).findVcsByName(vcs.getName()).getConfigurable(); - } - }; - return new SearchableConfigurable(){ + private Configurable createVcsConfigurableWrapper(@NotNull VcsDescriptor descriptor) { + return wrapConfigurable(new VcsConfigurableEP(myProject, descriptor)); + } - @Override - @Nls - public String getDisplayName() { - return vcs.getDisplayName(); - } + private static class VcsConfigurableEP extends ConfigurableEP { + @NotNull private final VcsDescriptor myDescriptor; - @Override - public String getHelpTopic() { - return delegate.getValue().getHelpTopic(); - } + public VcsConfigurableEP(@NotNull Project project, @NotNull VcsDescriptor descriptor) { + super(project); + myDescriptor = descriptor; + displayName = descriptor.getDisplayName(); + id = "vcs." + displayName; + } - @Override - public JComponent createComponent() { - return delegate.getValue().createComponent(); - } + @NotNull + @Override + protected ConfigurableEP.ObjectProducer createProducer() { + return new ObjectProducer() { + @Override + protected Object createElement() { + return ProjectLevelVcsManager.getInstance(getProject()).findVcsByName(myDescriptor.getName()).getConfigurable(); + } - @Override - public boolean isModified() { - return delegate.getValue().isModified(); - } + @Override + protected boolean canCreateElement() { + return true; + } - @Override - public void apply() throws ConfigurationException { - delegate.getValue().apply(); - } - - @Override - public void reset() { - delegate.getValue().reset(); - } - - @Override - public void disposeUIResources() { - delegate.getValue().disposeUIResources(); - } - - @Override - @NotNull - public String getId() { - return "vcs." + getDisplayName(); - } - - @Override - public String toString() { - return "VcsConfigurable for "+vcs.getDisplayName(); - } - }; + @Override + protected Class getType() { + return SearchableConfigurable.class; + } + }; + } } }