root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / fieldsTree / CheckBoxTreeCellEditor.java @ 9461
History | View | Annotate | Download (5.84 KB)
1 |
package com.iver.cit.gvsig.gui.panels.fieldsTree; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.event.MouseEvent; |
5 |
import java.util.EventObject; |
6 |
|
7 |
import javax.swing.AbstractCellEditor; |
8 |
import javax.swing.JCheckBox; |
9 |
import javax.swing.JTree; |
10 |
import javax.swing.event.ChangeEvent; |
11 |
import javax.swing.tree.TreeCellEditor; |
12 |
import javax.swing.tree.TreePath; |
13 |
|
14 |
import org.gvsig.remoteClient.gml.types.IXMLType; |
15 |
|
16 |
|
17 |
import com.iver.utiles.XMLEntity; |
18 |
|
19 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
20 |
*
|
21 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
22 |
*
|
23 |
* This program is free software; you can redistribute it and/or
|
24 |
* modify it under the terms of the GNU General Public License
|
25 |
* as published by the Free Software Foundation; either version 2
|
26 |
* of the License, or (at your option) any later version.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the Free Software
|
35 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
36 |
*
|
37 |
* For more information, contact:
|
38 |
*
|
39 |
* Generalitat Valenciana
|
40 |
* Conselleria d'Infraestructures i Transport
|
41 |
* Av. Blasco Ib??ez, 50
|
42 |
* 46010 VALENCIA
|
43 |
* SPAIN
|
44 |
*
|
45 |
* +34 963862235
|
46 |
* gvsig@gva.es
|
47 |
* www.gvsig.gva.es
|
48 |
*
|
49 |
* or
|
50 |
*
|
51 |
* IVER T.I. S.A
|
52 |
* Salamanca 50
|
53 |
* 46005 Valencia
|
54 |
* Spain
|
55 |
*
|
56 |
* +34 963163400
|
57 |
* dac@iver.es
|
58 |
*/
|
59 |
/* CVS MESSAGES:
|
60 |
*
|
61 |
* $Id$
|
62 |
* $Log$
|
63 |
* Revision 1.2 2006-12-26 10:25:37 ppiqueras
|
64 |
* Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
|
65 |
*
|
66 |
* Revision 1.1 2006/12/26 09:12:48 ppiqueras
|
67 |
* Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2). (En este caso se ha cambiado el nombre del paquete aparte de alguno otro nombre que puede haber cambiado).
|
68 |
*
|
69 |
* Revision 1.2 2006/10/31 12:24:04 jorpiell
|
70 |
* Comprobado el caso en el que los atributos no tienen tipo
|
71 |
*
|
72 |
* Revision 1.1 2006/10/27 11:33:19 jorpiell
|
73 |
* A?adida la treetable con los check box para seleccionar los atributos
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
/**
|
78 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
79 |
*/
|
80 |
public class CheckBoxTreeCellEditor extends AbstractCellEditor implements TreeCellEditor { |
81 |
CheckBoxTreeCellRenderer renderer = null;
|
82 |
ChangeEvent changeEvent = null; |
83 |
JTree tree;
|
84 |
FieldsTreeTable treetable; |
85 |
|
86 |
public CheckBoxTreeCellEditor(FieldsTreeTable treetable) {
|
87 |
this.treetable = treetable;
|
88 |
this.tree = (JTree)treetable.getTree(); |
89 |
this.renderer = new CheckBoxTreeCellRenderer(treetable); |
90 |
} |
91 |
|
92 |
/*
|
93 |
* (non-Javadoc)
|
94 |
* @see javax.swing.CellEditor#getCellEditorValue()
|
95 |
*/
|
96 |
public Object getCellEditorValue() { |
97 |
return null; |
98 |
} |
99 |
|
100 |
/*
|
101 |
* (non-Javadoc)
|
102 |
* @see javax.swing.CellEditor#isCellEditable(java.util.EventObject)
|
103 |
*/
|
104 |
public boolean isCellEditable(EventObject event) { |
105 |
if (event instanceof MouseEvent) { |
106 |
MouseEvent mouseEvent = (MouseEvent) event; |
107 |
TreePath path = tree.getPathForLocation(mouseEvent.getX(),
|
108 |
mouseEvent.getY()); |
109 |
if (path != null) { |
110 |
Object node = path.getLastPathComponent();
|
111 |
if ((node != null) && (node instanceof CheckBoxNode)) { |
112 |
CheckBoxNode selectedNode = (CheckBoxNode)node; |
113 |
if (mouseEvent.getClickCount() == 2){ |
114 |
|
115 |
}else if(mouseEvent.getClickCount() == 1){ |
116 |
changeAllChildren(selectedNode,!selectedNode.isSelected()); |
117 |
changeParentState(selectedNode,!selectedNode.isSelected()); |
118 |
tree.repaint(); |
119 |
} |
120 |
} |
121 |
} |
122 |
} |
123 |
return false; |
124 |
} |
125 |
|
126 |
/*
|
127 |
* (non-Javadoc)
|
128 |
* @see javax.swing.tree.TreeCellEditor#getTreeCellEditorComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int)
|
129 |
*/
|
130 |
public Component getTreeCellEditorComponent(JTree tree, Object value, |
131 |
boolean selected, boolean expanded, boolean leaf, int row) { |
132 |
Component editor = renderer.getTreeCellRendererComponent(tree, value,
|
133 |
true, expanded, leaf, row, true); |
134 |
|
135 |
if (editor instanceof JCheckBox) { |
136 |
//((JCheckBox) editor).addItemListener(new CheckBoxListener());
|
137 |
} |
138 |
return editor;
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* It enable or disable the parent node state depending of its children values
|
143 |
* @param selectedNode
|
144 |
* Selected node
|
145 |
* @param isSelected
|
146 |
* Current node status
|
147 |
*/
|
148 |
private void changeParentState(CheckBoxNode selectedNode,boolean isSelected){ |
149 |
CheckBoxNode parent = selectedNode.getParentNode(); |
150 |
while (parent != null){ |
151 |
if (isSelected != parent.isSelected()){
|
152 |
parent.setColor(TetraStateCheckBox.GREY); |
153 |
}else{
|
154 |
boolean isEnabled = true; |
155 |
for (int i=0 ; i<parent.getChildren().size() ; i++){ |
156 |
CheckBoxNode child = (CheckBoxNode)parent.getChildren().get(i); |
157 |
if (child != selectedNode){
|
158 |
if (parent.isSelected() != child.isSelected()){
|
159 |
isEnabled = false;
|
160 |
} |
161 |
} |
162 |
} |
163 |
if (!isEnabled){
|
164 |
parent.setColor(TetraStateCheckBox.GREY); |
165 |
}else{
|
166 |
parent.setColor(TetraStateCheckBox.WHITE); |
167 |
} |
168 |
|
169 |
} |
170 |
selectedNode = parent; |
171 |
parent = selectedNode.getParentNode(); |
172 |
} |
173 |
} |
174 |
|
175 |
|
176 |
/**
|
177 |
* It changes all the children status
|
178 |
* @param selectedNode
|
179 |
* Root node
|
180 |
* @param selected
|
181 |
* New state
|
182 |
*/
|
183 |
private void changeAllChildren(CheckBoxNode selectedNode,boolean selected){ |
184 |
for (int i=0 ; i<selectedNode.getChildren().size() ; i++){ |
185 |
CheckBoxNode child = ((CheckBoxNode)selectedNode.getChildren().get(i)); |
186 |
if ((child.getElement().getEntityType() == null) || |
187 |
(child.getElement().getEntityType().getType() != IXMLType.GML_GEOMETRY)){ |
188 |
child.setSelected(selected); |
189 |
} |
190 |
if (child.getChildren().size() > 0){ |
191 |
changeAllChildren(child,selected); |
192 |
} |
193 |
} |
194 |
} |
195 |
} |