java - 用于多节点编辑的 TreeCellEditor
问题描述
有人可以展示一个可以在一次编辑中更新多个节点的 TreeCellEditor 示例吗?据我所知,GetCellEditorValue()
只会更新一个节点。
我的编辑器当前接收选定的节点,比较它们并显示不同的值,同时显示节点共有的其他值。
我的构造函数初始化“myDevice”。
public DeviceEditor(Collection<DefaultMutableTreeNode> nodes) throws NoSuchFieldException {
System.out.println("CREATING NEW EDITOR \n");
this.nodes = nodes;
ObjectMatcher matcher = new ObjectMatcher();
try {
myDevice = matcher.match(nodes, DefaultDevice.CREATE_MULTIVALUE_DEFAULTDEVICE(), new DefaultDevice());
//System.out.println("Device= " + myDevice.getAddress() + " " + myDevice.getHostName());
} catch (Exception e) {
System.out.println(e);
}
initComponents();
}
TreeCellEditor 的方法
@Override
public Component getTreeCellEditorComponent(JTree jtree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
// this.tree = jtree;
return this;
}
@Override
public Object getCellEditorValue() {
//This value is what is populated into the JTree
return this.myDevice;
}
@Override
public boolean isCellEditable(EventObject eo) {
//should be true only if it's a leaf.
return true;
}
@Override
public boolean shouldSelectCell(EventObject eo) {
//Don't Select
return false;
}
@Override
public boolean stopCellEditing() {
try {
System.out.println("\n Cell Editing Stopped");
//update myDevice
if (!this.addressField.getText().equals(DefaultDevice.MULTIVALUE)) {
myDevice.setAddress(this.addressField.getText());
}
myDevice.setDeviceType(this.deviceTypeField.getText());
myDevice.setLocation(this.locationField.getText());
myDevice.setSerialNumber(this.serialField.getText());
myDevice.setUser(this.userField.getText());
myDevice.setPassword(new String(this.passwordField.getPassword()));
myDevice.setVendor(this.vendorField.getText());
myDevice.setModel(this.modelField.getText());
myDevice.setOS(this.osField.getText());
myDevice.setDescription(this.descriptionField.getText());
myDevice.setVersion(this.versionField.getText());
myDevice.setDeviceType(this.deviceTypeField.getText());
myDevice.setDisplayHostName(this.hostNameCheckBox.isSelected());
myDevice.setDisplayIPV4Address(this.ipV4checkBox.isSelected());
myDevice.setDisplayIPV6Address(this.ipV6CheckBox.isSelected());
DeviceEditor.UPDATE_DEVICES(nodes, myDevice);
return true;
} catch (IPConverter.InvalidIPException ex) {
Exceptions.printStackTrace(ex);
return false;
}
}
解决方案
推荐阅读
- c# - DeveloperExceptionPage 未通过 .NetCore 2.2 中的 Ajax 调用显示
- android - 将谷歌预测限制在特定国家/地区不起作用
- reactjs - 如何在 React 上仅打开 1 个面板?
- c++ - OpenCV 并从 OutputArrays 或 (Mat) 读取数据
- scala - pac4j-play SecureAction(扩展),类型不匹配
- qemu - sgx:EPC 部分为零
- vue.js - 为什么overflow-x hidden 与客户端边界矩形有交互
- splunk - 如何放置像算术这样的条件输出,值 o/p 应该大于 = 30k 并且小于 = 30 k
- azure - XSLT 在逻辑应用程序中出现异常
- php - SOAP-ERROR: Parsing WSDL: could't load from '...?wsdl' : failed to load external entity