diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index e8d578248581..352dbfdaceb2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -369,7 +369,8 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj setComment(initialSelection, comment); } - myCommitOptions = new CommitOptionsPanel(this, myHandlers, getAffectedVcses()); + //noinspection unchecked + myCommitOptions = new CommitOptionsPanel(this, myHandlers, (Set)getAffectedVcses()); restoreState(); myWarningLabel = new JBLabel(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt index a6aef14d5f6d..fd62fae98b58 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt @@ -1,193 +1,145 @@ -/* - * 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. - */ -package com.intellij.openapi.vcs.changes.ui; +// 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.vcs.changes.ui -import com.intellij.openapi.Disposable; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.CheckinProjectPanel; -import com.intellij.openapi.vcs.changes.ChangesUtil; -import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.PseudoMap; -import com.intellij.openapi.vcs.checkin.CheckinChangeListSpecificComponent; -import com.intellij.openapi.vcs.checkin.CheckinEnvironment; -import com.intellij.openapi.vcs.checkin.CheckinHandler; -import com.intellij.openapi.vcs.ui.RefreshableOnComponent; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.IdeBorderFactory; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.components.BorderLayoutPanel; -import org.jetbrains.annotations.NotNull; +import com.intellij.openapi.Disposable +import com.intellij.openapi.vcs.AbstractVcs +import com.intellij.openapi.vcs.CheckinProjectPanel +import com.intellij.openapi.vcs.VcsBundle.message +import com.intellij.openapi.vcs.changes.ChangesUtil.getAffectedVcses +import com.intellij.openapi.vcs.changes.ChangesUtil.getAffectedVcsesForFiles +import com.intellij.openapi.vcs.changes.LocalChangeList +import com.intellij.openapi.vcs.changes.PseudoMap +import com.intellij.openapi.vcs.checkin.CheckinChangeListSpecificComponent +import com.intellij.openapi.vcs.checkin.CheckinHandler +import com.intellij.openapi.vcs.ui.RefreshableOnComponent +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.ui.IdeBorderFactory +import com.intellij.ui.ScrollPaneFactory +import com.intellij.util.ui.JBUI +import com.intellij.util.ui.components.BorderLayoutPanel +import java.awt.BorderLayout +import java.util.Collections.unmodifiableList +import javax.swing.Box +import javax.swing.JPanel +import kotlin.collections.component1 +import kotlin.collections.component2 +import kotlin.collections.set -import javax.swing.*; -import java.awt.*; -import java.util.*; -import java.util.List; +private val VCS_COMPARATOR = compareBy, String>(String.CASE_INSENSITIVE_ORDER) { it.keyInstanceMethod.name } -import static com.intellij.openapi.vcs.VcsBundle.message; -import static com.intellij.util.containers.ContainerUtil.*; -import static java.util.Collections.unmodifiableList; +class CommitOptionsPanel(private val myCommitPanel: CheckinProjectPanel, + private val myHandlers: Collection, + vcses: Collection>) : BorderLayoutPanel(), Disposable { + private val myPerVcsOptionsPanels = mutableMapOf, JPanel>() + private val myAdditionalComponents = mutableListOf() + private val myCheckinChangeListSpecificComponents = mutableSetOf() + val additionalData = PseudoMap() + val isEmpty = init(vcses) -public class CommitOptionsPanel extends BorderLayoutPanel implements Disposable { + val additionalComponents: List get() = unmodifiableList(myAdditionalComponents) - private static final Comparator VCS_COMPARATOR = - Comparator.comparing(it -> it.getKeyInstanceMethod().getName(), String::compareToIgnoreCase); + fun saveState() = myAdditionalComponents.forEach { it.saveState() } - @NotNull private final CheckinProjectPanel myCommitPanel; - @NotNull private final Collection myHandlers; - @NotNull private final Map myPerVcsOptionsPanels = newHashMap(); - @NotNull private final List myAdditionalComponents = newArrayList(); - @NotNull private final Set myCheckinChangeListSpecificComponents = newHashSet(); - @NotNull private final PseudoMap myAdditionalData = new PseudoMap<>(); - private final boolean myEmpty; + fun restoreState() = myAdditionalComponents.forEach { it.restoreState() } - public CommitOptionsPanel(@NotNull CheckinProjectPanel panel, - @NotNull Collection handlers, - @NotNull Collection vcses) { - myCommitPanel = panel; - myHandlers = handlers; - myEmpty = init(vcses); - } + fun refresh() = myAdditionalComponents.forEach { it.refresh() } - public boolean isEmpty() { - return myEmpty; - } - - @NotNull - public List getAdditionalComponents() { - return unmodifiableList(myAdditionalComponents); - } - - @NotNull - public PseudoMap getAdditionalData() { - return myAdditionalData; - } - - public void saveState() { - myAdditionalComponents.forEach(RefreshableOnComponent::saveState); - } - - public void restoreState() { - myAdditionalComponents.forEach(RefreshableOnComponent::restoreState); - } - - public void refresh() { - myAdditionalComponents.forEach(RefreshableOnComponent::refresh); - } - - public void onChangeListSelected(@NotNull LocalChangeList changeList, List unversionedFiles) { - Set affectedVcses = union( - ChangesUtil.getAffectedVcses(changeList.getChanges(), myCommitPanel.getProject()), - ChangesUtil.getAffectedVcsesForFiles(unversionedFiles, myCommitPanel.getProject())); - for (Map.Entry entry : myPerVcsOptionsPanels.entrySet()) { - entry.getValue().setVisible(affectedVcses.contains(entry.getKey())); + fun onChangeListSelected(changeList: LocalChangeList, unversionedFiles: List) { + val affectedVcses = + getAffectedVcses(changeList.changes, myCommitPanel.project) + getAffectedVcsesForFiles(unversionedFiles, myCommitPanel.project) + for ((vcs, panel) in myPerVcsOptionsPanels) { + panel.isVisible = affectedVcses.contains(vcs) } - myCheckinChangeListSpecificComponents.forEach(component -> component.onChangeListSelected(changeList)); + myCheckinChangeListSpecificComponents.forEach { it.onChangeListSelected(changeList) } } - public void saveChangeListComponentsState() { - myCheckinChangeListSpecificComponents.forEach(CheckinChangeListSpecificComponent::saveState); + fun saveChangeListComponentsState() = myCheckinChangeListSpecificComponents.forEach { it.saveState() } + + override fun dispose() { } - @Override - public void dispose() { - } - - private boolean init(@NotNull Collection vcses) { - String borderTitleName = myCommitPanel.getCommitActionName().replace("_", "").replace("&", ""); - boolean hasVcsOptions = false; - Box vcsCommitOptions = Box.createVerticalBox(); - for (AbstractVcs vcs : sorted(vcses, VCS_COMPARATOR)) { - CheckinEnvironment checkinEnvironment = vcs.getCheckinEnvironment(); + private fun init(vcses: Collection>): Boolean { + val borderTitleName = myCommitPanel.commitActionName.replace("_", "").replace("&", "") + var hasVcsOptions = false + val vcsCommitOptions = Box.createVerticalBox() + for (vcs in vcses.sortedWith(VCS_COMPARATOR)) { + val checkinEnvironment = vcs.checkinEnvironment if (checkinEnvironment != null) { - RefreshableOnComponent options = checkinEnvironment.createAdditionalOptionsPanel(myCommitPanel, myAdditionalData); + val options = checkinEnvironment.createAdditionalOptionsPanel(myCommitPanel, additionalData) if (options != null) { - JPanel vcsOptions = new JPanel(new BorderLayout()); - vcsOptions.add(options.getComponent(), BorderLayout.CENTER); - vcsOptions.setBorder(IdeBorderFactory.createTitledBorder(vcs.getDisplayName(), true)); - vcsCommitOptions.add(vcsOptions); - myPerVcsOptionsPanels.put(vcs, vcsOptions); - myAdditionalComponents.add(options); - if (options instanceof CheckinChangeListSpecificComponent) { - myCheckinChangeListSpecificComponents.add((CheckinChangeListSpecificComponent)options); + val vcsOptions = JPanel(BorderLayout()) + vcsOptions.add(options.component, BorderLayout.CENTER) + vcsOptions.border = IdeBorderFactory.createTitledBorder(vcs.displayName, true) + vcsCommitOptions.add(vcsOptions) + myPerVcsOptionsPanels[vcs] = vcsOptions + myAdditionalComponents.add(options) + if (options is CheckinChangeListSpecificComponent) { + myCheckinChangeListSpecificComponents.add(options) } - hasVcsOptions = true; + hasVcsOptions = true } } } - boolean beforeVisible = false; - boolean afterVisible = false; - Box beforeBox = Box.createVerticalBox(); - Box afterBox = Box.createVerticalBox(); - for (CheckinHandler handler : myHandlers) { - RefreshableOnComponent beforePanel = handler.getBeforeCheckinConfigurationPanel(); + var beforeVisible = false + var afterVisible = false + val beforeBox = Box.createVerticalBox() + val afterBox = Box.createVerticalBox() + for (handler in myHandlers) { + val beforePanel = handler.beforeCheckinConfigurationPanel if (beforePanel != null) { - beforeVisible = true; - addCheckinHandlerComponent(beforePanel, beforeBox); + beforeVisible = true + addCheckinHandlerComponent(beforePanel, beforeBox) } - RefreshableOnComponent afterPanel = handler.getAfterCheckinConfigurationPanel(this); + val afterPanel = handler.getAfterCheckinConfigurationPanel(this) if (afterPanel != null) { - afterVisible = true; - addCheckinHandlerComponent(afterPanel, afterBox); + afterVisible = true + addCheckinHandlerComponent(afterPanel, afterBox) } } - if (!hasVcsOptions && !beforeVisible && !afterVisible) return true; + if (!hasVcsOptions && !beforeVisible && !afterVisible) return true - Box optionsBox = Box.createVerticalBox(); + val optionsBox = Box.createVerticalBox() if (hasVcsOptions) { - vcsCommitOptions.add(Box.createVerticalGlue()); - optionsBox.add(vcsCommitOptions); + vcsCommitOptions.add(Box.createVerticalGlue()) + optionsBox.add(vcsCommitOptions) } if (beforeVisible) { - beforeBox.add(Box.createVerticalGlue()); - JPanel beforePanel = new JPanel(new BorderLayout()); - beforePanel.add(beforeBox); - beforePanel.setBorder(IdeBorderFactory.createTitledBorder( - message("border.standard.checkin.options.group", borderTitleName), true)); - optionsBox.add(beforePanel); + beforeBox.add(Box.createVerticalGlue()) + val beforePanel = JPanel(BorderLayout()) + beforePanel.add(beforeBox) + beforePanel.border = IdeBorderFactory.createTitledBorder( + message("border.standard.checkin.options.group", borderTitleName), true) + optionsBox.add(beforePanel) } if (afterVisible) { - afterBox.add(Box.createVerticalGlue()); - JPanel afterPanel = new JPanel(new BorderLayout()); - afterPanel.add(afterBox); - afterPanel.setBorder(IdeBorderFactory.createTitledBorder( - message("border.standard.after.checkin.options.group", borderTitleName), true)); - optionsBox.add(afterPanel); + afterBox.add(Box.createVerticalGlue()) + val afterPanel = JPanel(BorderLayout()) + afterPanel.add(afterBox) + afterPanel.border = IdeBorderFactory.createTitledBorder( + message("border.standard.after.checkin.options.group", borderTitleName), true) + optionsBox.add(afterPanel) } - optionsBox.add(Box.createVerticalGlue()); - JPanel additionalOptionsPanel = new JPanel(new BorderLayout()); - additionalOptionsPanel.add(optionsBox, BorderLayout.NORTH); + optionsBox.add(Box.createVerticalGlue()) + val additionalOptionsPanel = JPanel(BorderLayout()) + additionalOptionsPanel.add(optionsBox, BorderLayout.NORTH) - JScrollPane optionsPane = ScrollPaneFactory.createScrollPane(additionalOptionsPanel, true); - addToCenter(optionsPane).withBorder(JBUI.Borders.emptyLeft(10)); - return false; + val optionsPane = ScrollPaneFactory.createScrollPane(additionalOptionsPanel, true) + addToCenter(optionsPane).withBorder(JBUI.Borders.emptyLeft(10)) + return false } - private void addCheckinHandlerComponent(@NotNull RefreshableOnComponent component, @NotNull Box container) { - container.add(component.getComponent()); - myAdditionalComponents.add(component); - if (component instanceof CheckinChangeListSpecificComponent) { - myCheckinChangeListSpecificComponents.add((CheckinChangeListSpecificComponent)component); + private fun addCheckinHandlerComponent(component: RefreshableOnComponent, container: Box) { + container.add(component.component) + myAdditionalComponents.add(component) + if (component is CheckinChangeListSpecificComponent) { + myCheckinChangeListSpecificComponents.add(component) } } }