Hello,
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