|
Lines 113-128
Link Here
|
| 113 |
|
113 |
|
| 114 |
protected static final String OLD_LABEL = "old_label"; //$NON-NLS-1$ |
114 |
protected static final String OLD_LABEL = "old_label"; //$NON-NLS-1$ |
| 115 |
protected static final String OLD_IMAGE = "old_image"; //$NON-NLS-1$ |
115 |
protected static final String OLD_IMAGE = "old_image"; //$NON-NLS-1$ |
| 116 |
|
|
|
| 117 |
/** |
| 118 |
* Map of parent nodes for which children were needed to "set data" |
| 119 |
* in the virtual widget. A parent is added to this map when we try go |
| 120 |
* get children but they aren't there yet. The children are retrieved |
| 121 |
* asynchronously, and later put back into the widgetry. |
| 122 |
* The value is an array of ints of the indicies of the children that |
| 123 |
* were requested. |
| 124 |
*/ |
| 125 |
private Map fParentsPendingChildren = new HashMap(); |
| 126 |
|
116 |
|
| 127 |
/** |
117 |
/** |
| 128 |
* Creates a new viewer |
118 |
* Creates a new viewer |
|
Lines 238-244
Link Here
|
| 238 |
* @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object) |
228 |
* @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object) |
| 239 |
*/ |
229 |
*/ |
| 240 |
protected synchronized void inputChanged(Object input, Object oldInput) { |
230 |
protected synchronized void inputChanged(Object input, Object oldInput) { |
| 241 |
fParentsPendingChildren.clear(); |
|
|
| 242 |
if (fUpdatePolicy == null) { |
231 |
if (fUpdatePolicy == null) { |
| 243 |
fUpdatePolicy = createUpdatePolicy(); |
232 |
fUpdatePolicy = createUpdatePolicy(); |
| 244 |
fUpdatePolicy.init(this); |
233 |
fUpdatePolicy.init(this); |
|
Lines 845-866
Link Here
|
| 845 |
widget.dispose(); |
834 |
widget.dispose(); |
| 846 |
} |
835 |
} |
| 847 |
} |
836 |
} |
| 848 |
|
|
|
| 849 |
/** |
| 850 |
* Unmaps the node from its widget and all of its children nodes from |
| 851 |
* their widgets. |
| 852 |
* |
| 853 |
* @param node |
| 854 |
*/ |
| 855 |
protected void unmapNode(ModelNode node) { |
| 856 |
unmapElement(node); |
| 857 |
ModelNode[] childrenNodes = node.getChildrenNodes(); |
| 858 |
if (childrenNodes != null) { |
| 859 |
for (int i = 0; i < childrenNodes.length; i++) { |
| 860 |
unmapNode(childrenNodes[i]); |
| 861 |
} |
| 862 |
} |
| 863 |
} |
| 864 |
|
837 |
|
| 865 |
/** |
838 |
/** |
| 866 |
* A node in the model has been updated |
839 |
* A node in the model has been updated |
|
Lines 870-877
Link Here
|
| 870 |
protected void nodeChanged(ModelNode node) { |
843 |
protected void nodeChanged(ModelNode node) { |
| 871 |
Widget widget = findItem(node); |
844 |
Widget widget = findItem(node); |
| 872 |
if (widget != null) { |
845 |
if (widget != null) { |
| 873 |
widget.setData(node.getElement()); |
846 |
clear(widget); |
| 874 |
internalRefresh(node); |
847 |
attemptPendingUpdates(); |
| 875 |
} |
848 |
} |
| 876 |
} |
849 |
} |
| 877 |
|
850 |
|
|
Lines 892-929
Link Here
|
| 892 |
} |
865 |
} |
| 893 |
|
866 |
|
| 894 |
/** |
867 |
/** |
| 895 |
* Called when nodes are set in the model. The children may not have been |
868 |
* Clears the given widget |
| 896 |
* retrieved yet when the tree got the call to "set data". |
|
|
| 897 |
* |
869 |
* |
| 898 |
* @param parent |
870 |
* @param item |
| 899 |
* @param children |
|
|
| 900 |
*/ |
871 |
*/ |
| 901 |
protected void nodeChildrenSet(ModelNode parent, ModelNode[] children) { |
|
|
| 902 |
int[] indicies = removePendingChildren(parent); |
| 903 |
Widget widget = findItem(parent); |
| 904 |
if (widget != null && !widget.isDisposed()) { |
| 905 |
if (indicies != null) { |
| 906 |
for (int i = 0; i < indicies.length; i++) { |
| 907 |
int index = indicies[i]; |
| 908 |
Widget item = getChildWidget(widget, index); |
| 909 |
if (item != null) { |
| 910 |
if (index < children.length) { |
| 911 |
ModelNode childNode = children[index]; |
| 912 |
mapElement(childNode, item); |
| 913 |
item.setData(childNode.getElement()); |
| 914 |
internalRefresh(childNode); |
| 915 |
} |
| 916 |
} |
| 917 |
} |
| 918 |
setItemCount(widget, children.length); |
| 919 |
} else { |
| 920 |
setItemCount(widget, children.length); |
| 921 |
} |
| 922 |
} |
| 923 |
attemptPendingUpdates(); |
| 924 |
} |
| 925 |
|
| 926 |
protected abstract void clear(Widget item); |
872 |
protected abstract void clear(Widget item); |
|
|
873 |
|
| 874 |
/** |
| 875 |
* Clears the children of the widget. |
| 876 |
* |
| 877 |
* @param item |
| 878 |
*/ |
| 879 |
protected abstract void clearChildren(Widget item); |
| 927 |
|
880 |
|
| 928 |
/** |
881 |
/** |
| 929 |
* Returns the child widet at the given index for the given parent or |
882 |
* Returns the child widet at the given index for the given parent or |
|
Lines 949-970
Link Here
|
| 949 |
protected void attemptPendingUpdates() { |
902 |
protected void attemptPendingUpdates() { |
| 950 |
attemptSelection(false); |
903 |
attemptSelection(false); |
| 951 |
} |
904 |
} |
| 952 |
|
905 |
|
| 953 |
/** |
906 |
/** |
| 954 |
* The children of a node have changed. |
907 |
* Notification a node's children have changed. |
|
|
908 |
* Updates the child count for the parent's widget |
| 909 |
* and clears children to be updated. |
| 955 |
* |
910 |
* |
| 956 |
* @param parent |
911 |
* @param parentNode |
| 957 |
*/ |
912 |
*/ |
| 958 |
protected void nodeChildrenChanged(ModelNode parentNode) { |
913 |
protected void nodeChildrenChanged(ModelNode parentNode) { |
| 959 |
ModelNode[] childrenNodes = parentNode.getChildrenNodes(); |
914 |
Widget widget = findItem(parentNode); |
|
|
915 |
if (widget != null && !widget.isDisposed()) { |
| 916 |
int childCount = parentNode.getChildCount(); |
| 917 |
clearChildren(widget); |
| 918 |
setItemCount(widget, childCount); |
| 919 |
attemptPendingUpdates(); |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
/** |
| 924 |
* Unmaps the node from its widget and all of its children nodes from |
| 925 |
* their widgets. |
| 926 |
* |
| 927 |
* @param node |
| 928 |
*/ |
| 929 |
protected void unmapNode(ModelNode node) { |
| 930 |
unmapElement(node); |
| 931 |
ModelNode[] childrenNodes = node.getChildrenNodes(); |
| 960 |
if (childrenNodes != null) { |
932 |
if (childrenNodes != null) { |
| 961 |
nodeChildrenSet(parentNode, childrenNodes); |
933 |
for (int i = 0; i < childrenNodes.length; i++) { |
| 962 |
} else { |
934 |
unmapNode(childrenNodes[i]); |
| 963 |
Widget widget = findItem(parentNode); |
|
|
| 964 |
if (widget != null && !widget.isDisposed()) { |
| 965 |
int childCount = parentNode.getChildCount(); |
| 966 |
setItemCount(widget, childCount); |
| 967 |
attemptPendingUpdates(); |
| 968 |
} |
935 |
} |
| 969 |
} |
936 |
} |
| 970 |
} |
937 |
} |
|
Lines 997-1034
Link Here
|
| 997 |
return findItem((Object)node); |
964 |
return findItem((Object)node); |
| 998 |
} |
965 |
} |
| 999 |
|
966 |
|
| 1000 |
/** |
|
|
| 1001 |
* Note that the child at the specified index was requested by a widget |
| 1002 |
* when revealed but that the data was not in the model yet. When the data |
| 1003 |
* becomes available, map it to its widget. |
| 1004 |
* |
| 1005 |
* @param parent |
| 1006 |
* @param index |
| 1007 |
*/ |
| 1008 |
protected synchronized void addPendingChildIndex(ModelNode parent, int index) { |
| 1009 |
int[] indicies = (int[]) fParentsPendingChildren.get(parent); |
| 1010 |
if (indicies == null) { |
| 1011 |
indicies = new int[]{index}; |
| 1012 |
} else { |
| 1013 |
int[] next = new int[indicies.length + 1]; |
| 1014 |
System.arraycopy(indicies, 0, next, 0, indicies.length); |
| 1015 |
next[indicies.length] = index; |
| 1016 |
indicies = next; |
| 1017 |
} |
| 1018 |
fParentsPendingChildren.put(parent, indicies); |
| 1019 |
} |
| 1020 |
|
| 1021 |
/** |
| 1022 |
* Removes and returns and children indicies that were pending for the given |
| 1023 |
* parent node. May return <code>null</code>. |
| 1024 |
* |
| 1025 |
* @param parent |
| 1026 |
* @return indicies of children that data were requested for or <code>null</code> |
| 1027 |
*/ |
| 1028 |
protected int[] removePendingChildren(ModelNode parent) { |
| 1029 |
return (int[]) fParentsPendingChildren.remove(parent); |
| 1030 |
} |
| 1031 |
|
| 1032 |
/* |
967 |
/* |
| 1033 |
* (non-Javadoc) |
968 |
* (non-Javadoc) |
| 1034 |
* |
969 |
* |
|
Lines 1059-1067
Link Here
|
| 1059 |
internalRefresh(child); |
994 |
internalRefresh(child); |
| 1060 |
} |
995 |
} |
| 1061 |
}); |
996 |
}); |
| 1062 |
} else { |
997 |
} |
| 1063 |
addPendingChildIndex(node, index); |
|
|
| 1064 |
} |
| 1065 |
return; |
998 |
return; |
| 1066 |
} |
999 |
} |
| 1067 |
} |
1000 |
} |