~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 * Bala Torati (Symbian) - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.ui.templateengine.pages;
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.HashMap;
 
15
import java.util.List;
 
16
import java.util.Map;
 
17
 
 
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;
 
23
 
 
24
 
 
25
/**
 
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(...)
 
29
 * 
 
30
 */
 
31
public class UIPagesProvider {
 
32
 
 
33
        /**
 
34
         * maintains the Page display order.
 
35
         */
 
36
        private List<String> orderVector;
 
37
 
 
38
 
 
39
        public UIPagesProvider() {
 
40
                orderVector = new ArrayList<String>();
 
41
        }
 
42
        
 
43
        /**
 
44
         * after getting this clear the Vector.
 
45
         * 
 
46
         * @return Vector
 
47
         */
 
48
        public List<String> getOrderVector() {
 
49
                return orderVector;
 
50
        }
 
51
 
 
52
        /**
 
53
         * re-initialize the Vector.
 
54
         */
 
55
        public void clearOrderVector() {
 
56
                orderVector = new ArrayList<String>();
 
57
        }
 
58
 
 
59
        /**
 
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.
 
64
         * 
 
65
         * @param uiElement
 
66
         *            UIElement group root element. Which can be converted to a
 
67
         *            UIPage.
 
68
         * @param valueStore
 
69
         * @return HashMap, UIPages corresponding to param aUIElement.
 
70
         */
 
71
        public Map<String, UIWizardPage> getWizardUIPages(UIElement uiElement, Map<String, String> valueStore) {
 
72
                int childCount = 0;
 
73
 
 
74
                try {
 
75
                        childCount = uiElement.getChildCount();
 
76
                } catch (SimpleElementException e) {
 
77
                        TemplateEngineUtil.log(e);
 
78
                }
 
79
 
 
80
                // HashMap of UIPages
 
81
                HashMap<String, UIWizardPage> pageMap = new HashMap<String, UIWizardPage>();
 
82
 
 
83
                // If uiElement contains other group elements as children.
 
84
                if (hasChildUIGroupElement(uiElement)) {
 
85
 
 
86
                        for (int i = 0; i < childCount; i++) {
 
87
                                try {
 
88
                                        pageMap.putAll(getWizardUIPages(uiElement.getChild(i), valueStore)); // recursion
 
89
                                } catch (SimpleElementException e) {
 
90
                                        TemplateEngineUtil.log(e);
 
91
                                }
 
92
                        }
 
93
                }
 
94
                else {
 
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);
 
99
 
 
100
                                pageMap.put((uiElement.getAttributes()).get(UIElement.ID), uiPage);
 
101
                                addToOrderVector((uiElement.getAttributes()).get(UIElement.ID));
 
102
                        }
 
103
                }
 
104
                return pageMap;
 
105
        }
 
106
 
 
107
        /**
 
108
         * whether the given (node in UIElementTree) UIElement contains children of
 
109
         * group type.
 
110
         * 
 
111
         * @param parent
 
112
         * @return boolean, true if it does, false otherwise.
 
113
         */
 
114
        public boolean hasChildUIGroupElement(UIElement parent) {
 
115
                boolean retVal = false;
 
116
                try {
 
117
                        if (parent.getChildCount() > 0) {
 
118
                                for (int i = 0; i < parent.getChildCount(); i++) {
 
119
                                        if (parent.getChild(i) instanceof SimpleUIElementGroup) {
 
120
                                                retVal = true;
 
121
                                                break;
 
122
                                        }
 
123
                                }
 
124
                        }
 
125
                } catch (SimpleElementException see) {
 
126
                        retVal = false;
 
127
                }
 
128
                return retVal;
 
129
        }
 
130
 
 
131
        /**
 
132
         * whether the given (node in UIElementTree) UIElement contains children of
 
133
         * UIElement type.
 
134
         * 
 
135
         * @param parent
 
136
         * @return boolean, true if it does, false otherwise.
 
137
         */
 
138
        public boolean hasChildUIElement(UIElement parent) {
 
139
                boolean retVal = false;
 
140
                try {
 
141
                        if (parent.getChildCount() > 0) {
 
142
                                for (int i = 0; i < parent.getChildCount(); i++) {
 
143
                                        if (parent.getChild(i) instanceof InputUIElement) {
 
144
                                                retVal = true;
 
145
                                                break;
 
146
                                        }
 
147
                                }
 
148
                        }
 
149
                } catch (SimpleElementException see) {
 
150
                        retVal = false;
 
151
                }
 
152
                return retVal;
 
153
        }
 
154
 
 
155
        /**
 
156
         * If the order vector contains the page id return, do not add it to order
 
157
         * vector. HashMap will not allow duplicate keys.
 
158
         * 
 
159
         * @param pageId
 
160
         */
 
161
        private void addToOrderVector(String pageId) {
 
162
                for(String id : orderVector) {
 
163
                        if (id.equalsIgnoreCase(pageId))
 
164
                                return;
 
165
                }
 
166
                orderVector.add(pageId);
 
167
        }
 
168
}