Statistics
| Revision:

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

History | View | Annotate | Download (5.1 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.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59

    
60
import org.gvsig.andami.PluginServices;
61

    
62

    
63

    
64
/**
65
 * Utility class to keep the list of available tables.
66
 *
67
 * @author jldominguez
68
 *
69
 */
70
public class AvailableTablesCheckBoxList extends JList {
71
    protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
72

    
73
    private static final Logger LOG = LoggerFactory
74
        .getLogger(AvailableTablesCheckBoxList.class);
75
    private WizardDB parent = null;
76
    private TablesListItem actingTable = null;
77

    
78
    public AvailableTablesCheckBoxList(WizardDB p) {
79
        parent = p;
80

    
81
        setCellRenderer(new CellRenderer());
82

    
83
        addMouseListener(new MouseAdapter() {
84
                public void mousePressed(MouseEvent e) {
85
                    int index = locationToIndex(e.getPoint());
86

    
87
                    if (index == -1) {
88
                        return;
89
                    }
90

    
91
                    actingTable = (TablesListItem) getModel().getElementAt(index);
92

    
93
                    if ((e.getClickCount() == 2) || (e.getX() < 15)) {
94
                        if (!actingTable.isActivated()) {
95
                            actingTable.activate();
96
                        }
97

    
98
                        actingTable.setSelected(!actingTable.isSelected());
99

    
100
                        if (actingTable.isSelected()) {
101
                            actingTable.setEnabledPanels(true);
102
                        }
103
                        else {
104
                            actingTable.setEnabledPanels(false);
105
                        }
106

    
107
                        repaint();
108
                    }
109

    
110
                    try {
111
                        parent.setSettingsPanels(actingTable);
112
                        parent.checkFinishable();
113
                    }
114
                    catch (Exception e1) {
115
                        actingTable.setEnabledPanels(false);
116
                        actingTable.setSelected(false);
117
                    LOG.error(
118
                        "While setting selected table: " +
119
                            e1.getMessage(), e1);
120
                        showConnectionErrorMessage(e1.getMessage());
121
                    }
122
                }
123
            });
124

    
125
        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
126
    }
127

    
128
    private void showConnectionErrorMessage(String _msg) {
129
            if (_msg==null) {
130
                        _msg="";
131
                }
132
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
133
        String title = PluginServices.getText(this, "connection_error");
134
        JOptionPane.showMessageDialog(this, title + msg, title,
135
            JOptionPane.ERROR_MESSAGE);
136
    }
137

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

    
154
            return checkbox;
155
        }
156
    }
157
}