Revision 34026 branches/v2_0_0_prep/extensions/extWFS2/src/org/gvsig/wfs/gui/panels/fieldstree/CheckBoxNode.java

View differences:

CheckBoxNode.java
3 3
import java.awt.Color;
4 4
import java.util.Vector;
5 5

  
6
import org.gvsig.remoteclient.wfs.schema.XMLElement;
7
import org.gvsig.remoteclient.wfs.schema.type.IXMLType;
8
import org.gvsig.remoteclient.wfs.schema.type.XMLComplexType;
6
import org.gvsig.remoteclient.wfs.WFSFeature;
7
import org.gvsig.remoteclient.wfs.WFSFeatureField;
9 8

  
10 9

  
11 10

  
......
74 73
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
75 74
 */
76 75
public class CheckBoxNode extends TetraStateCheckBox{
77
	private XMLElement element = null;	
78
	private CheckBoxNode parent = null;
79
	private Vector children = new Vector();	
80
	
81
	public CheckBoxNode(XMLElement element,CheckBoxNode parent){
82
		super();
83
		this.parent = parent;
84
		initialize(element);
85
	}
86
	
87
	private void initialize(XMLElement element){		
88
		this.setBackground(Color.WHITE);
89
		this.setText(fillNameWithBlancs(element.getName()));
90
		this.element = element;
91
		if (element.getEntityType() != null){
92
			if (element.getEntityType().getType() == IXMLType.COMPLEX){
93
				Vector subElements = ((XMLComplexType)element.getEntityType()).getAttributes();
94
				for (int i=0 ; i<subElements.size() ; i++){
95
					XMLElement child = (XMLElement)subElements.get(i);
96
					children.add(new CheckBoxNode(child,this));					
97
				}
98
			}else if(element.getEntityType().getType() == IXMLType.GML_GEOMETRY){
99
				this.setSelected(true);			
100
			}
101
		}
102
	}
103
	
104
	/**
105
	 * Return the max size for the combo labels
106
	 * @return
107
	 */
108
	public static int getTextLength(){
109
		return 200;
110
	}
111
	
112
	/**
113
	 * Fill the string with blancs
114
	 * @param name
115
	 * @return
116
	 */
117
	public static String fillNameWithBlancs(String name){
118
		String withBlancs = name;
119
		for (int i=name.length() ; i<getTextLength() ; i++){
120
			name = name + " ";
121
		}
122
		return name;
123
	}
124
	
125
	/**
126
	 * @return Returns the element.
127
	 */
128
	public XMLElement getElement() {
129
		return element;
130
	}
131
	
132
	/**
133
	 * @return Returns the children.
134
	 */
135
	public Vector getChildren() {
136
		return children;
137
	}
138
	
139
	public String toString(){
140
		return getElement().getName();
141
	}
142
	
143
	/**
144
	 * @return Returns the parent.
145
	 */
146
	public CheckBoxNode getParentNode() {
147
		return parent;
148
	}
149
}
150
//public class CheckBoxNode extends JPanel{
151
//private XMLElement element = null;	
152
//private CheckBoxNode parent = null;
153
//private Vector children = new Vector();	
154
//private TetraStateCheckBox checkBox = null;
155
//
156
//public CheckBoxNode(XMLElement element,CheckBoxNode parent){
157
//super();
158
//this.parent = parent;
159
//initialize(element);
160
//}
161
//
162
//private void initialize(XMLElement element){	
163
//this.setSize(new Dimension(300,400));
164
//checkBox = new TetraStateCheckBox();
165
//this.add(checkBox);		
166
//this.add(new JLabel(element.getName()));
167
//this.setBackground(Color.BLUE);		
168
//this.element = element;
169
//if (element.getEntityType().getType() == IXMLType.COMPLEX){
170
//Vector subElements = ((XMLComplexType)element.getEntityType()).getAttributes();
171
//for (int i=0 ; i<subElements.size() ; i++){
172
//XMLElement child = (XMLElement)subElements.get(i);
173
//children.add(new CheckBoxNode(child,this));					
174
//}
175
//}
176
//}
177
//
178
//public boolean isSelected(){
179
//return checkBox.isSelected();
180
//}
181
//
182
//public void setSelected(boolean selected){
183
//checkBox.setSelected(selected);
184
//}
185
//
186
//public void setColor(int color){
187
//checkBox.setColor(color);
188
//}
189
//
190
///**
191
//* @return Returns the element.
192
//*/
193
//public XMLElement getElement() {
194
//return element;
195
//}
196
//
197
///**
198
//* @return Returns the children.
199
//*/
200
//public Vector getChildren() {
201
//return children;
202
//}
203
//
204
//public String toString(){
205
//return getElement().getName();
206
//}
207
//
208
///**
209
//* @return Returns the parent.
210
//*/
211
//public CheckBoxNode getParentNode() {
212
//return parent;
213
//}
214
//}
76
    private WFSFeatureField featureField = null;
77
    private String featureFieldName = null;
78
    private CheckBoxNode parent = null;
79
    private Vector children = new Vector();	
80

  
81
    public CheckBoxNode(WFSFeatureField featureField,CheckBoxNode parent){
82
        super();
83
        this.parent = parent;
84
        initialize(featureField);
85
    }
86

  
87
    private void initialize(WFSFeature feature){     
88
        this.setBackground(Color.WHITE);
89
        featureFieldName = (fillNameWithBlancs(feature.getName()));
90
        this.setText(featureFieldName);
91
        for (int i=0 ; i< feature.getFieldSize() ; i++){
92
            children.add(new CheckBoxNode(feature.getFieldAt(i),this));                 
93
        }
94
    }
95

  
96
    private void initialize(WFSFeatureField featureField){		
97
        this.setBackground(Color.WHITE);
98
         featureFieldName = (fillNameWithBlancs(featureField.getName()));
99
         this.setText(featureFieldName);
100
        this.featureField = featureField;
101
        for (int i=0 ; i< featureField.getFieldSize() ; i++){
102
            children.add(new CheckBoxNode(featureField.getFieldAt(i),this));					
103
        }
104
        if(featureField.isGeometry()){
105
            this.setSelected(true);	
106

  
107
        }
108
    }
109

  
110
    /**
111
     * Return the max size for the combo labels
112
     * @return
113
     */
114
    public static int getTextLength(){
115
        return 200;
116
    }
117

  
118
    /**
119
     * Fill the string with blancs
120
     * @param name
121
     * @return
122
     */
123
    public static String fillNameWithBlancs(String name){
124
        String withBlancs = name;
125
        for (int i=name.length() ; i<getTextLength() ; i++){
126
            name = name + " ";
127
        }
128
        return name;
129
    }
130

  
131
    /**
132
     * @return Returns the element.
133
     */
134
    public WFSFeatureField getFeatureField() {
135
        return featureField;
136
    }
137

  
138
    /**
139
     * @return Returns the children.
140
     */
141
    public Vector getChildren() {
142
        return children;
143
    }
144

  
145
    public String toString(){
146
        return featureFieldName;
147
    }
148

  
149
    /**
150
     * @return Returns the parent.
151
     */
152
    public CheckBoxNode getParentNode() {
153
        return parent;
154
    }
155
}

Also available in: Unified diff