mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix table header glitch in update plugins dialog
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.util.ui.Table;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
@@ -26,6 +27,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class OrderPanel<T> extends JPanel{
|
||||
private String CHECKBOX_COLUMN_NAME;
|
||||
@@ -33,7 +35,7 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
private final Class<T> myEntryClass;
|
||||
private final JTable myEntryTable;
|
||||
|
||||
private final java.util.List<OrderPanelListener> myListeners = new ArrayList<OrderPanelListener>();
|
||||
private final List<OrderPanelListener> myListeners = new ArrayList<OrderPanelListener>();
|
||||
|
||||
private boolean myEntryEditable = false;
|
||||
|
||||
@@ -41,12 +43,12 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
this(entryClass, true);
|
||||
}
|
||||
|
||||
protected OrderPanel(Class<T> entryClass, boolean showSheckboxes) {
|
||||
protected OrderPanel(Class<T> entryClass, boolean showCheckboxes) {
|
||||
super(new BorderLayout());
|
||||
|
||||
myEntryClass = entryClass;
|
||||
|
||||
myEntryTable = new Table(new MyTableModel(showSheckboxes));
|
||||
myEntryTable = new JBTable(new MyTableModel(showCheckboxes));
|
||||
myEntryTable.setShowGrid(false);
|
||||
myEntryTable.setDragEnabled(false);
|
||||
myEntryTable.setShowHorizontalLines(false);
|
||||
@@ -89,11 +91,11 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
myEntryEditable = entryEditable;
|
||||
}
|
||||
|
||||
public void setCheckboxColumnName(String name) {
|
||||
public void setCheckboxColumnName(final String name) {
|
||||
final int width;
|
||||
if(name == null) {
|
||||
width = 0;
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
CHECKBOX_COLUMN_NAME = "";
|
||||
width = new JCheckBox().getPreferredSize().width;
|
||||
}
|
||||
else {
|
||||
CHECKBOX_COLUMN_NAME = name;
|
||||
@@ -101,7 +103,7 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
width = fontMetrics.stringWidth(" " + name + " ") + 4;
|
||||
}
|
||||
|
||||
final TableColumn checkboxColumn = myEntryTable.getTableHeader().getColumnModel().getColumn(getCheckboxColumn());
|
||||
final TableColumn checkboxColumn = myEntryTable.getColumnModel().getColumn(getCheckboxColumn());
|
||||
checkboxColumn.setWidth(width);
|
||||
checkboxColumn.setPreferredWidth(width);
|
||||
checkboxColumn.setMaxWidth(width);
|
||||
@@ -192,6 +194,7 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
|
||||
private class MyTableModel extends DefaultTableModel {
|
||||
private final boolean myShowCheckboxes;
|
||||
|
||||
public MyTableModel(boolean showCheckboxes) {
|
||||
myShowCheckboxes = showCheckboxes;
|
||||
}
|
||||
@@ -244,7 +247,8 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
}
|
||||
|
||||
public T getValueAt(int row) {
|
||||
return (T)((MyTableModel)myEntryTable.getModel()).getValueAt(row, getEntryColumn());
|
||||
//noinspection unchecked
|
||||
return (T)myEntryTable.getModel().getValueAt(row, getEntryColumn());
|
||||
}
|
||||
|
||||
public abstract boolean isCheckable(T entry);
|
||||
@@ -258,16 +262,14 @@ public abstract class OrderPanel<T> extends JPanel{
|
||||
return CHECKBOX_COLUMN_NAME;
|
||||
}
|
||||
|
||||
public java.util.List<T> getEntries() {
|
||||
public List<T> getEntries() {
|
||||
final TableModel model = myEntryTable.getModel();
|
||||
final int size = model.getRowCount();
|
||||
java.util.List<T> result = new ArrayList<T>(size);
|
||||
List<T> result = new ArrayList<T>(size);
|
||||
for (int idx = 0; idx < size; idx++) {
|
||||
result.add(getValueAt(idx));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+20
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -13,11 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 04-Dec-2007
|
||||
*/
|
||||
package com.intellij.openapi.updateSettings.impl;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
@@ -30,6 +25,10 @@ import com.intellij.ui.SimpleTextAttributes;
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
* Date: 04-Dec-2007
|
||||
*/
|
||||
public class DetectedPluginsPanel extends OrderPanel<PluginDownloader> {
|
||||
private final ArrayList<Listener> myListeners = new ArrayList<Listener>();
|
||||
private static final String AVAILABLE_VERSION = "available version: ";
|
||||
@@ -37,14 +36,25 @@ public class DetectedPluginsPanel extends OrderPanel<PluginDownloader> {
|
||||
|
||||
protected DetectedPluginsPanel() {
|
||||
super(PluginDownloader.class);
|
||||
getEntryTable().setDefaultRenderer(PluginDownloader.class, new ColoredTableCellRenderer(){
|
||||
protected void customizeCellRenderer(final JTable table, final Object value, final boolean selected, final boolean hasFocus, final int row, final int column) {
|
||||
final JTable entryTable = getEntryTable();
|
||||
entryTable.setTableHeader(null);
|
||||
entryTable.setDefaultRenderer(PluginDownloader.class, new ColoredTableCellRenderer() {
|
||||
protected void customizeCellRenderer(final JTable table,
|
||||
final Object value,
|
||||
final boolean selected,
|
||||
final boolean hasFocus,
|
||||
final int row,
|
||||
final int column) {
|
||||
final PluginDownloader downloader = (PluginDownloader)value;
|
||||
append(downloader.getPluginName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(PluginId.getId(downloader.getPluginId()));
|
||||
final String loadedVersion = downloader.getPluginVersion();
|
||||
if (loadedVersion != null || (ideaPluginDescriptor != null && ideaPluginDescriptor.getVersion() != null)) {
|
||||
append(" (" + (ideaPluginDescriptor != null && ideaPluginDescriptor.getVersion() != null ? INSTALLED_VERSION + ideaPluginDescriptor.getVersion() + (loadedVersion != null ? ", " : "") :"") + (loadedVersion != null ? AVAILABLE_VERSION + loadedVersion : "") + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
final String installedVersion = ideaPluginDescriptor != null && ideaPluginDescriptor.getVersion() != null
|
||||
? INSTALLED_VERSION + ideaPluginDescriptor.getVersion() + (loadedVersion != null ? ", " : "")
|
||||
: "";
|
||||
final String availableVersion = loadedVersion != null ? AVAILABLE_VERSION + loadedVersion : "";
|
||||
append(" (" + installedVersion + availableVersion + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -78,8 +88,7 @@ public class DetectedPluginsPanel extends OrderPanel<PluginDownloader> {
|
||||
myListeners.add(l);
|
||||
}
|
||||
|
||||
public static interface Listener {
|
||||
public interface Listener {
|
||||
void stateChanged();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user