mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
[file-history] rename MyColumnWrapper -> FileHistoryColumnWrapper and move it out of FileHistoryPanelImpl
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.history;
|
||||
|
||||
import com.intellij.ui.dualView.DualView;
|
||||
import com.intellij.ui.dualView.DualViewColumnInfo;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
|
||||
abstract class FileHistoryColumnWrapper<T> extends DualViewColumnInfo<FileHistoryPanelImpl.TreeNodeOnVcsRevision, Object> {
|
||||
@NotNull private final ColumnInfo<VcsFileRevision, T> myBaseColumn;
|
||||
|
||||
public FileHistoryColumnWrapper(@NotNull ColumnInfo<VcsFileRevision, T> additionalColumn) {
|
||||
super(additionalColumn.getName());
|
||||
myBaseColumn = additionalColumn;
|
||||
}
|
||||
|
||||
public Comparator<FileHistoryPanelImpl.TreeNodeOnVcsRevision> getComparator() {
|
||||
final Comparator<VcsFileRevision> comparator = myBaseColumn.getComparator();
|
||||
if (comparator == null) return null;
|
||||
return (o1, o2) -> {
|
||||
if (o1 == null) return -1;
|
||||
if (o2 == null) return 1;
|
||||
VcsFileRevision revision1 = o1.getRevision();
|
||||
VcsFileRevision revision2 = o2.getRevision();
|
||||
if (revision1 == null) return -1;
|
||||
if (revision2 == null) return 1;
|
||||
return comparator.compare(revision1, revision2);
|
||||
};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myBaseColumn.getName();
|
||||
}
|
||||
|
||||
public void setName(String s) {
|
||||
myBaseColumn.setName(s);
|
||||
}
|
||||
|
||||
public Class getColumnClass() {
|
||||
return myBaseColumn.getColumnClass();
|
||||
}
|
||||
|
||||
public boolean isCellEditable(FileHistoryPanelImpl.TreeNodeOnVcsRevision o) {
|
||||
return myBaseColumn.isCellEditable(o.getRevision());
|
||||
}
|
||||
|
||||
public void setValue(FileHistoryPanelImpl.TreeNodeOnVcsRevision o, Object aValue) {
|
||||
//noinspection unchecked
|
||||
myBaseColumn.setValue(o.getRevision(), (T)aValue);
|
||||
}
|
||||
|
||||
public TableCellRenderer getRenderer(FileHistoryPanelImpl.TreeNodeOnVcsRevision p0) {
|
||||
return myBaseColumn.getRenderer(p0.getRevision());
|
||||
}
|
||||
|
||||
public TableCellEditor getEditor(FileHistoryPanelImpl.TreeNodeOnVcsRevision item) {
|
||||
return myBaseColumn.getEditor(item.getRevision());
|
||||
}
|
||||
|
||||
public String getMaxStringValue() {
|
||||
final String superValue = myBaseColumn.getMaxStringValue();
|
||||
if (superValue != null) return superValue;
|
||||
return getMaxValue(myBaseColumn.getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getMaxValue(@NotNull String columnHeader) {
|
||||
TableView table = getDualView().getFlatView();
|
||||
if (table.getRowCount() == 0) return null;
|
||||
final Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
|
||||
int idx = 0;
|
||||
while (columns.hasMoreElements()) {
|
||||
TableColumn column = columns.nextElement();
|
||||
if (columnHeader.equals(column.getHeaderValue())) {
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
if (idx >= table.getColumnModel().getColumnCount() - 1) return null;
|
||||
final FontMetrics fm = table.getFontMetrics(table.getFont().deriveFont(Font.BOLD));
|
||||
final Object header = table.getColumnModel().getColumn(idx).getHeaderValue();
|
||||
double maxValue = fm.stringWidth((String)header);
|
||||
String value = (String)header;
|
||||
for (int i = 0; i < table.getRowCount(); i++) {
|
||||
final Object at = table.getValueAt(i, idx);
|
||||
if (at instanceof String) {
|
||||
final int newWidth = fm.stringWidth((String)at);
|
||||
if (newWidth > maxValue) {
|
||||
maxValue = newWidth;
|
||||
value = (String)at;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value + "ww";
|
||||
}
|
||||
|
||||
public int getAdditionalWidth() {
|
||||
return myBaseColumn.getAdditionalWidth();
|
||||
}
|
||||
|
||||
public int getWidth(JTable table) {
|
||||
return myBaseColumn.getWidth(table);
|
||||
}
|
||||
|
||||
public boolean shouldBeShownIsTheTree() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldBeShownIsTheTable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object valueOf(FileHistoryPanelImpl.TreeNodeOnVcsRevision o) {
|
||||
return myBaseColumn.valueOf(o.getRevision());
|
||||
}
|
||||
|
||||
protected abstract DualView getDualView();
|
||||
}
|
||||
@@ -77,9 +77,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
@@ -317,7 +315,12 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
ArrayList<DualViewColumnInfo> result = new ArrayList<>();
|
||||
if (additionalColumns != null) {
|
||||
for (ColumnInfo additionalColumn : additionalColumns) {
|
||||
result.add(new MyColumnWrapper(additionalColumn));
|
||||
result.add(new FileHistoryColumnWrapper(additionalColumn) {
|
||||
@Override
|
||||
protected DualView getDualView() {
|
||||
return myDualView;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -673,37 +676,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
return myFilePath.getVirtualFileParent();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getMaxValue(@NotNull String name) {
|
||||
TableView table = myDualView.getFlatView();
|
||||
if (table.getRowCount() == 0) return null;
|
||||
final Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
|
||||
int idx = 0;
|
||||
while (columns.hasMoreElements()) {
|
||||
TableColumn column = columns.nextElement();
|
||||
if (name.equals(column.getHeaderValue())) {
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
if (idx >= table.getColumnModel().getColumnCount() - 1) return null;
|
||||
final FontMetrics fm = table.getFontMetrics(table.getFont().deriveFont(Font.BOLD));
|
||||
final Object header = table.getColumnModel().getColumn(idx).getHeaderValue();
|
||||
double maxValue = fm.stringWidth((String)header);
|
||||
String value = (String)header;
|
||||
for (int i = 0; i < table.getRowCount(); i++) {
|
||||
final Object at = table.getValueAt(i, idx);
|
||||
if (at instanceof String) {
|
||||
final int newWidth = fm.stringWidth((String)at);
|
||||
if (newWidth > maxValue) {
|
||||
maxValue = newWidth;
|
||||
value = (String)at;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value + "ww";
|
||||
}
|
||||
|
||||
private void refreshRevisionsOrder() {
|
||||
final List<VcsFileRevision> list = myHistorySession.getRevisionList();
|
||||
myRevisionsOrder.clear();
|
||||
@@ -1510,84 +1482,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
}
|
||||
}
|
||||
|
||||
private class MyColumnWrapper<T> extends DualViewColumnInfo<TreeNodeOnVcsRevision, Object> {
|
||||
private final ColumnInfo<VcsFileRevision, T> myBaseColumn;
|
||||
|
||||
public MyColumnWrapper(ColumnInfo<VcsFileRevision, T> additionalColumn) {
|
||||
super(additionalColumn.getName());
|
||||
myBaseColumn = additionalColumn;
|
||||
}
|
||||
|
||||
public Comparator<TreeNodeOnVcsRevision> getComparator() {
|
||||
final Comparator<VcsFileRevision> comparator = myBaseColumn.getComparator();
|
||||
if (comparator == null) return null;
|
||||
return (o1, o2) -> {
|
||||
if (o1 == null) return -1;
|
||||
if (o2 == null) return 1;
|
||||
VcsFileRevision revision1 = o1.myRevision;
|
||||
VcsFileRevision revision2 = o2.myRevision;
|
||||
if (revision1 == null) return -1;
|
||||
if (revision2 == null) return 1;
|
||||
return comparator.compare(revision1, revision2);
|
||||
};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myBaseColumn.getName();
|
||||
}
|
||||
|
||||
public void setName(String s) {
|
||||
myBaseColumn.setName(s);
|
||||
}
|
||||
|
||||
public Class getColumnClass() {
|
||||
return myBaseColumn.getColumnClass();
|
||||
}
|
||||
|
||||
public boolean isCellEditable(TreeNodeOnVcsRevision o) {
|
||||
return myBaseColumn.isCellEditable(o.myRevision);
|
||||
}
|
||||
|
||||
public void setValue(TreeNodeOnVcsRevision o, Object aValue) {
|
||||
//noinspection unchecked
|
||||
myBaseColumn.setValue(o.myRevision, (T)aValue);
|
||||
}
|
||||
|
||||
public TableCellRenderer getRenderer(TreeNodeOnVcsRevision p0) {
|
||||
return myBaseColumn.getRenderer(p0.myRevision);
|
||||
}
|
||||
|
||||
public TableCellEditor getEditor(TreeNodeOnVcsRevision item) {
|
||||
return myBaseColumn.getEditor(item.myRevision);
|
||||
}
|
||||
|
||||
public String getMaxStringValue() {
|
||||
final String superValue = myBaseColumn.getMaxStringValue();
|
||||
if (superValue != null) return superValue;
|
||||
return getMaxValue(myBaseColumn.getName());
|
||||
}
|
||||
|
||||
public int getAdditionalWidth() {
|
||||
return myBaseColumn.getAdditionalWidth();
|
||||
}
|
||||
|
||||
public int getWidth(JTable table) {
|
||||
return myBaseColumn.getWidth(table);
|
||||
}
|
||||
|
||||
public boolean shouldBeShownIsTheTree() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldBeShownIsTheTable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object valueOf(TreeNodeOnVcsRevision o) {
|
||||
return myBaseColumn.valueOf(o.myRevision);
|
||||
}
|
||||
}
|
||||
|
||||
private class RefreshFileHistoryAction extends RefreshAction implements DumbAware {
|
||||
public RefreshFileHistoryAction() {
|
||||
super(VcsBundle.message("action.name.refresh"), VcsBundle.message("action.description.refresh"), AllIcons.Actions.Refresh);
|
||||
|
||||
Reference in New Issue
Block a user