1
/*******************************************************************************
2
* Copyright (c) 2007, 2008 Symbian Software Limited 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
9
* Bala Torati (Symbian) - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.ui.templateengine.pages;
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.List;
18
import org.eclipse.cdt.core.templateengine.TemplateEngineUtil;
19
import org.eclipse.cdt.ui.templateengine.SimpleElementException;
20
import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement;
21
import org.eclipse.cdt.ui.templateengine.uitree.SimpleUIElementGroup;
22
import org.eclipse.cdt.ui.templateengine.uitree.UIElement;
26
* The UIPagesProvider creates a Map of UIPages. The Map will have ID as key,
27
* UIPage as value. The sequence of call to get Map of UIPages. 1.
28
* clearOrderVector() for all PropertyGroup Elements. 2. getUIPages(...)
31
public class UIPagesProvider {
34
* maintains the Page display order.
36
private List<String> orderVector;
39
public UIPagesProvider() {
40
orderVector = new ArrayList<String>();
44
* after getting this clear the Vector.
48
public List<String> getOrderVector() {
53
* re-initialize the Vector.
55
public void clearOrderVector() {
56
orderVector = new ArrayList<String>();
60
* This class has methods to return an HashMap of UIPages. The UIPages will
61
* correspond to UIElement group passed as parameter to this method. For a
62
* group UIElement, the children count is taken. An array of UIPage for the
63
* count is created. The same is initialized with UIPages.
66
* UIElement group root element. Which can be converted to a
69
* @return HashMap, UIPages corresponding to param aUIElement.
71
public Map<String, UIWizardPage> getWizardUIPages(UIElement uiElement, Map<String, String> valueStore) {
75
childCount = uiElement.getChildCount();
76
} catch (SimpleElementException e) {
77
TemplateEngineUtil.log(e);
81
HashMap<String, UIWizardPage> pageMap = new HashMap<String, UIWizardPage>();
83
// If uiElement contains other group elements as children.
84
if (hasChildUIGroupElement(uiElement)) {
86
for (int i = 0; i < childCount; i++) {
88
pageMap.putAll(getWizardUIPages(uiElement.getChild(i), valueStore)); // recursion
89
} catch (SimpleElementException e) {
90
TemplateEngineUtil.log(e);
95
if ((hasChildUIElement(uiElement))) {
96
String label = uiElement.getAttributes().get(UIElement.TITLE);
97
String description = (uiElement.getAttributes()).get(UIElement.DESCRIPTION);
98
UIWizardPage uiPage = new UIWizardPage(label, description, uiElement, valueStore);
100
pageMap.put((uiElement.getAttributes()).get(UIElement.ID), uiPage);
101
addToOrderVector((uiElement.getAttributes()).get(UIElement.ID));
108
* whether the given (node in UIElementTree) UIElement contains children of
112
* @return boolean, true if it does, false otherwise.
114
public boolean hasChildUIGroupElement(UIElement parent) {
115
boolean retVal = false;
117
if (parent.getChildCount() > 0) {
118
for (int i = 0; i < parent.getChildCount(); i++) {
119
if (parent.getChild(i) instanceof SimpleUIElementGroup) {
125
} catch (SimpleElementException see) {
132
* whether the given (node in UIElementTree) UIElement contains children of
136
* @return boolean, true if it does, false otherwise.
138
public boolean hasChildUIElement(UIElement parent) {
139
boolean retVal = false;
141
if (parent.getChildCount() > 0) {
142
for (int i = 0; i < parent.getChildCount(); i++) {
143
if (parent.getChild(i) instanceof InputUIElement) {
149
} catch (SimpleElementException see) {
156
* If the order vector contains the page id return, do not add it to order
157
* vector. HashMap will not allow duplicate keys.
161
private void addToOrderVector(String pageId) {
162
for(String id : orderVector) {
163
if (id.equalsIgnoreCase(pageId))
166
orderVector.add(pageId);