1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*******************************************************************************
* Copyright (c) 2007, 2011 Symbian Software Limited and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Bala Torati (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.templateengine.uitree;
import java.util.List;
import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.templateengine.TemplateEngineUtil;
import org.eclipse.cdt.ui.templateengine.SimpleElementException;
import org.w3c.dom.Element;
/**
*
* call setgetUIElementTreeRootNull(), before createUIElementTree(...).
* UIElementTreeBuilderManager builds a UIElementTree.
*
* --------------UITree creation algorithm----------------------------
* createUIElementTree(UITreeRoot, RootPropertyGroupElement) UITreeRoot is
* initially null. createUIElementTree(UIElement parent, XML_Element element)
* Step 1. if( parent == null ) parent =
* UIElementTreeBuilderHelper.getUIElement(element).
* Step 2. else {
* Step 3. List
* childList = getChildList(element);
* Step 4. Iterator I =
* getIterator(childList);
* Step 5. for every element belonging to childList
* {
* Step 6. uiElement = getUIElement (element from childList); advance I to next
* Element. uiElement .setParent(parent); parent.put(uiElement );
* createUIElementTree(uiElement, element from childList);
* }
* }
* ---------------------------------------------------------------------
*
*/
public class UIElementTreeBuilderManager implements IUIElementTreeBuilderManager {
/**
* reference to iUIElementTreeBuilderHelper, which returns UIElement for Element.
*/
private UIElementTreeBuilderHelper uiElementTreeBuilderHelper;
/**
* The root of the UIElementTree.
*/
private UIElement uiTreeRoot = null;
/**
*
* @param uiElementTreeBuilderHelper
*/
public UIElementTreeBuilderManager(UIElementTreeBuilderHelper uiElementTreeBuilderHelper) {
this.uiElementTreeBuilderHelper = uiElementTreeBuilderHelper;
}
/**
* This method create the UIElementTree, by following the algorithm given
* above.
*/
@Override
public void createUIElementTree(UIElement uiParent, Element element) {
if (uiParent == null) {
uiTreeRoot = uiElementTreeBuilderHelper.getUIElement(element);
uiParent = uiTreeRoot;
}
if ((uiParent != null) && (uiParent instanceof GenericUIElementGroup)) {
List<Element> childList = TemplateEngine.getChildrenOfElement(element);
for (int listIndex = 0, l = childList.size(); listIndex < l; listIndex++) {
UIElement uiElement = uiElementTreeBuilderHelper.getUIElement(childList.get(listIndex));
if (uiElement != null) {
uiElement.setParent(uiParent);
} else {
continue;
}
try {
uiParent.addToChildList(uiElement);
} catch (SimpleElementException exp) {
TemplateEngineUtil.log(exp);
}
createUIElementTree(uiElement, childList.get(listIndex));
}
}
}
/**
*
* @return UIElement, root UIElement.
*/
public UIElement getUIElementTreeRoot() {
return uiTreeRoot;
}
/**
* sets the UIElementTree root element to null. This method is invoked
* before creating UIElementTree.
*/
public void setUIElementTreeRootNull() {
uiTreeRoot = null;
}
}
|