From 490a230235963dcf57e8bbcbc48d52244b1dde62 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Wed, 19 Oct 2016 14:12:14 +0300 Subject: [PATCH] svn: Removed unnecessary paging logic from "ToBeMergedDialog" * This logic hasn't been actually used for 6 years (disabled in 3ecc391 "SVN: one-click merge: remove pages concept" on 7/14/2010). And is not actually necessary - adding new rows to the table + scrolling is sufficient here. * Also removed unused related "PageEngine", "BasePageEngine", "PagedListWithActions" --- .../idea/svn/dialogs/BasePageEngine.java | 55 --------- .../idea/svn/dialogs/PageEngine.java | 24 ---- .../svn/dialogs/PagedListWithActions.java | 109 ------------------ .../idea/svn/integrate/ToBeMergedDialog.java | 93 +++++---------- 4 files changed, 31 insertions(+), 250 deletions(-) delete mode 100644 plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/BasePageEngine.java delete mode 100644 plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PageEngine.java delete mode 100644 plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PagedListWithActions.java diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/BasePageEngine.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/BasePageEngine.java deleted file mode 100644 index 626435ba5d68..000000000000 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/BasePageEngine.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2000-2010 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 org.jetbrains.idea.svn.dialogs; - -import com.intellij.util.containers.JBIterable; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class BasePageEngine implements PageEngine> { - @NotNull private final List> mySplitData; - private int myIdx; - - public BasePageEngine(@NotNull List data, int pageSize) { - mySplitData = JBIterable.from(data).split(pageSize, false).toList(); - myIdx = 0; - } - - public List getCurrent() { - return mySplitData.get(myIdx); - } - - public boolean hasNext() { - return myIdx < (mySplitData.size() - 1); - } - - public boolean hasPrevious() { - return myIdx > 0; - } - - public List next() { - if (! hasNext()) return null; - ++ myIdx; - return mySplitData.get(myIdx); - } - - public List previous() { - if (! hasPrevious()) return null; - -- myIdx; - return mySplitData.get(myIdx); - } -} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PageEngine.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PageEngine.java deleted file mode 100644 index 3a5db751bd54..000000000000 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PageEngine.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2000-2010 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 org.jetbrains.idea.svn.dialogs; - -public interface PageEngine { - boolean hasNext(); - boolean hasPrevious(); - T getCurrent(); - T next(); - T previous(); -} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PagedListWithActions.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PagedListWithActions.java deleted file mode 100644 index 4efaf23b77a7..000000000000 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PagedListWithActions.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2000-2010 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 org.jetbrains.idea.svn.dialogs; - -import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.*; -import com.intellij.ui.ScrollPaneFactory; - -import javax.swing.*; -import java.awt.*; -import java.util.List; - -public class PagedListWithActions { - private final JPanel myPanel; - private final PageEngine> myEngine; - private final InnerComponentManager myComponentManager; - private final AnAction[] myOtherActions; - - public PagedListWithActions(PageEngine> engine, - final InnerComponentManager componentManager, - final AnAction... otherActions) { - myEngine = engine; - myComponentManager = componentManager; - myOtherActions = otherActions; - myPanel = new JPanel(new BorderLayout()); - createView(); - } - - private void createView() { - myComponentManager.setData(myEngine.getCurrent()); - //myList.setListData(ArrayUtil.toObjectArray(myEngine.getCurrent())); - myPanel.add(ActionManager.getInstance().createActionToolbar("merge all", createListActions(), true).getComponent(), BorderLayout.NORTH); - final JScrollPane scroll = ScrollPaneFactory - .createScrollPane(myComponentManager.getComponent(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - myPanel.add(scroll, BorderLayout.CENTER); - } - - public JComponent getComponent() { - return myPanel; - } - - private ActionGroup createListActions() { - final DefaultActionGroup group = new DefaultActionGroup(); - group.add(new MyPrevious()); - group.add(new MyNext()); - group.addAll(myOtherActions); - return group; - } - - private class MyNext extends AnAction { - private MyNext() { - super("Next Page", "Next Page", AllIcons.Actions.Nextfile); - } - - @Override - public void actionPerformed(AnActionEvent e) { - final List data = myEngine.next(); - myComponentManager.setData(data); - myComponentManager.refresh(); - } - - @Override - public void update(AnActionEvent e) { - super.update(e); - e.getPresentation().setEnabled(myEngine.hasNext()); - e.getPresentation().setVisible(myEngine.hasNext()); - } - } - - private class MyPrevious extends AnAction { - private MyPrevious() { - super("Previous Page", "Previous Page", AllIcons.Actions.Prevfile); - } - - @Override - public void actionPerformed(AnActionEvent e) { - final List data = myEngine.previous(); - myComponentManager.setData(data); - myComponentManager.refresh(); - } - - @Override - public void update(AnActionEvent e) { - super.update(e); - e.getPresentation().setEnabled(myEngine.hasPrevious()); - e.getPresentation().setVisible(myEngine.hasPrevious()); - } - } - - public interface InnerComponentManager { - Component getComponent(); - void setData(List list); - void refresh(); - } -} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java index 70f9ae5e5c80..53c0768a90a9 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java @@ -16,7 +16,7 @@ package org.jetbrains.idea.svn.integrate; import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; @@ -25,6 +25,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.ui.popup.util.PopupUtil; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vcs.QuantitySelection; import com.intellij.openapi.vcs.VcsException; @@ -36,20 +37,16 @@ import com.intellij.openapi.vcs.changes.issueLinks.AbstractBaseTagMouseListener; import com.intellij.openapi.vcs.changes.ui.ChangeNodeDecorator; import com.intellij.openapi.vcs.changes.ui.ChangesBrowserNodeRenderer; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; -import com.intellij.ui.ClickListener; -import com.intellij.ui.SimpleColoredComponent; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.ui.TableViewSpeedSearch; +import com.intellij.ui.*; import com.intellij.ui.table.TableView; import com.intellij.util.ObjectUtils; import com.intellij.util.ui.ColumnInfo; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.ListTableModel; import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.components.BorderLayoutPanel; import com.intellij.vcsUtil.MoreAction; import org.jetbrains.annotations.NotNull; -import org.jetbrains.idea.svn.dialogs.BasePageEngine; -import org.jetbrains.idea.svn.dialogs.PageEngine; -import org.jetbrains.idea.svn.dialogs.PagedListWithActions; import org.jetbrains.idea.svn.history.SvnChangeList; import org.jetbrains.idea.svn.mergeinfo.ListMergeStatus; import org.jetbrains.idea.svn.mergeinfo.MergeChecker; @@ -66,13 +63,10 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.*; import java.util.List; -import java.util.function.Predicate; import java.util.stream.Collectors; import static com.intellij.util.containers.ContainerUtil.*; -import static com.intellij.util.containers.ContainerUtil.newHashMap; import static com.intellij.util.containers.ContainerUtilRt.emptyList; -import static com.intellij.util.containers.ContainerUtilRt.newArrayList; import static com.intellij.util.containers.ContainerUtilRt.newHashSet; import static java.util.Collections.singletonList; import static java.util.Collections.synchronizedMap; @@ -83,7 +77,7 @@ public class ToBeMergedDialog extends DialogWrapper { public static final int MERGE_ALL_CODE = 222; private final JPanel myPanel; @NotNull private final MergeContext myMergeContext; - private final PageEngine> myListsEngine; + @NotNull private final ListTableModel myRevisionsModel; private TableView myRevisionsList; private RepositoryChangesBrowser myRepositoryChangesBrowser; private Splitter mySplitter; @@ -100,7 +94,7 @@ public class ToBeMergedDialog extends DialogWrapper { private ToBeMergedDialog.MoreXAction myMore500Action; public ToBeMergedDialog(@NotNull MergeContext mergeContext, - @NotNull List lists, + @NotNull List changeLists, final String title, @NotNull MergeChecker mergeChecker, boolean allStatusesCalculated, @@ -113,10 +107,7 @@ public class ToBeMergedDialog extends DialogWrapper { myAllStatusesCalculated = allStatusesCalculated; setTitle(title); - // Paging is not used - "Load Xxx" buttons load corresponding new elements and add them to the end of the table. Single (first) page is - // always used. - myListsEngine = new BasePageEngine<>(lists, lists.size()); - + myRevisionsModel = new ListTableModel<>(new ColumnInfo[]{FAKE_COLUMN}, changeLists); myPanel = new JPanel(new BorderLayout()); myWiseSelection = new QuantitySelection<>(allStatusesCalculated); myAlreadyMerged = newHashSet(); @@ -126,7 +117,7 @@ public class ToBeMergedDialog extends DialogWrapper { enableLoadButtons(); if (!myAllStatusesCalculated) { - refreshListStatus(lists); + refreshListStatus(changeLists); } } @@ -143,21 +134,20 @@ public class ToBeMergedDialog extends DialogWrapper { } public long getLastNumber() { - // in current implementation we just have one page with all loaded change lists - myListsEngine.getCurrent() - CommittedChangeList lastLoadedList = getLastItem(myListsEngine.getCurrent()); + int totalRows = myRevisionsModel.getRowCount(); - return lastLoadedList != null ? lastLoadedList.getNumber() : 0; + return totalRows > 0 ? myRevisionsModel.getItem(totalRows - 1).getNumber() : 0; } - public void addMoreLists(final List list) { - myListsEngine.getCurrent().addAll(list); + public void addMoreLists(@NotNull List changeLists) { + myRevisionsModel.addRows(changeLists); myRevisionsList.revalidate(); myRevisionsList.repaint(); myMore100Action.setEnabled(true); myMore500Action.setEnabled(true); // TODO: This is necessary because myMore500Action was hidden in MoreXAction.actionPerformed() myMore500Action.setVisible(true); - refreshListStatus(list); + refreshListStatus(changeLists); } private boolean myDisposed; @@ -227,19 +217,13 @@ public class ToBeMergedDialog extends DialogWrapper { @NotNull public List getSelected() { - List result = newArrayList(); - result.addAll(myListsEngine.getCurrent()); - while (myListsEngine.hasNext()) { - result.addAll(myListsEngine.next()); - } - Set selected = myWiseSelection.getSelected(); Set unselected = myWiseSelection.getUnselected(); // todo: can be made faster - Predicate removeCondition = - myWiseSelection.areAllSelected() ? list -> unselected.contains(list.getNumber()) : list -> !selected.contains(list.getNumber()); - result.removeIf(removeCondition); - return result; + Condition filter = + myWiseSelection.areAllSelected() ? list -> !unselected.contains(list.getNumber()) : list -> selected.contains(list.getNumber()); + + return filter(myRevisionsModel.getItems(), filter); } @Override @@ -290,8 +274,7 @@ public class ToBeMergedDialog extends DialogWrapper { return element.getComment(); } }; - final ListTableModel flatModel = new ListTableModel<>(FAKE_COLUMN); - myRevisionsList.setModelAndUpdateColumns(flatModel); + myRevisionsList.setModelAndUpdateColumns(myRevisionsModel); myRevisionsList.setTableHeader(null); myRevisionsList.setShowGrid(false); final AbstractBaseTagMouseListener mouseListener = new AbstractBaseTagMouseListener() { @@ -307,36 +290,15 @@ public class ToBeMergedDialog extends DialogWrapper { }; mouseListener.installOn(myRevisionsList); - final PagedListWithActions.InnerComponentManager listsManager = - new PagedListWithActions.InnerComponentManager() { - @Override - public Component getComponent() { - return myRevisionsList; - } - - @Override - public void setData(List committedChangeLists) { - flatModel.setItems(committedChangeLists); - flatModel.fireTableDataChanged(); - } - - @Override - public void refresh() { - myRevisionsList.revalidate(); - myRevisionsList.repaint(); - } - }; myMore100Action = new MoreXAction(100); myMore500Action = new MoreXAction(500); - final PagedListWithActions byRevisions = - new PagedListWithActions<>(myListsEngine, listsManager, new MySelectAll(), new MyUnselectAll(), - myMore100Action, myMore500Action); + + BorderLayoutPanel panel = JBUI.Panels.simplePanel() + .addToCenter(ScrollPaneFactory.createScrollPane(myRevisionsList)) + .addToTop(createToolbar().getComponent()); mySplitter = new Splitter(false, 0.7f); - mySplitter.setFirstComponent(byRevisions.getComponent()); - - flatModel.setItems(myListsEngine.getCurrent()); - flatModel.fireTableDataChanged(); + mySplitter.setFirstComponent(panel); myRepositoryChangesBrowser = new RepositoryChangesBrowser(myMergeContext.getProject(), Collections.emptyList(), emptyList(), null); @@ -351,6 +313,13 @@ public class ToBeMergedDialog extends DialogWrapper { myPanel.add(mySplitter, BorderLayout.CENTER); } + @NotNull + private ActionToolbar createToolbar() { + DefaultActionGroup actions = new DefaultActionGroup(new MySelectAll(), new MyUnselectAll(), myMore100Action, myMore500Action); + + return ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actions, true); + } + @NotNull private List getAlreadyMergedPaths(@NotNull SvnChangeList svnChangeList) { Collection notMerged = myMergeChecker.getNotMergedPaths(svnChangeList);