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 / execution / panel / renderers / InstallStatusCellEditor.java @ 37831

History | View | Annotate | Download (3.01 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
package org.gvsig.installer.swing.impl.execution.panel.renderers;
23

    
24
import java.awt.Component;
25

    
26
import javax.swing.DefaultCellEditor;
27
import javax.swing.JCheckBox;
28
import javax.swing.JTable;
29

    
30
import org.gvsig.installer.swing.impl.execution.panel.SelectPackagesPanel;
31
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageStatus;
32

    
33
/**
34
 * @author gvSIG Team
35
 * @version $Id$
36
 * 
37
 */
38
public class InstallStatusCellEditor extends DefaultCellEditor {
39

    
40
        private static final long serialVersionUID = 1271382732175530111L;
41
        PackageStatus status;
42
        SelectPackagesPanel panel;
43

    
44
        public InstallStatusCellEditor(SelectPackagesPanel selectPackagesPanel) {
45
                super(new JCheckBox());
46
                this.panel = selectPackagesPanel;
47
        }
48

    
49
        @Override
50
        public Component getTableCellEditorComponent(JTable arg0, Object value,
51
                        boolean isSelected, int row, int col) {
52
                JCheckBox check = (JCheckBox) this.getComponent();
53
                status = (PackageStatus) value;
54

    
55
                switch (status) {
56

    
57
                case INSTALLED:
58
                        check.setEnabled(true);
59
                        check.setSelected(false);
60
                        break;
61

    
62
                case TO_REINSTALL:
63
                        check.setEnabled(true);
64
                        check.setSelected(true);
65
                        break;
66

    
67
                case NOT_INSTALLED:
68
                        check.setEnabled(true);
69
                        check.setSelected(false);
70
                        break;
71

    
72
                case TO_INSTALL:
73
                        check.setEnabled(true);
74
                        check.setSelected(true);
75
                        break;
76

    
77
                case INSTALLED_NOT_INSTALLABLE:
78
                        check.setEnabled(false);
79
                        break;
80

    
81
                case BROKEN:
82
                        check.setEnabled(false);
83
                        check.setSelected(false);
84
                        break;
85

    
86
                default:
87
                        check.setSelected(false);
88
                        check.setEnabled(false);
89
                        break;
90
                }
91
                return check;
92
        }
93

    
94
        @Override
95
        public Object getCellEditorValue() {
96
                JCheckBox check = (JCheckBox) this.getComponent();
97
                switch (status) {
98
                case INSTALLED:
99
                        if (check.isSelected()) {
100
                                status = PackageStatus.TO_REINSTALL;
101
                        }
102
                        break;
103

    
104
                case TO_REINSTALL:
105
                        if (!check.isSelected()) {
106
                                status = PackageStatus.INSTALLED;
107
                        }
108
                        break;
109

    
110
                case NOT_INSTALLED:
111
                        if (check.isSelected()) {
112
                                status = PackageStatus.TO_INSTALL;
113
                        }
114
                        break;
115

    
116
                case TO_INSTALL:
117
                        if (!check.isSelected()) {
118
                                status = PackageStatus.NOT_INSTALLED;
119
                        }
120
                        break;
121

    
122
                default:
123
                        break;
124
                }
125
                return status;
126
        }
127
}