}
}
dependencies = new HashMap<String, List<String>>();
boxes = new HashMap<String, CheckBox>();
GWTJahiaNodeTreeFactory treeGridFactory = new GWTJahiaNodeTreeFactory(Arrays.asList("/permissions"), Arrays.asList(GWTJahiaNode.ICON, GWTJahiaNode.CHILDREN_INFO, "j:dependencies"));
treeGridFactory.setOpenPath(openPath);
treeGridFactory.setNodeTypes(Arrays.asList("jnt:permission"));
BaseTreeLoader<GWTJahiaNode> loader = treeGridFactory.getLoader();
store = treeGridFactory.getStore();
final List<ColumnConfig> configs1 = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("");
column.setRenderer(new TreeGridCellRenderer());
column.setWidth(350);
configs1.add(column);
final GridCellRenderer<GWTJahiaNode> rolePermissionRenderer = new GridCellRenderer<GWTJahiaNode>() {
public Object render(final GWTJahiaNode currentNode, String property, ColumnData config,
final int rowIndex, final int colIndex, ListStore<GWTJahiaNode> s,
final Grid<GWTJahiaNode> grid) {
final CheckBox checkbox = new CheckBox();
checkbox.setValue(selection.contains(currentNode));
final GWTJahiaNode parentItem = store.getParent(currentNode);
checkbox.setToolTip(currentNode.getName());
boxes.put(currentNode.getPath(), checkbox);
checkbox.addListener(Events.Change, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent event) {
try {
if ((Boolean) ((FieldEvent) event).getValue()) {
selection.add(currentNode);
// Update dependencies
List<String> toCheck = dependencies.get(currentNode.getPath());
if (toCheck != null) {
for (String s1 : toCheck) {
CheckBox checkBox = boxes.get(s1);
if (checkBox!=null && !checkBox.getValue()) {
checkBox.setValue(true);
}
}
}
// Update children
checkbox.setData("partial", null);
List<GWTJahiaNode> l = store.getChildren(currentNode, true);
for (GWTJahiaNode node : l) {
CheckBox b = boxes.get(node.getPath());
if (b != null) {
b.setValue(true);
}
selection.remove(node);
}
// If all siblings set, set parent
if (parentItem != null) {
CheckBox parentBox = boxes.get(parentItem.getPath());
if (!parentBox.getValue()) {
List<GWTJahiaNode> siblings = store.getChildren(parentItem);
boolean checkParent = true;
for (GWTJahiaNode sibling : siblings) {
checkParent &= selection.contains(sibling);
}
if (checkParent) {
parentBox.setData("partial", null);
parentBox.setValue(true);
}
}
}
} else {
selection.remove(currentNode);
// Update dependencies
Set<String> toCheck = dependencies.keySet();
for (String s1 : toCheck) {
if (dependencies.get(s1).contains(currentNode.getPath())) {
CheckBox checkBox = boxes.get(s1);
if (checkBox != null && checkBox.getValue()) {
checkBox.setValue(false);
}
}
}
// Uncheck parent
if (parentItem != null) {
CheckBox parentBox = boxes.get(parentItem.getPath());
if (parentBox.getValue()) {
parentBox.setData("partial", Boolean.TRUE);
parentBox.setValue(false);
List<GWTJahiaNode> siblings = store.getChildren(parentItem);
for (GWTJahiaNode node : siblings) {
if (!node.getPath().equals(currentNode.getPath())) {
selection.add(node);
}
}
}
}
// Update children
if (checkbox.getData("partial") == null) {
checkbox.setData("partial", null);
List<GWTJahiaNode> l = store.getChildren(currentNode, true);
for (GWTJahiaNode node : l) {
CheckBox b = boxes.get(node.getPath());
if (b != null) {
b.setValue(false);
}
}
}
}
} catch (Exception e) {
Log.debug("Exception on "+currentNode.getPath(), e);
}
}
});
if (parentItem != null) {
CheckBox parentBox = boxes.get(parentItem.getPath());
if (parentBox.getValue()) {
checkbox.setValue(true);
selection.remove(currentNode);
}
}
return checkbox;
}
};
column = new ColumnConfig();
column.setRenderer(rolePermissionRenderer);
column.setId(engine.getNode().getName());
column.setHeader(engine.getNode().getName());
column.setWidth(100);
column.setSortable(false);
column.setGroupable(false);
configs1.add(column);
List<ColumnConfig> configs = configs1;
TreeGrid<GWTJahiaNode> treeGrid = treeGridFactory.getTreeGrid(new ColumnModel(configs));
treeGrid.setIconProvider(ContentModelIconProvider.getInstance());
treeGrid.setBorders(true);
treeGrid.setAutoExpandColumn("name");
treeGrid.setAutoExpandMax(1000);