KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > visitors > FrontTraversalVisitor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * FirstComponentVisitor.java
21  *
22  * Created on August 30, 2006, 8:27 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.schema.abe.visitors;
29
30 import java.util.List JavaDoc;
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 /**
45  *
46  * @author girix
47  */

48 public class FrontTraversalVisitor extends TraversalVisitor{
49     ABEBaseDropPanel currentComponent;
50     ABEBaseDropPanel result;
51     
52     /** Creates a new instance of FirstComponentVisitor */
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             //just point to the first complex type panel
64
result = getNextComponent(panel, null);
65         }else{
66             //means traverse to next comp
67
result = getNextComponent(panel, currentComponent);
68         }
69         if(result == null){
70             //means there are no comps or reached already last comp
71
//froward from GCTP is actually NSP
72
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             //just point to the first element panel
84
result = getNextComponent(panel, null);
85         }else{
86             //means traverse to next comp
87
result = getNextComponent(panel, currentComponent);
88         }
89         if(result == null){
90             //means there are no comps or reached already last comp
91
//froward from GEP is actually GCT
92
currentComponent = panel;
93             visit(panel.getContext().getInstanceDesignerPanel().getGlobalComplextypePanel());
94         }
95     }
96     
97     public void visit(StartTagPanel panel) {
98         if(currentComponent == panel){
99             //go to first attribute if available
100
List JavaDoc<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             //then go to next available attr
107
List JavaDoc<AbstractAttribute> attrList = ((AXIContainer)panel.getAXIComponent()).getAttributes();
108             int i = attrList.indexOf((AbstractAttribute)((AttributePanel)currentComponent).getAXIComponent());
109             if(i+1 < attrList.size()){
110                 //more attrs available. Go to next
111
result = panel.getChildUIComponentFor(attrList.get(i+1));
112                 return;
113             }
114         }
115         //else go down to next peer of me
116
ElementPanel ep = (ElementPanel) panel.getParent();
117         //this is a downward traversal visitors job
118
TraversalVisitor tv = new DownTraversalVisitor(panel);
119         ep.accept(tv);
120         result = tv.getResult();
121     }
122     
123     public void visit(NamespacePanel panel) {
124         //froward from NSP is actually GEP
125
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             //then we reached last comp. Mode down in the element panel
134
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         //has to be alway the start tag panel
143
if(currentComponent instanceof ContainerPanel){
144             //show children then put focus on start tag
145
elementPanel.expandChild();
146             result = elementPanel.getStartTagPanel();
147         }
148     }
149     
150     private ABEBaseDropPanel getNextComponent(ContainerPanel panel, ABEBaseDropPanel current) {
151         if(current != null){
152             //get the next after current
153
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                 //already at the last comp
160
return null;
161             }
162         }else{
163             //just return the first comp
164
if(panel.getAXIChildren().size() > 0){
165                 //return the first one
166
return panel.getChildUIComponentFor(panel.getAXIChildren().get(0));
167             }
168         }
169         return null;
170         
171     }
172     
173     
174     
175 }
176
Popular Tags