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