Statistics
| Revision:

root / branches / v10 / applications / appgvSIG / src / com / prodevelop / cit / gvsig / vectorialdb / wizard / AvailableTablesCheckBoxList.java @ 11935

History | View | Annotate | Download (5.04 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 com.prodevelop.cit.gvsig.vectorialdb.wizard;
44

    
45
import com.iver.andami.PluginServices;
46

    
47
import org.apache.log4j.Logger;
48

    
49
import java.awt.Component;
50
import java.awt.event.MouseAdapter;
51
import java.awt.event.MouseEvent;
52

    
53
import javax.swing.JList;
54
import javax.swing.JOptionPane;
55
import javax.swing.ListCellRenderer;
56
import javax.swing.ListSelectionModel;
57
import javax.swing.UIManager;
58
import javax.swing.border.Border;
59
import javax.swing.border.EmptyBorder;
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 WizardVectorialDB parent = null;
72
    private TablesListItem actingTable = null;
73

    
74
    public AvailableTablesCheckBoxList(WizardVectorialDB 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
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
125
        String title = PluginServices.getText(this, "connection_error");
126
        JOptionPane.showMessageDialog(this, title + msg, title,
127
            JOptionPane.ERROR_MESSAGE);
128
    }
129

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

    
146
            return checkbox;
147
        }
148
    }
149
}