Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / creation / model / SelectFilesTreeCheckNode.java @ 32290

History | View | Annotate | Download (3.37 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.installer.swing.impl.creation.model;
29

    
30
import java.io.File;
31
import java.util.Enumeration;
32

    
33
import javax.swing.tree.DefaultMutableTreeNode;
34
import javax.swing.tree.TreeNode;
35

    
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
38
 */
39
public class SelectFilesTreeCheckNode  extends DefaultMutableTreeNode {
40
        public final static int SINGLE_SELECTION = 0;
41
        public final static int DIG_IN_SELECTION = 4;
42
        protected int selectionMode;
43
        protected boolean isSelected;
44

    
45
        private File file = null;
46

    
47
        public SelectFilesTreeCheckNode(File file) {
48
                this(file, true, false);            
49
        }
50

    
51
        public SelectFilesTreeCheckNode(File file, boolean allowsChildren,
52
                        boolean isSelected) {
53
                super(file, allowsChildren);
54
                this.isSelected = isSelected;
55
                setSelectionMode(DIG_IN_SELECTION);
56
                this.file = file;            
57
                if (file.isDirectory()){
58
                        retrieveChildren();
59
                }
60
        }
61

    
62
        public void setSelectionMode(int mode) {
63
                selectionMode = mode;
64
        }
65

    
66
        public int getSelectionMode() {
67
                return selectionMode;
68
        }
69

    
70
        public void setSelected(boolean isSelected) {
71
                this.isSelected = isSelected;
72

    
73
                if ((selectionMode == DIG_IN_SELECTION) && (children != null)) {
74
                        Enumeration e = children.elements();
75
                        while (e.hasMoreElements()) {
76
                                SelectFilesTreeCheckNode node = (SelectFilesTreeCheckNode) e.nextElement();
77
                                node.setSelected(isSelected);
78
                        }
79
                }
80
        }
81

    
82
        public boolean isSelected() {
83
                return isSelected;
84
        }
85

    
86

    
87
        public boolean isFile() {
88
                return file.isFile();
89
        }
90

    
91
        /*
92
         * (non-Javadoc)
93
         * @see javax.swing.tree.DefaultMutableTreeNode#getChildAt(int)
94
         */
95
        @Override
96
        public TreeNode getChildAt(int index) {
97
                return super.getChildAt(index);                
98
        }
99

    
100
        /* (non-Javadoc)
101
         * @see javax.swing.tree.DefaultMutableTreeNode#getChildCount()
102
         */
103
        @Override
104
        public int getChildCount() {
105
                return super.getChildCount();
106
        }
107

    
108
        private void retrieveChildren()
109
        {
110
                File[] files = file.listFiles();
111
                for (int i=0 ; i<files.length ; i++){
112
                        add(new SelectFilesTreeCheckNode(files[i]));
113
                }                                
114
        }
115
        
116
        /**
117
         * @return the file
118
         */
119
        public File getFile() {
120
                return file;
121
        }
122

    
123
        /* (non-Javadoc)
124
         * @see javax.swing.tree.DefaultMutableTreeNode#toString()
125
         */
126
        @Override
127
        public String toString() {
128
                return file.getName();
129
        }
130
        
131

    
132
        // If you want to change "isSelected" by CellEditor,
133

    
134
//        public void setUserObject(Object obj) { 
135
//                if (obj instanceof Boolean) {
136
//                        setSelected(((Boolean)obj).booleanValue()); 
137
//                }else{
138
//                        super.setUserObject(obj); 
139
//                }
140
//        }
141

    
142

    
143
}