|
Link Here
|
| 135 |
StringTokenizer tokenizer; |
135 |
StringTokenizer tokenizer; |
| 136 |
String currentToken; |
136 |
String currentToken; |
| 137 |
|
137 |
|
| 138 |
// Sort nodes based on flattened display path composed of |
138 |
|
| 139 |
// actual labels of nodes referenced in category attribute. |
139 |
CategoryNode[] nodes = createCategoryNodes(getNodes()); |
| 140 |
Object[] sortedNodes = sortByCategories(getNodes()); |
140 |
// flag to indicate that some work was done in the inner loop over the nodes |
| 141 |
for (int i = 0; i < sortedNodes.length; i++) { |
141 |
boolean workDone; |
| 142 |
//Iterate through all the nodes |
142 |
do { |
| 143 |
CategoryNode categoryNode = (CategoryNode) sortedNodes[i]; |
143 |
//reset the flag |
| 144 |
Object node = categoryNode.getNode(); |
144 |
workDone = false; |
| 145 |
|
145 |
List deferred = new ArrayList(); |
| 146 |
String category = getCategory(node); |
146 |
for (int i = 0; i < nodes.length; i++) { |
| 147 |
if (category == null) { |
147 |
// Iterate through all the nodes |
| 148 |
topLevelNodes.add(node); |
148 |
CategoryNode categoryNode = nodes[i]; |
| 149 |
continue; |
149 |
Object node = categoryNode.getNode(); |
| 150 |
} |
150 |
|
| 151 |
// has category |
151 |
String category = getCategory(node); |
| 152 |
tokenizer = new StringTokenizer(category, PREFERENCE_SEPARATOR); |
152 |
if (category == null) { |
| 153 |
Object parent = null; |
153 |
topLevelNodes.add(node); |
| 154 |
while (tokenizer.hasMoreElements()) { |
154 |
continue; |
| 155 |
currentToken = tokenizer.nextToken(); |
|
|
| 156 |
Object child = null; |
| 157 |
if (parent == null) { |
| 158 |
child = findNode(currentToken); |
| 159 |
} else { |
| 160 |
child = findNode(parent, currentToken); |
| 161 |
} |
155 |
} |
| 162 |
if (child == null) { |
156 |
// has category |
| 163 |
parent = null; |
157 |
tokenizer = new StringTokenizer(category, PREFERENCE_SEPARATOR); |
| 164 |
break; |
158 |
Object parent = null; |
| 165 |
} else { |
159 |
while (tokenizer.hasMoreElements()) { |
|
|
160 |
currentToken = tokenizer.nextToken(); |
| 161 |
Object child = null; |
| 162 |
if (parent == null) { |
| 163 |
child = findNode(currentToken); |
| 164 |
} else { |
| 165 |
child = findNode(parent, currentToken); |
| 166 |
} |
| 167 |
|
| 168 |
if (child == null) { |
| 169 |
parent = null; |
| 170 |
break; |
| 171 |
} |
| 166 |
parent = child; |
172 |
parent = child; |
| 167 |
} |
173 |
} |
|
|
174 |
if (parent != null) { |
| 175 |
//we've done some work - the number of nodes to process has decreased |
| 176 |
workDone = true; |
| 177 |
add(parent, node); |
| 178 |
} else { |
| 179 |
// we haven't done any work - the parent for this node has not been found. |
| 180 |
deferred.add(categoryNode); |
| 181 |
} |
| 168 |
} |
182 |
} |
| 169 |
if (parent != null) { |
183 |
// reset the nodes to all that have yet to find their proper parent |
| 170 |
add(parent, node); |
184 |
nodes = (CategoryNode[]) deferred.toArray(new CategoryNode[deferred |
| 171 |
} else { |
185 |
.size()]); |
| 172 |
//Could not find the parent - log |
186 |
} while (nodes.length > 0 && workDone); // loop while we still have nodes to work on and the list is shrinking |
| 173 |
WorkbenchPlugin |
187 |
|
| 174 |
.log("Invalid preference page path: " + categoryNode.getFlatCategory()); //$NON-NLS-1$ |
188 |
// log anything left over. |
| 175 |
topLevelNodes.add(node); |
189 |
for (int i = 0; i < nodes.length; i++) { |
| 176 |
} |
190 |
CategoryNode categoryNode = nodes[i]; |
|
|
191 |
// Could not find the parent - log |
| 192 |
WorkbenchPlugin |
| 193 |
.log("Invalid preference page path: " + categoryNode.getFlatCategory()); //$NON-NLS-1$ |
| 194 |
topLevelNodes.add(categoryNode.getNode()); |
| 177 |
} |
195 |
} |
| 178 |
} |
196 |
} |
| 179 |
|
197 |
|
|
Link Here
|
| 204 |
* nodes. workbench node is excluded from sorting because it always |
222 |
* nodes. workbench node is excluded from sorting because it always |
| 205 |
* appears first in the dialog. |
223 |
* appears first in the dialog. |
| 206 |
*/ |
224 |
*/ |
| 207 |
Object[] sortByCategories(Collection nodesToCategorize) { |
225 |
CategoryNode[] createCategoryNodes(Collection nodesToCategorize) { |
| 208 |
//sort by categories |
226 |
//sort by categories |
| 209 |
List nodes = new ArrayList(); |
227 |
List nodes = new ArrayList(); |
| 210 |
|
228 |
|
|
Link Here
|
| 213 |
nodes.add(createCategoryNode(this, nodesIterator.next())); |
231 |
nodes.add(createCategoryNode(this, nodesIterator.next())); |
| 214 |
} |
232 |
} |
| 215 |
|
233 |
|
| 216 |
return nodes.toArray(); |
234 |
return (CategoryNode[]) nodes.toArray(new CategoryNode[nodes.size()]); |
| 217 |
} |
235 |
} |
| 218 |
|
236 |
|
| 219 |
/** |
237 |
/** |