Statistics
| Revision:

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 / SelectFilesTree.java @ 40560

History | View | Annotate | Download (2.8 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.ArrayList;
33
import java.util.List;
34

    
35
import javax.swing.JTree;
36
import javax.swing.tree.TreeSelectionModel;
37

    
38
/**
39
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
40
 */
41
public class SelectFilesTree extends JTree {
42

    
43
        /**
44
     * 
45
     */
46
        private static final long serialVersionUID = 9167217334192981460L;
47

    
48
        public SelectFilesTree() {
49
                super();
50
        }
51

    
52
        public void setApplicationDirectory(File applicationDirectory) {
53
                setModel(new SelectFilesTreeModel(applicationDirectory));
54
                setCellRenderer(new SelectFilesTreeCellRenderer());
55
                getSelectionModel().setSelectionMode(
56
                                TreeSelectionModel.SINGLE_TREE_SELECTION);
57
                addMouseListener(new SelectFilesTreeNodeSelectionListener(this));
58
        }
59

    
60
        public List<File> getSelectedFiles() {
61
                List<File> selectedFiles = new ArrayList<File>();
62
                addSelectedFiles((SelectFilesTreeCheckNode) getModel().getRoot(),
63
                                selectedFiles);
64
                return selectedFiles;
65
        }
66

    
67
        public void addSelectedFiles(SelectFilesTreeCheckNode node,
68
                        List<File> selectedFiles) {
69

    
70
                if (node.isSelected) {
71
                        File absolutePath = new File(node.getFile().getAbsolutePath());
72
                        if (!absolutePath.isDirectory()) {
73
                                selectedFiles.add(absolutePath);
74
                        } else {
75
                                traverseChildren(node, selectedFiles);
76
                        }
77
                } else {
78
                        if (node.getFile().isDirectory()) {
79
                                for (int i = 0; i < node.getChildCount(); i++) {
80
                                        addSelectedFiles((SelectFilesTreeCheckNode) node
81
                                                        .getChildAt(i), selectedFiles);
82
                                }
83
                                traverseChildren(node, selectedFiles);
84
                        }
85
                }
86
        }
87

    
88
        protected void traverseChildren(SelectFilesTreeCheckNode node,
89
                        List<File> selectedFiles) {
90
                for (int i = 0; i < node.getChildCount(); i++) {
91
                        addSelectedFiles((SelectFilesTreeCheckNode) node.getChildAt(i),
92
                                        selectedFiles);
93
                }
94

    
95
        }
96

    
97
}