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 @ 43360
History | View | Annotate | Download (4.94 KB)
1 | 40557 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | |
25 | package org.gvsig.geodb.vectorialdb.wizard; |
||
26 | |||
27 | import java.util.ArrayList; |
||
28 | import java.util.Iterator; |
||
29 | |||
30 | 40963 | jldominguez | import javax.swing.JOptionPane; |
31 | |||
32 | 40435 | jjdelcerro | import org.gvsig.andami.messages.NotificationManager; |
33 | 40963 | jldominguez | import org.gvsig.app.ApplicationLocator; |
34 | 43360 | jjdelcerro | import org.gvsig.app.ApplicationManager; |
35 | import org.gvsig.app.project.ProjectManager; |
||
36 | 40435 | jjdelcerro | 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 | 40963 | jldominguez | import org.gvsig.i18n.Messages; |
43 | 40435 | jjdelcerro | |
44 | |||
45 | public class TablesListItemVectorial extends TablesListItem { |
||
46 | private MapControl mc;
|
||
47 | |||
48 | |||
49 | 41258 | jjdelcerro | public TablesListItemVectorial(DBStoreParameters param,
|
50 | 40435 | jjdelcerro | MapControl _mc, WizardVectorialDB _parent) { |
51 | 41258 | jjdelcerro | super(param, _parent);
|
52 | 40435 | jjdelcerro | 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 | 41258 | jjdelcerro | ft = this.parent.getServerExplorer().getFeatureType(parameters);
|
64 | 40435 | jjdelcerro | } 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 | |||
86 | if (auxId.size() > 0) { |
||
87 | StringBuilder strb = new StringBuilder(); |
||
88 | strb.append('{');
|
||
89 | for (int i = 0; i < auxId.size() - 1; i++) { |
||
90 | strb.append(auxId.get(i)); |
||
91 | strb.append(',');
|
||
92 | } |
||
93 | strb.append(auxId.get(auxId.size() - 1));
|
||
94 | |||
95 | strb.append('}');
|
||
96 | 40963 | jldominguez | /*
|
97 | * Only the true PK from the DB
|
||
98 | */
|
||
99 | auxAll.clear(); |
||
100 | auxAll.add(strb.toString()); |
||
101 | } else {
|
||
102 | /*
|
||
103 | * If the table does not hace PK declared in the DB,
|
||
104 | * we let the user choose any field and show a warning dialog
|
||
105 | */
|
||
106 | showNoPkWarning(this.tableName);
|
||
107 | 40435 | jjdelcerro | } |
108 | 40963 | jldominguez | |
109 | // ===============================
|
||
110 | |||
111 | 40435 | jjdelcerro | ids = (String[]) auxAll.toArray(new String[auxAll.size()]); |
112 | int ids_size = ids.length;
|
||
113 | FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
||
114 | |||
115 | for (int i = 0; i < ids_size; i++) { |
||
116 | ids_ci[i] = new FieldComboItem(ids[i]);
|
||
117 | } |
||
118 | |||
119 | |||
120 | int geos_size = geo_atts.size();
|
||
121 | FieldComboItem[] geos_ci = new FieldComboItem[geos_size]; |
||
122 | |||
123 | for (int i = 0; i < geos_size; i++) { |
||
124 | dbattr = (FeatureAttributeDescriptor) geo_atts.get(i); |
||
125 | geos_ci[i] = new FieldComboItem(dbattr.getName(), dbattr.getSRS());
|
||
126 | } |
||
127 | |||
128 | tableSettingsPanel = new UserTableSettingsVectorialPanel(ids_ci,
|
||
129 | geos_ci, |
||
130 | tableName, mc, false, (WizardVectorialDB) parent,
|
||
131 | getParameters(), |
||
132 | currentProjection(espView, |
||
133 | ids_ci, geos_ci)); |
||
134 | } |
||
135 | |||
136 | return tableSettingsPanel;
|
||
137 | } |
||
138 | |||
139 | 40963 | jldominguez | private void showNoPkWarning(String tableName) { |
140 | 43360 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
141 | 40963 | jldominguez | String msg = Messages.getText(
|
142 | "_Table_NAME_does_not_have_declared_PK", new String[] { tableName } ); |
||
143 | msg = msg + "\n\n";
|
||
144 | msg = msg + Messages.getText( |
||
145 | "_If_layer_edited_saving_edits_will_not_be_possible");
|
||
146 | msg = msg + "\n";
|
||
147 | msg = msg + Messages.getText( |
||
148 | "_Strange_behavior_if_selected_ID_not_unique_values");
|
||
149 | msg = msg + " ";
|
||
150 | |||
151 | 43360 | jjdelcerro | application.messageDialog( |
152 | msg, |
||
153 | null,
|
||
154 | Messages.getText("_Id_field"),
|
||
155 | JOptionPane.WARNING_MESSAGE,
|
||
156 | "show_no_primary_key_warning_in_database_tables"
|
||
157 | ); |
||
158 | |||
159 | 40963 | jldominguez | } |
160 | |||
161 | 40435 | jjdelcerro | public void setEnabledPanels(boolean b) { |
162 | super.setEnabledPanels(b);
|
||
163 | tableSettingsPanel.enableSpatialControls(b); |
||
164 | tableSettingsPanel.enableAlphaControls(b); |
||
165 | } |
||
166 | |||
167 | } |