Revision 28459
trunk/extensions/extTableImport/src/org/gvsig/tableImport/importfields/ui/FieldPanel.java | ||
---|---|---|
1 |
package org.gvsig.tableImport.importfields.ui; |
|
2 |
|
|
3 |
import java.awt.GridBagConstraints; |
|
4 |
import java.awt.Insets; |
|
5 |
import java.awt.event.FocusEvent; |
|
6 |
import java.awt.event.FocusListener; |
|
7 |
import java.awt.event.ItemEvent; |
|
8 |
import java.awt.event.ItemListener; |
|
9 |
import java.awt.event.KeyEvent; |
|
10 |
import java.awt.event.KeyListener; |
|
11 |
import java.beans.PropertyChangeEvent; |
|
12 |
|
|
13 |
import javax.swing.JCheckBox; |
|
14 |
import javax.swing.JComponent; |
|
15 |
import javax.swing.JPanel; |
|
16 |
import javax.swing.JTextField; |
|
17 |
import javax.swing.event.DocumentEvent; |
|
18 |
import javax.swing.event.DocumentListener; |
|
19 |
|
|
20 |
public class FieldPanel extends JComponent implements DocumentListener, ItemListener,KeyListener, FocusListener { |
|
21 |
|
|
22 |
private static final long serialVersionUID = 1L; |
|
23 |
private JCheckBox chkImport = null; |
|
24 |
private JTextField txtSourceField = null; |
|
25 |
private JTextField txtTargetFieldName = null; |
|
26 |
private boolean txtTargetFieldName_changed = false; |
|
27 |
|
|
28 |
private boolean updating=false; |
|
29 |
/** |
|
30 |
* This is the default constructor |
|
31 |
*/ |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* This method initializes this |
|
36 |
* |
|
37 |
* @return void |
|
38 |
*/ |
|
39 |
protected void loadIn(JPanel panel) { |
|
40 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
41 |
gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL; |
|
42 |
// gridBagConstraints2.gridy = 0; |
|
43 |
gridBagConstraints2.weightx = 1.0; |
|
44 |
gridBagConstraints2.insets = new Insets(2, 2, 2, 2); |
|
45 |
gridBagConstraints2.gridx = 2; |
|
46 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
47 |
gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL; |
|
48 |
// gridBagConstraints1.gridy = 0; |
|
49 |
gridBagConstraints1.weightx = 1.0D; |
|
50 |
gridBagConstraints1.anchor = GridBagConstraints.CENTER; |
|
51 |
gridBagConstraints1.gridwidth = 1; |
|
52 |
gridBagConstraints1.insets = new Insets(2, 2, 2, 2); |
|
53 |
gridBagConstraints1.gridx = 1; |
|
54 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
55 |
gridBagConstraints.gridx = 0; |
|
56 |
gridBagConstraints.anchor = GridBagConstraints.CENTER; |
|
57 |
//gridBagConstraints.gridy = 0; |
|
58 |
//this.setSize(350, 28); |
|
59 |
//this.setLayout(new GridBagLayout()); |
|
60 |
//this.setPreferredSize(new Dimension(350, 28)); |
|
61 |
panel.add(getChkImport(), gridBagConstraints); |
|
62 |
panel.add(getTxtSourceField(), gridBagConstraints1); |
|
63 |
panel.add(getTxtTargetFieldName(), gridBagConstraints2); |
|
64 |
} |
|
65 |
|
|
66 |
protected void removeFrom(JPanel panel) { |
|
67 |
panel.remove(getChkImport()); |
|
68 |
panel.remove(getTxtSourceField()); |
|
69 |
panel.remove(getTxtTargetFieldName()); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* This method initializes chkImport |
|
74 |
* |
|
75 |
* @return javax.swing.JCheckBox |
|
76 |
*/ |
|
77 |
private JCheckBox getChkImport() { |
|
78 |
if (chkImport == null) { |
|
79 |
chkImport = new JCheckBox(); |
|
80 |
chkImport.setName("import"); |
|
81 |
chkImport.addItemListener(this); |
|
82 |
} |
|
83 |
return chkImport; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* This method initializes txtSourceField |
|
88 |
* |
|
89 |
* @return javax.swing.JTextField |
|
90 |
*/ |
|
91 |
private JTextField getTxtSourceField() { |
|
92 |
if (txtSourceField == null) { |
|
93 |
txtSourceField = new JTextField(); |
|
94 |
txtSourceField.setName("sourceField"); |
|
95 |
txtSourceField.setEditable(false); |
|
96 |
} |
|
97 |
return txtSourceField; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* This method initializes txtTargetFieldName |
|
102 |
* |
|
103 |
* @return javax.swing.JTextField |
|
104 |
*/ |
|
105 |
private JTextField getTxtTargetFieldName() { |
|
106 |
if (txtTargetFieldName == null) { |
|
107 |
txtTargetFieldName = new JTextField(); |
|
108 |
txtTargetFieldName.getDocument().addDocumentListener(this); |
|
109 |
txtTargetFieldName.addFocusListener(this); |
|
110 |
txtTargetFieldName.addKeyListener(this); |
|
111 |
} |
|
112 |
return txtTargetFieldName; |
|
113 |
} |
|
114 |
|
|
115 |
public boolean isToImport(){ |
|
116 |
return this.getChkImport().isSelected(); |
|
117 |
} |
|
118 |
|
|
119 |
public void setToImpor(boolean value){ |
|
120 |
this.updating=true; |
|
121 |
this.getChkImport().setSelected(value); |
|
122 |
this.updating=false; |
|
123 |
} |
|
124 |
|
|
125 |
public String getSourceField(){ |
|
126 |
return this.getTxtSourceField().getText(); |
|
127 |
} |
|
128 |
|
|
129 |
public void setSourceField(String fieldName){ |
|
130 |
this.updating=true; |
|
131 |
this.getTxtSourceField().setText(fieldName); |
|
132 |
this.updating=false; |
|
133 |
} |
|
134 |
|
|
135 |
public String getTargetFieldName(){ |
|
136 |
return this.getTxtTargetFieldName().getText(); |
|
137 |
} |
|
138 |
|
|
139 |
public void setTargetFieldName(String fieldName){ |
|
140 |
this.updating=true; |
|
141 |
this.getTxtTargetFieldName().setText(fieldName); |
|
142 |
this.updating=false; |
|
143 |
} |
|
144 |
public void propertyChange(PropertyChangeEvent evt) { |
|
145 |
if (evt.getSource().equals(this.getTxtTargetFieldName())){ |
|
146 |
firePropertyChange("targetFieldName", evt.getOldValue(), evt.getNewValue()); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
public void itemStateChanged(ItemEvent e) { |
|
151 |
boolean isSelected =e.getStateChange() == ItemEvent.SELECTED; |
|
152 |
|
|
153 |
if (e.getSource().equals(this.getChkImport())){ |
|
154 |
firePropertyChange("toImport", !isSelected, isSelected); |
|
155 |
} |
|
156 |
|
|
157 |
} |
|
158 |
public void changedUpdate(DocumentEvent e) { |
|
159 |
// FIXME: Peta porque antes de que termine el evento se hace un setText |
|
160 |
// firePropertyChange("targetFieldName", null, this.getTargetFieldName()); |
|
161 |
if (this.updating) return; |
|
162 |
this.txtTargetFieldName_changed=true; |
|
163 |
} |
|
164 |
|
|
165 |
public void insertUpdate(DocumentEvent e) { |
|
166 |
// FIXME: Peta porque antes de que termine el evento se hace un setText |
|
167 |
// firePropertyChange("targetFieldName", null, this.getTargetFieldName()); |
|
168 |
if (this.updating) return; |
|
169 |
this.txtTargetFieldName_changed=true; |
|
170 |
|
|
171 |
} |
|
172 |
public void removeUpdate(DocumentEvent e) { |
|
173 |
// FIXME: Peta porque antes de que termine el evento se hace un setText |
|
174 |
// firePropertyChange("targetFieldName", null, this.getTargetFieldName()); |
|
175 |
if (this.updating) return; |
|
176 |
this.txtTargetFieldName_changed=true; |
|
177 |
} |
|
178 |
|
|
179 |
public void keyPressed(KeyEvent e) { |
|
180 |
// TODO Auto-generated method stub |
|
181 |
} |
|
182 |
public void keyReleased(KeyEvent e) { |
|
183 |
if (this.txtTargetFieldName_changed){ |
|
184 |
firePropertyChange("targetFieldName", null, this.getTargetFieldName()); |
|
185 |
this.txtTargetFieldName_changed=false; |
|
186 |
} |
|
187 |
} |
|
188 |
public void keyTyped(KeyEvent e) { |
|
189 |
if (this.txtTargetFieldName_changed){ |
|
190 |
firePropertyChange("targetFieldName", null, this.getTargetFieldName()); |
|
191 |
this.txtTargetFieldName_changed=false; |
|
192 |
} |
|
193 |
|
|
194 |
} |
|
195 |
public void focusGained(FocusEvent e) { |
|
196 |
// TODO Auto-generated method stub |
|
197 |
|
|
198 |
} |
|
199 |
public void focusLost(FocusEvent e) { |
|
200 |
if (this.txtTargetFieldName_changed){ |
|
201 |
firePropertyChange("targetFieldName", null, this.getTargetFieldName()); |
|
202 |
this.txtTargetFieldName_changed=false; |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
} |
|
0 | 207 |
trunk/extensions/extTableImport/src/org/gvsig/tableImport/importfields/ui/LinkDefinitionPanel.java | ||
---|---|---|
1 |
package org.gvsig.tableImport.importfields.ui; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.awt.GridBagConstraints; |
|
5 |
import java.awt.GridBagLayout; |
|
6 |
import java.awt.Insets; |
|
7 |
import java.awt.event.ItemEvent; |
|
8 |
import java.awt.event.ItemListener; |
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.Iterator; |
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import javax.swing.DefaultComboBoxModel; |
|
14 |
import javax.swing.JComboBox; |
|
15 |
import javax.swing.JLabel; |
|
16 |
|
|
17 |
import jwizardcomponent.JWizardComponents; |
|
18 |
import jwizardcomponent.JWizardPanel; |
|
19 |
|
|
20 |
import org.gvsig.tableImport.importfields.ImportFieldParams; |
|
21 |
|
|
22 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
23 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
24 |
import com.iver.andami.PluginServices; |
|
25 |
import com.iver.andami.messages.NotificationManager; |
|
26 |
import com.iver.cit.gvsig.ProjectExtension; |
|
27 |
import com.iver.cit.gvsig.project.Project; |
|
28 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
|
29 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
|
30 |
|
|
31 |
public class LinkDefinitionPanel extends JWizardPanel implements ItemListener{ |
|
32 |
|
|
33 |
private static final long serialVersionUID = 1L; |
|
34 |
private JLabel lblTable = null; |
|
35 |
private JComboBox cbTable = null; |
|
36 |
private JLabel lblTableLinkField = null; |
|
37 |
private JComboBox cbTableLinkField = null; |
|
38 |
private JLabel lblTableToImport = null; |
|
39 |
private JComboBox cbTableToImport = null; |
|
40 |
private JLabel lblLinkFieldTableToImport = null; |
|
41 |
private JComboBox cbLinkFieldTableToImport = null; |
|
42 |
|
|
43 |
private JLabel lblMessage = null; |
|
44 |
private JLabel lblSpace = null; |
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
private ImportFieldParams params = null; |
|
49 |
private DefaultComboBoxModel cbTable_model; |
|
50 |
private DefaultComboBoxModel cbTableLinkField_model; |
|
51 |
private DefaultComboBoxModel cbTableToImport_model; |
|
52 |
private DefaultComboBoxModel cbLinkFieldTableToImport_model; |
|
53 |
private boolean updating; |
|
54 |
private JLabel lblSpace2; |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* This is the default constructor |
|
59 |
*/ |
|
60 |
public LinkDefinitionPanel(JWizardComponents wizardComponents, ImportFieldParams params) { |
|
61 |
super(wizardComponents); |
|
62 |
this.params = params; |
|
63 |
initialize(); |
|
64 |
this.update(); |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
public LinkDefinitionPanel() { |
|
70 |
super(null); |
|
71 |
initialize(); |
|
72 |
} |
|
73 |
|
|
74 |
public void update() { |
|
75 |
if (this.updating){ |
|
76 |
return; |
|
77 |
} |
|
78 |
this.updating= true; |
|
79 |
try{ |
|
80 |
if (this.params == null){ |
|
81 |
this.updating=false; |
|
82 |
return; |
|
83 |
} |
|
84 |
|
|
85 |
this.fillFieldsInComboModel(this.cbTableLinkField_model,this.params.getTableFieldList()); |
|
86 |
this.cbTableLinkField_model.setSelectedItem(this.params.getTableField()); |
|
87 |
|
|
88 |
this.fillFieldsInComboModel(this.cbLinkFieldTableToImport_model,this.params.getTableToImportFieldList()); |
|
89 |
this.cbLinkFieldTableToImport_model.setSelectedItem(this.params.getTableToImportField()); |
|
90 |
|
|
91 |
if (this.params.isValidLinkParams()){ |
|
92 |
this.lblMessage.setText(" "); |
|
93 |
this.setNextButtonEnabled(true); |
|
94 |
this.setFinishButtonEnabled(this.params.isValid()); |
|
95 |
} else{ |
|
96 |
this.lblMessage.setText(params.getValidationMsg()); |
|
97 |
this.setNextButtonEnabled(false); |
|
98 |
this.setFinishButtonEnabled(false); |
|
99 |
} |
|
100 |
super.update(); |
|
101 |
} finally { |
|
102 |
this.updating=false; |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
private void fillFieldsInComboModel( |
|
109 |
DefaultComboBoxModel model, |
|
110 |
ArrayList fieldList) { |
|
111 |
model.removeAllElements(); |
|
112 |
if (fieldList == null){ |
|
113 |
return; |
|
114 |
} |
|
115 |
Iterator iter = fieldList.iterator(); |
|
116 |
while (iter.hasNext()){ |
|
117 |
model.addElement(iter.next()); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
/** |
|
124 |
* This method initializes this |
|
125 |
* |
|
126 |
* @return void |
|
127 |
*/ |
|
128 |
private void initialize() { |
|
129 |
GridBagConstraints gridBagConstraints10 = new GridBagConstraints(); |
|
130 |
gridBagConstraints10.gridx = 0; |
|
131 |
gridBagConstraints10.insets = new Insets(5, 5, 5, 5); |
|
132 |
gridBagConstraints10.anchor = GridBagConstraints.SOUTHWEST; |
|
133 |
gridBagConstraints10.gridy = 0; |
|
134 |
gridBagConstraints10.fill =GridBagConstraints.VERTICAL; |
|
135 |
gridBagConstraints10.weighty = 1.0; |
|
136 |
|
|
137 |
GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); |
|
138 |
gridBagConstraints9.gridx = 0; |
|
139 |
gridBagConstraints9.insets = new Insets(5, 5, 5, 5); |
|
140 |
gridBagConstraints9.anchor = GridBagConstraints.SOUTHWEST; |
|
141 |
gridBagConstraints9.gridy = 5; |
|
142 |
gridBagConstraints9.fill =GridBagConstraints.VERTICAL; |
|
143 |
gridBagConstraints9.weighty = 1.0; |
|
144 |
GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
|
145 |
gridBagConstraints8.gridx = 0; |
|
146 |
gridBagConstraints8.insets = new Insets(5, 5, 5, 5); |
|
147 |
gridBagConstraints8.anchor = GridBagConstraints.SOUTHWEST; |
|
148 |
gridBagConstraints8.gridy = 6; |
|
149 |
gridBagConstraints8.fill =GridBagConstraints.HORIZONTAL; |
|
150 |
gridBagConstraints8.weightx = 1; |
|
151 |
gridBagConstraints8.gridwidth=2; |
|
152 |
GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
|
153 |
gridBagConstraints7.fill = GridBagConstraints.HORIZONTAL; |
|
154 |
gridBagConstraints7.gridy = 4; |
|
155 |
gridBagConstraints7.weightx = 1.0; |
|
156 |
gridBagConstraints7.insets = new Insets(5, 15, 5, 15); |
|
157 |
gridBagConstraints7.anchor = GridBagConstraints.NORTHWEST; |
|
158 |
gridBagConstraints7.gridx = 1; |
|
159 |
GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
|
160 |
gridBagConstraints6.gridx = 0; |
|
161 |
gridBagConstraints6.insets = new Insets(5, 5, 5, 5); |
|
162 |
gridBagConstraints6.anchor = GridBagConstraints.NORTHEAST; |
|
163 |
gridBagConstraints6.gridy = 4; |
|
164 |
lblLinkFieldTableToImport = new JLabel(); |
|
165 |
lblLinkFieldTableToImport.setText(PluginServices.getText(null,"link_field_table_to_import")); |
|
166 |
GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
|
167 |
gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL; |
|
168 |
gridBagConstraints5.gridy = 3; |
|
169 |
gridBagConstraints5.weightx = 1.0; |
|
170 |
gridBagConstraints5.insets = new Insets(5, 15, 5, 15); |
|
171 |
gridBagConstraints5.anchor = GridBagConstraints.NORTHWEST; |
|
172 |
gridBagConstraints5.gridx = 1; |
|
173 |
GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
|
174 |
gridBagConstraints4.gridx = 0; |
|
175 |
gridBagConstraints4.anchor = GridBagConstraints.NORTHEAST; |
|
176 |
gridBagConstraints4.insets = new Insets(5, 5, 5, 5); |
|
177 |
gridBagConstraints4.gridy = 3; |
|
178 |
lblTableToImport = new JLabel(); |
|
179 |
lblTableToImport.setText(PluginServices.getText(null,"table_to_import")); |
|
180 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
|
181 |
gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL; |
|
182 |
gridBagConstraints3.gridy = 2; |
|
183 |
gridBagConstraints3.weightx = 1.0; |
|
184 |
gridBagConstraints3.insets = new Insets(5, 15, 5, 15); |
|
185 |
gridBagConstraints3.anchor = GridBagConstraints.NORTHWEST; |
|
186 |
gridBagConstraints3.gridx = 1; |
|
187 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
188 |
gridBagConstraints2.gridx = 0; |
|
189 |
gridBagConstraints2.insets = new Insets(5, 5, 5, 5); |
|
190 |
gridBagConstraints2.anchor = GridBagConstraints.NORTHEAST; |
|
191 |
gridBagConstraints2.gridy = 2; |
|
192 |
lblTableLinkField = new JLabel(); |
|
193 |
lblTableLinkField.setText(PluginServices.getText(null,"link_field_of_table")); |
|
194 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
195 |
gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL; |
|
196 |
gridBagConstraints1.gridy = 1; |
|
197 |
gridBagConstraints1.weightx = 1.0; |
|
198 |
gridBagConstraints1.insets = new Insets(5, 15, 5, 15); |
|
199 |
gridBagConstraints1.anchor = GridBagConstraints.NORTHWEST; |
|
200 |
gridBagConstraints1.gridx = 1; |
|
201 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
202 |
gridBagConstraints.gridx = 0; |
|
203 |
gridBagConstraints.insets = new Insets(5, 5, 5, 5); |
|
204 |
gridBagConstraints.anchor = GridBagConstraints.NORTHEAST; |
|
205 |
gridBagConstraints.gridy = 1; |
|
206 |
lblTable = new JLabel(); |
|
207 |
lblTable.setText(PluginServices.getText(null,"table")); |
|
208 |
|
|
209 |
lblMessage = new JLabel(); |
|
210 |
lblSpace = new JLabel(); |
|
211 |
lblSpace2 = new JLabel(); |
|
212 |
|
|
213 |
|
|
214 |
this.setSize(400, 300); |
|
215 |
this.setLayout(new GridBagLayout()); |
|
216 |
this.setPreferredSize(new Dimension(400, 300)); |
|
217 |
this.add(lblTable, gridBagConstraints); |
|
218 |
this.add(getCbTable(), gridBagConstraints1); |
|
219 |
this.add(lblTableLinkField, gridBagConstraints2); |
|
220 |
this.add(getCbTableLinkField(), gridBagConstraints3); |
|
221 |
this.add(lblTableToImport, gridBagConstraints4); |
|
222 |
this.add(getCbTableToImport(), gridBagConstraints5); |
|
223 |
this.add(lblLinkFieldTableToImport, gridBagConstraints6); |
|
224 |
this.add(getCbLinkFieldTableToImport(), gridBagConstraints7); |
|
225 |
this.add(lblSpace, gridBagConstraints9); |
|
226 |
this.add(lblMessage, gridBagConstraints8); |
|
227 |
this.add(lblSpace2, gridBagConstraints10); |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* This method initializes cbTable |
|
233 |
* |
|
234 |
* @return javax.swing.JComboBox |
|
235 |
*/ |
|
236 |
private JComboBox getCbTable() { |
|
237 |
if (cbTable == null) { |
|
238 |
cbTable = new JComboBox(); |
|
239 |
this.cbTable_model = new DefaultComboBoxModel(); |
|
240 |
if (this.params.isLockTable()){ |
|
241 |
this.cbTable_model.addElement(params.getTable().getName()); |
|
242 |
this.cbTable.setEditable(false); |
|
243 |
cbTable.setModel(this.cbTable_model); |
|
244 |
this.cbTable.setSelectedIndex(0); |
|
245 |
this.cbTable.setEditable(false); |
|
246 |
} else{ |
|
247 |
this.fillProjectTableComboModel(this.cbTable_model); |
|
248 |
cbTable.addItemListener(this); |
|
249 |
cbTable.setModel(this.cbTable_model); |
|
250 |
cbTable_model.setSelectedItem(null); |
|
251 |
} |
|
252 |
} |
|
253 |
return cbTable; |
|
254 |
} |
|
255 |
|
|
256 |
private void fillProjectTableComboModel(DefaultComboBoxModel model){ |
|
257 |
Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
|
258 |
List ptables= project.getDocumentsByType(ProjectTableFactory.registerName); |
|
259 |
|
|
260 |
Iterator iter = ptables.iterator(); |
|
261 |
ProjectTable ptable; |
|
262 |
while (iter.hasNext()){ |
|
263 |
ptable = (ProjectTable) iter.next(); |
|
264 |
model.addElement( new ComboElement(ptable,ptable.getName())); |
|
265 |
} |
|
266 |
|
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* This method initializes cbTableLinkField |
|
271 |
* |
|
272 |
* @return javax.swing.JComboBox |
|
273 |
*/ |
|
274 |
private JComboBox getCbTableLinkField() { |
|
275 |
if (cbTableLinkField == null) { |
|
276 |
cbTableLinkField = new JComboBox(); |
|
277 |
this.cbTableLinkField_model = new DefaultComboBoxModel(); |
|
278 |
cbTableLinkField.addItemListener(this); |
|
279 |
cbTableLinkField.setModel(cbTableLinkField_model); |
|
280 |
|
|
281 |
} |
|
282 |
return cbTableLinkField; |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* This method initializes cbTableToImport |
|
287 |
* |
|
288 |
* @return javax.swing.JComboBox |
|
289 |
*/ |
|
290 |
private JComboBox getCbTableToImport() { |
|
291 |
if (cbTableToImport == null) { |
|
292 |
cbTableToImport = new JComboBox(); |
|
293 |
this.cbTableToImport_model = new DefaultComboBoxModel(); |
|
294 |
this.fillProjectTableComboModel(this.cbTableToImport_model); |
|
295 |
this.cbTableToImport_model.setSelectedItem(null); |
|
296 |
cbTableToImport.setModel(cbTableToImport_model); |
|
297 |
cbTableToImport.addItemListener(this); |
|
298 |
} |
|
299 |
return cbTableToImport; |
|
300 |
} |
|
301 |
|
|
302 |
/** |
|
303 |
* This method initializes cbLinkFieldTableToImport |
|
304 |
* |
|
305 |
* @return javax.swing.JComboBox |
|
306 |
*/ |
|
307 |
private JComboBox getCbLinkFieldTableToImport() { |
|
308 |
if (cbLinkFieldTableToImport == null) { |
|
309 |
cbLinkFieldTableToImport = new JComboBox(); |
|
310 |
this.cbLinkFieldTableToImport_model = new DefaultComboBoxModel(); |
|
311 |
cbLinkFieldTableToImport.setModel(cbLinkFieldTableToImport_model); |
|
312 |
cbLinkFieldTableToImport.addItemListener(this); |
|
313 |
} |
|
314 |
return cbLinkFieldTableToImport; |
|
315 |
} |
|
316 |
|
|
317 |
private class ComboElement { |
|
318 |
|
|
319 |
private String description; |
|
320 |
private Object value; |
|
321 |
|
|
322 |
public ComboElement(Object value,String description){ |
|
323 |
this.value = value; |
|
324 |
this.description=description; |
|
325 |
} |
|
326 |
|
|
327 |
public String toString() { |
|
328 |
return this.description; |
|
329 |
} |
|
330 |
|
|
331 |
public Object getValue(){ |
|
332 |
return this.value; |
|
333 |
} |
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
} |
|
338 |
|
|
339 |
public void itemStateChanged(ItemEvent e) { |
|
340 |
if (this.updating){ |
|
341 |
return; |
|
342 |
} |
|
343 |
if (e.getStateChange() == ItemEvent.DESELECTED){ |
|
344 |
return; |
|
345 |
} |
|
346 |
Object src = e.getSource(); |
|
347 |
|
|
348 |
ComboElement element = null; |
|
349 |
String strElement=null; |
|
350 |
try{ |
|
351 |
element = (ComboElement) e.getItem(); |
|
352 |
} catch (ClassCastException ex){ |
|
353 |
strElement= (String) e.getItem(); |
|
354 |
} |
|
355 |
if (src == this.cbTable){ |
|
356 |
if (this.params.isLockTable()){ |
|
357 |
return; |
|
358 |
} |
|
359 |
try { |
|
360 |
this.params.setTable((ProjectTable)element.getValue()); |
|
361 |
} catch (ReadDriverException e1) { |
|
362 |
NotificationManager.addError(e1); |
|
363 |
} |
|
364 |
} else if (src == this.cbTableLinkField){ |
|
365 |
this.params.setTableField((String)strElement); |
|
366 |
|
|
367 |
} else if (src == this.cbTableToImport){ |
|
368 |
try { |
|
369 |
this.params.setTableToImport((ProjectTable)element.getValue()); |
|
370 |
} catch (ReadDriverException e1) { |
|
371 |
NotificationManager.addError(e1); |
|
372 |
} |
|
373 |
|
|
374 |
} else if (src == this.cbLinkFieldTableToImport){ |
|
375 |
this.params.setTableToImportField(strElement); |
|
376 |
} |
|
377 |
this.update(); |
|
378 |
|
|
379 |
} |
|
380 |
|
|
381 |
} |
|
0 | 382 |
trunk/extensions/extTableImport/src/org/gvsig/tableImport/importfields/ui/ImportFieldPanel.java | ||
---|---|---|
1 |
package org.gvsig.tableImport.importfields.ui; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.awt.GridBagConstraints; |
|
5 |
import java.awt.GridBagLayout; |
|
6 |
import java.awt.Insets; |
|
7 |
import java.awt.event.ActionEvent; |
|
8 |
import java.awt.event.ActionListener; |
|
9 |
import java.beans.PropertyChangeEvent; |
|
10 |
import java.beans.PropertyChangeListener; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Iterator; |
|
13 |
|
|
14 |
import javax.swing.JButton; |
|
15 |
import javax.swing.JLabel; |
|
16 |
import javax.swing.JPanel; |
|
17 |
import javax.swing.JScrollPane; |
|
18 |
|
|
19 |
import jwizardcomponent.JWizardComponents; |
|
20 |
import jwizardcomponent.JWizardPanel; |
|
21 |
|
|
22 |
import org.gvsig.tableImport.importfields.ImportFieldParams; |
|
23 |
import org.gvsig.tableImport.importfields.ImportFieldParams.FielToImport; |
|
24 |
|
|
25 |
import com.iver.andami.PluginServices; |
|
26 |
|
|
27 |
public class ImportFieldPanel extends JWizardPanel implements PropertyChangeListener, ActionListener { |
|
28 |
|
|
29 |
private static final long serialVersionUID = 1L; |
|
30 |
private JPanel pLista = null; |
|
31 |
private JPanel pButtons = null; |
|
32 |
private JButton bAll = null; |
|
33 |
private JButton bNone = null; |
|
34 |
private JLabel lblSpace = null; |
|
35 |
private JScrollPane jScrollPane = null; |
|
36 |
private JLabel lblMessage = null; |
|
37 |
|
|
38 |
private boolean updating; |
|
39 |
private ImportFieldParams params = null; |
|
40 |
private GridBagConstraints pLista_gbContraints; |
|
41 |
private ArrayList fields = new ArrayList(); |
|
42 |
|
|
43 |
|
|
44 |
/** |
|
45 |
* This is the default constructor |
|
46 |
*/ |
|
47 |
public ImportFieldPanel(JWizardComponents wizardComponents, ImportFieldParams params) { |
|
48 |
super(wizardComponents); |
|
49 |
initialize(); |
|
50 |
this.params = params; |
|
51 |
initialize(); |
|
52 |
this.update(); |
|
53 |
} |
|
54 |
|
|
55 |
public ImportFieldPanel() { |
|
56 |
super(null); |
|
57 |
initialize(); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* This method initializes this |
|
62 |
* |
|
63 |
* @return void |
|
64 |
*/ |
|
65 |
private void initialize() { |
|
66 |
GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); |
|
67 |
gridBagConstraints31.gridx = 0; |
|
68 |
gridBagConstraints31.fill = GridBagConstraints.HORIZONTAL; |
|
69 |
gridBagConstraints31.gridy = 1; |
|
70 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
|
71 |
gridBagConstraints11.fill = GridBagConstraints.BOTH; |
|
72 |
gridBagConstraints11.weighty = 1.0; |
|
73 |
gridBagConstraints11.insets = new Insets(5, 5, 5, 5); |
|
74 |
gridBagConstraints11.weightx = 1.0; |
|
75 |
gridBagConstraints11.anchor = GridBagConstraints.FIRST_LINE_START; |
|
76 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
77 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; |
|
78 |
gridBagConstraints.gridy = 2; |
|
79 |
gridBagConstraints.weightx = 1.0; |
|
80 |
gridBagConstraints.weighty = 0.0D; |
|
81 |
gridBagConstraints.gridheight = 1; |
|
82 |
gridBagConstraints.gridx = 0; |
|
83 |
this.setSize(400, 300); |
|
84 |
this.setLayout(new GridBagLayout()); |
|
85 |
this.setPreferredSize(new Dimension(400, 300)); |
|
86 |
this.add(getJScrollPane(), gridBagConstraints11); |
|
87 |
this.add(getPButtons(), gridBagConstraints); |
|
88 |
this.add(lblMessage, gridBagConstraints31); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* This method initializes lLista |
|
93 |
* |
|
94 |
* @return javax.swing.JList |
|
95 |
*/ |
|
96 |
private JPanel getLLista() { |
|
97 |
if (pLista == null) { |
|
98 |
pLista = new JPanel(); |
|
99 |
pLista.setName("lista"); |
|
100 |
pLista.setLayout(new GridBagLayout()); |
|
101 |
pLista_gbContraints = new GridBagConstraints(); |
|
102 |
pLista_gbContraints.anchor = GridBagConstraints.FIRST_LINE_START; |
|
103 |
pLista_gbContraints.fill = GridBagConstraints.HORIZONTAL; |
|
104 |
pLista_gbContraints.weightx = 1; |
|
105 |
pLista_gbContraints.gridx=1; |
|
106 |
// pLista_gbContraints.gridy=GridBagConstraints.REMAINDER; |
|
107 |
|
|
108 |
} |
|
109 |
return pLista; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* This method initializes pButtons |
|
114 |
* |
|
115 |
* @return javax.swing.JPanel |
|
116 |
*/ |
|
117 |
private JPanel getPButtons() { |
|
118 |
if (pButtons == null) { |
|
119 |
lblMessage = new JLabel(); |
|
120 |
if (this.params == null){ |
|
121 |
lblMessage.setText("Message"); |
|
122 |
} else{ |
|
123 |
lblMessage.setText(" "); |
|
124 |
} |
|
125 |
GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
|
126 |
gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL; |
|
127 |
gridBagConstraints4.weightx = 1.0D; |
|
128 |
gridBagConstraints4.gridy = 1; |
|
129 |
gridBagConstraints4.gridx = 0; |
|
130 |
lblSpace = new JLabel(); |
|
131 |
lblSpace.setText(" "); |
|
132 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
|
133 |
gridBagConstraints3.anchor = GridBagConstraints.EAST; |
|
134 |
gridBagConstraints3.ipady = 0; |
|
135 |
gridBagConstraints3.insets = new Insets(5, 5, 5, 5); |
|
136 |
gridBagConstraints3.gridy = 1; |
|
137 |
gridBagConstraints3.ipadx = 0; |
|
138 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
139 |
gridBagConstraints2.anchor = GridBagConstraints.EAST; |
|
140 |
gridBagConstraints2.ipady = 0; |
|
141 |
gridBagConstraints2.insets = new Insets(5, 5, 5, 5); |
|
142 |
gridBagConstraints2.gridy = 1; |
|
143 |
gridBagConstraints2.ipadx = 0; |
|
144 |
pButtons = new JPanel(); |
|
145 |
pButtons.setLayout(new GridBagLayout()); |
|
146 |
pButtons.add(lblSpace, gridBagConstraints4); |
|
147 |
pButtons.add(getBAll(), gridBagConstraints2); |
|
148 |
pButtons.add(getBNone(), gridBagConstraints3); |
|
149 |
} |
|
150 |
return pButtons; |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* This method initializes bAll |
|
155 |
* |
|
156 |
* @return javax.swing.JButton |
|
157 |
*/ |
|
158 |
private JButton getBAll() { |
|
159 |
if (bAll == null) { |
|
160 |
bAll = new JButton(); |
|
161 |
bAll.setText(PluginServices.getText(null,"select_all")); |
|
162 |
bAll.setActionCommand("all"); |
|
163 |
bAll.setName("all"); |
|
164 |
bAll.addActionListener(this); |
|
165 |
} |
|
166 |
return bAll; |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* This method initializes bNone |
|
171 |
* |
|
172 |
* @return javax.swing.JButton |
|
173 |
*/ |
|
174 |
private JButton getBNone() { |
|
175 |
if (bNone == null) { |
|
176 |
bNone = new JButton(); |
|
177 |
bNone.setText(PluginServices.getText(null,"clear_selection")); |
|
178 |
bNone.setActionCommand("none"); |
|
179 |
bNone.setName("none"); |
|
180 |
bNone.addActionListener(this); |
|
181 |
} |
|
182 |
return bNone; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* This method initializes jScrollPane |
|
187 |
* |
|
188 |
* @return javax.swing.JScrollPane |
|
189 |
*/ |
|
190 |
private JScrollPane getJScrollPane() { |
|
191 |
if (jScrollPane == null) { |
|
192 |
jScrollPane = new JScrollPane(); |
|
193 |
jScrollPane.setViewportView(getLLista()); |
|
194 |
} |
|
195 |
return jScrollPane; |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
public void update() { |
|
200 |
try{ |
|
201 |
if (this.updating){ |
|
202 |
return; |
|
203 |
} |
|
204 |
this.updating= true; |
|
205 |
if (this.params == null){ |
|
206 |
return; |
|
207 |
} |
|
208 |
ArrayList fieldsToImport = this.params.getFieldsToImport(); |
|
209 |
if (fieldsToImport == null){ |
|
210 |
this.getLLista().removeAll(); |
|
211 |
return; |
|
212 |
} |
|
213 |
this.fillList(fieldsToImport); |
|
214 |
|
|
215 |
if (this.params.isValid()){ |
|
216 |
this.setFinishButtonEnabled(true); |
|
217 |
this.lblMessage.setText(" "); |
|
218 |
}else{ |
|
219 |
this.setFinishButtonEnabled(false); |
|
220 |
this.lblMessage.setText(params.getValidationMsg()); |
|
221 |
} |
|
222 |
super.update(); |
|
223 |
} finally { |
|
224 |
this.updating=false; |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
private void fillList(ArrayList fieldsToImport) { |
|
229 |
FielToImport fieldDef; |
|
230 |
FieldPanel fieldElement; |
|
231 |
int i; |
|
232 |
for (i=0;i<fieldsToImport.size();i++){ |
|
233 |
fieldDef = (FielToImport) fieldsToImport.get(i); |
|
234 |
if (this.fields.size()> i){ |
|
235 |
fieldElement = (FieldPanel) this.fields.get(i); |
|
236 |
} else{ |
|
237 |
fieldElement = this.addNewFieldPanel(); |
|
238 |
} |
|
239 |
fieldElement.setToImpor(fieldDef.toImport); |
|
240 |
fieldElement.setSourceField(fieldDef.originalFieldName); |
|
241 |
fieldElement.setTargetFieldName(fieldDef.fieldNameToUse); |
|
242 |
} |
|
243 |
for (i=this.fields.size()-1;i>=fieldsToImport.size();i--){ |
|
244 |
fieldElement= (FieldPanel) this.fields.remove(i);; |
|
245 |
fieldElement.removeFrom(this.getLLista()); |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
private FieldPanel addNewFieldPanel() { |
|
251 |
FieldPanel fieldElement = new FieldPanel(); |
|
252 |
fieldElement.addPropertyChangeListener(this); |
|
253 |
fieldElement.loadIn(this.getLLista()); |
|
254 |
this.fields.add(fieldElement); |
|
255 |
this.doLayout(); |
|
256 |
return fieldElement; |
|
257 |
} |
|
258 |
|
|
259 |
public void propertyChange(PropertyChangeEvent evt) { |
|
260 |
if (this.updating){ |
|
261 |
return; |
|
262 |
} |
|
263 |
if (!(evt.getSource() instanceof FieldPanel)){ |
|
264 |
return; |
|
265 |
} |
|
266 |
String srcField = ((FieldPanel) evt.getSource()).getSourceField(); |
|
267 |
Iterator iter = this.params.getFieldsToImport().iterator(); |
|
268 |
while (iter.hasNext()){ |
|
269 |
FielToImport field = (FielToImport) iter.next(); |
|
270 |
if (field.originalFieldName.equals(srcField)){ |
|
271 |
if (evt.getPropertyName().equals("toImport")){ |
|
272 |
field.toImport = ((Boolean)evt.getNewValue()).booleanValue(); |
|
273 |
// System.out.println("set to " +field.toImport +" toImpor of "+ srcField); |
|
274 |
} else if (evt.getPropertyName().equals("targetFieldName")){ |
|
275 |
field.fieldNameToUse = (String) evt.getNewValue(); |
|
276 |
// System.out.println("set to " +field.fieldNameToUse +" nameToUse of "+ srcField); |
|
277 |
} |
|
278 |
break; |
|
279 |
} |
|
280 |
|
|
281 |
} |
|
282 |
this.update(); |
|
283 |
} |
|
284 |
|
|
285 |
public void actionPerformed(ActionEvent e) { |
|
286 |
boolean toImpor=false; |
|
287 |
if (e.getActionCommand().equals(this.getBAll().getActionCommand())){ |
|
288 |
toImpor=true; |
|
289 |
} else if (e.getActionCommand().equals(this.getBNone().getActionCommand())){ |
|
290 |
toImpor=false; |
|
291 |
} |
|
292 |
Iterator iter = this.params.getFieldsToImport().iterator(); |
|
293 |
while (iter.hasNext()){ |
|
294 |
((FielToImport)iter.next()).toImport=toImpor; |
|
295 |
} |
|
296 |
this.update(); |
|
297 |
} |
|
298 |
|
|
299 |
} |
|
0 | 300 |
trunk/extensions/extTableImport/src/org/gvsig/tableImport/importfields/ImportFieldsExtension.java | ||
---|---|---|
1 |
package org.gvsig.tableImport.importfields; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Iterator; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import javax.swing.ImageIcon; |
|
9 |
|
|
10 |
import org.gvsig.tableImport.importfields.ImportFieldParams.FielToImport; |
|
11 |
import org.gvsig.tableImport.importfields.ui.ImportFieldPanel; |
|
12 |
import org.gvsig.tableImport.importfields.ui.LinkDefinitionPanel; |
|
13 |
|
|
14 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
15 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
16 |
import com.hardcode.gdbms.engine.values.Value; |
|
17 |
import com.iver.andami.PluginServices; |
|
18 |
import com.iver.andami.messages.NotificationManager; |
|
19 |
import com.iver.andami.plugins.Extension; |
|
20 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
21 |
import com.iver.andami.ui.wizard.WizardAndami; |
|
22 |
import com.iver.cit.gvsig.EditionUtilities; |
|
23 |
import com.iver.cit.gvsig.fmap.core.IRow; |
|
24 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
25 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
|
26 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
27 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
|
28 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
|
29 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
|
30 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
31 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
|
32 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
|
33 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
34 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
|
35 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
36 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
37 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 |
* Extensi?n que permite importar datos en una tabla. |
|
42 |
* |
|
43 |
* @author jmvivo |
|
44 |
*/ |
|
45 |
public class ImportFieldsExtension extends Extension { |
|
46 |
|
|
47 |
public void initialize() { |
|
48 |
// TODO Auto-generated method stub |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
|
54 |
*/ |
|
55 |
public boolean isEnabled() { |
|
56 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
57 |
if (!(v instanceof Table)) { |
|
58 |
return false; |
|
59 |
} |
|
60 |
IEditableSource ies=((Table)v).getModel().getModelo(); |
|
61 |
if (!(ies instanceof IWriteable)){ |
|
62 |
return false; |
|
63 |
|
|
64 |
} |
|
65 |
IWriter writer =((IWriteable) ies).getWriter(); |
|
66 |
if (writer == null){ |
|
67 |
return false; |
|
68 |
} |
|
69 |
if (!writer.canAlterTable()){ |
|
70 |
return false; |
|
71 |
} |
|
72 |
|
|
73 |
return true; |
|
74 |
|
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
|
79 |
*/ |
|
80 |
public boolean isVisible() { |
|
81 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
82 |
|
|
83 |
if (v == null) { |
|
84 |
return false; |
|
85 |
// } else if (!(v instanceof Table) && !(v instanceof BaseView)) { |
|
86 |
} else if (!(v instanceof Table) ) { |
|
87 |
return false; |
|
88 |
} |
|
89 |
return true; |
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
public void execute(String actionCommand) { |
|
94 |
ImportFieldParams param = new ImportFieldParams(); |
|
95 |
|
|
96 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
97 |
if (v instanceof Table){ |
|
98 |
Table table = (Table) v; |
|
99 |
param.setLockTable(true); |
|
100 |
try { |
|
101 |
param.setTable(table.getModel()); |
|
102 |
} catch (ReadDriverException e) { |
|
103 |
NotificationManager.showMessageError(PluginServices.getText(null, "Failed_filling_table"), e); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
ImageIcon logo = new javax.swing.ImageIcon(this.getClass().getClassLoader().getResource("images/package_graphics.png")); |
|
109 |
|
|
110 |
WizardAndami wizard = new WizardAndami(logo); |
|
111 |
// Adds the wizard panels: |
|
112 |
|
|
113 |
LinkDefinitionPanel linkPanel = new LinkDefinitionPanel(wizard.getWizardComponents(),param); |
|
114 |
wizard.getWizardComponents().addWizardPanel(linkPanel); |
|
115 |
|
|
116 |
ImportFieldPanel fieldsPanel = new ImportFieldPanel(wizard.getWizardComponents(),param); |
|
117 |
wizard.getWizardComponents().addWizardPanel(fieldsPanel); |
|
118 |
|
|
119 |
wizard.getWizardComponents().getFinishButton().setEnabled(false); |
|
120 |
wizard.getWindowInfo().setWidth(640); |
|
121 |
wizard.getWindowInfo().setHeight(350); |
|
122 |
wizard.getWindowInfo().setTitle(PluginServices.getText(this, "import_fields")); |
|
123 |
|
|
124 |
wizard.getWizardComponents().setFinishAction(new ImportFieldsAction(wizard ,param)); |
|
125 |
|
|
126 |
PluginServices.getMDIManager().addWindow(wizard); |
|
127 |
|
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
public void doImportField(ImportFieldParams params) throws Exception{ |
|
132 |
|
|
133 |
if (!params.isValid()){ |
|
134 |
//TODO: ver que excepcion a lanzar |
|
135 |
throw new Exception("invalid Paramenters: "+ params.getValidationMsg()); |
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
IEditableSource edSource=null; |
|
140 |
IEditableSource edSourceToImport=params.getTableToImport().getModelo(); |
|
141 |
|
|
142 |
SelectableDataSource rsSourceToImport=edSourceToImport.getRecordset(); |
|
143 |
|
|
144 |
ArrayList fieldsToImport = new ArrayList(); |
|
145 |
ArrayList fieldsToImport_des= new ArrayList(); |
|
146 |
ArrayList fieldsToImport_pos= new ArrayList(); |
|
147 |
Iterator iter; |
|
148 |
Map values; |
|
149 |
int i; |
|
150 |
|
|
151 |
try{ |
|
152 |
rsSourceToImport.start(); |
|
153 |
|
|
154 |
// Cargamos la lista con los campos que vamos a importar |
|
155 |
iter =params.getFieldsToImport().iterator(); |
|
156 |
FielToImport fieldToImport; |
|
157 |
while (iter.hasNext()){ |
|
158 |
fieldToImport = (FielToImport) iter.next(); |
|
159 |
if (fieldToImport.toImport){ |
|
160 |
fieldsToImport.add(fieldToImport); |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
// Cargamos la lista de la definicio de capos desde la |
|
165 |
// tabla a importar |
|
166 |
iter = fieldsToImport.iterator(); |
|
167 |
FieldDescription[] toImportAllFieldsDescription = edSourceToImport.getFieldsDescription(); |
|
168 |
FieldDescription tmpFieldDesc, newFieldDesc; |
|
169 |
|
|
170 |
while (iter.hasNext()){ |
|
171 |
fieldToImport = (FielToImport) iter.next(); |
|
172 |
for (i=0;i<toImportAllFieldsDescription.length;i++){ |
|
173 |
tmpFieldDesc =toImportAllFieldsDescription[i]; |
|
174 |
if (tmpFieldDesc.getFieldName().equals(fieldToImport.originalFieldName)){ |
|
175 |
newFieldDesc = tmpFieldDesc.cloneField(); |
|
176 |
newFieldDesc.setFieldLength(tmpFieldDesc.getFieldLength()); |
|
177 |
newFieldDesc.setFieldName(fieldToImport.fieldNameToUse); |
|
178 |
newFieldDesc.setDefaultValue(tmpFieldDesc.getDefaultValue()); |
|
179 |
newFieldDesc.setFieldAlias(fieldToImport.fieldNameToUse); |
|
180 |
newFieldDesc.setFieldType(tmpFieldDesc.getFieldType()); |
|
181 |
fieldsToImport_des.add(newFieldDesc); |
|
182 |
fieldsToImport_pos.add(new Integer(i)); |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
//Cagamos los valores en un hash |
|
188 |
values= this.loadValuesFromSource( |
|
189 |
rsSourceToImport, |
|
190 |
params.getTableToImportField(), |
|
191 |
fieldsToImport_pos); |
|
192 |
} catch (Exception e){ |
|
193 |
throw e; |
|
194 |
}finally{ |
|
195 |
|
|
196 |
rsSourceToImport.stop(); |
|
197 |
rsSourceToImport = null; |
|
198 |
edSourceToImport = null; |
|
199 |
} |
|
200 |
|
|
201 |
FLyrVect layer=null; |
|
202 |
|
|
203 |
|
|
204 |
boolean changeEditing = false; |
|
205 |
// Ponemos en edicion si no lo esta |
|
206 |
if (params.getTable().getAssociatedTable() instanceof FLyrVect){ |
|
207 |
// Viene de una capa |
|
208 |
layer = (FLyrVect) params.getTable().getAssociatedTable(); |
|
209 |
if (!layer.isEditing()){ |
|
210 |
layer.setEditing(true); |
|
211 |
changeEditing=true; |
|
212 |
} |
|
213 |
edSource = (VectorialEditableAdapter)layer.getSource(); |
|
214 |
} else { |
|
215 |
// es una tabla normal |
|
216 |
edSource = params.getTable().getModelo(); |
|
217 |
if (!edSource.isEditing()){ |
|
218 |
edSource.startEdition(EditionEvent.ALPHANUMERIC); |
|
219 |
changeEditing=true; |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
edSource.startComplexRow(); |
|
224 |
|
|
225 |
int originalFieldsCount = edSource.getRecordset().getFieldCount(); |
|
226 |
int finalFieldsCount = originalFieldsCount + fieldsToImport.size(); |
|
227 |
// A?adimos los campos |
|
228 |
iter = fieldsToImport_des.iterator(); |
|
229 |
while (iter.hasNext()){ |
|
230 |
((EditableAdapter)edSource).addField((FieldDescription) iter.next()); |
|
231 |
} |
|
232 |
|
|
233 |
// Recorremos la fuente y vamos actualizando |
|
234 |
int rowCount = edSource.getRowCount(); |
|
235 |
IRowEdited originalRow; |
|
236 |
IRow newRow; |
|
237 |
IRowEdited newRowEdited; |
|
238 |
Value[] finalValues; |
|
239 |
Value[] originalValues; |
|
240 |
Value[] valuesToUse; |
|
241 |
Value key; |
|
242 |
int column; |
|
243 |
int srcKeyPos = edSource.getRecordset().getFieldIndexByName(params.getTableField()); |
|
244 |
for (i=0;i<rowCount;i++){ |
|
245 |
originalRow = edSource.getRow(i); |
|
246 |
|
|
247 |
key = originalRow.getAttribute(srcKeyPos); |
|
248 |
valuesToUse = (Value[]) values.get(key); |
|
249 |
if (valuesToUse == null){ |
|
250 |
continue; |
|
251 |
} |
|
252 |
newRow = originalRow.getLinkedRow().cloneRow(); |
|
253 |
originalValues = newRow.getAttributes(); |
|
254 |
finalValues = new Value[finalFieldsCount]; |
|
255 |
System.arraycopy(originalValues, 0, finalValues, 0, originalFieldsCount); |
|
256 |
for (column = 0;column < valuesToUse.length;column++){ |
|
257 |
finalValues[column+originalFieldsCount]= valuesToUse[column]; |
|
258 |
} |
|
259 |
newRow.setAttributes(finalValues); |
|
260 |
newRowEdited = new DefaultRowEdited(newRow, |
|
261 |
IRowEdited.STATUS_MODIFIED, i); |
|
262 |
edSource.modifyRow(newRowEdited.getIndex(), newRowEdited.getLinkedRow(), "", |
|
263 |
EditionEvent.ALPHANUMERIC); |
|
264 |
|
|
265 |
} |
|
266 |
|
|
267 |
edSource.endComplexRow("Import fields"); |
|
268 |
if (changeEditing){ |
|
269 |
if (layer == null){ |
|
270 |
IWriter writer= ((IWriteable)edSource).getWriter(); |
|
271 |
writer.initialize(edSource.getTableDefinition()); |
|
272 |
edSource.stopEdition(writer, EditionEvent.ALPHANUMERIC); |
|
273 |
edSource.getSelection().clear(); |
|
274 |
|
|
275 |
|
|
276 |
} else{ |
|
277 |
layer.setRecordset(edSource.getRecordset()); |
|
278 |
ISpatialWriter spatialWriter = (ISpatialWriter) ((VectorialEditableAdapter)edSource).getWriter(); |
|
279 |
ILayerDefinition lyrDef =EditionUtilities.createLayerDefinition(layer); |
|
280 |
spatialWriter.initialize(lyrDef); |
|
281 |
edSource.stopEdition(spatialWriter,EditionEvent.ALPHANUMERIC); |
|
282 |
layer.setEditing(false); |
|
283 |
edSource.getSelection().clear(); |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
} |
|
292 |
|
|
293 |
private Map loadValuesFromSource(SelectableDataSource source, String keyFieldName, ArrayList fieldsPositions) throws ReadDriverException{ |
|
294 |
HashMap values= new HashMap(); |
|
295 |
int row,i; |
|
296 |
Value[] rowValues; |
|
297 |
Value key; |
|
298 |
int keyPos = source.getFieldIndexByName(keyFieldName); |
|
299 |
long rowCount =source.getRowCount(); |
|
300 |
for (row=0;row < rowCount;row++){ |
|
301 |
key = source.getFieldValue(row, keyPos); |
|
302 |
if (values.containsKey(key)){ |
|
303 |
continue; |
|
304 |
} |
|
305 |
rowValues = new Value[fieldsPositions.size()]; |
|
306 |
|
|
307 |
for (i=0;i<fieldsPositions.size();i++){ |
|
308 |
rowValues[i]=source.getFieldValue(row, ((Integer)fieldsPositions.get(i)).intValue()); |
|
309 |
} |
|
310 |
|
|
311 |
values.put(key, rowValues); |
|
312 |
|
|
313 |
} |
|
314 |
|
|
315 |
return values; |
|
316 |
} |
|
317 |
|
|
318 |
} |
|
0 | 319 |
trunk/extensions/extTableImport/src/org/gvsig/tableImport/importfields/ImportFieldsAction.java | ||
---|---|---|
1 |
package org.gvsig.tableImport.importfields; |
|
2 |
|
|
3 |
import jwizardcomponent.FinishAction; |
|
4 |
|
|
5 |
import com.iver.andami.PluginServices; |
|
6 |
import com.iver.andami.messages.NotificationManager; |
|
7 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
8 |
import com.iver.andami.ui.wizard.WizardAndami; |
|
9 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
10 |
|
|
11 |
public class ImportFieldsAction extends FinishAction { |
|
12 |
|
|
13 |
private WizardAndami wizard; |
|
14 |
private ImportFieldParams params; |
|
15 |
|
|
16 |
public ImportFieldsAction(WizardAndami wizard,ImportFieldParams params) { |
|
17 |
super(wizard.getWizardComponents()); |
|
18 |
|
|
19 |
this.wizard = wizard; |
|
20 |
this.params = params; |
|
21 |
} |
|
22 |
|
|
23 |
public void performAction() { |
|
24 |
if (params.isValid()){ |
|
25 |
ImportFieldsExtension ext = (ImportFieldsExtension) PluginServices.getExtension(ImportFieldsExtension.class); |
|
26 |
try { |
|
27 |
ext.doImportField(this.params); |
|
28 |
} catch (Exception e) { |
|
29 |
NotificationManager.addError(e); |
|
30 |
return; |
|
31 |
} |
|
32 |
|
|
33 |
} |
|
34 |
PluginServices.getMDIManager().closeWindow(this.wizard); |
|
35 |
|
|
36 |
//TODO: Cuando la tabla es de una capa y no esta en edici?n no se refresca |
|
37 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows(); |
|
38 |
Table tableWindow; |
|
39 |
for (int i=0;i<windows.length;i++){ |
|
40 |
if (windows[i] instanceof Table){ |
|
41 |
tableWindow = (Table) windows[i]; |
|
42 |
if (tableWindow.getModel().equals(params.getTable())){ |
|
43 |
tableWindow.setModel(params.getTable()); |
|
44 |
break; |
|
45 |
} |
|
46 |
} |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
trunk/extensions/extTableImport/src/org/gvsig/tableImport/importfields/ImportFieldParams.java | ||
---|---|---|
1 |
package org.gvsig.tableImport.importfields; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Iterator; |
|
5 |
|
|
6 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
7 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
8 |
import com.iver.andami.PluginServices; |
|
9 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
10 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
|
11 |
|
|
12 |
public class ImportFieldParams { |
|
13 |
private boolean lockTable=false; |
|
14 |
private ArrayList tableFieldList = null; |
|
15 |
private ArrayList tableFieldList_types = null; |
|
16 |
private ProjectTable table=null; |
|
17 |
private ProjectTable tableToImport=null; |
|
18 |
private ArrayList tableToImportFieldList; |
|
19 |
private ArrayList tableToImportFieldList_types; |
|
20 |
private ArrayList fieldsToImport=null; |
|
21 |
private String tableField=null; |
|
22 |
private String tableToImportField=null; |
|
23 |
public String getTableToImportField() { |
|
24 |
return tableToImportField; |
|
25 |
} |
|
26 |
|
|
27 |
public void setTableToImportField(String tableToImportField) { |
|
28 |
this.tableToImportField = tableToImportField; |
|
29 |
} |
|
30 |
|
|
31 |
private String validationMsg=""; |
|
32 |
|
|
33 |
|
|
34 |
public boolean isValidLinkParams(){ |
|
35 |
this.clearValidationMsg(); |
|
36 |
if (this.table == null){ |
|
37 |
this.validationMsg=PluginServices.getText(null,"missing_table"); |
|
38 |
return false; |
|
39 |
} |
|
40 |
if (this.tableFieldList == null){ |
|
41 |
this.validationMsg=PluginServices.getText(null,"cant_load_table_fields"); |
|
42 |
return false; |
|
43 |
} |
|
44 |
if (this.tableToImport == null){ |
|
45 |
this.validationMsg=PluginServices.getText(null,"missing_table_to_import"); |
|
46 |
return false; |
|
47 |
} |
|
48 |
if (this.tableToImportFieldList == null){ |
|
49 |
this.validationMsg=PluginServices.getText(null,"cant_load_table_to_import_fields"); |
|
50 |
return false; |
|
51 |
} |
|
52 |
if (this.tableField == null || this.tableField.length()== 0){ |
|
53 |
this.validationMsg=PluginServices.getText(null,"missing_table_field_for_link"); |
|
54 |
return false; |
|
55 |
} |
|
56 |
if (this.tableToImportField == null || this.tableToImportField.length()== 0){ |
|
57 |
this.validationMsg=PluginServices.getText(null,"missing_table_to_import_field_for_link"); |
|
58 |
return false; |
|
59 |
} |
|
60 |
if (!this.tableFieldList.contains(this.tableField)){ |
|
61 |
this.validationMsg=PluginServices.getText(null,"field_for_link_not_found_in_table"); |
|
62 |
return false; |
|
63 |
} |
|
64 |
if (!this.tableToImportFieldList.contains(this.tableToImportField)){ |
|
65 |
this.validationMsg=PluginServices.getText(null,"field_for_link_not_found_in_table_to_import"); |
|
66 |
return false; |
|
67 |
} |
|
68 |
if (!this.isCompatibleFieldTypes( |
|
69 |
(Integer)this.tableFieldList_types.get( |
|
70 |
this.tableFieldList.indexOf(this.tableField)), |
|
71 |
(Integer)this.tableToImportFieldList_types.get( |
|
72 |
this.tableToImportFieldList.indexOf(this.tableToImportField)) |
|
73 |
)){ |
|
74 |
this.validationMsg=PluginServices.getText(null,"incompatible_types_of_link_fields"); |
|
75 |
return false; |
|
76 |
|
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
return true; |
|
81 |
} |
|
82 |
|
|
83 |
private boolean isCompatibleFieldTypes(Integer object, Integer object2) { |
|
84 |
// TODO implementar mejor |
|
85 |
return object.intValue() == object2.intValue(); |
|
86 |
} |
|
87 |
|
|
88 |
public boolean isValid(){ |
|
89 |
this.clearValidationMsg(); |
|
90 |
if (!this.isValidLinkParams()) |
|
91 |
return false; |
|
92 |
|
|
93 |
if(this.fieldsToImport == null){ |
|
94 |
this.loadFieldsToImport(); |
|
95 |
// this.validationMsg=PluginServices.getText(null,"missing_fields_to_import_list"); |
|
96 |
return false; |
|
97 |
} |
|
98 |
|
|
99 |
boolean isSelectedAField=false; |
|
100 |
boolean haveFieldNameConflict=false; |
|
101 |
Iterator iter = this.fieldsToImport.iterator(); |
|
102 |
Iterator iterTable; |
|
103 |
while (iter.hasNext()){ |
|
104 |
FielToImport field = (FielToImport) iter.next(); |
|
105 |
if (field.toImport){ |
|
106 |
isSelectedAField=true; |
|
107 |
iterTable = this.tableFieldList.iterator(); |
|
108 |
while (iterTable.hasNext()){ |
|
109 |
if (((String)iterTable.next()).equals(field.fieldNameToUse)){ |
|
110 |
this.validationMsg=PluginServices.getText(null, "field_name_conflict") +": " +field.fieldNameToUse; |
|
111 |
haveFieldNameConflict=true; |
|
112 |
break; |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
} |
|
118 |
if (!isSelectedAField){ |
|
119 |
this.validationMsg=PluginServices.getText(null, "missing_field_to_import"); |
|
120 |
return false; |
|
121 |
} |
|
122 |
return !haveFieldNameConflict; |
|
123 |
|
|
124 |
} |
|
125 |
|
|
126 |
private void loadFieldsToImport() { |
|
127 |
Iterator iter = this.tableToImportFieldList.iterator(); |
|
128 |
if (this.fieldsToImport == null){ |
|
129 |
this.fieldsToImport = new ArrayList(); |
|
130 |
} |
|
131 |
FielToImport field; |
|
132 |
while (iter.hasNext()){ |
|
133 |
field = new FielToImport(); |
|
134 |
field.originalFieldName = (String) iter.next(); |
|
135 |
field.fieldNameToUse= field.originalFieldName; |
|
136 |
this.addFieldsToImportContains(field); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
private void addFieldsToImportContains(FielToImport field){ |
|
141 |
Iterator iter = this.fieldsToImport.iterator(); |
|
142 |
FielToImport old; |
|
143 |
boolean found=false; |
|
144 |
while (iter.hasNext()){ |
|
145 |
old = (FielToImport) iter.next(); |
|
146 |
if (old.originalFieldName.equals(field.originalFieldName)){ |
|
147 |
found=true; |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
if (!found){ |
|
152 |
this.fieldsToImport.add(field); |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
156 |
|
|
157 |
public class FielToImport{ |
|
158 |
public boolean toImport=false; |
|
159 |
public String originalFieldName=null; |
|
160 |
public String fieldNameToUse=null; |
|
161 |
} |
|
162 |
|
|
163 |
public ProjectTable getTable() { |
|
164 |
return table; |
|
165 |
} |
|
166 |
|
|
167 |
public void setTable(ProjectTable table) throws ReadDriverException { |
|
168 |
if (this.table == table) |
|
169 |
return; |
|
170 |
this.table = table; |
|
171 |
this.fieldsToImport=null; |
|
172 |
this.tableFieldList=null; |
|
173 |
this.tableFieldList_types=null; |
|
174 |
this.tableField=null; |
|
175 |
|
|
176 |
if (this.table == null){ |
|
177 |
return; |
|
178 |
} |
|
179 |
|
|
180 |
try { |
|
181 |
SelectableDataSource ds = this.table.getModelo().getRecordset(); |
|
182 |
ds.start(); |
|
183 |
|
|
184 |
String[] names= ds.getFieldNames(); |
|
185 |
this.tableFieldList = new ArrayList(names.length); |
|
186 |
this.tableFieldList_types = new ArrayList(names.length); |
|
187 |
for (int i=0;i<names.length;i++){ |
Also available in: Unified diff