我如何向我的 gwt 树提供数据

发布于 2024-08-28 04:23:51 字数 1885 浏览 5 评论 0 原文

所以我需要为我的 gwt 项目创建一棵包含树项的树。我正在使用复合模式来存储需要放置在树中的所有信息。

用户有一个扩展层次结构的根文件夹,该根文件夹有一个层次结构对象列表,可以是文件位置或文件夹。我遇到的麻烦是根据这种模式构建我的树。这些数据全部使用 hibernate 存储在 mysql 数据库中

我如何能够将其实现为 gwt 中的树。

此外,我创建的树项目必须引用回该对象,以便我可以重命名或移动它。

@Entity
@Table(name ="HIERARCHY")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(
name = "HIERARCHY_TYPE", discriminatorType = DiscriminatorType.STRING)      
public abstract class  Hierarchy implements Serializable {

 @Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "hierarchy_id", updatable = false, nullable = false)
private int hId;



@Entity
@DiscriminatorValue("F")
public class Folder extends Hierarchy  {

@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@JoinTable(name = "FOLDER_JOIN_FILELOCATION", joinColumns = { 
    @JoinColumn(name = "folder_id") }, inverseJoinColumns = { 
    @JoinColumn(name = "file_information_id") })
private List<Hierarchy> children = new ArrayList<Hierarchy>() ;
@Column(name = "folder_name")
private String folderName;

@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinTable(name="FOLDER_JOIN_FOLDER",
    joinColumns = @JoinColumn(name="parent_folder_id"),
    inverseJoinColumns = @JoinColumn(name="folder_ID")
 ) 
private Hierarchy parent;




@Entity
@DiscriminatorValue("FI")
public class FileInformation extends Hierarchy  {


@Column (name = "location")
private String location;

@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
 @JoinTable(name="FILEINFORMATION_JOIN_FOLDER",
    joinColumns = @JoinColumn(name="filelocation_id"),
    inverseJoinColumns = @JoinColumn(name="folder_ID")
)  
private Hierarchy parent;

现在我想基于这个结构构建树。如果我的逻辑是错误的,你能给我指出正确的方向吗?

Tree tree = new Tree();

现在,对于文件夹中的每个文件夹或文件信息,我想创建一个树项目?该树项还必须引用回对象本身

So i need to create a tree with tree items for my gwt project. i am using the composite pattern to store all the information i need to be placed within a tree.

A User has a root Folder that extends Hierarchy, this root Folder then has a list of Hierarchy objects, that can be FileLocations or Folders. Trouble i am having is building my tree based on this pattern. this data is all stored using hibernate in a mysql database

How would i be able to implement this as a tree in gwt.

Also the tree item that i create would have to reference back to the object so i can rename or move it.

@Entity
@Table(name ="HIERARCHY")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(
name = "HIERARCHY_TYPE", discriminatorType = DiscriminatorType.STRING)      
public abstract class  Hierarchy implements Serializable {

 @Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "hierarchy_id", updatable = false, nullable = false)
private int hId;



@Entity
@DiscriminatorValue("F")
public class Folder extends Hierarchy  {

@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@JoinTable(name = "FOLDER_JOIN_FILELOCATION", joinColumns = { 
    @JoinColumn(name = "folder_id") }, inverseJoinColumns = { 
    @JoinColumn(name = "file_information_id") })
private List<Hierarchy> children = new ArrayList<Hierarchy>() ;
@Column(name = "folder_name")
private String folderName;

@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinTable(name="FOLDER_JOIN_FOLDER",
    joinColumns = @JoinColumn(name="parent_folder_id"),
    inverseJoinColumns = @JoinColumn(name="folder_ID")
 ) 
private Hierarchy parent;




@Entity
@DiscriminatorValue("FI")
public class FileInformation extends Hierarchy  {


@Column (name = "location")
private String location;

@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
 @JoinTable(name="FILEINFORMATION_JOIN_FOLDER",
    joinColumns = @JoinColumn(name="filelocation_id"),
    inverseJoinColumns = @JoinColumn(name="folder_ID")
)  
private Hierarchy parent;

now so i want to build the tree based on this structure. if my logic is wrong could you point me in the right direction

Tree tree = new Tree();

Now for every Folder or fileInformation within a Folder i want to create a tree item? that tree item must also reference back to the object itself

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆啦不做梦 2024-09-04 04:23:51

这一切都可以通过向您的 GWT-RPC 请求轻松完成服务器和 TreeItem 类。

启动时(或者当您想要第一次显示树时),调用您的服务,并在回调中使用 tree.addItem() 将这些项目添加到树中。这在很大程度上取决于数据库的结构以及将信息传递给客户端的方式,但这应该可以帮助您入门。

另一种选择是使用 GWT-incubatorFastTree 类,适用于显示大树,并用于例如,仅在打开文件夹时加载数据。

This can all be done pretty easily with GWT-RPC requests to your server and the Tree and TreeItem classes in the client.

On startup (or when you want to display the tree for the first time), make a call to your service, and in the callback add those items to the tree using tree.addItem(). A lot of how easy this is will depend on how your database is structured and how you pass the information to the client, but that should get you started.

Another option is to use GWT-incubator's FastTree class, which is good for showing large trees, and for only loading data when a folder is opened, for example.

一身骄傲 2024-09-04 04:23:51

您必须遍历文件夹/层次结构并找到节点,然后将此父节点添加到一个TreeItemt,然后找到子节点,并将它们添加到 t,现在对于找到的每个子项,执行相同的操作。

You have to traverse your Folder / Hierarchy and find the parent node, then add this parent to the one TreeItem t, then find the parents children, and add them to t, now for each children found, do the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文