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