gpt4 book ai didi

java - 单击子节点的子节点,线条消失 - Primefaces 3.4 思维导图

转载 作者:行者123 更新时间:2023-12-01 15:03:09 24 4
gpt4 key购买 nike

问题本质上如上所述。在此处的示例中:

http://www.primefaces.org/showcase-labs/ui/mindmap.jsf

如果您单击 NS(s),您可以单击您选择的子节点之一,例如 ns7.google.com,然后返回 NS(s),因为连接它们的行仍然存在。

我有 6 个条目,例如 1、2、3、4、5、6。它们都以各种方式链接,并在思维导图中以颜色显示。假设“1”是根节点。然后 2,3,4,5,6 出现。假设我单击 6 - 思维导图将重新绘制以显示 6 的链接,其中 1 位于角落以显示它是根。但是,如果我单击除 1 之外的任何节点,链接线都会消失,大多数节点也是如此(我不知道为什么有时是其中一些节点,有时是不同的节点,有时是一个节点,有时是全部节点!)我不能再走回头路了。下面是思维导图 bean 和 html 的代码:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jsf;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import jpa.entities.Enginetable;
import jpa.session.EnginetableFacade;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.mindmap.DefaultMindmapNode;
import org.primefaces.model.mindmap.MindmapNode;

/**
*
* @author AOL
*/
@Named(value = "mmBean")
@RequestScoped
public class mmBean implements Serializable{

@EJB
private jpa.session.EnginetableFacade ejbFacade;
private MindmapNode root;

private MindmapNode selectedNode;

private List<Enginetable> elements;
private List<Enginetable> filteredElements;
private List<Enginetable> userlist;

private Enginetable selectedElement;
private Enginetable[] selectedElements;


private List<Enginetable> elementlist = new ArrayList<Enginetable>();

private Enginetable nodeentity = new Enginetable();
private Enginetable rootentity = new Enginetable();
private Enginetable user = new Enginetable();

private static final String[] username;

static{

username = new String[10];
username[0] = "Mercedes";
username[1] = "BMW";
username[2] = "Volvo";
username[3] = "Audi";
username[4] = "Renault";
username[5] = "Opel";
username[6] = "Volkswagen";
username[7] = "Chrysler";
username[8] = "Ferrari";
username[9] = "Ford";
}

/**
* Creates a new instance of MmBean
*/
public mmBean() {
}

@PostConstruct
public void init() {
///if(elements==null){
elements = new ArrayList<Enginetable>();
this.userlist = this.getFullList();
Enginetable entity;
//}
//remoteuser=null;
// this.populateRandomElements(elements, 10);
this.populateRandomElements(elements,6);

// filteredElements = new ArrayList<Graphelement>();
this.user = this.userlist.get(0);
this.rootentity = this.user;
root = new DefaultMindmapNode(user.getStartnode(), "Google", "006666", false);
/*MindmapNode bmw = new DefaultMindmapNode("BMW", "IP Nos", "6e9ebf", true);
MindmapNode volvo = new DefaultMindmapNode("Volvo", "Names", "6e9ebf", true);
MindmapNode audi = new DefaultMindmapNode("Audi", "Malicious ", "6e9ebf", true);
MindmapNode renault = new DefaultMindmapNode("Renault", "IP Nos", "6e9ebf", true);
MindmapNode opel = new DefaultMindmapNode("Opel", "Names", "6e9ebf", true);
MindmapNode volkwagen = new DefaultMindmapNode("Volkswagen", "Malicious ", "6e9ebf", true);
MindmapNode chrysler = new DefaultMindmapNode("Chrysler", "IP Nos", "6e9ebf", true);
MindmapNode ferrari = new DefaultMindmapNode("Ferrari", "Names", "6e9ebf", true);
MindmapNode ford = new DefaultMindmapNode("Ford", "Malicious ", "6e9ebf", true);*/


Object label = root.getLabel();


for( int i = 0 ; i < this.userlist.size() ; i++){

entity = this.userlist.get(i);


if ( !label.equals(entity.getStartnode() ) && this.user.getEndnode().equals(entity.getStartnode() ) ) { ////this.rootentity.getEndnode().equals(entity.getStartnode())

root.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "33FF00", true));

}

else if ( !label.equals(entity.getStartnode() ) && this.user.getEndnode() != entity.getStartnode() ){

root.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "CC0000", true));

}

}

}

public void setElements(List<Enginetable> elements) {
this.elements = elements;
}

public List<Enginetable> getElements() {
return elements;
}
public void setFilteredElements(List<Enginetable> filteredElements) {
//this.filteredElements = filteredElements;
this.elements=filteredElements;
}

public List<Enginetable> getFilteredElements() {
return filteredElements;
}

public void setSelectedElements(Enginetable[] selectedElements) {
this.selectedElements = selectedElements;
}

public Enginetable[] getSelectedElements() {
return selectedElements;
}

public void setSelectedElement(Enginetable selectedElement) {
this.selectedElement = selectedElement;
}

public Enginetable getSelectedElement() {
return selectedElement;
}

public MindmapNode getRoot() {
return root;
}

public MindmapNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(MindmapNode selectedNode) {
this.selectedNode = selectedNode;
}



public void onNodeSelect(SelectEvent event) {
MindmapNode node = (MindmapNode) event.getObject();


for( int i = 0 ; i < this.elements.size() ; i++){
Enginetable entity;
Object label = node.getLabel();
Object rootlabel = this.root.getLabel();

entity = userlist.get(i);

if ( entity.getStartnode() == rootlabel ){
this.rootentity = entity;
}
if ( entity.getStartnode() == label ){
this.nodeentity = entity;
}

}
//load children of select node and add via node.addNode(childNode);
//populate if not already loaded
if(node.getChildren().isEmpty()) {
this.setChildNodes( node );
}
}


public void onNodeDblselect(SelectEvent event) {
this.selectedNode = (MindmapNode) event.getObject();
}


private EnginetableFacade getFacade() {
return ejbFacade;
}



private void populateRandomElements(List<Enginetable> list, int size) {
userlist = this.getFullList();
for(int i = 0 ; i < size ; i++) {

Enginetable gel = new Enginetable();
gel.setMoveid(i);
gel.setUserid(i);
gel.setStartnode(username[i]);
gel.setEndnode(username[9-i]);
gel.setConnections(username[9-i]);
// gel.setPurpose("dubious");
// gel.setRelationship("naughty");
// gel.setExperimentid(1);
gel.setNewinfovalue(1);
gel.setNewconnectioncost(1);
list.add(gel);
}
}

//


public Integer getMoveId(Enginetable ent) {
return ent.getMoveid();
}

public void setMoveId(Enginetable ent, Integer id) {
ent.setMoveid(id);
}

public Integer getUserId(Enginetable ent) {
return ent.getMoveid();
}

public void setUserId(Enginetable ent, Integer id) {
ent.setMoveid(id);
}

public String getStartNode(Enginetable ent) {
return ent.getStartnode();
}

public void setStartNode(Enginetable ent, String startnode) {
ent.setStartnode(startnode);
}

public String getEndNode(Enginetable ent) {
return ent.getEndnode();
}

public void setEndNode(Enginetable ent, String endnode) {
ent.setEndnode(endnode);
}

/* public int getExperimentid(Enginetable ent) {
return ent.getExperimentid();
}

public void setExperimentid(Enginetable ent, int experimentid) {
ent.setExperimentid(experimentid);
}*/

public int getNewInfoValue(Enginetable ent) {
return ent.getNewinfovalue();
}

public void setNewInfoValue(Enginetable ent, int totalinfovalue) {
ent.setNewinfovalue(totalinfovalue);
}

public String getConnections(Enginetable ent) {
return ent.getConnections();
}

public void setConnections(Enginetable ent, String connections) {
ent.setConnections(connections);
}

public String getNewConnections(Enginetable ent) {
return ent.getConnections();
}

public void setNewConnections(Enginetable ent, String newconnections) {
ent.setConnections( newconnections );
}

/* public String getUserName(Enginetable ent) {
return ent.getUsername();
}

public void setUsername(Enginetable ent, String name) {
ent.setUsername(name);
}
*/

// ADDED BY AODHÁN

public List<Enginetable> getListByUsername(String user){
return this.ejbFacade.getEnginetableByUsername(user);
}

public List<Enginetable> getListByUserID( int id ){
return this.ejbFacade.getEnginetableByUserid(id);
}

public List<Enginetable> getFullList(){
return this.ejbFacade.getFullEnginetable();
}

public void setChildNodes( MindmapNode node ){

for( int i = 0 ; i < this.userlist.size() ; i++){
Enginetable entity;

entity = this.userlist.get(i);

if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() != null : !this.nodeentity.getEndnode().equals(entity.getStartnode())) && (this.rootentity.getEndnode() == null ? entity.getStartnode() == null : this.rootentity.getEndnode().equals(entity.getStartnode())) ) {

node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "33FF00"));

}

else if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() == null : this.nodeentity.getEndnode().equals(entity.getStartnode())) && (this.rootentity.getEndnode() == null ? entity.getStartnode() == null : this.rootentity.getEndnode().equals(entity.getStartnode())) ) {

node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "0066FF"));

}

else if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() == null : this.nodeentity.getEndnode().equals(entity.getStartnode())) && (this.rootentity.getEndnode() == null ? entity.getStartnode() != null : !this.rootentity.getEndnode().equals(entity.getStartnode())) ) {

node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "FFCC00"));

}

else if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() != null : !this.nodeentity.getEndnode().equals(entity.getStartnode())) && (this.rootentity.getEndnode() == null ? entity.getStartnode() != null : !this.rootentity.getEndnode().equals(entity.getStartnode())) ) {

node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "CC0000"));

}

}
}
}

HTML:

<h:form>
<p:mindmap value="#{mmBean.root}" style="width:100%;height:600px">
<p:ajax event="select" listener="#{mmBean.onNodeSelect}" />
<p:ajax event="dblselect" listener="#{mmBean.onNodeDblselect}" update="output" oncomplete="details.show()"/>
</p:mindmap>

<p:dialog widgetVar="details" header="Node Details" resizable="false" modal="true" showEffect="fade" hideEffect="fade">
<h:outputText id="output" value="#{mmBean.selectedNode.data}" />
</p:dialog>
</h:form>

非常感谢任何帮助。

最佳答案

我也遇到过同样的问题,并通过简单地添加 @SessionScoped 而不是 @RequestScoped 来消除它。

现在我可以选择并双击,如 PF 示例所示。

关于java - 单击子节点的子节点,线条消失 - Primefaces 3.4 思维导图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343389/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com