mirror of https://gitee.com/makejava/EasyCode.git
优化自动配置宽度问题
This commit is contained in:
parent
f3c904a0ee
commit
a56da01141
|
@ -1,8 +1,6 @@
|
||||||
package com.sjhy.plugin.factory;
|
package com.sjhy.plugin.factory;
|
||||||
|
|
||||||
import com.intellij.openapi.ui.ComboBox;
|
import com.intellij.openapi.ui.ComboBox;
|
||||||
import com.intellij.ui.BooleanTableCellEditor;
|
|
||||||
import com.intellij.ui.JBColor;
|
|
||||||
import com.intellij.ui.components.JBTextField;
|
import com.intellij.ui.components.JBTextField;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -10,7 +8,6 @@ import javax.swing.table.TableCellEditor;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表格编辑器构建工厂类
|
* 表格编辑器构建工厂类
|
||||||
|
@ -37,10 +34,6 @@ public class CellEditorFactory {
|
||||||
return new DefaultCellEditor(comboBox);
|
return new DefaultCellEditor(comboBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TableCellEditor createBooleanEditor() {
|
|
||||||
return new BooleanTableCellEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文本框编辑器
|
* 创建文本框编辑器
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.sjhy.plugin.ui;
|
||||||
|
|
||||||
import com.intellij.openapi.ui.ComboBoxTableRenderer;
|
import com.intellij.openapi.ui.ComboBoxTableRenderer;
|
||||||
import com.intellij.openapi.ui.DialogWrapper;
|
import com.intellij.openapi.ui.DialogWrapper;
|
||||||
|
import com.intellij.ui.BooleanTableCellEditor;
|
||||||
import com.intellij.ui.BooleanTableCellRenderer;
|
import com.intellij.ui.BooleanTableCellRenderer;
|
||||||
import com.intellij.ui.ToolbarDecorator;
|
import com.intellij.ui.ToolbarDecorator;
|
||||||
import com.intellij.ui.table.JBTable;
|
import com.intellij.ui.table.JBTable;
|
||||||
|
@ -54,19 +55,30 @@ public class ConfigTableDialog extends DialogWrapper {
|
||||||
JBTable table = new JBTable(model);
|
JBTable table = new JBTable(model);
|
||||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
|
||||||
|
int totalWidth = 0;
|
||||||
|
|
||||||
// 配置列编辑器
|
// 配置列编辑器
|
||||||
table.getColumn("name").setCellEditor(CellEditorFactory.createTextFieldEditor());
|
TableColumn nameColumn = table.getColumn("name");
|
||||||
|
nameColumn.setCellEditor(CellEditorFactory.createTextFieldEditor());
|
||||||
|
nameColumn.setMinWidth(100);
|
||||||
|
totalWidth+=100;
|
||||||
TableColumn typeColumn = table.getColumn("type");
|
TableColumn typeColumn = table.getColumn("type");
|
||||||
typeColumn.setCellRenderer(new ComboBoxTableRenderer<>(GlobalDict.DEFAULT_JAVA_TYPE_LIST));
|
typeColumn.setCellRenderer(new ComboBoxTableRenderer<>(GlobalDict.DEFAULT_JAVA_TYPE_LIST));
|
||||||
typeColumn.setCellEditor(CellEditorFactory.createComboBoxEditor(true, GlobalDict.DEFAULT_JAVA_TYPE_LIST));
|
typeColumn.setCellEditor(CellEditorFactory.createComboBoxEditor(true, GlobalDict.DEFAULT_JAVA_TYPE_LIST));
|
||||||
typeColumn.setMinWidth(120);
|
typeColumn.setMinWidth(120);
|
||||||
table.getColumn("comment").setCellEditor(CellEditorFactory.createTextFieldEditor());
|
totalWidth+=120;
|
||||||
|
TableColumn commentColumn = table.getColumn("comment");
|
||||||
|
commentColumn.setCellEditor(CellEditorFactory.createTextFieldEditor());
|
||||||
|
commentColumn.setMinWidth(140);
|
||||||
|
totalWidth+=140;
|
||||||
// 其他附加列
|
// 其他附加列
|
||||||
for (ColumnConfig columnConfig : CurrGroupUtils.getCurrColumnConfigGroup().getElementList()) {
|
for (ColumnConfig columnConfig : CurrGroupUtils.getCurrColumnConfigGroup().getElementList()) {
|
||||||
TableColumn column = table.getColumn(columnConfig.getTitle());
|
TableColumn column = table.getColumn(columnConfig.getTitle());
|
||||||
switch (columnConfig.getType()) {
|
switch (columnConfig.getType()) {
|
||||||
case TEXT:
|
case TEXT:
|
||||||
column.setCellEditor(CellEditorFactory.createTextFieldEditor());
|
column.setCellEditor(CellEditorFactory.createTextFieldEditor());
|
||||||
|
column.setMinWidth(120);
|
||||||
|
totalWidth+=120;
|
||||||
break;
|
break;
|
||||||
case SELECT:
|
case SELECT:
|
||||||
if (StringUtils.isEmpty(columnConfig.getSelectValue())) {
|
if (StringUtils.isEmpty(columnConfig.getSelectValue())) {
|
||||||
|
@ -80,10 +92,14 @@ public class ConfigTableDialog extends DialogWrapper {
|
||||||
column.setCellRenderer(new ComboBoxTableRenderer<>(split));
|
column.setCellRenderer(new ComboBoxTableRenderer<>(split));
|
||||||
column.setCellEditor(CellEditorFactory.createComboBoxEditor(false, split));
|
column.setCellEditor(CellEditorFactory.createComboBoxEditor(false, split));
|
||||||
}
|
}
|
||||||
|
column.setMinWidth(100);
|
||||||
|
totalWidth+=100;
|
||||||
break;
|
break;
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
column.setCellRenderer(new BooleanTableCellRenderer());
|
column.setCellRenderer(new BooleanTableCellRenderer());
|
||||||
column.setCellEditor(CellEditorFactory.createBooleanEditor());
|
column.setCellEditor(new BooleanTableCellEditor());
|
||||||
|
column.setMinWidth(60);
|
||||||
|
totalWidth+=60;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -92,7 +108,7 @@ public class ConfigTableDialog extends DialogWrapper {
|
||||||
|
|
||||||
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
|
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
|
||||||
this.mainPanel.add(decorator.createPanel(), BorderLayout.CENTER);
|
this.mainPanel.add(decorator.createPanel(), BorderLayout.CENTER);
|
||||||
this.mainPanel.setMinimumSize(new Dimension(600, 300));
|
this.mainPanel.setMinimumSize(new Dimension(totalWidth, Math.max(300, totalWidth / 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue