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