KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > observable > tree > AbstractObservableTree


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Brad Reynolds - bug 164134
11  *******************************************************************************/

12
13 package org.eclipse.core.internal.databinding.observable.tree;
14
15 import org.eclipse.core.databinding.observable.AbstractObservable;
16 import org.eclipse.core.databinding.observable.Realm;
17 import org.eclipse.core.databinding.util.Policy;
18 import org.eclipse.core.internal.databinding.BindingMessages;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.ListenerList;
21 import org.eclipse.core.runtime.Status;
22
23 /**
24  * @since 3.3
25  *
26  */

27 public abstract class AbstractObservableTree extends AbstractObservable
28         implements IObservableTree {
29
30     private boolean stale;
31
32     private ListenerList treeListeners = new ListenerList(ListenerList.IDENTITY);
33
34     /**
35      * @param realm
36      */

37     public AbstractObservableTree(Realm realm) {
38         super(realm);
39     }
40
41     public void addChild(TreePath parentPath, Object JavaDoc childElement) {
42         throw new UnsupportedOperationException JavaDoc();
43     }
44
45     public void addTreeChangeListener(ITreeChangeListener listener) {
46         treeListeners.add(listener);
47     }
48
49     public int getChildCount(TreePath parentPath) {
50         return getChildren(parentPath).length;
51     }
52
53     public boolean hasChildren(TreePath parentPath) {
54         return getChildCount(parentPath) > 0;
55     }
56
57     public void insertChild(TreePath parentPath, int index, Object JavaDoc childElement) {
58         throw new UnsupportedOperationException JavaDoc();
59     }
60
61     public boolean isLazy() {
62         return false;
63     }
64
65     public boolean isOrdered() {
66         return false;
67     }
68
69     public void removeChild(TreePath parentPath, Object JavaDoc childElement) {
70         throw new UnsupportedOperationException JavaDoc();
71     }
72
73     public void removeChild(TreePath parentPath, int index) {
74         throw new UnsupportedOperationException JavaDoc();
75     }
76
77     public void removeTreeChangeListener(ITreeChangeListener listener) {
78         treeListeners.remove(listener);
79     }
80
81     public void setChildCount(TreePath parentPath, int count) {
82         throw new UnsupportedOperationException JavaDoc();
83     }
84
85     public void setChildren(TreePath parentPath, Object JavaDoc[] children) {
86         throw new UnsupportedOperationException JavaDoc();
87     }
88
89     public void updateChildren(IChildrenUpdate update) {
90         TreePath parent = update.getParent();
91         Object JavaDoc[] children = getChildren(parent);
92         for (int i = 0; i < update.getLength(); i++) {
93             int targetIndex = update.getOffset() + i;
94             if (targetIndex < children.length) {
95                 update.setChild(children[targetIndex], targetIndex);
96             } else {
97                 update
98                         .setStatus(new Status(
99                                 IStatus.WARNING,
100                                 Policy.JFACE_DATABINDING,
101                                 IStatus.OK,
102                                 BindingMessages
103                                         .getString(BindingMessages.INDEX_OUT_OF_RANGE),
104                                         null));
105             }
106         }
107         update.done();
108     }
109
110     public void updateChildrenCount(IChildrenCountUpdate update) {
111         TreePath[] parents = update.getParents();
112         for (int i = 0; i < parents.length; i++) {
113             update.setChildCount(parents[i], getChildCount(parents[i]));
114         }
115         update.done();
116     }
117
118     public void updateHasChildren(IHasChildrenUpdate update) {
119         TreePath[] parents = update.getElements();
120         for (int i = 0; i < parents.length; i++) {
121             update.setHasChilren(parents[i], hasChildren(parents[i]));
122         }
123         update.done();
124     }
125
126     public boolean isStale() {
127         return stale;
128     }
129
130     /**
131      * @param stale
132      */

133     public void setStale(boolean stale) {
134         this.stale = stale;
135         if (stale) {
136             fireStale();
137         }
138     }
139
140     protected void fireTreeChange(TreeDiff diff) {
141         // fire general change event first
142
fireChange();
143
144         Object JavaDoc[] listeners = treeListeners.getListeners();
145         TreeChangeEvent event = new TreeChangeEvent(this, diff);
146         for (int i = 0; i < listeners.length; i++) {
147             ((ITreeChangeListener) listeners[i]).handleTreeChange(event);
148         }
149     }
150
151 }
152
Popular Tags