mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[log] refactor: move getting selected changes from table to table model
This commit is contained in:
@@ -4,20 +4,15 @@ import com.intellij.openapi.actionSystem.CommonShortcuts;
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.actionSystem.DataSink;
|
||||
import com.intellij.openapi.actionSystem.TypeSafeDataProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Splitter;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.committed.CommittedChangesTreeBrowser;
|
||||
import com.intellij.openapi.vcs.changes.ui.ChangesBrowser;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.components.JBLoadingPanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.data.LoadingDetails;
|
||||
import com.intellij.vcs.log.data.VcsLogDataHolder;
|
||||
import com.intellij.vcs.log.graph.elements.Node;
|
||||
import com.intellij.vcs.log.ui.VcsLogUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -26,7 +21,6 @@ import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -37,8 +31,6 @@ import java.util.List;
|
||||
*/
|
||||
public class ActiveSurface extends JPanel implements TypeSafeDataProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("Vcs.Log");
|
||||
|
||||
@NotNull private final VcsLogGraphTable myGraphTable;
|
||||
@NotNull private final BranchesPanel myBranchesPanel;
|
||||
@NotNull private final VcsLogDataHolder myLogDataHolder;
|
||||
@@ -122,15 +114,7 @@ public class ActiveSurface extends JPanel implements TypeSafeDataProvider {
|
||||
|
||||
@Nullable
|
||||
public List<Change> getSelectedChanges() {
|
||||
List<Change> changes = new ArrayList<Change>();
|
||||
for (Node node : myGraphTable.getSelectedNodes()) {
|
||||
VcsFullCommitDetails commitData = myLogDataHolder.getCommitDetailsGetter().getCommitData(node);
|
||||
if (commitData instanceof LoadingDetails) {
|
||||
return null;
|
||||
}
|
||||
changes.addAll(commitData.getChanges());
|
||||
}
|
||||
return CommittedChangesTreeBrowser.zipChanges(changes);
|
||||
return myGraphTable.getSelectedChanges();
|
||||
}
|
||||
|
||||
private class CommitSelectionListener implements ListSelectionListener {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.vcs.log.ui.frame;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
@@ -31,8 +32,6 @@ import javax.swing.table.TableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.vcs.log.graph.render.PrintParameters.HEIGHT_CELL;
|
||||
@@ -42,6 +41,7 @@ import static com.intellij.vcs.log.graph.render.PrintParameters.HEIGHT_CELL;
|
||||
*/
|
||||
public class VcsLogGraphTable extends JBTable {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(VcsLogGraphTable.class);
|
||||
private static final int ROOT_INDICATOR_WIDTH = 5;
|
||||
|
||||
@NotNull private final VcsLogUI myUI;
|
||||
@@ -103,6 +103,16 @@ public class VcsLogGraphTable extends JBTable {
|
||||
return commitCell.getPrintCell();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<Change> getSelectedChanges() {
|
||||
TableModel model = getModel();
|
||||
if (!(model instanceof GraphTableModel)) {
|
||||
LOG.error("Unexpected table model passed to the VcsLogGraphTable: " + model);
|
||||
return null;
|
||||
}
|
||||
return ((GraphTableModel)model).getSelectedChanges(getSelectedRows());
|
||||
}
|
||||
|
||||
private class MyMouseAdapter extends MouseAdapter {
|
||||
private final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
|
||||
private final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR);
|
||||
@@ -178,23 +188,6 @@ public class VcsLogGraphTable extends JBTable {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Node> getSelectedNodes() {
|
||||
int[] selectedRows = getSelectedRows();
|
||||
return nodes(selectedRows);
|
||||
}
|
||||
|
||||
private List<Node> nodes(int[] selectedRows) {
|
||||
List<Node> result = new ArrayList<Node>();
|
||||
Arrays.sort(selectedRows);
|
||||
for (int rowIndex : selectedRows) {
|
||||
Node node = PositionUtil.getNode(getGraphPrintCellForRow(getModel(), rowIndex));
|
||||
if (node != null) {
|
||||
result.add(node);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class RootCellRenderer extends JPanel implements TableCellRenderer {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(RootCellRenderer.class);
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package com.intellij.vcs.log.ui.tables;
|
||||
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.committed.CommittedChangesTreeBrowser;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsRef;
|
||||
import com.intellij.vcs.log.VcsShortCommitDetails;
|
||||
import com.intellij.vcs.log.data.DataPack;
|
||||
import com.intellij.vcs.log.data.LoadingDetails;
|
||||
import com.intellij.vcs.log.data.VcsLogDataHolder;
|
||||
import com.intellij.vcs.log.graph.elements.Node;
|
||||
import com.intellij.vcs.log.graph.render.GraphCommitCell;
|
||||
import com.intellij.vcs.log.graph.render.PositionUtil;
|
||||
import com.intellij.vcs.log.printmodel.GraphPrintCell;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author erokhins
|
||||
@@ -113,4 +118,40 @@ public class GraphTableModel extends AbstractTableModel {
|
||||
return COLUMN_NAMES[column];
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<Change> getSelectedChanges(int[] selectedRows) {
|
||||
List<Change> changes = new ArrayList<Change>();
|
||||
for (Node node : nodes(selectedRows)) {
|
||||
VcsFullCommitDetails commitData = myDataHolder.getCommitDetailsGetter().getCommitData(node);
|
||||
if (commitData instanceof LoadingDetails) {
|
||||
return null;
|
||||
}
|
||||
changes.addAll(commitData.getChanges());
|
||||
}
|
||||
return CommittedChangesTreeBrowser.zipChanges(changes);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Node> nodes(int[] selectedRows) {
|
||||
List<Node> result = new ArrayList<Node>();
|
||||
Arrays.sort(selectedRows);
|
||||
for (int rowIndex : selectedRows) {
|
||||
Node node = PositionUtil.getNode(getGraphPrintCellForRow(rowIndex));
|
||||
if (node != null) {
|
||||
result.add(node);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GraphPrintCell getGraphPrintCellForRow(int row) {
|
||||
Object commitValue = getValueAt(row, AbstractVcsLogTableModel.COMMIT_COLUMN);
|
||||
if (commitValue instanceof GraphCommitCell) {
|
||||
GraphCommitCell commitCell = (GraphCommitCell)commitValue;
|
||||
return commitCell.getPrintCell();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user