1 11 12 package org.eclipse.ui.internal.intro.impl.model; 13 14 import java.util.Enumeration ; 15 import java.util.Map ; 16 17 import org.eclipse.ui.intro.config.IntroElement; 18 import org.osgi.framework.Bundle; 19 import org.w3c.dom.Element ; 20 import org.w3c.dom.Text ; 21 22 25 public class IntroGroup extends AbstractIntroContainer { 26 27 protected static final String TAG_GROUP = "group"; private static final String ATT_LABEL = "label"; private static final String ATT_COMPUTED = "computed"; private static final String ATT_EXPANDABLE = "expandable"; private static final String ATT_EXPANDED = "expanded"; private static final String P_UPPERCASE = "capitalizeTitles"; private String label; 34 37 IntroGroup(Element element, Bundle bundle, String base) { 38 super(element, bundle, base); 39 } 40 41 protected void loadFromParent() { 42 } 43 44 private void resolve() { 45 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 props = root.getTheme().getProperties(); 52 String value = (String )props.get(P_UPPERCASE); 53 if (value!=null && value.equalsIgnoreCase("true")) label = label.toUpperCase(); 55 } 56 } 57 } 58 } 59 60 63 public String getLabel() { 64 resolve(); 65 return label; 66 } 67 68 73 public int getType() { 74 return AbstractIntroElement.GROUP; 75 } 76 77 public boolean isExpandable() { 78 String value=getAttribute(element, ATT_EXPANDABLE); 79 return value!=null && value.equalsIgnoreCase("true"); } 81 82 public boolean isExpanded() { 83 String value=getAttribute(element, ATT_EXPANDED); 84 return value!=null && value.equalsIgnoreCase("true"); } 86 87 protected void loadChildren() { 88 String value = getAttribute(element, ATT_COMPUTED); 89 if (value!=null && value.equalsIgnoreCase("true")) 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 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 Element clone = target.getOwnerDocument().createElement(node.getName()); 113 Enumeration atts = node.getAttributes(); 115 for (;atts.hasMoreElements();) { 116 String aname = (String )atts.nextElement(); 117 String avalue = node.getAttribute(aname); 118 clone.setAttribute(aname, avalue); 119 } 120 String value = node.getValue(); 122 if (value!=null) { 123 Text textNode = target.getOwnerDocument().createTextNode(value); 124 clone.appendChild(textNode); 125 } 126 IntroElement [] cnodes = node.getChildren(); 128 if (cnodes.length>0) 129 addDynamicNodes(clone, cnodes); 130 target.appendChild(clone); 132 } 133 } 134 | Popular Tags |