mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
sortablecolumnmodel -> jtable row sorter
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<grid id="57687" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="25" y="74" width="265" height="175"/>
|
||||
<xy x="25" y="74" width="329" height="175"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
|
||||
@@ -238,6 +238,10 @@ public abstract class AbstractFileTreeTable<T> extends TreeTable {
|
||||
return new HashMap<VirtualFile, T>(myCurrentMapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTree(JTree tree) {
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -399,19 +399,12 @@ public class DualView extends JPanel {
|
||||
}
|
||||
|
||||
public void setRoot(final TreeNode node, final List<Object> selection) {
|
||||
ListTableModel model = myFlatView.getListTableModel();
|
||||
final int column = model.getSortedColumnIndex();
|
||||
final int sortingType = model.getSortingType();
|
||||
|
||||
final List<Object> currentlySelected = myFlatView.getSelectedObjects();
|
||||
final List<Object> targetSelection = (currentlySelected != null && (! currentlySelected.isEmpty())) ? currentlySelected : selection;
|
||||
//final Object obj = myFlatView.getSelectedObject() != null ? myFlatView.getSelectedObject() : selection;
|
||||
|
||||
myTreeView.getTreeViewModel().setRoot(node);
|
||||
|
||||
if (column != -1) {
|
||||
model.sortByColumn(column, sortingType);
|
||||
}
|
||||
if ((targetSelection != null) && (! targetSelection.isEmpty())) {
|
||||
final List items = myFlatView.getItems();
|
||||
for (Object selElement : targetSelection) {
|
||||
@@ -447,19 +440,21 @@ public class DualView extends JPanel {
|
||||
int column) {
|
||||
Component result = myRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
Object treeNode = null;
|
||||
|
||||
final int modelRow = table.convertRowIndexToModel(row);
|
||||
|
||||
if (myCurrentView == myTreeView) {
|
||||
TreePath path = myTreeView.getTree().getPathForRow(row);
|
||||
TreePath path = myTreeView.getTree().getPathForRow(modelRow);
|
||||
if (path != null) {
|
||||
treeNode = path.getLastPathComponent();
|
||||
}
|
||||
}
|
||||
else if (myCurrentView == myFlatView) {
|
||||
treeNode = myFlatView.getItems().get(row);
|
||||
treeNode = myFlatView.getItems().get(modelRow);
|
||||
}
|
||||
|
||||
myCellWrapper.wrap(result, table, value, isSelected, hasFocus, row, column, treeNode);
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,14 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.ui.HighlightableCellRenderer;
|
||||
import com.intellij.ui.table.ItemsProvider;
|
||||
import com.intellij.ui.table.SelectionProvider;
|
||||
import com.intellij.ui.table.TableHeaderRenderer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns;
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTable;
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTableCellRenderer;
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTableModel;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
@@ -48,8 +47,6 @@ public class TreeTableView extends TreeTable implements ItemsProvider, Selection
|
||||
super(treeTableModel);
|
||||
setRootVisible(false);
|
||||
|
||||
getTableHeader().setDefaultRenderer(new TableHeaderRenderer(treeTableModel));
|
||||
|
||||
setTreeCellRenderer(new TreeCellRenderer() {
|
||||
private final TreeCellRenderer myBaseRenderer = new HighlightableCellRenderer();
|
||||
public Component getTreeCellRendererComponent(JTree tree1,
|
||||
@@ -71,7 +68,6 @@ public class TreeTableView extends TreeTable implements ItemsProvider, Selection
|
||||
public void setTableModel(TreeTableModel treeTableModel) {
|
||||
super.setTableModel(treeTableModel);
|
||||
LOG.assertTrue(treeTableModel instanceof SortableColumnModel);
|
||||
getTableHeader().setDefaultRenderer(new TableHeaderRenderer((SortableColumnModel)treeTableModel));
|
||||
}
|
||||
|
||||
private void setSizes() {
|
||||
|
||||
@@ -18,9 +18,10 @@ package com.intellij.ui.table;
|
||||
import com.intellij.Patches;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.ComponentWithEmptyText;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.util.ui.StatusText;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -36,6 +37,7 @@ import java.awt.event.MouseEvent;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.EventObject;
|
||||
|
||||
public class JBTable extends JTable implements ComponentWithEmptyText, ComponentWithExpandableItems<TableCell> {
|
||||
@@ -82,7 +84,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
public void columnRemoved(TableColumnModelEvent e) {
|
||||
}
|
||||
});
|
||||
getTableHeader().setDefaultRenderer(new MyTableHeaderRenderer());
|
||||
|
||||
//noinspection UnusedDeclaration
|
||||
boolean marker = Patches.SUN_BUG_ID_4503845; // Don't remove. It's a marker for find usages
|
||||
}
|
||||
@@ -91,6 +93,30 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
return getRowCount() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(final TableModel model) {
|
||||
super.setModel(model);
|
||||
|
||||
if (model instanceof SortableColumnModel) {
|
||||
final SortableColumnModel sortableModel = (SortableColumnModel)model;
|
||||
if (sortableModel.isSortable()) {
|
||||
final TableRowSorter<TableModel> rowSorter = createRowSorter(model);
|
||||
setRowSorter(rowSorter);
|
||||
final RowSorter.SortKey sortKey = sortableModel.getDefaultSortKey();
|
||||
if (sortKey != null && sortKey.getColumn() >= 0 && sortKey.getColumn() < model.getColumnCount()) {
|
||||
if (sortableModel.getColumnInfos()[sortKey.getColumn()].isSortable()) {
|
||||
rowSorter.setSortKeys(Arrays.asList(sortKey));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final RowSorter<? extends TableModel> rowSorter = getRowSorter();
|
||||
if (rowSorter instanceof DefaultColumnInfoBasedRowSorter) {
|
||||
setRowSorter(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
if (myEnableAntialiasing) {
|
||||
@@ -171,27 +197,6 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
return myExpandableItemsHandler;
|
||||
}
|
||||
|
||||
private static class MyTableHeaderRenderer extends DefaultTableCellRenderer {
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
if (table != null) {
|
||||
JTableHeader header = table.getTableHeader();
|
||||
if (header != null) {
|
||||
setForeground(header.getForeground());
|
||||
setBackground(header.getBackground());
|
||||
setFont(header.getFont());
|
||||
}
|
||||
if (!table.isEnabled()) {
|
||||
setForeground(UIUtil.getTextInactiveTextColor());
|
||||
}
|
||||
}
|
||||
setText(value == null ? "" : value.toString());
|
||||
setBorder(UIUtil.getTableHeaderCellBorder());
|
||||
setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNotify() {
|
||||
final KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||
//noinspection HardCodedStringLiteral
|
||||
@@ -275,13 +280,6 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
}
|
||||
}
|
||||
|
||||
public void fixColumnWidthToHeader(final int columnIdx) {
|
||||
final TableColumn column = getColumnModel().getColumn(columnIdx);
|
||||
final int width = getTableHeader().getFontMetrics(getTableHeader().getFont()).stringWidth(getColumnName(columnIdx)) + 2;
|
||||
column.setMinWidth(width);
|
||||
column.setMaxWidth(width);
|
||||
}
|
||||
|
||||
private final class MyMouseListener extends MouseAdapter {
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
if (SwingUtilities.isRightMouseButton(e)) {
|
||||
@@ -295,4 +293,106 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MethodMayBeStatic", "unchecked"})
|
||||
protected TableRowSorter<TableModel> createRowSorter(final TableModel model) {
|
||||
return new DefaultColumnInfoBasedRowSorter(model);
|
||||
}
|
||||
|
||||
protected static class DefaultColumnInfoBasedRowSorter extends TableRowSorter<TableModel> {
|
||||
public DefaultColumnInfoBasedRowSorter(final TableModel model) {
|
||||
super(model);
|
||||
setModelWrapper(new TableRowSorterModelWrapper(model));
|
||||
setMaxSortKeys(1);
|
||||
setSortsOnUpdates(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<?> getComparator(final int column) {
|
||||
final TableModel model = getModel();
|
||||
if (model instanceof SortableColumnModel) {
|
||||
final ColumnInfo[] columnInfos = ((SortableColumnModel)model).getColumnInfos();
|
||||
if (column >= 0 && column < columnInfos.length) {
|
||||
final Comparator comparator = columnInfos[column].getComparator();
|
||||
if (comparator != null) return comparator;
|
||||
}
|
||||
}
|
||||
|
||||
return super.getComparator(column);
|
||||
}
|
||||
|
||||
protected boolean useToString(int column) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSortable(final int column) {
|
||||
final TableModel model = getModel();
|
||||
if (model instanceof SortableColumnModel) {
|
||||
final ColumnInfo[] columnInfos = ((SortableColumnModel)model).getColumnInfos();
|
||||
if (column >= 0 && column < columnInfos.length) {
|
||||
return columnInfos[column].isSortable() && columnInfos[column].getComparator() != null;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private class TableRowSorterModelWrapper extends ModelWrapper<TableModel, Integer> {
|
||||
private TableModel myModel;
|
||||
|
||||
private TableRowSorterModelWrapper(@NotNull final TableModel model) {
|
||||
myModel = model;
|
||||
}
|
||||
|
||||
public TableModel getModel() {
|
||||
return myModel;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return (myModel == null) ? 0 : myModel.getColumnCount();
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return (myModel == null) ? 0 : myModel.getRowCount();
|
||||
}
|
||||
|
||||
public Object getValueAt(int row, int column) {
|
||||
if (myModel instanceof SortableColumnModel) {
|
||||
return ((SortableColumnModel)myModel).getRowValue(row);
|
||||
}
|
||||
|
||||
return myModel.getValueAt(row, column);
|
||||
}
|
||||
|
||||
public String getStringValueAt(int row, int column) {
|
||||
TableStringConverter converter = getStringConverter();
|
||||
if (converter != null) {
|
||||
// Use the converter
|
||||
String value = converter.toString(
|
||||
myModel, row, column);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// No converter, use getValueAt followed by toString
|
||||
Object o = getValueAt(row, column);
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
String string = o.toString();
|
||||
if (string == null) {
|
||||
return "";
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public Integer getIdentifier(int index) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,14 +15,12 @@
|
||||
*/
|
||||
package com.intellij.ui.table;
|
||||
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
@@ -30,6 +28,7 @@ import java.awt.*;
|
||||
/**
|
||||
* author: lesya
|
||||
*/
|
||||
@Deprecated
|
||||
public class TableHeaderRenderer extends JPanel implements TableCellRenderer{
|
||||
private final SortableColumnModel myModel;
|
||||
protected final JLabel myLabel = new JLabel("", JLabel.CENTER);
|
||||
@@ -72,16 +71,16 @@ public class TableHeaderRenderer extends JPanel implements TableCellRenderer{
|
||||
}
|
||||
final ColumnInfo columnInfo = myModel.getColumnInfos()[logicalIndex];
|
||||
String labelString = columnInfo.getName();
|
||||
if (myModel.isSortable() && columnInfo.isSortable() && myModel.getSortedColumnIndex() == logicalIndex) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
labelString = "<html><b>" + labelString + "</b></html>";
|
||||
if (myModel.getSortingType() == SortableColumnModel.SORT_ASCENDING) {
|
||||
icon = IconLoader.getIcon("/actions/sortAsc.png");
|
||||
}
|
||||
if (myModel.getSortingType() == SortableColumnModel.SORT_DESCENDING) {
|
||||
icon = IconLoader.getIcon("/actions/sortDesc.png");
|
||||
}
|
||||
}
|
||||
//if (myModel.isSortable() && columnInfo.isSortable() && myModel.getSortedColumnIndex() == logicalIndex) {
|
||||
// //noinspection HardCodedStringLiteral
|
||||
// labelString = "<html><b>" + labelString + "</b></html>";
|
||||
// if (myModel.getSortingType() == SortableColumnModel.SORT_ASCENDING) {
|
||||
// icon = IconLoader.getIcon("/actions/sortAsc.png");
|
||||
// }
|
||||
// if (myModel.getSortingType() == SortableColumnModel.SORT_DESCENDING) {
|
||||
// icon = IconLoader.getIcon("/actions/sortDesc.png");
|
||||
// }
|
||||
//}
|
||||
final Icon columnIcon = columnInfo.getIcon();
|
||||
myLabel.setIcon(columnIcon);
|
||||
myLabel.setIconTextGap(10);
|
||||
|
||||
@@ -27,8 +27,6 @@ import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -41,29 +39,6 @@ public class TableView<Item> extends BaseTableView implements ItemsProvider, Sel
|
||||
|
||||
public TableView(final ListTableModel<Item> model) {
|
||||
super(model);
|
||||
final JTableHeader tableHeader = getTableHeader();
|
||||
if (tableHeader != null) {
|
||||
tableHeader.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
private void processEvent(MouseEvent e) {
|
||||
final int column = convertColumnIndexToModel(tableHeader.columnAtPoint(e.getPoint()));
|
||||
if (column > -1) {
|
||||
onHeaderClicked(column, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
setModel(model);
|
||||
}
|
||||
|
||||
@@ -82,10 +57,6 @@ public class TableView<Item> extends BaseTableView implements ItemsProvider, Sel
|
||||
|
||||
public void setModel(final ListTableModel<Item> model) {
|
||||
super.setModel(model);
|
||||
final JTableHeader header = getTableHeader();
|
||||
if (header != null) {
|
||||
header.setDefaultRenderer(new TableHeaderRenderer(model));
|
||||
}
|
||||
updateColumnSizes();
|
||||
}
|
||||
|
||||
@@ -201,25 +172,6 @@ public class TableView<Item> extends BaseTableView implements ItemsProvider, Sel
|
||||
return getListTableModel().getItems();
|
||||
}
|
||||
|
||||
public void resortKeepSelection() {
|
||||
final int column = getSelectedColumn();
|
||||
if (column != -1) {
|
||||
SortableColumnModel model = getListTableModel();
|
||||
Collection<Item> selection = getSelection();
|
||||
model.sortByColumn(column);
|
||||
setSelection(selection);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onHeaderClicked(int column, MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 1) {
|
||||
SortableColumnModel model = getListTableModel();
|
||||
Collection<Item> selection = getSelection();
|
||||
model.sortByColumn(column);
|
||||
setSelection(selection);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMinRowHeight(int i) {
|
||||
setRowHeight(Math.max(i, getRowHeight()));
|
||||
}
|
||||
|
||||
+4
@@ -17,6 +17,7 @@ package com.intellij.ui.treeStructure.treetable;
|
||||
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
@@ -64,4 +65,7 @@ public class ListTreeTableModel extends DefaultTreeModel implements TreeTableMod
|
||||
myColumns[column].setValue(node, aValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTree(JTree tree) {
|
||||
}
|
||||
}
|
||||
|
||||
+23
-14
@@ -18,20 +18,28 @@ package com.intellij.ui.treeStructure.treetable;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.util.*;
|
||||
|
||||
public class ListTreeTableModelOnColumns extends DefaultTreeModel
|
||||
implements TreeTableModel, SortableColumnModel{
|
||||
|
||||
private ColumnInfo[] myColumns;
|
||||
private JTree myTree;
|
||||
|
||||
public ListTreeTableModelOnColumns(TreeNode root, ColumnInfo[] columns) {
|
||||
super(root);
|
||||
myColumns = columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTree(JTree tree) {
|
||||
myTree = tree;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return myColumns.length;
|
||||
}
|
||||
@@ -48,6 +56,21 @@ public class ListTreeTableModelOnColumns extends DefaultTreeModel
|
||||
return ((TreeNode) parent).getChildAt(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRowValue(final int row) {
|
||||
final TreePath path = myTree.getPathForRow(row);
|
||||
if (path != null) {
|
||||
return path.getLastPathComponent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSorter.SortKey getDefaultSortKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getChildCount(Object parent) {
|
||||
return ((TreeNode) parent).getChildCount();
|
||||
}
|
||||
@@ -103,20 +126,6 @@ public class ListTreeTableModelOnColumns extends DefaultTreeModel
|
||||
}
|
||||
}
|
||||
|
||||
public void sortByColumn(int columnIndex) {
|
||||
}
|
||||
|
||||
public void sortByColumn(int columnIndex, int sortingType) {
|
||||
}
|
||||
|
||||
public int getSortedColumnIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getSortingType() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setSortable(boolean aBoolean) {
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -41,6 +41,8 @@ public class TreeTableCellRenderer implements TableCellRenderer, ClientPropertyH
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
int modelRow = table.convertRowIndexToModel(row);
|
||||
|
||||
if (myTreeCellRenderer != null)
|
||||
myTree.setCellRenderer(myTreeCellRenderer);
|
||||
if (isSelected){
|
||||
@@ -51,14 +53,15 @@ public class TreeTableCellRenderer implements TableCellRenderer, ClientPropertyH
|
||||
myTree.setBackground(table.getBackground());
|
||||
myTree.setForeground(table.getForeground());
|
||||
}
|
||||
|
||||
TableModel model = myTreeTable.getModel();
|
||||
myTree.setTreeTableTreeBorder(hasFocus && model.getColumnClass(column).equals(TreeTableModel.class) ? myDefaultBorder : null);
|
||||
myTree.setVisibleRow(row);
|
||||
myTree.setVisibleRow(modelRow);
|
||||
|
||||
final Object treeObject = myTree.getPathForRow(row).getLastPathComponent();
|
||||
final Object treeObject = myTree.getPathForRow(modelRow).getLastPathComponent();
|
||||
boolean leaf = myTree.getModel().isLeaf(treeObject);
|
||||
final boolean expanded = myTree.isExpanded(row);
|
||||
Component component = myTree.getCellRenderer().getTreeCellRendererComponent(myTree, treeObject, isSelected, expanded, leaf, row, hasFocus);
|
||||
final boolean expanded = myTree.isExpanded(modelRow);
|
||||
Component component = myTree.getCellRenderer().getTreeCellRendererComponent(myTree, treeObject, isSelected, expanded, leaf, modelRow, hasFocus);
|
||||
if (component instanceof JComponent) {
|
||||
table.setToolTipText(((JComponent)component).getToolTipText());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.ui.treeStructure.treetable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.TreeModel;
|
||||
|
||||
/**
|
||||
@@ -61,4 +62,6 @@ public interface TreeTableModel extends TreeModel {
|
||||
* at column number <code>column</code>.
|
||||
*/
|
||||
void setValueAt(Object aValue, Object node, int column);
|
||||
|
||||
void setTree(JTree tree);
|
||||
}
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ public class TreeTableModelAdapter extends AbstractTableModel {
|
||||
this.tree = tree;
|
||||
this.treeTableModel = treeTableModel;
|
||||
this.table = table;
|
||||
this.treeTableModel.setTree(tree);
|
||||
|
||||
tree.addTreeExpansionListener(new TreeExpansionListener() {
|
||||
// Don't use fireTableRowsInserted() here; the selection model
|
||||
|
||||
+10
-9
@@ -41,20 +41,19 @@ import java.util.Map;
|
||||
public class AvailablePluginsTableModel extends PluginTableModel {
|
||||
private final Map<PluginId, String> myUpdateVersions = new HashMap<PluginId, String>();
|
||||
|
||||
public AvailablePluginsTableModel(SortableProvider sortableProvider) {
|
||||
super(sortableProvider,
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_NAME, sortableProvider),
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_DOWNLOADS, sortableProvider),
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_DATE, sortableProvider) {
|
||||
public AvailablePluginsTableModel() {
|
||||
super(new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_NAME),
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_DOWNLOADS),
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_DATE) {
|
||||
@Override
|
||||
protected int getHorizontalAlignment() {
|
||||
return SwingConstants.TRAILING;
|
||||
}
|
||||
},
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_CATEGORY, sortableProvider));
|
||||
new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_CATEGORY));
|
||||
|
||||
setSortKey(new RowSorter.SortKey(getNameColumn(), SortOrder.ASCENDING));
|
||||
view = new ArrayList<IdeaPluginDescriptor>();
|
||||
sortByColumn(getNameColumn());
|
||||
}
|
||||
|
||||
public void addData(List<IdeaPluginDescriptor> list) {
|
||||
@@ -67,7 +66,8 @@ public class AvailablePluginsTableModel extends PluginTableModel {
|
||||
view.add(descr);
|
||||
myUpdateVersions.put(descr.getPluginId(), descr.getVersion());
|
||||
}
|
||||
safeSort();
|
||||
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
private static void updateStatus(final IdeaPluginDescriptor descr) {
|
||||
@@ -103,7 +103,8 @@ public class AvailablePluginsTableModel extends PluginTableModel {
|
||||
myUpdateVersions.put(descr.getPluginId(), descr.getVersion());
|
||||
}
|
||||
}
|
||||
safeSort();
|
||||
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-10
@@ -16,18 +16,17 @@
|
||||
package com.intellij.ide.plugins;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.ui.BooleanTableCellEditor;
|
||||
import com.intellij.ui.BooleanTableCellRenderer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -52,8 +51,7 @@ public class InstalledPluginsTableModel extends PluginTableModel {
|
||||
public static Set<PluginId> updatedPlugins = new HashSet<PluginId>();
|
||||
private final Map<PluginId, Boolean> myEnabled = new HashMap<PluginId, Boolean>();
|
||||
|
||||
public InstalledPluginsTableModel(SortableProvider sortableProvider) {
|
||||
super.sortableProvider = sortableProvider;
|
||||
public InstalledPluginsTableModel() {
|
||||
super.columns = new ColumnInfo[]{new EnabledPluginInfo(), new NameColumnInfo(), new BundledColumnInfo()};
|
||||
view = new ArrayList<IdeaPluginDescriptor>(Arrays.asList(PluginManager.getPlugins()));
|
||||
reset(view);
|
||||
@@ -62,7 +60,8 @@ public class InstalledPluginsTableModel extends PluginTableModel {
|
||||
@NonNls final String s = iterator.next().getPluginId().getIdString();
|
||||
if ("com.intellij".equals(s)) iterator.remove();
|
||||
}
|
||||
sortByColumn(getNameColumn());
|
||||
|
||||
setSortKey(new RowSorter.SortKey(getNameColumn(), SortOrder.ASCENDING));
|
||||
}
|
||||
|
||||
public static int getCheckboxColumn() {
|
||||
@@ -102,7 +101,8 @@ public class InstalledPluginsTableModel extends PluginTableModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
safeSort();
|
||||
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,6 +113,7 @@ public class InstalledPluginsTableModel extends PluginTableModel {
|
||||
view.add(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
super.filter(filtered);
|
||||
}
|
||||
|
||||
@@ -216,20 +217,19 @@ public class InstalledPluginsTableModel extends PluginTableModel {
|
||||
}
|
||||
|
||||
public Comparator<IdeaPluginDescriptorImpl> getComparator() {
|
||||
final boolean sortDirection = (sortableProvider.getSortOrder() == SortableColumnModel.SORT_ASCENDING);
|
||||
return new Comparator<IdeaPluginDescriptorImpl>() {
|
||||
public int compare(final IdeaPluginDescriptorImpl o1, final IdeaPluginDescriptorImpl o2) {
|
||||
if (myEnabled.get(o1.getPluginId())) {
|
||||
if (myEnabled.get(o2.getPluginId())) {
|
||||
return 0;
|
||||
}
|
||||
return sortDirection ? -1 : 1;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
if (!myEnabled.get(o2.getPluginId())) {
|
||||
return 0;
|
||||
}
|
||||
return sortDirection ? 1 : -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -282,7 +282,7 @@ public class InstalledPluginsTableModel extends PluginTableModel {
|
||||
|
||||
private class NameColumnInfo extends PluginManagerColumnInfo {
|
||||
public NameColumnInfo() {
|
||||
super(PluginManagerColumnInfo.COLUMN_NAME, sortableProvider);
|
||||
super(COLUMN_NAME);
|
||||
}
|
||||
|
||||
public TableCellRenderer getRenderer(final IdeaPluginDescriptor ideaPluginDescriptor) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
@@ -57,12 +56,10 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
};
|
||||
|
||||
private final int columnIdx;
|
||||
private final SortableProvider mySortableProvider;
|
||||
|
||||
public PluginManagerColumnInfo(int columnIdx, SortableProvider sortableProvider) {
|
||||
public PluginManagerColumnInfo(int columnIdx) {
|
||||
super(COLUMNS[columnIdx]);
|
||||
this.columnIdx = columnIdx;
|
||||
mySortableProvider = sortableProvider;
|
||||
}
|
||||
|
||||
public String valueOf(IdeaPluginDescriptor base) {
|
||||
@@ -94,14 +91,12 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
}
|
||||
|
||||
public Comparator<IdeaPluginDescriptor> getComparator() {
|
||||
final boolean sortDirection = (mySortableProvider.getSortOrder() == SortableColumnModel.SORT_ASCENDING);
|
||||
|
||||
switch (columnIdx) {
|
||||
case COLUMN_NAME:
|
||||
return new Comparator<IdeaPluginDescriptor>() {
|
||||
public int compare(IdeaPluginDescriptor o1, IdeaPluginDescriptor o2) {
|
||||
String name1 = (sortDirection ? o1 : o2).getName();
|
||||
String name2 = (sortDirection ? o2 : o1).getName();
|
||||
String name1 = o1.getName();
|
||||
String name2 = o2.getName();
|
||||
return compareStrings(name1, name2);
|
||||
}
|
||||
};
|
||||
@@ -109,11 +104,6 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
case COLUMN_DOWNLOADS:
|
||||
return new Comparator<IdeaPluginDescriptor>() {
|
||||
public int compare(IdeaPluginDescriptor o1, IdeaPluginDescriptor o2) {
|
||||
if (!sortDirection) {
|
||||
IdeaPluginDescriptor swap = o2;
|
||||
o2 = o1;
|
||||
o1 = swap;
|
||||
}
|
||||
String count1 = (o1 instanceof PluginNode) ? ((PluginNode)o1).getDownloads() : ((IdeaPluginDescriptorImpl)o1).getDownloads();
|
||||
String count2 = (o2 instanceof PluginNode) ? ((PluginNode)o2).getDownloads() : ((IdeaPluginDescriptorImpl)o2).getDownloads();
|
||||
if (count1 != null && count2 != null) {
|
||||
@@ -131,8 +121,8 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
case COLUMN_CATEGORY:
|
||||
return new Comparator<IdeaPluginDescriptor>() {
|
||||
public int compare(IdeaPluginDescriptor o1, IdeaPluginDescriptor o2) {
|
||||
String cat1 = (sortDirection ? o1 : o2).getCategory();
|
||||
String cat2 = (sortDirection ? o2 : o1).getCategory();
|
||||
String cat1 = o1.getCategory();
|
||||
String cat2 = o2.getCategory();
|
||||
return compareStrings(cat1, cat2);
|
||||
}
|
||||
};
|
||||
@@ -140,11 +130,6 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
case COLUMN_DATE:
|
||||
return new Comparator<IdeaPluginDescriptor>() {
|
||||
public int compare(IdeaPluginDescriptor o1, IdeaPluginDescriptor o2) {
|
||||
if (!sortDirection) {
|
||||
IdeaPluginDescriptor swap = o2;
|
||||
o2 = o1;
|
||||
o1 = swap;
|
||||
}
|
||||
long date1 = (o1 instanceof PluginNode) ? ((PluginNode)o1).getDate() : ((IdeaPluginDescriptorImpl)o1).getDate();
|
||||
long date2 = (o2 instanceof PluginNode) ? ((PluginNode)o2).getDate() : ((IdeaPluginDescriptorImpl)o2).getDate();
|
||||
if (date1 > date2) {
|
||||
|
||||
+61
-42
@@ -22,13 +22,15 @@ import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.options.BaseConfigurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableModel;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -57,8 +59,31 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
|
||||
public void reset() {
|
||||
myPluginManagerMain.reset();
|
||||
myUISettings.getSplitterProportionsData().restoreSplitterProportions(myPluginManagerMain.getMainPanel());
|
||||
myUISettings.getAvailableTableProportions().restoreProportion(myPluginManagerMain.getAvailablePluginsTable());
|
||||
myUISettings.getInstalledTableProportions().restoreProportion(myPluginManagerMain.getInstalledPluginTable());
|
||||
|
||||
final PluginTable availablePluginsTable = myPluginManagerMain.getAvailablePluginsTable();
|
||||
final PluginTable installedPluginTable = myPluginManagerMain.getInstalledPluginTable();
|
||||
|
||||
myUISettings.getAvailableTableProportions().restoreProportion(availablePluginsTable);
|
||||
myUISettings.getInstalledTableProportions().restoreProportion(installedPluginTable);
|
||||
|
||||
restoreSorting(availablePluginsTable, true);
|
||||
restoreSorting(installedPluginTable, false);
|
||||
}
|
||||
|
||||
private void restoreSorting(final PluginTable table, final boolean available) {
|
||||
final RowSorter<? extends TableModel> rowSorter = table.getRowSorter();
|
||||
if (rowSorter != null) {
|
||||
final int column = available ? myUISettings.AVAILABLE_SORT_COLUMN : myUISettings.INSTALLED_SORT_COLUMN;
|
||||
if (column >= 0) {
|
||||
final int orderOrdinal = available ? myUISettings.AVAILABLE_SORT_COLUMN_ORDER : myUISettings.INSTALLED_SORT_COLUMN_ORDER;
|
||||
for (final SortOrder sortOrder : SortOrder.values()) {
|
||||
if (sortOrder.ordinal() == orderOrdinal) {
|
||||
rowSorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(column, sortOrder)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getHelpTopic() {
|
||||
@@ -68,16 +93,46 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
|
||||
public void disposeUIResources() {
|
||||
if (myPluginManagerMain != null) {
|
||||
myUISettings.getSplitterProportionsData().saveSplitterProportions(myPluginManagerMain.getMainPanel());
|
||||
myUISettings.getAvailableTableProportions().saveProportion(myPluginManagerMain.getAvailablePluginsTable());
|
||||
myUISettings.getInstalledTableProportions().saveProportion(myPluginManagerMain.getInstalledPluginTable());
|
||||
final PluginTable availablePluginsTable = myPluginManagerMain.getAvailablePluginsTable();
|
||||
final PluginTable installedPluginTable = myPluginManagerMain.getInstalledPluginTable();
|
||||
myUISettings.getAvailableTableProportions().saveProportion(availablePluginsTable);
|
||||
myUISettings.getInstalledTableProportions().saveProportion(installedPluginTable);
|
||||
|
||||
saveSorting(availablePluginsTable, true);
|
||||
saveSorting(installedPluginTable, false);
|
||||
|
||||
Disposer.dispose(myPluginManagerMain);
|
||||
myPluginManagerMain = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSorting(final PluginTable availablePluginsTable, final boolean available) {
|
||||
final RowSorter<? extends TableModel> rowSorter = availablePluginsTable.getRowSorter();
|
||||
if (rowSorter != null) {
|
||||
final List<? extends RowSorter.SortKey> sortKeys = rowSorter.getSortKeys();
|
||||
if (sortKeys.size() > 0) {
|
||||
final RowSorter.SortKey sortKey = sortKeys.get(0);
|
||||
if (available) {
|
||||
myUISettings.AVAILABLE_SORT_COLUMN = sortKey.getColumn();
|
||||
myUISettings.AVAILABLE_SORT_COLUMN_ORDER = sortKey.getSortOrder().ordinal();
|
||||
}
|
||||
else {
|
||||
myUISettings.INSTALLED_SORT_COLUMN = sortKey.getColumn();
|
||||
myUISettings.INSTALLED_SORT_COLUMN_ORDER = sortKey.getSortOrder().ordinal();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JComponent createComponent() {
|
||||
if (myPluginManagerMain == null) {
|
||||
myPluginManagerMain = new PluginManagerMain( new MyInstalledProvider() , new MyAvailableProvider());
|
||||
myPluginManagerMain = new PluginManagerMain( );
|
||||
|
||||
final PluginTable availablePluginsTable = myPluginManagerMain.getAvailablePluginsTable();
|
||||
final PluginTable installedPluginTable = myPluginManagerMain.getInstalledPluginTable();
|
||||
restoreSorting(availablePluginsTable, true);
|
||||
restoreSorting(installedPluginTable, false);
|
||||
}
|
||||
|
||||
return myPluginManagerMain.getMainPanel();
|
||||
@@ -116,42 +171,6 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
|
||||
return IconLoader.getIcon("/general/pluginManager.png");
|
||||
}
|
||||
|
||||
private class MyInstalledProvider implements SortableProvider {
|
||||
public int getSortOrder() {
|
||||
return myUISettings.INSTALLED_SORT_COLUMN_ORDER;
|
||||
}
|
||||
|
||||
public int getSortColumn() {
|
||||
return myUISettings.INSTALLED_SORT_COLUMN;
|
||||
}
|
||||
|
||||
public void setSortOrder(int sortOrder) {
|
||||
myUISettings.INSTALLED_SORT_COLUMN_ORDER = sortOrder;
|
||||
}
|
||||
|
||||
public void setSortColumn(int sortColumn) {
|
||||
myUISettings.INSTALLED_SORT_COLUMN = sortColumn;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyAvailableProvider implements SortableProvider {
|
||||
public int getSortOrder() {
|
||||
return myUISettings.AVAILABLE_SORT_COLUMN_ORDER;
|
||||
}
|
||||
|
||||
public int getSortColumn() {
|
||||
return myUISettings.AVAILABLE_SORT_COLUMN;
|
||||
}
|
||||
|
||||
public void setSortOrder(int sortOrder) {
|
||||
myUISettings.AVAILABLE_SORT_COLUMN_ORDER = sortOrder;
|
||||
}
|
||||
|
||||
public void setSortColumn(int sortColumn) {
|
||||
myUISettings.AVAILABLE_SORT_COLUMN = sortColumn;
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return getHelpTopic();
|
||||
}
|
||||
|
||||
@@ -104,11 +104,11 @@ public class PluginManagerMain implements Disposable {
|
||||
|
||||
private final MyPluginsFilter myFilter = new MyPluginsFilter();
|
||||
|
||||
public PluginManagerMain(final SortableProvider installedProvider, final SortableProvider availableProvider) {
|
||||
public PluginManagerMain() {
|
||||
myDescriptionTextArea.addHyperlinkListener(new MyHyperlinkListener());
|
||||
myChangeNotesTextArea.addHyperlinkListener(new MyHyperlinkListener());
|
||||
|
||||
installedPluginsModel = new InstalledPluginsTableModel(installedProvider);
|
||||
installedPluginsModel = new InstalledPluginsTableModel();
|
||||
installedPluginTable = new PluginTable(installedPluginsModel);
|
||||
|
||||
installedPluginTable.setColumnWidth(2, 45);
|
||||
@@ -132,7 +132,7 @@ public class PluginManagerMain implements Disposable {
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
|
||||
|
||||
|
||||
availablePluginsModel = new AvailablePluginsTableModel(availableProvider);
|
||||
availablePluginsModel = new AvailablePluginsTableModel();
|
||||
availablePluginsTable = new PluginTable(availablePluginsModel);
|
||||
// Downloads
|
||||
availablePluginsTable.setColumnWidth(1, 70);
|
||||
|
||||
@@ -15,20 +15,21 @@
|
||||
*/
|
||||
package com.intellij.ide.plugins;
|
||||
|
||||
import com.intellij.ide.ui.SplitterProportionsDataImpl;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ui.SplitterProportionsData;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.ide.ui.SplitterProportionsDataImpl;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
@@ -46,9 +47,9 @@ public class PluginManagerUISettings implements PersistentStateComponent<Element
|
||||
public int AVAILABLE_SORT_COLUMN = 0;
|
||||
public int INSTALLED_SORT_COLUMN = 1;
|
||||
public int CART_SORT_COLUMN = 0;
|
||||
public int AVAILABLE_SORT_COLUMN_ORDER = SortableColumnModel.SORT_ASCENDING;
|
||||
public int INSTALLED_SORT_COLUMN_ORDER = SortableColumnModel.SORT_ASCENDING;
|
||||
public int CART_SORT_COLUMN_ORDER = SortableColumnModel.SORT_ASCENDING;
|
||||
public int AVAILABLE_SORT_COLUMN_ORDER = SortOrder.ASCENDING.ordinal();
|
||||
public int INSTALLED_SORT_COLUMN_ORDER = SortOrder.ASCENDING.ordinal();
|
||||
public int CART_SORT_COLUMN_ORDER = SortOrder.ASCENDING.ordinal();
|
||||
|
||||
@NonNls private static final String INSTALLED = "installed";
|
||||
@NonNls private static final String AVAILABLE = "available";
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.intellij.ide.plugins;
|
||||
import com.intellij.ui.TableUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.util.ui.Table;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -26,8 +25,6 @@ import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -40,7 +37,7 @@ public class PluginTable extends Table {
|
||||
public PluginTable(final PluginTableModel model) {
|
||||
super(model);
|
||||
|
||||
initializeHeader(model);
|
||||
initializeHeader();
|
||||
|
||||
for (int i = 0; i < model.getColumnCount(); i++) {
|
||||
TableColumn column = getColumnModel().getColumn(i);
|
||||
@@ -79,35 +76,8 @@ public class PluginTable extends Table {
|
||||
return columnInfo.getRenderer(((PluginTableModel)getModel()).getObjectAt(row));
|
||||
}
|
||||
|
||||
private void initializeHeader(final PluginTableModel model) {
|
||||
private void initializeHeader() {
|
||||
final JTableHeader header = getTableHeader();
|
||||
|
||||
header.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int column = getTableHeader().getColumnModel().getColumnIndexAtX(e.getX());
|
||||
|
||||
if (model.sortableProvider.getSortColumn() == column) {
|
||||
if (model.sortableProvider.getSortOrder() == SortableColumnModel.SORT_DESCENDING) {
|
||||
model.sortableProvider.setSortOrder(SortableColumnModel.SORT_ASCENDING);
|
||||
}
|
||||
else {
|
||||
model.sortableProvider.setSortOrder(SortableColumnModel.SORT_DESCENDING);
|
||||
}
|
||||
}
|
||||
else {
|
||||
model.sortableProvider.setSortOrder(SortableColumnModel.SORT_ASCENDING);
|
||||
model.sortableProvider.setSortColumn(column);
|
||||
}
|
||||
|
||||
final IdeaPluginDescriptor[] selectedObjects = getSelectedObjects();
|
||||
model.sortByColumn(column);
|
||||
if (selectedObjects != null){
|
||||
select(selectedObjects);
|
||||
}
|
||||
|
||||
header.repaint();
|
||||
}
|
||||
});
|
||||
header.setReorderingAllowed(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -33,15 +33,18 @@ import java.util.List;
|
||||
*/
|
||||
abstract public class PluginTableModel extends AbstractTableModel implements SortableColumnModel {
|
||||
protected ColumnInfo[] columns;
|
||||
protected SortableProvider sortableProvider;
|
||||
protected List<IdeaPluginDescriptor> view;
|
||||
private RowSorter.SortKey myDefaultSortKey;
|
||||
|
||||
protected PluginTableModel() {
|
||||
}
|
||||
|
||||
public PluginTableModel(SortableProvider sortableProvider, ColumnInfo... columns) {
|
||||
public PluginTableModel(ColumnInfo... columns) {
|
||||
this.columns = columns;
|
||||
this.sortableProvider = sortableProvider;
|
||||
}
|
||||
|
||||
public void setSortKey(final RowSorter.SortKey sortKey) {
|
||||
myDefaultSortKey = sortKey;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
@@ -64,18 +67,20 @@ abstract public class PluginTableModel extends AbstractTableModel implements Sor
|
||||
return columns[column].getName();
|
||||
}
|
||||
|
||||
public int getSortedColumnIndex() {
|
||||
return sortableProvider.getSortColumn();
|
||||
}
|
||||
|
||||
public int getSortingType() {
|
||||
return sortableProvider.getSortOrder();
|
||||
}
|
||||
|
||||
public IdeaPluginDescriptor getObjectAt (int row) {
|
||||
return view.get(row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRowValue(int row) {
|
||||
return getObjectAt(row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSorter.SortKey getDefaultSortKey() {
|
||||
return myDefaultSortKey;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return view.size();
|
||||
}
|
||||
@@ -92,16 +97,6 @@ abstract public class PluginTableModel extends AbstractTableModel implements Sor
|
||||
columns[columnIndex].setValue(getObjectAt(rowIndex), aValue);
|
||||
}
|
||||
|
||||
public void sortByColumn(int columnIndex) {
|
||||
Collections.sort(view, columns[columnIndex].getComparator());
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public void sortByColumn(int columnIndex, int sortingType) {
|
||||
sortByColumn(columnIndex);
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<IdeaPluginDescriptorImpl> dependent(IdeaPluginDescriptorImpl plugin) {
|
||||
ArrayList<IdeaPluginDescriptorImpl> list = new ArrayList<IdeaPluginDescriptorImpl>();
|
||||
for (IdeaPluginDescriptor any : view) {
|
||||
@@ -123,12 +118,7 @@ abstract public class PluginTableModel extends AbstractTableModel implements Sor
|
||||
public abstract void modifyData(List<IdeaPluginDescriptor> list);
|
||||
|
||||
public void filter(ArrayList<IdeaPluginDescriptor> filtered){
|
||||
safeSort();
|
||||
}
|
||||
|
||||
protected void safeSort() {
|
||||
final int sortColumn = sortableProvider.getSortColumn();
|
||||
sortByColumn(-1 < sortColumn && sortColumn < getColumnCount() ? sortColumn : 0);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public abstract int getNameColumn();
|
||||
|
||||
@@ -225,6 +225,10 @@ public class ActionsTree {
|
||||
super(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTree(JTree tree) {
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -681,13 +681,6 @@ public class AbstractPopup implements JBPopup {
|
||||
listener.beforeShown(new LightweightWindowEvent(this));
|
||||
}
|
||||
|
||||
Window w = myPopup.getWindow();
|
||||
if (w != null) {
|
||||
WindowManagerEx.WindowShadowMode mode =
|
||||
myShadowed ? WindowManagerEx.WindowShadowMode.NORMAL : WindowManagerEx.WindowShadowMode.DISABLED;
|
||||
WindowManagerEx.getInstanceEx().setWindowShadow(myWindow, mode);
|
||||
}
|
||||
|
||||
myPopup.setRequestFocus(myRequestFocus);
|
||||
myPopup.show();
|
||||
|
||||
@@ -838,6 +831,10 @@ public class AbstractPopup implements JBPopup {
|
||||
wndManager.setWindowMask(window, mask);
|
||||
}
|
||||
|
||||
WindowManagerEx.WindowShadowMode mode =
|
||||
myShadowed ? WindowManagerEx.WindowShadowMode.NORMAL : WindowManagerEx.WindowShadowMode.DISABLED;
|
||||
WindowManagerEx.getInstanceEx().setWindowShadow(window, mode);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
-20
@@ -16,34 +16,14 @@
|
||||
package com.intellij.execution.testframework.sm.runner.ui.statistics;
|
||||
|
||||
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.NullableFunction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Roman Chernyatchik
|
||||
*/
|
||||
public abstract class BaseColumn extends ColumnInfo<SMTestProxy, String> {
|
||||
private final NullableFunction<List<SMTestProxy>, Object> oldSortFun =
|
||||
new NullableFunction<List<SMTestProxy>, Object>() {
|
||||
@Nullable
|
||||
public Object fun(final List<SMTestProxy> proxies) {
|
||||
BaseColumn.super.sort(proxies);
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
public BaseColumn(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sort(@NotNull final List<SMTestProxy> testProxies) {
|
||||
//Invariant: comparator should left Total(initially at row = 0) row as uppermost element!
|
||||
StatisticsTableModel.applySortOperation(testProxies, oldSortFun);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-32
@@ -18,7 +18,6 @@ package com.intellij.execution.testframework.sm.runner.ui.statistics;
|
||||
import com.intellij.execution.testframework.sm.SMRunnerUtil;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ui.ListTableModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -36,18 +35,9 @@ public class StatisticsTableModel extends ListTableModel<SMTestProxy> {
|
||||
|
||||
private SMTestProxy myCurrentSuite;
|
||||
|
||||
private final NullableFunction<List<SMTestProxy>, Object> oldReverseModelItemsFun =
|
||||
new NullableFunction<List<SMTestProxy>, Object>() {
|
||||
@Nullable
|
||||
public Object fun(final List<SMTestProxy> proxies) {
|
||||
StatisticsTableModel.super.reverseModelItems(proxies);
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
public StatisticsTableModel() {
|
||||
super(new ColumnTest(), new ColumnDuration(), new ColumnResults());
|
||||
setSortable(false); // TODO: fix me
|
||||
}
|
||||
|
||||
public void updateModelOnProxySelected(final SMTestProxy proxy) {
|
||||
@@ -113,27 +103,6 @@ public class StatisticsTableModel extends ListTableModel<SMTestProxy> {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reverseModelItems(final List<SMTestProxy> testProxies) {
|
||||
//Invariant: comparator should left Total(initally at row = 0) row as uppermost element!
|
||||
applySortOperation(testProxies, oldReverseModelItemsFun);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function allow sort operation to all except first element(e.g. Total row)
|
||||
* @param proxies Tests or suites
|
||||
* @param sortOperation Closure
|
||||
*/
|
||||
protected static void applySortOperation(final List<SMTestProxy> proxies,
|
||||
final NullableFunction<List<SMTestProxy>, Object> sortOperation) {
|
||||
|
||||
//Invariant: comparator should left Total(initally at row = 0) row as uppermost element!
|
||||
final int size = proxies.size();
|
||||
if (size > 1) {
|
||||
sortOperation.fun(proxies.subList(1, size));
|
||||
}
|
||||
}
|
||||
|
||||
public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) {
|
||||
// Setting value is prevented!
|
||||
LOG.error("value: " + aValue + " row: " + rowIndex + " column: " + columnIndex);
|
||||
|
||||
+6
-7
@@ -17,7 +17,6 @@ package com.intellij.execution.testframework.sm.runner.ui.statistics;
|
||||
|
||||
import com.intellij.execution.testframework.sm.runner.BaseSMTRunnerTestCase;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -67,7 +66,7 @@ public class SMTRunnerStatisticsTableModelTest extends BaseSMTRunnerTestCase {
|
||||
myStatisticsTableModel.updateModelOnProxySelected(myRootSuite);
|
||||
assertSameElements(getItems(), myRootSuite, suite1, suite2);
|
||||
}
|
||||
|
||||
/*
|
||||
public void testSort_ColumnTest() {
|
||||
final SMTestProxy firstSuite = createSuiteProxy("K_suite1", myRootSuite);
|
||||
final SMTestProxy lastSuite = createSuiteProxy("L_suite1", myRootSuite);
|
||||
@@ -119,7 +118,7 @@ public class SMTRunnerStatisticsTableModelTest extends BaseSMTRunnerTestCase {
|
||||
myStatisticsTableModel.sortByColumn(1, SortableColumnModel.SORT_ASCENDING);
|
||||
assertOrderedEquals(getItems(), myRootSuite, firstTest, firstSuite, lastSuite, lastTest);
|
||||
}
|
||||
|
||||
*/
|
||||
public void testGotoParentSuite_ResultsRoot() {
|
||||
// create test sturcure
|
||||
final SMTestProxy rootSuite = createSuiteProxy("rootSuite");
|
||||
@@ -160,17 +159,17 @@ public class SMTRunnerStatisticsTableModelTest extends BaseSMTRunnerTestCase {
|
||||
myStatisticsTableModel.updateModelOnProxySelected(rootSuite);
|
||||
|
||||
//sort with another sort type
|
||||
myStatisticsTableModel.sortByColumn(0, SortableColumnModel.SORT_ASCENDING);
|
||||
//myStatisticsTableModel.sortByColumn(0, SortableColumnModel.SORT_ASCENDING);
|
||||
//resort
|
||||
myStatisticsTableModel.sortByColumn(2, SortableColumnModel.SORT_DESCENDING);
|
||||
//myStatisticsTableModel.sortByColumn(2, SortableColumnModel.SORT_DESCENDING);
|
||||
assertOrderedEquals(getItems(),
|
||||
rootSuite, suite4, suite3, suite2, suite1, errorTest1, failedTest1, passedTest1);
|
||||
//reverse
|
||||
myStatisticsTableModel.sortByColumn(2, SortableColumnModel.SORT_ASCENDING);
|
||||
//myStatisticsTableModel.sortByColumn(2, SortableColumnModel.SORT_ASCENDING);
|
||||
assertOrderedEquals(getItems(),
|
||||
rootSuite, passedTest1, failedTest1, errorTest1, suite1, suite2, suite3, suite4);
|
||||
//direct
|
||||
myStatisticsTableModel.sortByColumn(2, SortableColumnModel.SORT_DESCENDING);
|
||||
//myStatisticsTableModel.sortByColumn(2, SortableColumnModel.SORT_DESCENDING);
|
||||
assertOrderedEquals(getItems(),
|
||||
rootSuite, suite4, suite3, suite2, suite1, errorTest1, failedTest1, passedTest1);
|
||||
}
|
||||
|
||||
@@ -15,15 +15,12 @@
|
||||
*/
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ColumnInfo <Item, Aspect> {
|
||||
|
||||
@@ -69,13 +66,6 @@ public abstract class ColumnInfo <Item, Aspect> {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public void sort(@NotNull List<Item> list) {
|
||||
Comparator<Item> comparator = getComparator();
|
||||
if (comparator != null) {
|
||||
Collections.sort(list, comparator);
|
||||
}
|
||||
}
|
||||
|
||||
public Class getColumnClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@@ -15,26 +15,40 @@
|
||||
*/
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ListTableModel<Item> extends TableViewModel<Item> implements ItemRemovable {
|
||||
private ColumnInfo[] myColumnInfos;
|
||||
private List<Item> myItems;
|
||||
private int mySortByColumn;
|
||||
private int mySortingType = SortableColumnModel.SORT_ASCENDING;
|
||||
|
||||
private boolean myIsSortable = true;
|
||||
private boolean myIsSortable = false;
|
||||
private SortOrder mySortOrder = SortOrder.ASCENDING;
|
||||
|
||||
public ListTableModel(ColumnInfo... columnInfos) {
|
||||
this(columnInfos, new ArrayList<Item>(), 0);
|
||||
this(columnInfos, new ArrayList<Item>(), 0, SortOrder.ASCENDING);
|
||||
}
|
||||
|
||||
public ListTableModel(ColumnInfo[] columnNames, List<Item> items, int selectedColumn) {
|
||||
this(columnNames, items, selectedColumn, SortOrder.ASCENDING);
|
||||
}
|
||||
|
||||
public ListTableModel(ColumnInfo[] columnNames, List<Item> items, int selectedColumn, final SortOrder order) {
|
||||
myColumnInfos = columnNames;
|
||||
myItems = items;
|
||||
mySortByColumn = selectedColumn;
|
||||
setSortable(true);
|
||||
resort();
|
||||
mySortOrder = order;
|
||||
|
||||
setSortable(ContainerUtil.find(columnNames, new Condition<ColumnInfo>() {
|
||||
@Override
|
||||
public boolean value(ColumnInfo columnInfo) {
|
||||
return columnInfo.isSortable();
|
||||
}
|
||||
}) != null);
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
@@ -57,6 +71,20 @@ public class ListTableModel<Item> extends TableViewModel<Item> implements ItemRe
|
||||
return myItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSorter.SortKey getDefaultSortKey() {
|
||||
if (mySortByColumn != -1) {
|
||||
return new RowSorter.SortKey(mySortByColumn, mySortOrder);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRowValue(int row) {
|
||||
return myItems.get(row);
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return myColumnInfos.length;
|
||||
}
|
||||
@@ -64,7 +92,6 @@ public class ListTableModel<Item> extends TableViewModel<Item> implements ItemRe
|
||||
public void setItems(List<Item> items) {
|
||||
myItems = items;
|
||||
fireTableDataChanged();
|
||||
resort();
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
@@ -98,70 +125,10 @@ public class ListTableModel<Item> extends TableViewModel<Item> implements ItemRe
|
||||
return Collections.unmodifiableList(myItems);
|
||||
}
|
||||
|
||||
public void sortByColumn(int columnIndex) {
|
||||
if (mySortByColumn == columnIndex) {
|
||||
reverseOrder(columnIndex);
|
||||
}
|
||||
else {
|
||||
mySortByColumn = columnIndex;
|
||||
mySortingType = SortableColumnModel.SORT_ASCENDING;
|
||||
resort();
|
||||
}
|
||||
}
|
||||
|
||||
public void sortByColumn(int columnIndex, int sortingType) {
|
||||
if (mySortByColumn != columnIndex) {
|
||||
mySortByColumn = columnIndex;
|
||||
mySortingType = sortingType;
|
||||
resort();
|
||||
}
|
||||
else if (mySortingType != sortingType) {
|
||||
reverseOrder(columnIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void reverseOrder(final int columnIndex) {
|
||||
if (mySortingType == SortableColumnModel.SORT_ASCENDING) {
|
||||
mySortingType = SortableColumnModel.SORT_DESCENDING;
|
||||
}
|
||||
else {
|
||||
mySortingType = SortableColumnModel.SORT_ASCENDING;
|
||||
}
|
||||
if (myIsSortable && myColumnInfos[columnIndex].isSortable()) {
|
||||
reverseModelItems(myItems);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void reverseModelItems(final List<Item> items) {
|
||||
Collections.reverse(items);
|
||||
}
|
||||
|
||||
protected Object getAspectOf(int aspectIndex, Object item) {
|
||||
return myColumnInfos[aspectIndex].valueOf(item);
|
||||
}
|
||||
|
||||
private void resort() {
|
||||
if (myIsSortable && mySortByColumn >= 0 && mySortByColumn < myColumnInfos.length) {
|
||||
final ColumnInfo columnInfo = myColumnInfos[mySortByColumn];
|
||||
if (columnInfo.isSortable()) {
|
||||
columnInfo.sort(myItems);
|
||||
if (mySortingType == SortableColumnModel.SORT_DESCENDING) {
|
||||
reverseModelItems(myItems);
|
||||
}
|
||||
fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getSortedColumnIndex() {
|
||||
return mySortByColumn;
|
||||
}
|
||||
|
||||
public int getSortingType() {
|
||||
return mySortingType;
|
||||
}
|
||||
|
||||
public void setSortable(boolean aBoolean) {
|
||||
myIsSortable = aBoolean;
|
||||
}
|
||||
@@ -187,7 +154,6 @@ public class ListTableModel<Item> extends TableViewModel<Item> implements ItemRe
|
||||
public void addRows(final Collection<Item> items) {
|
||||
myItems.addAll(items);
|
||||
fireTableRowsInserted(myItems.size() - items.size(), myItems.size() - 1);
|
||||
// resort();
|
||||
}
|
||||
|
||||
public Object getItem(final int rowIndex) {
|
||||
|
||||
@@ -15,23 +15,19 @@
|
||||
*/
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public interface SortableColumnModel {
|
||||
int SORT_ASCENDING = 1;
|
||||
int SORT_DESCENDING = 2;
|
||||
|
||||
ColumnInfo[] getColumnInfos();
|
||||
|
||||
void sortByColumn(int columnIndex);
|
||||
void sortByColumn(int columnIndex, int sortingType);
|
||||
|
||||
int getSortedColumnIndex();
|
||||
|
||||
int getSortingType();
|
||||
|
||||
void setSortable(boolean aBoolean);
|
||||
|
||||
boolean isSortable();
|
||||
|
||||
Object getRowValue(int row);
|
||||
|
||||
@Nullable
|
||||
RowSorter.SortKey getDefaultSortKey();
|
||||
}
|
||||
|
||||
-2
@@ -77,8 +77,6 @@ public class ChangesBrowserDialog extends DialogWrapper {
|
||||
myChanges.addRows(committedChangeLists);
|
||||
if (selectFirst) {
|
||||
myCommittedChangesBrowser.selectFirstIfAny();
|
||||
} else {
|
||||
myCommittedChangesBrowser.resortKeepSelection();
|
||||
}
|
||||
}
|
||||
}.callMe();
|
||||
|
||||
+8
-11
@@ -31,7 +31,6 @@ import com.intellij.openapi.vcs.changes.ui.ChangesBrowser;
|
||||
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -64,7 +63,14 @@ public class CommittedChangesBrowser extends JPanel {
|
||||
|
||||
myProject = project;
|
||||
myTableModel = tableModel;
|
||||
myTableModel.sortByChangesColumn(ChangeListColumn.DATE, SortableColumnModel.SORT_DESCENDING);
|
||||
|
||||
for (int i = 0; i < myTableModel.getColumnCount(); i++) {
|
||||
if (ChangeListColumn.DATE.getTitle().equals(myTableModel.getColumnName(i))) {
|
||||
myTableModel.setSortKey(new RowSorter.SortKey(i, SortOrder.DESCENDING));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
myChangeListsView = new TableView<CommittedChangeList>(myTableModel);
|
||||
myChangeListsView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
@@ -177,12 +183,6 @@ public class CommittedChangesBrowser extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
public void resortKeepSelection() {
|
||||
if (myTableModel.getRowCount() > 0) {
|
||||
myChangeListsView.resortKeepSelection();
|
||||
}
|
||||
}
|
||||
|
||||
public void addToolBar(JComponent toolBar) {
|
||||
myLeftPanel.add(toolBar, BorderLayout.NORTH);
|
||||
}
|
||||
@@ -192,10 +192,7 @@ public class CommittedChangesBrowser extends JPanel {
|
||||
}
|
||||
|
||||
public void setModel(CommittedChangesTableModel tableModel) {
|
||||
ChangeListColumn sortColumn = myTableModel.getSortColumn();
|
||||
int sortingType = myTableModel.getSortingType();
|
||||
myTableModel = tableModel;
|
||||
myTableModel.sortByChangesColumn(sortColumn, sortingType);
|
||||
myChangeListsView.setModel(tableModel);
|
||||
tableModel.fireTableStructureChanged();
|
||||
}
|
||||
|
||||
+7
-18
@@ -27,14 +27,15 @@ import com.intellij.openapi.vcs.changes.ChangeList;
|
||||
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.ListTableModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class CommittedChangesTableModel extends ListTableModel<CommittedChangeList> {
|
||||
private final boolean myAsynchLoad;
|
||||
private static final ChangeListColumn[] ourDefaultColumns = new ChangeListColumn[] { ChangeListColumn.DATE, ChangeListColumn.NAME };
|
||||
private RowSorter.SortKey mySortKey;
|
||||
|
||||
public CommittedChangesTableModel(final List<CommittedChangeList> changeLists, boolean asynchLoad) {
|
||||
super(buildColumnInfos(ourDefaultColumns), changeLists, 0);
|
||||
@@ -46,25 +47,13 @@ public class CommittedChangesTableModel extends ListTableModel<CommittedChangeLi
|
||||
myAsynchLoad = asynchLoad;
|
||||
}
|
||||
|
||||
public void sortByChangesColumn(final ChangeListColumn column, int sortingType) {
|
||||
if (column == null) {
|
||||
return;
|
||||
}
|
||||
final ColumnInfo[] columnInfos = getColumnInfos();
|
||||
for(int i=0; i<columnInfos.length; i++) {
|
||||
ColumnInfoAdapter adapter = (ColumnInfoAdapter) columnInfos [i];
|
||||
if (adapter.getColumn() == column) {
|
||||
sortByColumn(i, sortingType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected void setSortKey(final RowSorter.SortKey sortKey) {
|
||||
mySortKey = sortKey;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ChangeListColumn getSortColumn() {
|
||||
int index = getSortedColumnIndex();
|
||||
if (index < 0) return null;
|
||||
return ((ColumnInfoAdapter) getColumnInfos() [index]).getColumn();
|
||||
@Override
|
||||
public RowSorter.SortKey getDefaultSortKey() {
|
||||
return mySortKey;
|
||||
}
|
||||
|
||||
private static ColumnInfo[] buildColumnInfos(final ChangeListColumn[] columns) {
|
||||
|
||||
@@ -66,9 +66,9 @@ import com.intellij.ui.dualView.CellWrapper;
|
||||
import com.intellij.ui.dualView.DualTreeElement;
|
||||
import com.intellij.ui.dualView.DualView;
|
||||
import com.intellij.ui.dualView.DualViewColumnInfo;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.SortableColumnModel;
|
||||
import com.intellij.util.ui.TableViewModel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -80,6 +80,7 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
@@ -147,11 +148,6 @@ public class FileHistoryPanelImpl<S extends CommittedChangeList, U extends Chang
|
||||
return object.getRevisionNumber().asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sort(@NotNull List<VcsFileRevision> vcsFileRevisions) {
|
||||
Collections.sort(vcsFileRevisions, myRevisionsInOrderComparator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredStringValue() {
|
||||
return "123.4567";
|
||||
@@ -503,28 +499,14 @@ public class FileHistoryPanelImpl<S extends CommittedChangeList, U extends Chang
|
||||
|
||||
myDualView.setCellWrapper(new MyCellWrapper(sessionGetter));
|
||||
|
||||
TableViewModel sortableModel = myDualView.getFlatView().getTableViewModel();
|
||||
final TableView flatView = myDualView.getFlatView();
|
||||
TableViewModel sortableModel = flatView.getTableViewModel();
|
||||
sortableModel.setSortable(true);
|
||||
|
||||
if (null == null) {
|
||||
sortableModel.sortByColumn(0, SortableColumnModel.SORT_DESCENDING);
|
||||
final RowSorter<? extends TableModel> rowSorter = flatView.getRowSorter();
|
||||
if (rowSorter != null) {
|
||||
rowSorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.DESCENDING)));
|
||||
}
|
||||
else {
|
||||
sortableModel.sortByColumn(getColumnIndex(null), SortableColumnModel.SORT_DESCENDING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getColumnIndex(final ColumnInfo defaultColumnToSortBy) {
|
||||
for (int i = 0; i < COLUMNS.length; i++) {
|
||||
DualViewColumnInfo dualViewColumnInfo = COLUMNS[i];
|
||||
if (dualViewColumnInfo instanceof MyColumnWrapper) {
|
||||
if (((MyColumnWrapper)dualViewColumnInfo).getOriginalColumn() == defaultColumnToSortBy) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void makeBold(Component component) {
|
||||
|
||||
-13
@@ -22,7 +22,6 @@ import com.intellij.ui.ListScrollingUtil;
|
||||
import com.intellij.ui.SortedListModel;
|
||||
import com.intellij.ui.TableUtil;
|
||||
import com.intellij.ui.table.BaseTableView;
|
||||
import com.intellij.ui.table.TableHeaderRenderer;
|
||||
import com.intellij.util.config.AbstractProperty;
|
||||
import com.intellij.util.config.ListProperty;
|
||||
import com.intellij.util.config.StorageProperty;
|
||||
@@ -372,15 +371,6 @@ public abstract class UIPropertyBinding {
|
||||
}
|
||||
table.setSurrendersFocusOnKeystroke(true);
|
||||
// support for sorting
|
||||
header.setDefaultRenderer(new TableHeaderRenderer(myModel));
|
||||
header.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (myModel.isSortable()) {
|
||||
final int column = table.convertColumnIndexToModel(header.columnAtPoint(e.getPoint()));
|
||||
myModel.sortByColumn(column);
|
||||
}
|
||||
}
|
||||
});
|
||||
myModel.addTableModelListener(new TableModelListener() {
|
||||
public void tableChanged(final TableModelEvent e) {
|
||||
final JTableHeader header = getComponent().getTableHeader();
|
||||
@@ -406,9 +396,6 @@ public abstract class UIPropertyBinding {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sortByColumn != -1) {
|
||||
myModel.sortByColumn(sortByColumn, myModel.getSortingType());
|
||||
}
|
||||
}
|
||||
TableUtil.ensureSelectionExists(getComponent());
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ public class StatisticsTable extends ListTableModel {
|
||||
private TestProxy myTest;
|
||||
private JUnitRunningModel myModel;
|
||||
|
||||
public StatisticsTable(final ColumnInfo[] collumnNames) {
|
||||
super(collumnNames);
|
||||
public StatisticsTable(final ColumnInfo[] columnNames) {
|
||||
super(columnNames);
|
||||
}
|
||||
|
||||
public void setModel(final JUnitRunningModel model) {
|
||||
@@ -62,16 +62,6 @@ public class StatisticsTable extends ListTableModel {
|
||||
setItems(new ArrayList());
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return super.getRowCount() + 1;
|
||||
}
|
||||
|
||||
public Object getValueAt(final int rowIndex, final int columnIndex) {
|
||||
if (rowIndex == 0)
|
||||
return testProperty(columnIndex);
|
||||
return super.getValueAt(rowIndex - 1, columnIndex);
|
||||
}
|
||||
|
||||
public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) {
|
||||
LOG.error("value: " + aValue + " row: " + rowIndex + " column: " + columnIndex);
|
||||
}
|
||||
@@ -80,6 +70,7 @@ public class StatisticsTable extends ListTableModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: move out of the table
|
||||
private Object testProperty(final int columnIndex) {
|
||||
if (columnIndex == 0)
|
||||
return ExecutionBundle.message("junit.runing.info.total.label");
|
||||
@@ -89,15 +80,13 @@ public class StatisticsTable extends ListTableModel {
|
||||
public TestProxy getTestAt(final int rowIndex) {
|
||||
if (rowIndex < 0 || rowIndex > getItems().size())
|
||||
return null;
|
||||
return (rowIndex == 0) ? myTest : (TestProxy)getItems().get(rowIndex - 1);
|
||||
return (TestProxy)getItems().get(rowIndex);
|
||||
}
|
||||
|
||||
public int getIndexOf(final Object test) {
|
||||
if (test == myTest)
|
||||
return 0;
|
||||
for (int i = 0; i < getItems().size(); i++) {
|
||||
final Object child = getItems().get(i);
|
||||
if (child == test) return i + 1;
|
||||
if (child == test) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -40,12 +40,6 @@ class TestTableRenderer implements TableCellRenderer {
|
||||
final int row, final int column) {
|
||||
final int modelColumn = table.convertColumnIndexToModel(column);
|
||||
final TableCellRenderer renderer = myRenderers[modelColumn];
|
||||
if (row == 0) {
|
||||
final Component component = ((modelColumn == 0) ? myLeftTopRenderer : renderer).
|
||||
getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
component.setFont(component.getFont().deriveFont(Font.BOLD));
|
||||
return component;
|
||||
}
|
||||
return renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user