📄 resulttreetable.java
字号:
protected void updateColumnsFromModel()
{
TableColumnModel cm = getColumnModel();
if (cm != null)
for (int columnIndex = 0; columnIndex < cm.getColumnCount(); columnIndex++)
updateColumn(cm.getColumn(columnIndex), columnIndex);
}
protected void updateColumn(TableColumn tc, int columnIndex)
{
Object o = this.params.getValue(CatalogKey.TABLE_COLUMN_CELL_EDITOR);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof TableCellEditor)
tc.setCellEditor((TableCellEditor) o);
}
o = this.params.getValue(CatalogKey.TABLE_COLUMN_CELL_RENDERER);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof TableCellRenderer)
tc.setCellRenderer((TableCellRenderer) o);
}
o = this.params.getValue(CatalogKey.TABLE_COLUMN_HEADER_RENDERER);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof TableCellRenderer)
tc.setHeaderRenderer((TableCellRenderer) o);
}
o = this.params.getValue(CatalogKey.TABLE_COLUMN_HEADER_VALUE);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null)
tc.setHeaderValue(o);
}
// Intentionally ignoring setIdentifier (not used).
o = this.params.getValue(CatalogKey.TABLE_COLUMN_MAX_WIDTH);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof Integer)
tc.setMaxWidth((Integer) o);
}
o = this.params.getValue(CatalogKey.TABLE_COLUMN_MIN_WIDTH);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof Integer)
tc.setMinWidth((Integer) o);
}
// Intentionally ignoring setModelIndex (not used).
o = this.params.getValue(CatalogKey.TABLE_COLUMN_PREFERRED_WIDTH);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof Integer)
tc.setPreferredWidth((Integer) o);
}
// Intentionally ignoring setWidth (in favor of preferredWidth).
o = this.params.getValue(CatalogKey.TABLE_COLUMN_RESIZABLE);
if (o != null && o instanceof Object[])
{
o = getObjectAt((Object[]) o, columnIndex);
if (o != null && o instanceof Boolean)
tc.setResizable((Boolean) o);
}
}
protected static class ResultListener implements ResultListListener
{
private ResultTreeTable treeTable;
public ResultListener(ResultTreeTable treeTable)
{
this.treeTable = treeTable;
}
public void listChanged(ResultListEvent e)
{
if (e != null)
{
int type = e.getType();
if (type == ResultListEvent.ADD || type == ResultListEvent.REMOVE)
{
this.treeTable.reloadResultListInSwingThread();
}
else if (e.getType() == ResultListEvent.UPDATE && e.getStartIndex() != -1 && e.getEndIndex() != -1)
{
this.treeTable.reloadResultsInSwingThread(e.getStartIndex(), e.getEndIndex());
}
else // type == ResultListEvent.PASSIVE_UPDATE
{
this.treeTable.repaintInSwingThread();
}
}
}
}
protected static class ExpansionListener implements TreeExpansionListener
{
private ResultTreeTable treeTable;
public ExpansionListener(ResultTreeTable treeTable)
{
this.treeTable = treeTable;
}
public void treeExpanded(TreeExpansionEvent event)
{
if (event != null && event.getPath() != null)
{
Object node = event.getPath().getLastPathComponent();
if (node != null && node instanceof TreeTableNode)
{
if (this.treeTable != null)
{
this.treeTable.nodeExpanded((TreeTableNode) node);
}
}
}
}
public void treeCollapsed(TreeExpansionEvent event)
{
}
}
protected static class MouseListener implements MouseMotionListener
{
private ResultTreeTable treeTable;
public MouseListener(ResultTreeTable treeTable)
{
this.treeTable = treeTable;
}
public void mouseDragged(MouseEvent event)
{
}
public void mouseMoved(MouseEvent event)
{
if (event != null)
if (this.treeTable != null)
this.treeTable.mouseMoved(event);
}
}
protected static Boolean asBoolean(Object o)
{
if (o == null)
return null;
if (o instanceof Boolean)
return (Boolean) o;
String s = o.toString();
if (s == null)
return null;
return Boolean.parseBoolean(s.trim());
}
protected static Integer asInteger(Object o)
{
if (o == null)
return null;
if (o instanceof Number)
return ((Number) o).intValue();
String s = o.toString();
if (s == null)
return null;
try
{
return Integer.parseInt(s.trim());
}
catch (Exception e)
{
String message = "catalog.CannotConvertToInteger " + s;
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
return null;
}
protected static Boolean[] asBooleanArray(Object o)
{
if (o == null)
return null;
if (o instanceof Boolean[])
return (Boolean[]) o;
String[] s = asStringArray(o);
if (s == null)
return null;
Boolean[] array = new Boolean[s.length];
for (int i = 0; i < s.length; i++)
array[i] = asBoolean(s[i]);
return array;
}
protected static Integer[] asIntegerArray(Object o)
{
if (o == null)
return null;
if (o instanceof Integer[])
return (Integer[]) o;
String[] s = asStringArray(o);
if (s == null)
return null;
Integer[] array = new Integer[s.length];
for (int i = 0; i < s.length; i++)
array[i] = asInteger(s[i]);
return array;
}
protected static String[] asStringArray(Object o)
{
if (o == null)
return null;
if (o instanceof String[])
return (String[]) o;
String s = o.toString();
if (s == null)
return null;
return s.split(",");
}
protected static Class[] asClassArray(Object o)
{
if (o == null)
return null;
if (o instanceof Class[])
return (Class[]) o;
String[] s = asStringArray(o);
if (s == null)
return null;
Class[] array = new Class[s.length];
for (int i = 0; i < s.length; i++)
array[i] = getClassForName(s[i]);
return array;
}
protected static Object[] asInstanceArray(Object o)
{
if (o == null)
return null;
if (o instanceof Object[])
return (Object[]) o;
String[] s = asStringArray(o);
if (s == null)
return null;
Object[] array = new Object[s.length];
for (int i = 0; i < s.length; i++)
{
Class<?> cls = getClassForName(s[i]);
if (cls != null)
array[i] = newInstanceOf(cls);
}
return array;
}
protected static Object[] asPropertyKeys(Object o, int columnCount)
{
if (o == null)
return null;
if (o instanceof Object[])
return (Object[]) o;
String[] s = asStringArray(o);
if (s == null)
return null;
Object[] array = new Object[s.length];
for (int i = 0; i < s.length; i++)
{
array[i] = null;
if (columnCount > 0 && (i % (1 + columnCount)) == 0)
array[i] = getClassForName(s[i]);
if (array[i] == null)
array[i] = s[i];
}
return array;
}
protected static Class<?> getClassForName(String className)
{
Class<?> cls = null;
try
{
if (className != null && className.length() > 0)
cls = Class.forName(className.trim());
}
catch (Exception e)
{
String message = "catalog.CannotCreateClassForName " + className;
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
return cls;
}
protected static Object newInstanceOf(Class<?> cls)
{
Object obj = null;
try
{
if (cls != null)
obj = cls.newInstance();
}
catch (Exception e)
{
String message = "catalog.CannotCreateInstanceOfClass " + cls;
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
return obj;
}
protected Object getObjectAt(Object[] array, int index)
{
if (array == null)
return null;
if (index < 0 || index >= array.length)
return null;
return array[index];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -