|
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 832-866
Link Here
|
| 832 |
protected AsynchronousModel getModel() { |
821 |
protected AsynchronousModel getModel() { |
| 833 |
return fModel; |
822 |
return fModel; |
| 834 |
} |
823 |
} |
| 835 |
|
|
|
| 836 |
/** |
| 837 |
* A node has been disposed from the model. |
| 838 |
* |
| 839 |
* @param node |
| 840 |
*/ |
| 841 |
protected void nodeDisposed(ModelNode node) { |
| 842 |
Widget widget = findItem(node); |
| 843 |
if (widget != null) { |
| 844 |
unmapNode(node); |
| 845 |
widget.dispose(); |
| 846 |
} |
| 847 |
} |
| 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 |
|
824 |
|
| 865 |
/** |
825 |
/** |
| 866 |
* A node in the model has been updated |
826 |
* A node in the model has been updated |
|
Lines 870-877
Link Here
|
| 870 |
protected void nodeChanged(ModelNode node) { |
830 |
protected void nodeChanged(ModelNode node) { |
| 871 |
Widget widget = findItem(node); |
831 |
Widget widget = findItem(node); |
| 872 |
if (widget != null) { |
832 |
if (widget != null) { |
| 873 |
widget.setData(node.getElement()); |
833 |
clear(widget); |
| 874 |
internalRefresh(node); |
834 |
attemptPendingUpdates(); |
| 875 |
} |
835 |
} |
| 876 |
} |
836 |
} |
| 877 |
|
837 |
|
|
Lines 892-929
Link Here
|
| 892 |
} |
852 |
} |
| 893 |
|
853 |
|
| 894 |
/** |
854 |
/** |
| 895 |
* Called when nodes are set in the model. The children may not have been |
855 |
* Clears the given widget |
| 896 |
* retrieved yet when the tree got the call to "set data". |
|
|
| 897 |
* |
856 |
* |
| 898 |
* @param parent |
857 |
* @param item |
| 899 |
* @param children |
|
|
| 900 |
*/ |
858 |
*/ |
| 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); |
859 |
protected abstract void clear(Widget item); |
|
|
860 |
|
| 861 |
/** |
| 862 |
* Clears the children of the widget. |
| 863 |
* |
| 864 |
* @param item |
| 865 |
*/ |
| 866 |
protected abstract void clearChildren(Widget item); |
| 927 |
|
867 |
|
| 928 |
/** |
868 |
/** |
| 929 |
* Returns the child widet at the given index for the given parent or |
869 |
* Returns the child widet at the given index for the given parent or |
|
Lines 949-970
Link Here
|
| 949 |
protected void attemptPendingUpdates() { |
889 |
protected void attemptPendingUpdates() { |
| 950 |
attemptSelection(false); |
890 |
attemptSelection(false); |
| 951 |
} |
891 |
} |
| 952 |
|
892 |
|
| 953 |
/** |
893 |
/** |
| 954 |
* The children of a node have changed. |
894 |
* Notification a node's children have changed. |
|
|
895 |
* Updates the child count for the parent's widget |
| 896 |
* and clears children to be updated. |
| 955 |
* |
897 |
* |
| 956 |
* @param parent |
898 |
* @param parentNode |
| 957 |
*/ |
899 |
*/ |
| 958 |
protected void nodeChildrenChanged(ModelNode parentNode) { |
900 |
protected void nodeChildrenChanged(ModelNode parentNode) { |
| 959 |
ModelNode[] childrenNodes = parentNode.getChildrenNodes(); |
901 |
Widget widget = findItem(parentNode); |
|
|
902 |
if (widget != null && !widget.isDisposed()) { |
| 903 |
int childCount = parentNode.getChildCount(); |
| 904 |
setItemCount(widget, childCount); |
| 905 |
clearChildren(widget); |
| 906 |
attemptPendingUpdates(); |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
/** |
| 911 |
* Unmaps the node from its widget and all of its children nodes from |
| 912 |
* their widgets. |
| 913 |
* |
| 914 |
* @param node |
| 915 |
*/ |
| 916 |
protected void unmapNode(ModelNode node) { |
| 917 |
unmapElement(node); |
| 918 |
ModelNode[] childrenNodes = node.getChildrenNodes(); |
| 960 |
if (childrenNodes != null) { |
919 |
if (childrenNodes != null) { |
| 961 |
nodeChildrenSet(parentNode, childrenNodes); |
920 |
for (int i = 0; i < childrenNodes.length; i++) { |
| 962 |
} else { |
921 |
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 |
} |
922 |
} |
| 969 |
} |
923 |
} |
| 970 |
} |
924 |
} |
|
Lines 997-1034
Link Here
|
| 997 |
return findItem((Object)node); |
951 |
return findItem((Object)node); |
| 998 |
} |
952 |
} |
| 999 |
|
953 |
|
| 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 |
/* |
954 |
/* |
| 1033 |
* (non-Javadoc) |
955 |
* (non-Javadoc) |
| 1034 |
* |
956 |
* |
|
Lines 1042-1047
Link Here
|
| 1042 |
|
964 |
|
| 1043 |
Widget parentItem = getParentWidget(event.item); |
965 |
Widget parentItem = getParentWidget(event.item); |
| 1044 |
int index = event.index; |
966 |
int index = event.index; |
|
|
967 |
if (index == -1) { |
| 968 |
return; |
| 969 |
} |
| 1045 |
|
970 |
|
| 1046 |
ModelNode[] nodes = getModel().getNodes(parentItem.getData()); |
971 |
ModelNode[] nodes = getModel().getNodes(parentItem.getData()); |
| 1047 |
if (nodes != null) { |
972 |
if (nodes != null) { |
|
Lines 1059-1073
Link Here
|
| 1059 |
internalRefresh(child); |
984 |
internalRefresh(child); |
| 1060 |
} |
985 |
} |
| 1061 |
}); |
986 |
}); |
| 1062 |
} else { |
987 |
} |
| 1063 |
addPendingChildIndex(node, index); |
|
|
| 1064 |
} |
| 1065 |
return; |
988 |
return; |
| 1066 |
} |
989 |
} |
| 1067 |
} |
990 |
} |
| 1068 |
} |
991 |
} |
| 1069 |
} |
992 |
} |
| 1070 |
|
993 |
|
| 1071 |
protected abstract void restoreLabels(Item item); |
994 |
protected abstract void restoreLabels(Item item); |
| 1072 |
|
995 |
|
| 1073 |
/** |
996 |
/** |