diff --git a/platform/lang-impl/src/com/intellij/execution/impl/EditConfigurationsDialog.java b/platform/lang-impl/src/com/intellij/execution/impl/EditConfigurationsDialog.java index 0c053b17e5dd..33bb9bf21d23 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/EditConfigurationsDialog.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/EditConfigurationsDialog.java @@ -1,19 +1,4 @@ -/* - * 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. - * 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. - */ - +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.impl; import com.intellij.execution.ExecutionBundle; @@ -31,12 +16,13 @@ import java.awt.event.ComponentEvent; public class EditConfigurationsDialog extends SingleConfigurableEditor implements RunDialogBase { protected Executor myExecutor; - public EditConfigurationsDialog(final Project project) { + public EditConfigurationsDialog(@NotNull Project project) { this(project, null); } - public EditConfigurationsDialog(final Project project, @Nullable final ConfigurationFactory factory) { + public EditConfigurationsDialog(@NotNull Project project, @Nullable ConfigurationFactory factory) { super(project, new RunConfigurable(project).selectConfigurableOnShow(factory == null), "#com.intellij.execution.impl.EditConfigurationsDialog", IdeModalityType.IDE); + ((RunConfigurable)getConfigurable()).setRunDialog(this); setTitle(ExecutionBundle.message("run.debug.dialog.title")); setHorizontalStretch(1.3F); @@ -53,10 +39,8 @@ public class EditConfigurationsDialog extends SingleConfigurableEditor implement getContentPanel().addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { - if (configuration != null) { - configurable.updateRightPanel(configuration); - getContentPanel().removeComponentListener(this); - } + configurable.updateRightPanel(configuration); + getContentPanel().removeComponentListener(this); } }); } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt index e260c4d80319..efdd1f849150 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt @@ -65,7 +65,7 @@ private fun getName(userObject: Any): String { } } -open class RunConfigurable @JvmOverloads constructor(private val myProject: Project, private var myRunDialog: RunDialogBase? = null) : BaseConfigurable(), Disposable { +open class RunConfigurable @JvmOverloads constructor(private val myProject: Project, var runDialog: RunDialogBase? = null) : BaseConfigurable(), Disposable { @Volatile private var isDisposed: Boolean = false val root = DefaultMutableTreeNode("Root") val treeModel = MyTreeModel(root) @@ -357,10 +357,6 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj return userObject } - fun setRunDialog(runDialog: RunDialogBase) { - myRunDialog = runDialog - } - fun updateRightPanel(configurable: Configurable) { rightPanel.removeAll() selectedConfigurable = configurable @@ -449,10 +445,10 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj addIcon.border = JBUI.Borders.empty(0, 3, 0, 3) messagePanel.add(addIcon) - val configurationTypeDescription = if (configurationType != null) - configurationType.configurationTypeDescription - else - ExecutionBundle.message("run.configuration.default.type.description") + val configurationTypeDescription = when { + configurationType != null -> configurationType.configurationTypeDescription + else -> ExecutionBundle.message("run.configuration.default.type.description") + } messagePanel.add(JLabel(ExecutionBundle.message("empty.run.configuration.panel.text.label3", configurationTypeDescription))) rightPanel.removeAll() @@ -555,10 +551,10 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj wholePanel = JPanel(BorderLayout()) DataManager.registerDataProvider(wholePanel!!) { dataId -> - if (RunConfigurationSelector.KEY.name == dataId) - RunConfigurationSelector { configuration -> selectConfiguration(configuration) } - else - null + when (dataId) { + RunConfigurationSelector.KEY.name -> RunConfigurationSelector { configuration -> selectConfiguration(configuration) } + else -> null + } } splitter.firstComponent = createLeftPanel() @@ -645,8 +641,9 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj } fun updateActiveConfigurationFromSelected() { - if (selectedConfigurable != null && selectedConfigurable is SingleConfigurationConfigurable<*>) { - runManager.selectedConfiguration = (selectedConfigurable as SingleConfigurationConfigurable<*>).settings as RunnerAndConfigurationSettings + val selectedConfigurable = selectedConfigurable + if (selectedConfigurable is SingleConfigurationConfigurable<*>) { + runManager.selectedConfiguration = selectedConfigurable.settings } } @@ -832,7 +829,8 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj } private fun updateDialog() { - val executor = (if (myRunDialog != null) myRunDialog!!.executor else null) ?: return + val runDialog = runDialog + val executor = runDialog?.executor ?: return val buffer = StringBuilder() buffer.append(executor.id) val configuration = selectedConfiguration @@ -840,8 +838,8 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj buffer.append(" - ") buffer.append(configuration.nameText) } - myRunDialog!!.setOKActionEnabled(canRunConfiguration(configuration, executor)) - myRunDialog!!.setTitle(buffer.toString()) + runDialog.setOKActionEnabled(canRunConfiguration(configuration, executor)) + runDialog.setTitle(buffer.toString()) } private fun setupDialogBounds() { @@ -871,7 +869,7 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj } private fun clickDefaultButton() { - myRunDialog?.clickDefaultButton() + runDialog?.clickDefaultButton() } private val selectedConfigurationTypeNode: DefaultMutableTreeNode? diff --git a/platform/platform-impl/src/com/intellij/openapi/options/ex/SingleConfigurableEditor.java b/platform/platform-impl/src/com/intellij/openapi/options/ex/SingleConfigurableEditor.java index bc9036104ae0..f78b75d2c3a6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/ex/SingleConfigurableEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/ex/SingleConfigurableEditor.java @@ -1,18 +1,4 @@ -/* - * 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. - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.options.ex; import com.intellij.CommonBundle; @@ -53,7 +39,7 @@ public class SingleConfigurableEditor extends DialogWrapper { private boolean mySaveAllOnClose; public SingleConfigurableEditor(@Nullable Project project, - Configurable configurable, + @NotNull Configurable configurable, @NonNls String dimensionKey, final boolean showApplyButton, @NotNull IdeModalityType ideModalityType) { @@ -75,7 +61,7 @@ public class SingleConfigurableEditor extends DialogWrapper { } public SingleConfigurableEditor(Component parent, - Configurable configurable, + @NotNull Configurable configurable, String dimensionServiceKey, final boolean showApplyButton, final IdeModalityType ideModalityType) { @@ -135,7 +121,7 @@ public class SingleConfigurableEditor extends DialogWrapper { return myProject; } - private static String createTitleString(Configurable configurable) { + private static String createTitleString(@NotNull Configurable configurable) { String displayName = configurable.getDisplayName(); LOG.assertTrue(displayName != null, configurable.getClass().getName()); return displayName.replaceAll("\n", " ");