
de.lessvoid.nifty.controls.treebox.TreeBoxItemController Maven / Gradle / Ivy
package de.lessvoid.nifty.controls.treebox;
import de.lessvoid.nifty.controls.TreeItem;
import de.lessvoid.nifty.controls.listbox.ListBoxItemController;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.logging.Logger;
/**
* This is the default controller for the items of the {@link de.lessvoid.nifty.controls.TreeBox}. It takes care for
* forwarding the clicks to the expand button the {@link de.lessvoid.nifty.controls.TreeBox} in order to update the
* display of the tree.
*
* @param the type of the object displayed in the tree
*/
public class TreeBoxItemController extends ListBoxItemController> {
@Nonnull
private static final Logger log = Logger.getLogger(TreeBoxItemController.class.getName());
/**
* The control that is parent to this tree item.
*/
@SuppressWarnings("deprecation")
@Nullable
private TreeBoxControl parentControl;
@SuppressWarnings({ "deprecation", "NullableProblems" })
void setParentControl(@Nonnull final TreeBoxControl control) {
parentControl = control;
}
/**
* This function is called in case the expand component of the tree entry is clicked. The event will be forwarded
* to the parent control in order to update the tree.
*/
public void expandButtonClicked() {
if (parentControl == null) {
log.warning("Can't handle click to expend button as long as the parent control is not applied.");
return;
}
final TreeItem item = getItem();
if (item == null || item.isLeaf()) {
return;
}
item.setExpanded(!item.isExpanded());
parentControl.updateList(item);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy