svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / creation / model / SelectFilesTreeCheckNode.java @ 40560
History | View | Annotate | Download (3.51 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.installer.swing.impl.creation.model; |
30 |
|
31 |
import java.io.File; |
32 |
import java.util.Enumeration; |
33 |
|
34 |
import javax.swing.tree.DefaultMutableTreeNode; |
35 |
import javax.swing.tree.TreeNode; |
36 |
|
37 |
/**
|
38 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
39 |
*/
|
40 |
public class SelectFilesTreeCheckNode extends DefaultMutableTreeNode { |
41 |
|
42 |
/**
|
43 |
*
|
44 |
*/
|
45 |
private static final long serialVersionUID = 8722862821986059646L; |
46 |
public final static int SINGLE_SELECTION = 0; |
47 |
public final static int DIG_IN_SELECTION = 4; |
48 |
protected int selectionMode; |
49 |
protected boolean isSelected; |
50 |
|
51 |
private File file = null; |
52 |
|
53 |
public SelectFilesTreeCheckNode(File file) { |
54 |
this(file, true, false); |
55 |
} |
56 |
|
57 |
public SelectFilesTreeCheckNode(File file, boolean allowsChildren, |
58 |
boolean isSelected) {
|
59 |
super(file, allowsChildren);
|
60 |
this.isSelected = isSelected;
|
61 |
setSelectionMode(DIG_IN_SELECTION); |
62 |
this.file = file;
|
63 |
if (file.isDirectory()) {
|
64 |
retrieveChildren(); |
65 |
} |
66 |
} |
67 |
|
68 |
public void setSelectionMode(int mode) { |
69 |
selectionMode = mode; |
70 |
} |
71 |
|
72 |
public int getSelectionMode() { |
73 |
return selectionMode;
|
74 |
} |
75 |
|
76 |
public void setSelected(boolean isSelected) { |
77 |
this.isSelected = isSelected;
|
78 |
|
79 |
if ((selectionMode == DIG_IN_SELECTION) && (children != null)) { |
80 |
Enumeration e = children.elements();
|
81 |
while (e.hasMoreElements()) {
|
82 |
SelectFilesTreeCheckNode node = (SelectFilesTreeCheckNode) e |
83 |
.nextElement(); |
84 |
node.setSelected(isSelected); |
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
public boolean isSelected() { |
90 |
return isSelected;
|
91 |
} |
92 |
|
93 |
public boolean isFile() { |
94 |
return file.isFile();
|
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
*
|
100 |
* @see javax.swing.tree.DefaultMutableTreeNode#getChildAt(int)
|
101 |
*/
|
102 |
@Override
|
103 |
public TreeNode getChildAt(int index) { |
104 |
return super.getChildAt(index); |
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
*
|
110 |
* @see javax.swing.tree.DefaultMutableTreeNode#getChildCount()
|
111 |
*/
|
112 |
@Override
|
113 |
public int getChildCount() { |
114 |
return super.getChildCount(); |
115 |
} |
116 |
|
117 |
private void retrieveChildren() { |
118 |
File[] files = file.listFiles(); |
119 |
for (int i = 0; i < files.length; i++) { |
120 |
add(new SelectFilesTreeCheckNode(files[i]));
|
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* @return the file
|
126 |
*/
|
127 |
public File getFile() { |
128 |
return file;
|
129 |
} |
130 |
|
131 |
/*
|
132 |
* (non-Javadoc)
|
133 |
*
|
134 |
* @see javax.swing.tree.DefaultMutableTreeNode#toString()
|
135 |
*/
|
136 |
@Override
|
137 |
public String toString() { |
138 |
return file.getName();
|
139 |
} |
140 |
|
141 |
// If you want to change "isSelected" by CellEditor,
|
142 |
|
143 |
// public void setUserObject(Object obj) {
|
144 |
// if (obj instanceof Boolean) {
|
145 |
// setSelected(((Boolean)obj).booleanValue());
|
146 |
// }else{
|
147 |
// super.setUserObject(obj);
|
148 |
// }
|
149 |
// }
|
150 |
|
151 |
} |