dynamictreenodebean.java
来自「OperaMasks是一种基于J2EE的Web开发技术」· Java 代码 · 共 137 行
JAVA
137 行
package demo.tree;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.tree.impl.UITree;
import org.operamasks.faces.component.tree.impl.UITreeNode;
/**
*
* This managed bean is generated automatically
*/
@ManagedBean(name="DynamicTreeNodeBean", scope=ManagedBeanScope.REQUEST)
public class DynamicTreeNodeBean {
@Bind
private UITree tree;
@Bind
private String text;
@Bind
private String icon;
@Bind
private String checked;
@Bind
private String response;
@Action
public void tree_onselect(){
UITreeNode node = tree.getSelectedNode();
if(node != null){
this.text = node.getText();
this.icon = node.getIcon();
setCheckState(node);
}
process();
}
@Action
public void addNode(){
UITreeNode node = tree.getSelectedNode();
if(node != null){
UITreeNode newNode = new UITreeNode();
newNode.setText(this.text);
newNode.setIcon(this.icon);
newNode.setChecked(getCheckState());
node.add(newNode);
process();
}
}
@Action
public void deleteNode(){
UITreeNode node = tree.getSelectedNode();
if(node != null && node.getParent() instanceof UITreeNode){
if(node != null){
node.remove();
}
process();
this.text = "";
this.icon = "";
this.checked = "";
}
}
@Action
public void modifyNode(){
UITreeNode node = tree.getSelectedNode();
if(node != null){
node.setText(this.text);
node.setIcon(this.icon);
node.setChecked(getCheckState());
process();
}
}
private Boolean getCheckState(){
if("none".equals(this.checked)){
return null;
}
if("checked".equals(this.checked)){
return true;
}
if("unchecked".equals(this.checked)){
return false;
}
return null;
}
private void setCheckState(UITreeNode node){
if(node.getChecked() == null){
this.checked = "none";
}else if(Boolean.TRUE.equals(node.getChecked())){
this.checked = "checked";
}else if(Boolean.FALSE.equals(node.getChecked())){
this.checked = "unchecked";
}
}
@Action
public void tree_oncheck(){
UITreeNode node = tree.getEventNode();
if(node != null){
setCheckState(node);
process();
}
}
private void process(){
response = "";
if(tree.getEventNode() != null){
response += "响应事件的节点是:" + tree.getEventNode().getText();
response += "<br/>";
}
response += "勾中的节点是:";
for(UITreeNode node : tree.getCheckedNodes()){
response += node.getText() + ",";
}
response += "<br/>";
if(tree.getSelectedNode() != null){
response += "选中的节点是:" + tree.getSelectedNode().getText();
}
}
@Action
public void collopseAll(){
tree.collapseAll();
}
@Action
public void expandAll(){
tree.expandAll();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?