svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / vectorialdb / wizard / TablesListItemVectorial.java @ 43420
History | View | Annotate | Download (5.37 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.geodb.vectorialdb.wizard; |
26 |
|
27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
29 |
|
30 |
import javax.swing.JOptionPane; |
31 |
|
32 |
import org.gvsig.andami.messages.NotificationManager; |
33 |
import org.gvsig.app.ApplicationLocator; |
34 |
import org.gvsig.app.ApplicationManager; |
35 |
import org.gvsig.app.project.ProjectManager; |
36 |
import org.gvsig.fmap.dal.DataTypes; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
40 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
41 |
import org.gvsig.fmap.mapcontrol.MapControl; |
42 |
import org.gvsig.i18n.Messages; |
43 |
|
44 |
|
45 |
public class TablesListItemVectorial extends TablesListItem { |
46 |
private MapControl mc;
|
47 |
|
48 |
|
49 |
public TablesListItemVectorial(DBStoreParameters param,
|
50 |
MapControl _mc, WizardVectorialDB _parent) { |
51 |
super(param, _parent);
|
52 |
mc = _mc; |
53 |
} |
54 |
|
55 |
public UserTableSettingsPanel getUserTableSettingsPanel(String espView) { |
56 |
if (tableSettingsPanel == null) { |
57 |
|
58 |
String[] ids = new String[0]; |
59 |
FeatureType ft = null;
|
60 |
FeatureAttributeDescriptor dbattr = null;
|
61 |
|
62 |
try {
|
63 |
ft = this.parent.getServerExplorer().getFeatureType(parameters);
|
64 |
} catch (DataException e) {
|
65 |
NotificationManager.addError(e); |
66 |
return null; |
67 |
} |
68 |
|
69 |
ArrayList auxAll = new ArrayList(); |
70 |
|
71 |
ArrayList geo_atts = new ArrayList(); |
72 |
ArrayList auxId = new ArrayList(); |
73 |
Iterator iter = ft.iterator();
|
74 |
while (iter.hasNext()) {
|
75 |
dbattr = (FeatureAttributeDescriptor) iter.next(); |
76 |
if (dbattr.getDataType().getType() == DataTypes.GEOMETRY) {
|
77 |
geo_atts.add(dbattr); |
78 |
} |
79 |
if (dbattr.isPrimaryKey()) {
|
80 |
auxId.add(dbattr.getName()); |
81 |
} |
82 |
auxAll.add(dbattr.getName()); |
83 |
|
84 |
} |
85 |
if( geo_atts.isEmpty() ) {
|
86 |
iter = ft.iterator(); |
87 |
while (iter.hasNext()) {
|
88 |
dbattr = (FeatureAttributeDescriptor) iter.next(); |
89 |
if (dbattr.getDataType().getType() == DataTypes.BYTEARRAY ||
|
90 |
dbattr.getDataType().getType() == DataTypes.STRING) { |
91 |
geo_atts.add(dbattr); |
92 |
} |
93 |
} |
94 |
} |
95 |
|
96 |
if (auxId.size() > 0) { |
97 |
StringBuilder strb = new StringBuilder(); |
98 |
strb.append('{');
|
99 |
for (int i = 0; i < auxId.size() - 1; i++) { |
100 |
strb.append(auxId.get(i)); |
101 |
strb.append(',');
|
102 |
} |
103 |
strb.append(auxId.get(auxId.size() - 1));
|
104 |
|
105 |
strb.append('}');
|
106 |
/*
|
107 |
* Only the true PK from the DB
|
108 |
*/
|
109 |
auxAll.clear(); |
110 |
auxAll.add(strb.toString()); |
111 |
} else {
|
112 |
/*
|
113 |
* If the table does not hace PK declared in the DB,
|
114 |
* we let the user choose any field and show a warning dialog
|
115 |
*/
|
116 |
showNoPkWarning(this.tableName);
|
117 |
} |
118 |
|
119 |
// ===============================
|
120 |
|
121 |
ids = (String[]) auxAll.toArray(new String[auxAll.size()]); |
122 |
int ids_size = ids.length;
|
123 |
FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
124 |
|
125 |
for (int i = 0; i < ids_size; i++) { |
126 |
ids_ci[i] = new FieldComboItem(ids[i]);
|
127 |
} |
128 |
|
129 |
|
130 |
int geos_size = geo_atts.size();
|
131 |
FieldComboItem[] geos_ci = new FieldComboItem[geos_size]; |
132 |
|
133 |
for (int i = 0; i < geos_size; i++) { |
134 |
dbattr = (FeatureAttributeDescriptor) geo_atts.get(i); |
135 |
geos_ci[i] = new FieldComboItem(dbattr.getName(), dbattr.getSRS());
|
136 |
} |
137 |
|
138 |
tableSettingsPanel = new UserTableSettingsVectorialPanel(ids_ci,
|
139 |
geos_ci, |
140 |
tableName, mc, false, (WizardVectorialDB) parent,
|
141 |
getParameters(), |
142 |
currentProjection(espView, |
143 |
ids_ci, geos_ci)); |
144 |
} |
145 |
|
146 |
return tableSettingsPanel;
|
147 |
} |
148 |
|
149 |
private void showNoPkWarning(String tableName) { |
150 |
ApplicationManager application = ApplicationLocator.getManager(); |
151 |
String msg = Messages.getText(
|
152 |
"_Table_NAME_does_not_have_declared_PK", new String[] { tableName } ); |
153 |
msg = msg + "\n\n";
|
154 |
msg = msg + Messages.getText( |
155 |
"_If_layer_edited_saving_edits_will_not_be_possible");
|
156 |
msg = msg + "\n";
|
157 |
msg = msg + Messages.getText( |
158 |
"_Strange_behavior_if_selected_ID_not_unique_values");
|
159 |
msg = msg + " ";
|
160 |
|
161 |
application.messageDialog( |
162 |
msg, |
163 |
null,
|
164 |
Messages.getText("_Id_field"),
|
165 |
JOptionPane.WARNING_MESSAGE,
|
166 |
"show_no_primary_key_warning_in_database_tables"
|
167 |
); |
168 |
|
169 |
} |
170 |
|
171 |
public void setEnabledPanels(boolean b) { |
172 |
super.setEnabledPanels(b);
|
173 |
tableSettingsPanel.enableSpatialControls(b); |
174 |
tableSettingsPanel.enableAlphaControls(b); |
175 |
} |
176 |
|
177 |
} |