Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 383ce7bd736b |
comparison
equal
deleted
inserted
replaced
76:f05e6e8b2f2d | 78:0a55d2d5a946 |
---|---|
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 module org.eclipse.core.internal.databinding.observable.tree.AbstractObservableTree; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.core.databinding.observable.AbstractObservable; | |
18 import org.eclipse.core.databinding.observable.Realm; | |
19 import org.eclipse.core.databinding.util.Policy; | |
20 import org.eclipse.core.internal.databinding.BindingMessages; | |
21 import org.eclipse.core.runtime.IStatus; | |
22 import org.eclipse.core.runtime.ListenerList; | |
23 import org.eclipse.core.runtime.Status; | |
24 | |
25 /** | |
26 * @since 3.3 | |
27 * | |
28 */ | |
29 public abstract class AbstractObservableTree : AbstractObservable | |
30 , IObservableTree { | |
31 | |
32 private bool stale; | |
33 | |
34 private ListenerList treeListeners = new ListenerListcast(ListenerList.IDENTITY); | |
35 | |
36 /** | |
37 * @param realm | |
38 */ | |
39 public this(Realm realm) { | |
40 super(realm); | |
41 } | |
42 | |
43 public void addChild(TreePath parentPath, Object childElement) { | |
44 throw new UnsupportedOperationException(); | |
45 } | |
46 | |
47 public void addTreeChangeListener(ITreeChangeListener listener) { | |
48 treeListeners.add(listener); | |
49 } | |
50 | |
51 public int getChildCount(TreePath parentPath) { | |
52 return getChildren(parentPath).length; | |
53 } | |
54 | |
55 public bool hasChildren(TreePath parentPath) { | |
56 return getChildCount(parentPath) > 0; | |
57 } | |
58 | |
59 public void insertChild(TreePath parentPath, int index, Object childElement) { | |
60 throw new UnsupportedOperationException(); | |
61 } | |
62 | |
63 public bool isLazy() { | |
64 return false; | |
65 } | |
66 | |
67 public bool isOrdered() { | |
68 return false; | |
69 } | |
70 | |
71 public void removeChild(TreePath parentPath, Object childElement) { | |
72 throw new UnsupportedOperationException(); | |
73 } | |
74 | |
75 public void removeChild(TreePath parentPath, int index) { | |
76 throw new UnsupportedOperationException(); | |
77 } | |
78 | |
79 public void removeTreeChangeListener(ITreeChangeListener listener) { | |
80 treeListeners.remove(listener); | |
81 } | |
82 | |
83 public void setChildCount(TreePath parentPath, int count) { | |
84 throw new UnsupportedOperationException(); | |
85 } | |
86 | |
87 public void setChildren(TreePath parentPath, Object[] children) { | |
88 throw new UnsupportedOperationException(); | |
89 } | |
90 | |
91 public void updateChildren(IChildrenUpdate update) { | |
92 TreePath parent = update.getParent(); | |
93 Object[] children = getChildren(parent); | |
94 for (int i = 0; i < update.getLength(); i++) { | |
95 int targetIndex = update.getOffset() + i; | |
96 if (targetIndex < children.length) { | |
97 update.setChild(children[targetIndex], targetIndex); | |
98 } else { | |
99 update | |
100 .setStatus(new Status( | |
101 IStatus.WARNING, | |
102 Policy.JFACE_DATABINDING, | |
103 IStatus.OK, | |
104 BindingMessages | |
105 .getStringcast(BindingMessages.INDEX_OUT_OF_RANGE), | |
106 null)); | |
107 } | |
108 } | |
109 update.done(); | |
110 } | |
111 | |
112 public void updateChildrenCount(IChildrenCountUpdate update) { | |
113 TreePath[] parents = update.getParents(); | |
114 for (int i = 0; i < parents.length; i++) { | |
115 update.setChildCount(parents[i], getChildCount(parents[i])); | |
116 } | |
117 update.done(); | |
118 } | |
119 | |
120 public void updateHasChildren(IHasChildrenUpdate update) { | |
121 TreePath[] parents = update.getElements(); | |
122 for (int i = 0; i < parents.length; i++) { | |
123 update.setHasChilren(parents[i], hasChildren(parents[i])); | |
124 } | |
125 update.done(); | |
126 } | |
127 | |
128 public bool isStale() { | |
129 return stale; | |
130 } | |
131 | |
132 /** | |
133 * @param stale | |
134 */ | |
135 public void setStale(bool stale) { | |
136 this.stale = stale; | |
137 if (stale) { | |
138 fireStale(); | |
139 } | |
140 } | |
141 | |
142 protected void fireTreeChange(TreeDiff diff) { | |
143 // fire general change event first | |
144 fireChange(); | |
145 | |
146 Object[] listeners = treeListeners.getListeners(); | |
147 TreeChangeEvent event = new TreeChangeEvent(this, diff); | |
148 for (int i = 0; i < listeners.length; i++) { | |
149 (cast(ITreeChangeListener) listeners[i]).handleTreeChange(event); | |
150 } | |
151 } | |
152 | |
153 } |