我有一个 JXTreeTable,它在左侧有一个节点树(不同的数据类型),在右侧有一个网格(默认情况下)。
现在我希望所有显示的值(也是树标题)都取自 getValueAt(row,column) 方法,而不是树节点由它们的 toString() 方法呈现
如何强制 JXTreeTable 不采用特定于类的 toString() 并使用 getValueAt(...) 返回的值?
谢谢!
这是我的模型:
public class TreeTableGroupTreeTableModel extends AbstractTreeTableModel {
private final static String[] COLUMN_NAMES = { "Tree",
"Add/Edit", "Remove" };
//Group-Hierarchy:
private JXGroup groupRootObject;
public TreeTableGroupTreeTableModel(JXGroup groupRoot) {
this.groupRootObject = groupRoot;
}
// Here is my structure:
//GROUP 1-1 ModuleAggregation 1-* Modules 1-1 JXGroupAccessMemberAggregation 1-* JXGroupAccessSimpleUserObjectLeaf
/**
* Returns the value for the node at columnIndex. The node must be managed
* by this model. Unamanaged nodes should throw an IllegalArgumentException.
*
*
* node - the node whose value is to be queried column - the column whose
* value is to be queried
*/
@Override
public Object getValueAt(Object node, int column) {
System.out.println(node.getClass());
if (node instanceof JXGroup) {
switch (column) {
case 0:
return "this should render this string instead of the class tostring()";//((JXGroup) node);
case 1:
case 2:
return "";
}
} else if (node instanceof JXGroupAccessModuleAggregation) {
switch (column) {
case 0:
return "Modules";
case 1:
return "ADD";
case 2:
return "REMOVE ALL";
}
} else if (node instanceof JXGroupAccessModule) {
switch (column) {
case 0:
return ((JXGroupAccessModule) node).getModule();
case 1:
return "ADD";
case 2:
return "REMOVE";
}
} else if (node instanceof JXGroupAccessMemberAggregation) {
switch (column) {
case 0:
return "Members";
case 1:
return "ADD";
case 2:
return "REMOVE ALL";
}
} else if (node instanceof JXGroupAccessSimpleUserObjectLeaf) {
switch (column) {
case 0:
SimpleUserObject c = FunctionsUser.getUser(
metaDataPackage.getUsers(),
((JXGroupAccessSimpleUserObjectLeaf) node).getUserId().getId());
return c.getShowAs();
case 1:
return "";
case 2:
return "REMOVE";
}
}
return null;
}
/**
* Sets the value for the node at columnIndex to value. The node must be
* managed by this model. Unamanaged nodes should throw an
* IllegalArgumentException.
*
* value - the new value node - the node whose value is to be changed column
* - the column whose value is to be changed
*/
@Override
public void setValueAt(Object value, Object node, int column) {
return; // changes are not allowed
}
@Override
public Object getRoot() {
return groupRootObject;
}
@Override
public int getColumnCount() {
return COLUMN_NAMES.length;
}
@Override
public String getColumnName(int column) {
return COLUMN_NAMES[column];
}
@Override
public boolean isCellEditable(Object node, int column) {
return false;
}
@Override
public boolean isLeaf(Object node) {
return node instanceof JXGroupAccessCategoryLeaf
|| node instanceof JXGroupAccessChapterLeaf
|| node instanceof JXGroupAccessEntryLeaf
|| node instanceof JXGroupAccessSimpleUserObjectLeaf;
}
@Override
public int getChildCount(Object obj) {
if (!(obj instanceof JXICountable)) {
System.out.println("parsing error. should be JXCountable (but is "
+ obj.getClass() + ")");
return 0;
}
JXICountable obj2 = (JXICountable) obj;
return obj2.getChildrenCount();
}
@Override
public Object getChild(Object parent, int index) {
if (parent instanceof JXITreeNodeAble) {
return ((JXITreeNodeAble) parent).getChild(index);
}
throw new IllegalArgumentException(
"parent is not a member of JXITreeNodeAble");
}
@Override
public int getIndexOfChild(Object parent, Object child) {
if (parent instanceof JXITreeNodeAble) {
return ((JXITreeNodeAble) parent).getIndexOfChild(child);
}
throw new IllegalArgumentException(
"parent is not a member of JXITreeNodeAble");
}
}