org.squirrelframework.foundation.data.HierarchyItem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of squirrel-foundation Show documentation
Show all versions of squirrel-foundation Show documentation
foundation module of squirrel framework which provided event driven infrastructure and a finite state machine implementation.
package org.squirrelframework.foundation.data;
import java.util.List;
import org.squirrelframework.foundation.component.Observable;
import org.squirrelframework.foundation.event.SquirrelEvent;
/**
* Generic tree structure interface which handles basic tree structure
* operations, e.g. get children items, get parent item, set item value and so
* on. Support event notifications for tree item operations, e.g. attach new
* item, detach old item and set new item value.
*
* @author Henry.He
*
* @param
* the type of tree item
* @param
* the type of item value
*/
public interface HierarchyItem, N> extends Observable {
List getChildren();
List getRawChildren();
List getAllRawChildren();
boolean hasChildren();
M getParent();
boolean isRoot();
M getRoot();
M detach();
N getValue();
Class> getType();
void setValue(N newValue);
List getAllChildren();
List getAllChildren(boolean includeThis, boolean isDepthFirst);
List getAllRawChildren(boolean includeThis, boolean isDepthFirst);
> T getItemProvider(Class provideType);
boolean isLeaf();
void setData(String key, Object newData);
Object removeData(String key);
Object getData(String key);
void clearData();
String toLog();
/**
*
* The {@code ItemEventListener} listens to all the events that are extended
* from {@link ItemEvent}.
*
*
*
* item.addListener(ItemEvent.class,
* new TreeItem.ItemEventListener<TreeNode, BaseEntity>() {
* @Override
* public void itemEvent(ItemEvent<TreeNode, BaseEntity> event) {
* // process event logic ...
* }
* });
*
*
*/
interface ItemEventListener, N> {
void itemEvent(ItemEvent event);
}
/**
* Base event of all the tree item events.
*/
interface ItemEvent, N> extends SquirrelEvent {
/**
* @return tree item that event happens on
*/
M getSourceItem();
}
void addListener(ItemEventListener listener);
void removeListener(ItemEventListener listener);
/**
* The {@code ValueChangeListener} listens to {@link ValueChangeEvent}.
*/
interface ValueChangeListener, N> {
void valueChange(ValueChangeEvent event);
}
/**
* The {@code ValueChangeEvent} was fired when new value was set to tree
* item.
*/
interface ValueChangeEvent, N> extends
ItemEvent {
/**
* @return old value of tree item.
*/
N getOldValue();
/**
* @return new value of tree item.
*/
N getNewValue();
}
void addListener(ValueChangeListener listener);
void removeListener(ValueChangeListener listener);
/**
* The {@code ItemRemovedListener} listens to {@link ItemRemovedEvent}.
*/
interface ItemRemovedListener, N> {
void itemRemoved(ItemRemovedEvent event);
}
/**
* The {@code ItemRemovedEvent} was fired when existed tree item was removed
* from the tree.
*/
interface ItemRemovedEvent, N> extends
ItemEvent {
/**
* @return parent of removed item
*/
M getRemovedFrom();
/**
* @return removed item
*/
M getRemovedItem();
}
void addListener(ItemRemovedListener listener);
void removeListener(ItemRemovedListener listener);
/**
* The {@code ItemAttachedListener} listens to {@link ItemAttachedEvent}.
*/
interface ItemAttachedListener, N> {
void itemAttached(ItemAttachedEvent event);
}
/**
* The {@code ItemAttachedEvent} was fired when new tree item was attached
* to the tree.
*/
interface ItemAttachedEvent, N> extends
ItemEvent {
/**
* @return parent of new item
*/
M getAddTo();
/**
* @return new item
*/
M getNewItem();
}
void addListener(ItemAttachedListener listener);
void removeListener(ItemAttachedListener listener);
}