001: /* TreeDataEvent.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Aug 10 2007, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zul.event;
020:
021: import org.zkoss.zul.TreeModel;
022:
023: /**
024: * Defines an event that encapsulates changes to a tree.
025: *
026: * @author Jeff Liu
027: * @since ZK 3.0.0
028: */
029: public class TreeDataEvent {
030: /** Identifies changing contents of nodes. */
031: public static final int CONTENTS_CHANGED = 0;
032: /** Identifies the addition of children to a node. */
033: public static final int INTERVAL_ADDED = 1;
034: /** Identifies the removal of children to a node. */
035: public static final int INTERVAL_REMOVED = 2;
036:
037: private final TreeModel _model;
038: private final int _type;
039: private final int _indexFrom;
040: private final int _indexTo;
041: private final Object _parent;
042:
043: /** Contructor.
044: *
045: * @param type one of {@link #CONTENTS_CHANGED},
046: * {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}.
047: * @param parent - the parent node that its children being modified .
048: * @param indexFrom the lower index of the change range
049: * @param indexTo the upper index of the change range
050: */
051: public TreeDataEvent(TreeModel model, int type, Object parent,
052: int indexFrom, int indexTo) {
053: if (model == null)
054: throw new NullPointerException();
055: checkInterval(indexFrom, indexTo, model.getChildCount(parent));
056: _model = model;
057: _type = type;
058: _parent = parent;
059: _indexFrom = indexFrom;
060: _indexTo = indexTo;
061: }
062:
063: /*
064: * Check the interval
065: */
066: private static void checkInterval(int from, int to, int len) {
067: if (from > to)
068: throw new IllegalArgumentException(
069: "'from' should be less than or equal to 'to'. from: "
070: + from + ", to: " + to);
071: if (from < 0)
072: throw new ArrayIndexOutOfBoundsException(
073: "Out of bound. from : " + from);
074: }
075:
076: /** Returns the tree model that fires this event.
077: */
078: public TreeModel getModel() {
079: return _model;
080: }
081:
082: /** Returns the event type. One of {@link #CONTENTS_CHANGED},
083: * {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}.
084: */
085: public int getType() {
086: return _type;
087: }
088:
089: /**
090: * Returns the parent node that one of its children being modified
091: * @return the parent node that one of its children being modified
092: */
093: public Object getParent() {
094: return _parent;
095: }
096:
097: /**
098: * Return the lower index of the change range
099: * @return the lower index of the change range
100: */
101: public int getIndexFrom() {
102: return _indexFrom;
103: }
104:
105: /**
106: * Return the upper index of the change range
107: * @return the upper index of the change range
108: */
109: public int getIndexTo() {
110: return _indexTo;
111: }
112:
113: }
|