Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / AvailableTablesCheckBoxList.java @ 29628

History | View | Annotate | Download (5.05 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package org.gvsig.geodb.vectorialdb.wizard;
44

    
45
import java.awt.Component;
46
import java.awt.event.MouseAdapter;
47
import java.awt.event.MouseEvent;
48

    
49
import javax.swing.JList;
50
import javax.swing.JOptionPane;
51
import javax.swing.ListCellRenderer;
52
import javax.swing.ListSelectionModel;
53
import javax.swing.UIManager;
54
import javax.swing.border.Border;
55
import javax.swing.border.EmptyBorder;
56

    
57
import org.apache.log4j.Logger;
58
import org.gvsig.andami.PluginServices;
59

    
60

    
61

    
62
/**
63
 * Utility class to keep the list of available tables.
64
 *
65
 * @author jldominguez
66
 *
67
 */
68
public class AvailableTablesCheckBoxList extends JList {
69
    protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
70
    private static Logger logger = Logger.getLogger(AvailableTablesCheckBoxList.class.getName());
71
    private WizardDB parent = null;
72
    private TablesListItem actingTable = null;
73

    
74
    public AvailableTablesCheckBoxList(WizardDB p) {
75
        parent = p;
76

    
77
        setCellRenderer(new CellRenderer());
78

    
79
        addMouseListener(new MouseAdapter() {
80
                public void mousePressed(MouseEvent e) {
81
                    int index = locationToIndex(e.getPoint());
82

    
83
                    if (index == -1) {
84
                        return;
85
                    }
86

    
87
                    actingTable = (TablesListItem) getModel().getElementAt(index);
88

    
89
                    if ((e.getClickCount() == 2) || (e.getX() < 15)) {
90
                        if (!actingTable.isActivated()) {
91
                            actingTable.activate();
92
                        }
93

    
94
                        actingTable.setSelected(!actingTable.isSelected());
95

    
96
                        if (actingTable.isSelected()) {
97
                            actingTable.setEnabledPanels(true);
98
                        }
99
                        else {
100
                            actingTable.setEnabledPanels(false);
101
                        }
102

    
103
                        repaint();
104
                    }
105

    
106
                    try {
107
                        parent.setSettingsPanels(actingTable);
108
                        parent.checkFinishable();
109
                    }
110
                    catch (Exception e1) {
111
                        actingTable.setEnabledPanels(false);
112
                        actingTable.setSelected(false);
113
                        logger.error("While setting selected table: " +
114
                            e1.getMessage(), e1);
115
                        showConnectionErrorMessage(e1.getMessage());
116
                    }
117
                }
118
            });
119

    
120
        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
121
    }
122

    
123
    private void showConnectionErrorMessage(String _msg) {
124
            if (_msg==null) {
125
                        _msg="";
126
                }
127
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
128
        String title = PluginServices.getText(this, "connection_error");
129
        JOptionPane.showMessageDialog(this, title + msg, title,
130
            JOptionPane.ERROR_MESSAGE);
131
    }
132

    
133
    protected class CellRenderer implements ListCellRenderer {
134
        public Component getListCellRendererComponent(JList list, Object value,
135
            int index, boolean isSelected, boolean cellHasFocus) {
136
            TablesListItem checkbox = (TablesListItem) value;
137
            checkbox.setBackground(isSelected ? getSelectionBackground()
138
                                              : getBackground());
139
            checkbox.setForeground(isSelected ? getSelectionForeground()
140
                                              : getForeground());
141
            checkbox.setEnabled(isEnabled());
142
            checkbox.setFont(getFont());
143
            checkbox.setFocusPainted(false);
144
            checkbox.setBorderPainted(true);
145
            checkbox.setBorder(isSelected
146
                ? UIManager.getBorder("List.focusCellHighlightBorder")
147
                : noFocusBorder);
148

    
149
            return checkbox;
150
        }
151
    }
152
}