Not sure if this is possible and please let me know if I’m heading in the wrong direction.
I’ve started out with:
public class MySQLContainer extends SQLContainer implements Collapsible
I’ve create two additional fields in my MySQL database:
parentid
leaf (0 or 1)
I use Filters to implement most all the Collapsible Interface methods
getChildren, getParent, rootItemIds(), etc.
My Issue:
I’m looking at using Filters to show or hide the items in TreeTable. When the folder is not collapsed I add a new OR Compare.Equal “parentid” filter
Ex. new Or(Compare.Equal(“parentid”, 0), etc))
This all works fine and shows me the correct items BUT they don’t display correctly. They display in the MySQL creation order, so my children can be above or below my folder. Now I can try to create some elaborate Sorting based on another field to keep my children appear to be inside the folders But I don’t think that’s the way to go.
Am I trying to do something with TreeTable and SQLContainer that’s not possible or impractical? Is there another direction I should head in?
I changed some stuff and looks like I got it working…
changed
public class MySQLContainer extends SQLContainer implements Collapsible
to
public class MySQLContainer extends SQLContainer implements Container.Hierarchical
I must have not have been implementing the Collapsible methods correctly. And I also added:
private SQLContainer workingContainer;
public MySQLContainer(QueryDelegate delegate) throws SQLException {
super(delegate);
workingContainer = new SQLContainer(getQueryDelegate());
}
I ran all my filters on the workingContainer attached to the same MySQL Table. For some reason addContainerFilter(new Compare.Equal(…)) caused an infinite loop in the Collection<?> rootItemIds() method. Changing it to workingContainer.addContainerFilter(new Compare.Equal(…)) fixed that.
Hi,
i have the same issue as you
can you please post your hole code
i have to publish my table in the database in a tree form so far i’ve come to acheive the connection with the database(mysql)
but i dont know how to display my data in a tree form
thKS in advance
I’m not too clear if I’m following everything correctly but where the XXXXXXX goes should be a new TableQuery pointing to the same database.
In place of the XXXXXXX put
new TableQuery(“Your Database Name”, “Your new or same Connection Pool”)
When ever you getChildren, getParent, etc I have success by only adding and removing filters on your “userContainer”. Putting any filters on your “userHierarchicalContainer” for me seemed to mess things up.
One thing to watch out for is when you commit() to your container… you’ll need to refresh the other containers pointing to the same database otherwise they’ll contain out dated information in their cache.
Thank you Dana fr your answer…I did it, so the TreeTable finally appears in the app. Now, I still can’t make it appear just as I want…Coud you please help me out with my code?..If it is not too much asking…
Here is what I have…
Conection Pool:
//works perfect, here I create "userContainer3"
public void initContainers() {
try{
TableQuery q1=new TableQuery("users", connectionPool);
q1.setVersionColumn("VERSION");
userContainer2=new SQLContainer(q1);
userContainer3=new UserHierarchicalContainer(q1);
} catch (SQLException e) {
e.printStackTrace();
}
}
public UserHierarchicalContainer getUserContainer3() {
return userContainer3;
which I call from my TreeTable:
public class OrgChart extends TreeTable {
private Conexion conexion=new Conexion();
private SQLContainer contenedor= conexion.getUserContainer3();
public static final Object[] MOSTRAR = new Object[]
{"completeName"};
public OrgChart(Ver003Application app) {
setContainerDataSource(contenedor);
setVisibleColumns(MOSTRAR);
setSizeFull();
setSelectable(true);
setImmediate(true);
setNullSelectionAllowed(false);
}
}
and here is what I think is not working, my UserHierarchicalContainer class, which is used to initiate the userContainer3:
public class UserHierarchicalContainer extends SQLContainer implements Hierarchical {
private SQLContainer userContainer=null;
public UserHierarchicalContainer(QueryDelegate delegate)
throws SQLException {
super(delegate);
userContainer = new SQLContainer(getQueryDelegate());
}
public Collection<?> getChildren(Object itemId) {
String filter = (String) getItem(itemId).getItemProperty("userId").getValue();
userContainer.addContainerFilter("parentId", filter, false, false);
ArrayList<Object> children = new ArrayList<Object>();
children.addAll(userContainer.getItemIds());
userContainer.removeContainerFilters("parentId");
if (children.size()>0){
return children;
} else
return null;
}
public Object getParent(Object itemId) {
for (Object userId: getItemIds()){
int root=(Integer) getItem(userId).getItemProperty("parentId").getValue();
if (root==0)
return false;
}
return getContainerProperty(itemId, "parentId").getValue();
}
public Collection<?> rootItemIds() {
String filter = "0";
userContainer.addContainerFilter("parentId", filter, false, false);
ArrayList<Object> root = new ArrayList<Object>();
root.addAll(userContainer.getItemIds());
userContainer.removeContainerFilters("parentId");
if (root.size()>0){
return root;
} else
return null;
}
public boolean setParent(Object itemId, Object newParentId)
throws UnsupportedOperationException {
throw new UnsupportedOperationException("Not implemented here");
}
public boolean areChildrenAllowed(Object itemId) {
return hasChildren(itemId);
}
public boolean setChildrenAllowed(Object itemId, boolean childrenAllowed)
throws UnsupportedOperationException {
throw new UnsupportedOperationException("Not implemented here");
}
public boolean isRoot(Object itemId) {
for (Object userId: getItemIds()){
int root=(Integer) getItem(userId).getItemProperty("parentId").getValue();
if (root==0)
return true;
}
return false;
}
public boolean hasChildren(Object itemId) {
for (Object userId: getItemIds()){
int leaf=(Integer) getItem(userId).getItemProperty("leaf").getValue();
if (leaf==0)
return true;
}
return false;
}
}