Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / prodevelop / cit / gvsig / vectorialdb / wizard / TablesListItem.java @ 24759

History | View | Annotate | Download (7.14 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 java.util.ArrayList;
46
import java.util.Iterator;
47

    
48
import javax.swing.JCheckBox;
49

    
50
import org.cresques.cts.IProjection;
51
import org.gvsig.fmap.dal.exception.ReadException;
52
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
53
import org.gvsig.fmap.dal.feature.FeatureType;
54
import org.gvsig.fmap.data.feature.db.DBAttributeDescriptor;
55
import org.gvsig.fmap.data.feature.db.DBExplorer;
56
import org.gvsig.fmap.data.feature.db.DBStoreParameters;
57
import org.gvsig.fmap.mapcontrol.MapControl;
58

    
59
import com.iver.andami.messages.NotificationManager;
60
import com.iver.cit.gvsig.addlayer.AddLayerDialog;
61
import com.iver.cit.gvsig.gui.panels.CRSSelectPanel;
62

    
63

    
64
/**
65
 * Utility class that represents a table list item as a selectable check box.
66
 *
67
 * @author jldominguez
68
 *
69
 */
70
public class TablesListItem extends JCheckBox {
71
    private String tableName = "";
72
    private UserSelectedFieldsPanel selectedFieldsPanel = null;
73
    private UserTableSettingsPanel tableSettingsPanel = null;
74
    private MapControl mc;
75
    private WizardVectorialDB parent = null;
76
    private boolean activated = false;
77
    private CRSSelectPanel jPanelProj;
78
        private DBStoreParameters parameters;
79
        private DBExplorer explorer;
80

    
81
    public TablesListItem(DBExplorer explorer, DBStoreParameters parameters,
82
                        MapControl _mc, WizardVectorialDB _parent) {
83
        tableName = parameters.getTableName();
84
        setText(tableName);
85
        this.parameters = parameters;
86
        this.explorer=explorer;
87
        mc = _mc;
88
        parent = _parent;
89
    }
90

    
91
    public void activate() {
92
        activated = true;
93
        selectedFieldsPanel.loadValues();
94
        tableSettingsPanel.loadValues();
95
    }
96

    
97
    public boolean isActivated() {
98
        return activated;
99
    }
100

    
101
    /**
102
     * Tells whether this item prevents the wizard from being in a valid final state.
103
     * @return whether this item prevents the wizard from being in a valid final state.
104
     */
105
    public boolean disturbsWizardValidity() {
106
        if (isSelected()) {
107
            return (!hasValidValues());
108
        }
109
        else {
110
            return false;
111
        }
112
    }
113

    
114
    private boolean hasValidValues() {
115
        return tableSettingsPanel.hasValidValues();
116
    }
117

    
118
    public String toString() {
119
        return tableName;
120
    }
121

    
122
    public String getTableName() {
123
        return tableName;
124
    }
125

    
126
    public void setEnabledPanels(boolean b) {
127
        selectedFieldsPanel.enableControls(b);
128
        tableSettingsPanel.enableSpatialControls(b);
129
        tableSettingsPanel.enableAlphaControls(b);
130
    }
131

    
132
    public UserSelectedFieldsPanel getUserSelectedFieldsPanel() {
133
        if (selectedFieldsPanel == null) {
134
                FeatureType ft=null;
135
                        try {
136
                                ft = explorer.getFeatureTypes(parameters)[0];
137
                        } catch (ReadException e) {
138
                                // TODO Auto-generated catch block
139
                                e.printStackTrace();
140
                        }
141
                FeatureAttributeDescriptor[] allf=(FeatureAttributeDescriptor[])ft.toArray(new FeatureAttributeDescriptor[0]);
142
            selectedFieldsPanel = new UserSelectedFieldsPanel(allf, true,
143
                    parent);
144
        }
145

    
146
        return selectedFieldsPanel;
147
    }
148

    
149
    public UserTableSettingsPanel getUserTableSettingsPanel(String espView) {
150
        if (tableSettingsPanel == null) {
151

    
152
                String[] ids = new String[0];
153
                FeatureType ft=null;
154

    
155
                        try {
156
                                ft = explorer.getFeatureTypes(parameters)[0];
157
                        } catch (ReadException e) {
158
                                // TODO Auto-generated catch block
159
                                e.printStackTrace();
160
                        }
161

    
162

    
163
                       ids = ft.getFields();
164

    
165
                String[] geos = new String[0];
166
                ArrayList auxGeo = new ArrayList();
167
                        ArrayList auxId = new ArrayList();
168
                Iterator iter = ft.iterator();
169
                        while (iter.hasNext()) {
170
                                DBAttributeDescriptor dbattr = (DBAttributeDescriptor) iter
171
                                                .next();
172
                                if (dbattr.getDataType() == dbattr.TYPE_GEOMETRY) {
173
                                        auxGeo.add(dbattr.getName());
174
                                }
175
//                                 if (dbattr.isPrimaryKey()) {
176
                                        auxId.add(dbattr.getName());
177
//                                 }
178

    
179
                        }
180

    
181
                        geos = (String[]) auxGeo.toArray(new String[0]);
182
                        ids = (String[]) auxId.toArray(new String[0]);
183

    
184
            int ids_size = ids.length;
185
            FieldComboItem[] ids_ci = new FieldComboItem[ids_size];
186

    
187
            for (int i = 0; i < ids_size; i++) {
188
                                ids_ci[i] = new FieldComboItem(ids[i]);
189
                        }
190

    
191
            int geos_size = geos.length;
192
            FieldComboItem[] geos_ci = new FieldComboItem[geos_size];
193

    
194
            for (int i = 0; i < geos_size; i++) {
195
                                geos_ci[i] = new FieldComboItem(geos[i]);
196
                        }
197

    
198
            tableSettingsPanel = new UserTableSettingsPanel(ids_ci, geos_ci,
199
                              tableName, mc, true, parent, projectionPanel(espView,ids_ci,geos_ci));
200
        }
201

    
202
        return tableSettingsPanel;
203
    }
204
    public CRSSelectPanel projectionPanel(String espView,
205
                        FieldComboItem[] ids_ci, FieldComboItem[] geos_ci) {
206
                IProjection proj = AddLayerDialog.getLastProjection();
207
                        try {
208
                                ArrayList list=new ArrayList(1);
209
                                list.add(espView);
210
                                FeatureType ft=null;
211
                                try {
212
                                        ft = explorer.getFeatureTypes(parameters)[0];
213
                                } catch (ReadException e) {
214
                                        // TODO Auto-generated catch block
215
                                        e.printStackTrace();
216
                                }
217
                                ft.setAllSRS(list);
218
                        } catch (Exception e) {
219
                                NotificationManager.addInfo("Incorrect projection", e);
220
                        }
221
                return getJPanelProj(proj);
222
        }
223
    private CRSSelectPanel getJPanelProj(IProjection proj) {
224
                        jPanelProj = CRSSelectPanel.getPanel(proj);
225

    
226
                        jPanelProj.setTransPanelActive(true);
227
                        jPanelProj.setBounds(new java.awt.Rectangle(210, 22, 280, 32));
228
                        jPanelProj.setPreferredSize(new java.awt.Dimension(448,35));
229
                        jPanelProj.addActionListener(new java.awt.event.ActionListener() {
230
                                public void actionPerformed(java.awt.event.ActionEvent e) {
231
                                if (jPanelProj.isOkPressed()) {
232
                                        AddLayerDialog.setLastProjection(jPanelProj.getCurProj());
233
                                }
234
                                }
235
                        });
236

    
237
                return jPanelProj;
238
        }
239
    public DBStoreParameters getParameters() {
240
            return parameters;
241
    }
242
}