1 19 27 28 package org.netbeans.modules.xml.schema.abe.visitors; 29 30 import java.util.List ; 31 import org.netbeans.modules.xml.axi.AXIComponent; 32 import org.netbeans.modules.xml.axi.AXIContainer; 33 import org.netbeans.modules.xml.axi.AbstractAttribute; 34 import org.netbeans.modules.xml.schema.abe.ABEBaseDropPanel; 35 import org.netbeans.modules.xml.schema.abe.AttributePanel; 36 import org.netbeans.modules.xml.schema.abe.CompositorPanel; 37 import org.netbeans.modules.xml.schema.abe.ContainerPanel; 38 import org.netbeans.modules.xml.schema.abe.ElementPanel; 39 import org.netbeans.modules.xml.schema.abe.GlobalComplextypeContainerPanel; 40 import org.netbeans.modules.xml.schema.abe.GlobalElementsContainerPanel; 41 import org.netbeans.modules.xml.schema.abe.NamespacePanel; 42 import org.netbeans.modules.xml.schema.abe.StartTagPanel; 43 44 48 public class FrontTraversalVisitor extends TraversalVisitor{ 49 ABEBaseDropPanel currentComponent; 50 ABEBaseDropPanel result; 51 52 53 public FrontTraversalVisitor(ABEBaseDropPanel currentComponent) { 54 this.currentComponent = currentComponent; 55 } 56 57 public ABEBaseDropPanel getResult(){ 58 return result; 59 } 60 61 public void visit(GlobalComplextypeContainerPanel panel) { 62 if(currentComponent instanceof GlobalElementsContainerPanel){ 63 result = getNextComponent(panel, null); 65 }else{ 66 result = getNextComponent(panel, currentComponent); 68 } 69 if(result == null){ 70 result = panel.getContext().getNamespacePanel(); 73 } 74 } 75 76 public void visit(AttributePanel panel) { 77 StartTagPanel stp = (StartTagPanel) panel.getParent(); 78 visit(stp); 79 } 80 81 public void visit(GlobalElementsContainerPanel panel) { 82 if(currentComponent instanceof NamespacePanel){ 83 result = getNextComponent(panel, null); 85 }else{ 86 result = getNextComponent(panel, currentComponent); 88 } 89 if(result == null){ 90 currentComponent = panel; 93 visit(panel.getContext().getInstanceDesignerPanel().getGlobalComplextypePanel()); 94 } 95 } 96 97 public void visit(StartTagPanel panel) { 98 if(currentComponent == panel){ 99 List <AbstractAttribute> attrList = ((AXIContainer)panel.getAXIComponent()).getAttributes(); 101 if( (attrList != null) && (attrList.size() > 0) ){ 102 result = panel.getChildUIComponentFor(attrList.get(0)); 103 return; 104 } 105 }else if(currentComponent instanceof AttributePanel){ 106 List <AbstractAttribute> attrList = ((AXIContainer)panel.getAXIComponent()).getAttributes(); 108 int i = attrList.indexOf((AbstractAttribute)((AttributePanel)currentComponent).getAXIComponent()); 109 if(i+1 < attrList.size()){ 110 result = panel.getChildUIComponentFor(attrList.get(i+1)); 112 return; 113 } 114 } 115 ElementPanel ep = (ElementPanel) panel.getParent(); 117 TraversalVisitor tv = new DownTraversalVisitor(panel); 119 ep.accept(tv); 120 result = tv.getResult(); 121 } 122 123 public void visit(NamespacePanel panel) { 124 GlobalElementsContainerPanel gecp = panel.getContext(). 126 getInstanceDesignerPanel().getGlobalElementsPanel(); 127 visit(gecp); 128 } 129 130 public void visit(CompositorPanel panel) { 131 result = getNextComponent(panel, currentComponent); 132 if(result == null){ 133 ABEBaseDropPanel elmp = (ABEBaseDropPanel) panel.getParentContainerPanel(); 135 TraversalVisitor tv = new DownTraversalVisitor(panel); 136 elmp.accept(tv); 137 result = tv.getResult(); 138 } 139 } 140 141 public void visit(ElementPanel elementPanel) { 142 if(currentComponent instanceof ContainerPanel){ 144 elementPanel.expandChild(); 146 result = elementPanel.getStartTagPanel(); 147 } 148 } 149 150 private ABEBaseDropPanel getNextComponent(ContainerPanel panel, ABEBaseDropPanel current) { 151 if(current != null){ 152 AXIComponent comp = current.getAXIComponent(); 154 int i = panel.getAXIChildren().indexOf(comp); 155 if(i+1 < panel.getAXIChildren().size()){ 156 return panel.getChildUIComponentFor(panel.getAXIChildren().get(i+1)); 157 158 }else{ 159 return null; 161 } 162 }else{ 163 if(panel.getAXIChildren().size() > 0){ 165 return panel.getChildUIComponentFor(panel.getAXIChildren().get(0)); 167 } 168 } 169 return null; 170 171 } 172 173 174 175 } 176 | Popular Tags |