KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > IntroGroup


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.intro.impl.model;
13
14 import java.util.Enumeration JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.ui.intro.config.IntroElement;
18 import org.osgi.framework.Bundle;
19 import org.w3c.dom.Element JavaDoc;
20 import org.w3c.dom.Text JavaDoc;
21
22 /**
23  * An intro div.
24  */

25 public class IntroGroup extends AbstractIntroContainer {
26
27     protected static final String JavaDoc TAG_GROUP = "group"; //$NON-NLS-1$
28
private static final String JavaDoc ATT_LABEL = "label"; //$NON-NLS-1$
29
private static final String JavaDoc ATT_COMPUTED = "computed"; //$NON-NLS-1$
30
private static final String JavaDoc ATT_EXPANDABLE = "expandable"; //$NON-NLS-1$
31
private static final String JavaDoc ATT_EXPANDED = "expanded"; //$NON-NLS-1$
32
private static final String JavaDoc P_UPPERCASE = "capitalizeTitles"; //$NON-NLS-1$
33
private String JavaDoc label;
34     /**
35      * @param element
36      */

37     IntroGroup(Element element, Bundle bundle, String JavaDoc base) {
38         super(element, bundle, base);
39     }
40     
41     protected void loadFromParent() {
42     }
43     
44     private void resolve() {
45         // reinitialize if there are variables in the value.
46
if (label==null) {
47             label = getAttribute(element, ATT_LABEL);
48             if (label!=null) {
49                 IntroModelRoot root = getModelRoot();
50                 if (root!=null && root.getTheme()!=null) {
51                     Map JavaDoc props = root.getTheme().getProperties();
52                     String JavaDoc value = (String JavaDoc)props.get(P_UPPERCASE);
53                     if (value!=null && value.equalsIgnoreCase("true")) //$NON-NLS-1$
54
label = label.toUpperCase();
55                 }
56             }
57         }
58     }
59
60     /**
61      * @return Returns the label.
62      */

63     public String JavaDoc getLabel() {
64         resolve();
65         return label;
66     }
67     
68     /*
69      * (non-Javadoc)
70      *
71      * @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
72      */

73     public int getType() {
74         return AbstractIntroElement.GROUP;
75     }
76     
77     public boolean isExpandable() {
78         String JavaDoc value=getAttribute(element, ATT_EXPANDABLE);
79         return value!=null && value.equalsIgnoreCase("true"); //$NON-NLS-1$
80
}
81     
82     public boolean isExpanded() {
83         String JavaDoc value=getAttribute(element, ATT_EXPANDED);
84         return value!=null && value.equalsIgnoreCase("true"); //$NON-NLS-1$
85
}
86     
87     protected void loadChildren() {
88         String JavaDoc value = getAttribute(element, ATT_COMPUTED);
89         if (value!=null && value.equalsIgnoreCase("true")) //$NON-NLS-1$
90
loadDynamicNodes();
91         super.loadChildren();
92     }
93
94     private void loadDynamicNodes() {
95         IntroModelRoot root = getModelRoot();
96         if (root==null)
97             return;
98         AbstractIntroPage page = getParentPage();
99         String JavaDoc pageId = page.getId();
100         IntroElement [] nodes = root.getConfigurer().getGroupChildren(pageId, getId());
101         addDynamicNodes(this.element, nodes);
102     }
103   
104     private void addDynamicNodes(Element target, IntroElement [] nodes) {
105         for (int i=0; i<nodes.length; i++) {
106             IntroElement node = nodes[i];
107             addDynamicNode(target, node);
108         }
109     }
110     private void addDynamicNode(Element target, IntroElement node) {
111         // clone node itself
112
Element clone = target.getOwnerDocument().createElement(node.getName());
113         // set attributes
114
Enumeration JavaDoc atts = node.getAttributes();
115         for (;atts.hasMoreElements();) {
116             String JavaDoc aname = (String JavaDoc)atts.nextElement();
117             String JavaDoc avalue = node.getAttribute(aname);
118             clone.setAttribute(aname, avalue);
119         }
120         // set value
121
String JavaDoc value = node.getValue();
122         if (value!=null) {
123             Text JavaDoc textNode = target.getOwnerDocument().createTextNode(value);
124             clone.appendChild(textNode);
125         }
126         // clone children
127
IntroElement [] cnodes = node.getChildren();
128         if (cnodes.length>0)
129             addDynamicNodes(clone, cnodes);
130         // add the clone to the target
131
target.appendChild(clone);
132     }
133 }
134
Popular Tags