svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / gui / Table.java @ 9532
History | View | Annotate | Download (47.5 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. 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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.table.gui; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Component; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.event.KeyAdapter; |
47 |
import java.awt.event.KeyEvent; |
48 |
import java.awt.event.KeyListener; |
49 |
import java.awt.event.MouseAdapter; |
50 |
import java.awt.event.MouseEvent; |
51 |
import java.beans.PropertyChangeEvent; |
52 |
import java.beans.PropertyChangeListener; |
53 |
import java.io.IOException; |
54 |
import java.sql.Types; |
55 |
import java.text.ParseException; |
56 |
import java.util.BitSet; |
57 |
import java.util.EventObject; |
58 |
|
59 |
import javax.swing.BorderFactory; |
60 |
import javax.swing.DefaultCellEditor; |
61 |
import javax.swing.DefaultListSelectionModel; |
62 |
import javax.swing.JComponent; |
63 |
import javax.swing.JFrame; |
64 |
import javax.swing.JLabel; |
65 |
import javax.swing.JOptionPane; |
66 |
import javax.swing.JPanel; |
67 |
import javax.swing.JTextField; |
68 |
import javax.swing.UIManager; |
69 |
import javax.swing.border.Border; |
70 |
import javax.swing.event.ListSelectionEvent; |
71 |
import javax.swing.event.ListSelectionListener; |
72 |
import javax.swing.table.AbstractTableModel; |
73 |
import javax.swing.table.DefaultTableColumnModel; |
74 |
import javax.swing.table.TableCellRenderer; |
75 |
import javax.swing.table.TableColumn; |
76 |
|
77 |
import org.apache.log4j.Logger; |
78 |
|
79 |
import com.hardcode.driverManager.DriverLoadException; |
80 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
81 |
import com.hardcode.gdbms.engine.values.Value; |
82 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
83 |
import com.iver.andami.PluginServices; |
84 |
import com.iver.andami.messages.NotificationManager; |
85 |
import com.iver.andami.ui.mdiFrame.MainFrame; |
86 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
87 |
import com.iver.andami.ui.mdiManager.IWindowTransform; |
88 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
89 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
90 |
import com.iver.cit.gvsig.fmap.MapContext; |
91 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
92 |
import com.iver.cit.gvsig.fmap.core.DefaultRow; |
93 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
94 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
95 |
import com.iver.cit.gvsig.fmap.core.IRow; |
96 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
97 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
98 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
99 |
import com.iver.cit.gvsig.fmap.edition.AfterFieldEditEvent; |
100 |
import com.iver.cit.gvsig.fmap.edition.AfterRowEditEvent; |
101 |
import com.iver.cit.gvsig.fmap.edition.BeforeFieldEditEvent; |
102 |
import com.iver.cit.gvsig.fmap.edition.BeforeRowEditEvent; |
103 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
104 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
105 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
106 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
107 |
import com.iver.cit.gvsig.fmap.edition.IEditionListener; |
108 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
109 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
110 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
111 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
112 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
113 |
import com.iver.cit.gvsig.fmap.edition.commands.CommandListener; |
114 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
115 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
116 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
117 |
import com.iver.cit.gvsig.fmap.layers.SelectionEvent; |
118 |
import com.iver.cit.gvsig.fmap.layers.SelectionListener; |
119 |
import com.iver.cit.gvsig.project.documents.table.EditionTable; |
120 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
121 |
import com.iver.utiles.swing.jtable.FieldSelectionEvent; |
122 |
import com.iver.utiles.swing.jtable.FieldSelectionListener; |
123 |
import com.iver.utiles.swing.jtable.SelectionHeaderSupport; |
124 |
|
125 |
/**
|
126 |
* DOCUMENT ME!
|
127 |
*
|
128 |
* @author Fernando Gonz?lez Cort?s
|
129 |
*/
|
130 |
public class Table extends JPanel implements SingletonWindow, EditionTable, |
131 |
IWindowListener,CommandListener, IWindowTransform, IEditionListener { |
132 |
private static Logger logger = Logger.getLogger(Table.class.getName()); |
133 |
private javax.swing.JScrollPane jScrollPane = null; |
134 |
protected javax.swing.JTable table = null; |
135 |
protected ProjectTable model = null; |
136 |
protected JLabel jLabelStatus = null; |
137 |
protected MapContext fmap;
|
138 |
protected boolean updating = false; |
139 |
private TableSelectionListener selectionListener = new TableSelectionListener(); |
140 |
private long numReg = 0; |
141 |
protected SelectionHeaderSupport headerSelectionSupport = new SelectionHeaderSupport(); |
142 |
private long[] orderIndexes = null; |
143 |
private long[] orderIndexesInverted = null; |
144 |
private IRow[] rowsCopied = null; |
145 |
private WindowInfo m_viewInfo = null; |
146 |
private boolean isPalette=false; |
147 |
private String[] antAliases; |
148 |
private int[] antMapping; |
149 |
/**
|
150 |
* This is the default constructor
|
151 |
*/
|
152 |
public Table() {
|
153 |
super();
|
154 |
initialize(); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* DOCUMENT ME!
|
159 |
*
|
160 |
* @return DOCUMENT ME!
|
161 |
*/
|
162 |
public ProjectTable getModel() {
|
163 |
return model;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* DOCUMENT ME!
|
168 |
*
|
169 |
* @return DOCUMENT ME!
|
170 |
*/
|
171 |
public BitSet getSelectedFieldIndices() { |
172 |
BitSet bs=headerSelectionSupport.getSelectedColumns();
|
173 |
// BitSet newbs=new BitSet();
|
174 |
// for (int i =1;i<bs.length();i++){
|
175 |
// if (bs.get(i))
|
176 |
// newbs.set(i-1);
|
177 |
// }
|
178 |
// return newbs;
|
179 |
return bs;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* DOCUMENT ME!
|
184 |
*
|
185 |
* @return DOCUMENT ME!
|
186 |
*/
|
187 |
public int[] getSelectedRowIndices() { |
188 |
return getTable().getSelectedRows();
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* DOCUMENT ME!
|
193 |
*/
|
194 |
protected void refreshControls() { |
195 |
try {
|
196 |
MainFrame mF = PluginServices.getMainFrame(); |
197 |
|
198 |
if (mF != null) { |
199 |
PluginServices.getMDIManager().getWindowInfo(Table.this).setTitle(PluginServices.getText( |
200 |
this, "Tabla") + ": " + model.getName()); |
201 |
} |
202 |
|
203 |
if (model.getAssociatedTable() != null) { |
204 |
this.fmap = ((FLayer) model.getAssociatedTable()).getMapContext();
|
205 |
} else {
|
206 |
this.fmap = null; |
207 |
} |
208 |
|
209 |
SelectableDataSource dataSource = model.getModelo() |
210 |
.getRecordset(); |
211 |
dataSource.mapExternalFields(); |
212 |
logger.debug("dataSource.start()");
|
213 |
dataSource.start(); |
214 |
|
215 |
// model.createAlias();
|
216 |
|
217 |
ColumnModel cm=new ColumnModel(model);
|
218 |
// cm.setDataModel(model);
|
219 |
getTable().setColumnModel(cm); |
220 |
|
221 |
AbstractTableModel dataModel = new DataSourceDataModel(model); |
222 |
|
223 |
getModel().createAlias(); |
224 |
|
225 |
getTable().setModel(dataModel); |
226 |
|
227 |
// TableColumn column = null;
|
228 |
// for (int i = 0; i < model.getColumnCount(); i++) {
|
229 |
// column = table.getColumnModel().getColumn(i);
|
230 |
// int w=model.getColumn(i).getWidth();
|
231 |
// column.setPreferredWidth(w); //sport column is bigger
|
232 |
// System.err.println("Table.Dentro de refreshControls. column=" + column.toString());
|
233 |
//
|
234 |
// }
|
235 |
//
|
236 |
for (int i=0;i<dataModel.getColumnCount();i++) { |
237 |
if (getModel().getModelo().getRecordset().getFieldType(i)==Types.STRUCT) { |
238 |
TableColumn tc=getTable().getColumnModel().getColumn(i);
|
239 |
ValueComplexRenderer vcr=new ValueComplexRenderer();
|
240 |
tc.setCellRenderer(vcr); |
241 |
ValueComplexEditor vce=new ValueComplexEditor();
|
242 |
tc.setCellEditor(vce); |
243 |
} |
244 |
} |
245 |
// TableColumn tc=getTable().getColumnModel().getColumn(0);
|
246 |
// tc.setCellRenderer(new MyTableCellRenderer());
|
247 |
|
248 |
|
249 |
headerSelectionSupport.setTableHeader(getTable().getTableHeader()); |
250 |
headerSelectionSupport.addFieldSelectionListener(new FieldSelectionListener() {
|
251 |
public void fieldSelected(FieldSelectionEvent e) { |
252 |
if (PluginServices.getMainFrame() != null) { |
253 |
PluginServices.getMainFrame().enableControls(); |
254 |
} |
255 |
} |
256 |
}); |
257 |
|
258 |
model.getModelo().getRecordset().addSelectionListener(selectionListener); |
259 |
|
260 |
updateSelection(); |
261 |
} catch (DriverException e) {
|
262 |
NotificationManager.addError("No se pudo leer la informaci?n", e);
|
263 |
} catch (DriverLoadException e) {
|
264 |
NotificationManager.addError("No se pudo leer la informaci?n", e);
|
265 |
} |
266 |
} |
267 |
|
268 |
/**
|
269 |
* DOCUMENT ME!
|
270 |
*
|
271 |
* @param table DOCUMENT ME!
|
272 |
*/
|
273 |
public void setModel(ProjectTable table) { |
274 |
model = table; |
275 |
|
276 |
//Gesti?n del nombre de la ventana
|
277 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
278 |
public void propertyChange(PropertyChangeEvent evt) { |
279 |
if (evt.getPropertyName().equals("name")) { |
280 |
PluginServices.getMDIManager().getWindowInfo(Table.this) |
281 |
.setTitle(PluginServices.getText(this,
|
282 |
"Tabla") + ": " + (String) evt.getNewValue()); |
283 |
} else if (evt.getPropertyName().equals("model")) { |
284 |
refreshControls(); |
285 |
} |
286 |
} |
287 |
}); |
288 |
|
289 |
IEditableSource ies=getModel().getModelo(); |
290 |
ies.addEditionListener(this);
|
291 |
|
292 |
refreshControls(); |
293 |
|
294 |
|
295 |
} |
296 |
class MyTableCellRenderer extends JLabel implements TableCellRenderer { |
297 |
final Border grayBorder = BorderFactory.createLineBorder(Color.darkGray); |
298 |
|
299 |
MyTableCellRenderer() { |
300 |
|
301 |
} |
302 |
|
303 |
public Component getTableCellRendererComponent(javax.swing.JTable table, |
304 |
Object value, boolean isSelected, boolean hasFocus, int row, |
305 |
int col) {
|
306 |
JLabel label=new JLabel(String.valueOf(row+1)); |
307 |
label.setForeground(Color.blue);
|
308 |
label.setOpaque(true);
|
309 |
if (isSelected)
|
310 |
label.setBackground(Color.yellow);
|
311 |
else
|
312 |
label.setBackground(UIManager.getColor("Button.background")); |
313 |
|
314 |
label.setBorder(grayBorder); |
315 |
return label;
|
316 |
} |
317 |
} |
318 |
|
319 |
/**
|
320 |
*
|
321 |
*/
|
322 |
public void updateSelection() { |
323 |
updating = true;
|
324 |
try {
|
325 |
DefaultListSelectionModel sm = (DefaultListSelectionModel) getTable() |
326 |
.getSelectionModel(); |
327 |
sm.clearSelection(); |
328 |
|
329 |
BitSet bs = (model.getModelo().getRecordset()).getSelection();
|
330 |
sm.setValueIsAdjusting(true);
|
331 |
|
332 |
if (orderIndexes != null) { |
333 |
for (int i = 0; i < orderIndexes.length; i++) { |
334 |
if (bs.get(i)) {
|
335 |
sm.addSelectionInterval((int) orderIndexesInverted[i],
|
336 |
(int) orderIndexesInverted[i]);
|
337 |
if (isEditing())
|
338 |
table.setEditingRow((int)orderIndexesInverted[i]);
|
339 |
} |
340 |
} |
341 |
} else {
|
342 |
for (int i = bs.nextSetBit(0); i >= 0; |
343 |
i = bs.nextSetBit(i + 1)) {
|
344 |
sm.addSelectionInterval(i, i); |
345 |
if (isEditing())
|
346 |
table.setEditingRow(i); |
347 |
} |
348 |
} |
349 |
|
350 |
sm.setValueIsAdjusting(false);
|
351 |
try {
|
352 |
numReg = model.getModelo().getRowCount(); |
353 |
} catch (IOException e) { |
354 |
e.printStackTrace(); |
355 |
} |
356 |
|
357 |
jLabelStatus.setText(" " +
|
358 |
(model.getModelo().getRecordset()).getSelection() |
359 |
.cardinality() + " / " + numReg + " " + |
360 |
PluginServices.getText(this, "registros_seleccionados_total") + |
361 |
".");
|
362 |
if (PluginServices.getMainFrame() != null) |
363 |
PluginServices.getMainFrame().enableControls(); |
364 |
} catch (DriverIOException e) {
|
365 |
e.printStackTrace(); |
366 |
} catch (DriverLoadException e) {
|
367 |
e.printStackTrace(); |
368 |
} |
369 |
updating = false;
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* This method initializes this
|
374 |
*/
|
375 |
protected void initialize() { |
376 |
jLabelStatus = new JLabel(); |
377 |
setLayout(new java.awt.BorderLayout());
|
378 |
jLabelStatus.setText("");
|
379 |
jLabelStatus.setName("");
|
380 |
jLabelStatus.setPreferredSize(new java.awt.Dimension(100, 18)); |
381 |
add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
382 |
this.add(jLabelStatus, java.awt.BorderLayout.SOUTH);
|
383 |
this.setPreferredSize(new Dimension(300,200)); |
384 |
} |
385 |
|
386 |
/**
|
387 |
* This method initializes table
|
388 |
*
|
389 |
* @return javax.swing.JTable
|
390 |
*/
|
391 |
public javax.swing.JTable getTable() {
|
392 |
if (table == null) { |
393 |
table = new javax.swing.JTable();
|
394 |
table.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); |
395 |
table.setSelectionModel(new DefaultListSelectionModel()); |
396 |
table.getTableHeader().addMouseListener(new MouseHandler());
|
397 |
table.addKeyListener(new TableKeyListener());
|
398 |
table.addMouseListener(new MouseRow());
|
399 |
table.setSelectionForeground(Color.blue);
|
400 |
table.setSelectionBackground(Color.yellow);
|
401 |
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
402 |
public void valueChanged(ListSelectionEvent e) { |
403 |
|
404 |
if (updating) {
|
405 |
return;
|
406 |
} |
407 |
|
408 |
SelectableDataSource dataModel = null;
|
409 |
|
410 |
try {
|
411 |
dataModel = Table.this.model.getModelo() |
412 |
.getRecordset(); |
413 |
} catch (DriverLoadException e1) {
|
414 |
e1.printStackTrace(); |
415 |
} |
416 |
|
417 |
DefaultListSelectionModel model = (DefaultListSelectionModel) table.getSelectionModel(); |
418 |
BitSet selection = dataModel.getSelection();
|
419 |
|
420 |
for (int i = e.getFirstIndex(); i <= e.getLastIndex(); |
421 |
i++) { |
422 |
if (orderIndexes != null) { |
423 |
selection.set((int) orderIndexes[i],
|
424 |
model.isSelectedIndex(i)); |
425 |
} else {
|
426 |
selection.set(i, model.isSelectedIndex(i)); |
427 |
} |
428 |
} |
429 |
|
430 |
if (e.getValueIsAdjusting() == false) { |
431 |
if (fmap != null) { |
432 |
fmap.endAtomicEvent(); |
433 |
} |
434 |
|
435 |
dataModel.fireSelectionEvents(); |
436 |
} else {
|
437 |
if (fmap != null) { |
438 |
fmap.beginAtomicEvent(); |
439 |
} |
440 |
} |
441 |
|
442 |
jLabelStatus.setText(" " + selection.cardinality() +
|
443 |
" / " + numReg + " " + |
444 |
PluginServices.getText(this,
|
445 |
"registros_seleccionados_total") + "."); |
446 |
|
447 |
} |
448 |
}); |
449 |
|
450 |
JTextField tf=new JTextField(); |
451 |
table.setDefaultEditor(Number.class, new DefaultEditor(tf)); |
452 |
table.setDefaultEditor(String.class, new DefaultEditor(tf)); |
453 |
table.setDefaultEditor(Object.class, new DefaultEditor(tf)); |
454 |
} |
455 |
|
456 |
return table;
|
457 |
} |
458 |
protected class DefaultEditor extends DefaultCellEditor { |
459 |
public Component getTableCellEditorComponent(javax.swing.JTable table, |
460 |
Object value, boolean isSelected, int row, int column) { |
461 |
JTextField tf=(JTextField)super.getTableCellEditorComponent(table, value, isSelected, |
462 |
row, column); |
463 |
if (isSelected){
|
464 |
tf.setBackground(new Color(230,220,220)); |
465 |
tf.selectAll(); |
466 |
|
467 |
} |
468 |
return tf;
|
469 |
} |
470 |
|
471 |
public DefaultEditor(JTextField tf) { |
472 |
super(tf);
|
473 |
//MouseListener[] mouseListeners=getTable().getEditorComponent().getMouseListeners();
|
474 |
// if (!mouseListeners[mouseListeners.length-1].getClass().equals(MouseRow.class)){
|
475 |
tf.addMouseListener(new MouseRow());
|
476 |
// }
|
477 |
getComponent().addKeyListener(new KeyAdapter() { |
478 |
int keyPressed = 0; |
479 |
|
480 |
public void keyPressed(KeyEvent ke) { |
481 |
if (ke.getKeyCode() != KeyEvent.VK_TAB) |
482 |
keyPressed++; |
483 |
JTextField tf = (JTextField) getComponent(); |
484 |
|
485 |
|
486 |
if (ke.getKeyCode() == KeyEvent.VK_RIGHT |
487 |
|| ke.getKeyCode() == KeyEvent.VK_ENTER) {
|
488 |
int caretPosition = tf.getCaretPosition();
|
489 |
if (caretPosition >= tf.getText().length()) {
|
490 |
int x = table.getSelectedColumn();
|
491 |
int y = table.getSelectedRow();
|
492 |
if (x + 1 >= table.getColumnCount()) { |
493 |
x = 0;
|
494 |
y++; |
495 |
} else {
|
496 |
x++; |
497 |
} |
498 |
//table.changeSelection(y, x, false, true);
|
499 |
//initEditField(x,y);
|
500 |
getComponent().setEnabled(false);
|
501 |
} |
502 |
|
503 |
} else if (ke.getKeyCode() == KeyEvent.VK_LEFT) { |
504 |
int caretPosition = tf.getCaretPosition();
|
505 |
if (caretPosition <= 0) { |
506 |
int x = table.getSelectedColumn();
|
507 |
int y = table.getSelectedRow();
|
508 |
if (x == 0) { |
509 |
x = table.getColumnCount() - 1;
|
510 |
if (y - 1 < 0) |
511 |
y = table.getRowCount() - 1;
|
512 |
else
|
513 |
y--; |
514 |
} else {
|
515 |
x--; |
516 |
} |
517 |
//table.changeSelection(y, x, false, true);
|
518 |
//initEditField(x,y);
|
519 |
getComponent().setEnabled(false);
|
520 |
} |
521 |
|
522 |
} |
523 |
} |
524 |
|
525 |
public void keyReleased(KeyEvent ke) { |
526 |
JComponent editor = (JComponent) DefaultEditor.this |
527 |
.getComponent(); |
528 |
if (editor instanceof JTextField) { |
529 |
if (keyPressed == 0) { |
530 |
((JTextField) editor).setText(String.valueOf(ke |
531 |
.getKeyChar())); |
532 |
} |
533 |
} |
534 |
keyPressed--; |
535 |
if (keyPressed < 0) |
536 |
keyPressed = 0;
|
537 |
getComponent().setEnabled(true);
|
538 |
} |
539 |
}); |
540 |
|
541 |
} |
542 |
|
543 |
public Object getCellEditorValue() { |
544 |
String s = ((JTextField) (DefaultEditor.this.getComponent())) |
545 |
.getText(); |
546 |
getComponent().setEnabled(true);
|
547 |
return s;
|
548 |
} |
549 |
|
550 |
public boolean isCellEditable(EventObject event) { |
551 |
// IF NUMBER OF CLICKS IS LESS THAN THE CLICKCOUNTTOSTART RETURN
|
552 |
// FALSE
|
553 |
// FOR CELL EDITING.
|
554 |
if (event instanceof MouseEvent) { |
555 |
return ((MouseEvent) event).getClickCount() >= getClickCountToStart(); |
556 |
} |
557 |
|
558 |
return true; |
559 |
} |
560 |
} |
561 |
|
562 |
|
563 |
|
564 |
|
565 |
/**
|
566 |
* This method initializes jScrollPane
|
567 |
*
|
568 |
* @return javax.swing.JScrollPane
|
569 |
*/
|
570 |
protected javax.swing.JScrollPane getJScrollPane() {
|
571 |
if (jScrollPane == null) { |
572 |
jScrollPane = new javax.swing.JScrollPane();
|
573 |
jScrollPane.setViewportView(getTable()); |
574 |
} |
575 |
|
576 |
return jScrollPane;
|
577 |
} |
578 |
|
579 |
/**
|
580 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
|
581 |
*/
|
582 |
public Object getWindowModel() { |
583 |
return model;
|
584 |
} |
585 |
|
586 |
/**
|
587 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
588 |
* for this Table. It is not intended to retrieve the ViewInfo object in a
|
589 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
590 |
* to retrieve the ViewInfo object at any time after the creation of the
|
591 |
* object.
|
592 |
*
|
593 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
594 |
*/
|
595 |
public WindowInfo getWindowInfo() {
|
596 |
if (m_viewInfo==null) { |
597 |
m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE |
|
598 |
WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE); |
599 |
m_viewInfo.setTitle(PluginServices.getText(this, "Tabla")+ " : " +model.getName()); |
600 |
m_viewInfo.setWidth(300);
|
601 |
m_viewInfo.setHeight(200);
|
602 |
} |
603 |
return m_viewInfo;
|
604 |
} |
605 |
|
606 |
/**
|
607 |
* DOCUMENT ME!
|
608 |
*
|
609 |
* @param indexes
|
610 |
*
|
611 |
* @throws IOException
|
612 |
*/
|
613 |
public void setOrder(long[] indexes){ |
614 |
orderIndexes = indexes; |
615 |
orderIndexesInverted = new long[orderIndexes.length]; |
616 |
|
617 |
for (int i = 0; i < indexes.length; i++) { |
618 |
orderIndexesInverted[(int) indexes[i]] = i;
|
619 |
} |
620 |
|
621 |
updating = true;
|
622 |
((DataSourceDataModel) getTable().getModel()).fireTableDataChanged(); |
623 |
updating = false;
|
624 |
|
625 |
updateSelection(); |
626 |
} |
627 |
|
628 |
/* public void startEditing() throws DriverException{
|
629 |
// dw = model.getModelo().getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER);
|
630 |
// dw.beginTrans();
|
631 |
}
|
632 |
*/
|
633 |
|
634 |
/**
|
635 |
* DOCUMENT ME!
|
636 |
*/
|
637 |
|
638 |
/* public void cancelEditing() throws DriverException {
|
639 |
dw.rollBackTrans();
|
640 |
dw = null;
|
641 |
}
|
642 |
*/
|
643 |
|
644 |
/**
|
645 |
* DOCUMENT ME!
|
646 |
*/
|
647 |
|
648 |
/* public void stopEditing() throws DriverException {
|
649 |
// dw.commitTrans();
|
650 |
// dw = null;
|
651 |
// model.getModelo().stop();
|
652 |
// model.getModelo().start();
|
653 |
}
|
654 |
*/
|
655 |
|
656 |
/**
|
657 |
* DOCUMENT ME!
|
658 |
*/
|
659 |
|
660 |
/* public boolean isEditing() {
|
661 |
return dw != null;
|
662 |
}
|
663 |
*/
|
664 |
|
665 |
/**
|
666 |
* Quita los campos seleccionados
|
667 |
*/
|
668 |
public void clearSelectedFields() { |
669 |
headerSelectionSupport.clearSelectedColumns(); |
670 |
} |
671 |
|
672 |
/**
|
673 |
* DOCUMENT ME!
|
674 |
*
|
675 |
* @param index DOCUMENT ME!
|
676 |
*
|
677 |
* @return DOCUMENT ME!
|
678 |
*/
|
679 |
public Value[] getValueRow(int index) { |
680 |
DataSourceDataModel dsdm = (DataSourceDataModel) getTable().getModel(); |
681 |
Value[] values = new Value[dsdm.getColumnCount()]; |
682 |
|
683 |
for (int i = 0; i < dsdm.getColumnCount(); i++) { |
684 |
values[i] = (Value) dsdm.getValueAt(index, i); |
685 |
} |
686 |
|
687 |
return values;
|
688 |
} |
689 |
|
690 |
/* private void refresh() throws DriverException{
|
691 |
//dw.commitTrans();
|
692 |
//model.getModelo().stop();
|
693 |
//dw.beginTrans();
|
694 |
//DataSourceDataModel dsdm=(DataSourceDataModel)getTable().getModel();
|
695 |
//dsdm.fireTableDataChanged();
|
696 |
}*/
|
697 |
/* public void addEmptyRow() throws DriverException{
|
698 |
ValueCollection valuePK=new ValueCollection();
|
699 |
valuePK.setValues(new Value[]{ValueFactory.createValue(dw.getRowCount())});
|
700 |
dw.insertEmptyRow(valuePK);
|
701 |
refresh();
|
702 |
}
|
703 |
*/
|
704 |
/* public void copySelectedRows() throws DriverException{
|
705 |
int[] sel=getSelectedRowIndices();
|
706 |
for(int i=0;i<sel.length;i++){
|
707 |
rowsCopied.add(getValueRow(sel[i]));
|
708 |
}
|
709 |
}
|
710 |
*/
|
711 |
/* public void addSelectionToEnd() throws DriverException {
|
712 |
for (int i=0;i<rowsCopied.size();i++){
|
713 |
dw.insertFilledRow((Value[])rowsCopied.get(i));
|
714 |
}
|
715 |
refresh();
|
716 |
}
|
717 |
*/
|
718 |
/*public void delSelectionRow() throws DriverException{
|
719 |
int[] sel=getSelectedRowIndices();
|
720 |
for(int i=sel.length-1;i>=0;i--){
|
721 |
dw.deleteRow(sel[i]);
|
722 |
}
|
723 |
refresh();
|
724 |
}
|
725 |
*/
|
726 |
/*public boolean isCopy(){
|
727 |
return !rowsCopied.isEmpty();
|
728 |
}
|
729 |
*/
|
730 |
/*
|
731 |
public void addSelectionToRow() throws DriverException {
|
732 |
int[] sel=getSelectedRowIndices();
|
733 |
dw.insertFilledRow((Value[])rowsCopied.get(i),sel[0]);
|
734 |
refresh();
|
735 |
}
|
736 |
*/
|
737 |
public void startEditing() throws EditionException { |
738 |
getModel().getModelo().startEdition(EditionEvent.ALPHANUMERIC); |
739 |
// Guardamos el estado actual para recuperarlo si cancelamos la edici?n.
|
740 |
antAliases = getModel().getAliases(); |
741 |
antMapping = getModel().getMapping(); |
742 |
//int row=table.getSelectedRow();
|
743 |
//int column=table.getSelectedColumn();
|
744 |
//if (row!=-1 && column!=-1)
|
745 |
// initEditField(column,row);
|
746 |
|
747 |
// View[] views = (View[]) PluginServices.getMDIManager().getAllViews();
|
748 |
//
|
749 |
// for (int i=0 ; i<views.length ; i++){
|
750 |
// if (views[i] instanceof com.iver.cit.gvsig.gui.View){
|
751 |
// com.iver.cit.gvsig.gui.View view=(com.iver.cit.gvsig.gui.View)views[i];
|
752 |
// FLayers layers =view.getMapControl().getMapContext().getLayers();
|
753 |
// for (int j=0;j<layers.getLayersCount();j++){
|
754 |
// if (layers.getLayer(j).equals(this.getModel().getAssociatedTable())){
|
755 |
// view.showConsole();
|
756 |
// ((FLyrVect)layers.getLayer(j)).setActive(true);
|
757 |
// ((FLyrVect)layers.getLayer(j)).setEditing(true);
|
758 |
// }
|
759 |
// }
|
760 |
// }
|
761 |
// }
|
762 |
} |
763 |
private void initEditField(int[] x,int[] y){ |
764 |
if (getTable().getRowCount()>0){ |
765 |
if (isEditing()) {
|
766 |
|
767 |
if (x.length == 1 && y.length == 1) |
768 |
table.editCellAt(y[0], x[0]); |
769 |
JTextField tf = (JTextField) table.getEditorComponent(); |
770 |
if (tf != null) { |
771 |
tf.selectAll(); |
772 |
tf.requestFocus(); |
773 |
} |
774 |
// if (y.length > 0 && x.length > 0) {
|
775 |
// getTable().setRowSelectionInterval(y[0], y[y.length - 1]);
|
776 |
// getTable().setColumnSelectionInterval(x[0], x[x.length - 1]);
|
777 |
// }
|
778 |
|
779 |
} |
780 |
} |
781 |
} |
782 |
/**
|
783 |
* DOCUMENT ME!
|
784 |
*/
|
785 |
public void stopEditing() { |
786 |
try {
|
787 |
this.stopEditingCell();
|
788 |
|
789 |
FLyrVect lyr = (FLyrVect) getModel().getAssociatedTable(); |
790 |
|
791 |
if ((lyr != null) && |
792 |
lyr.getSource() instanceof VectorialEditableAdapter) {
|
793 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) lyr.getSource(); |
794 |
ISpatialWriter spatialWriter = (ISpatialWriter) vea.getOriginalDriver(); |
795 |
vea.stopEdition(spatialWriter,EditionEvent.ALPHANUMERIC); |
796 |
lyr.setSource(vea.getOriginalAdapter()); |
797 |
lyr.setEditing(false);
|
798 |
refreshControls(); |
799 |
|
800 |
} else {
|
801 |
|
802 |
IEditableSource ies=getModel().getModelo(); |
803 |
if (ies instanceof IWriteable) |
804 |
{ |
805 |
IWriteable w = (IWriteable) ies; |
806 |
IWriter writer = w.getWriter(); |
807 |
if (writer == null) |
808 |
{ |
809 |
NotificationManager.addError("No existe driver de escritura para la tabla"
|
810 |
+ getModel().getName(), new EditionException());
|
811 |
} |
812 |
else
|
813 |
{ |
814 |
ITableDefinition tableDef = ies.getTableDefinition(); |
815 |
writer.initialize(tableDef); |
816 |
|
817 |
ies.stopEdition(writer,EditionEvent.ALPHANUMERIC); |
818 |
|
819 |
// TODO: RELOAD
|
820 |
// EditableAdapter edAdapter = (EditableAdapter) ies;
|
821 |
// // Restaura el datasource a su estado original
|
822 |
// edAdapter.setOriginalDataSource(edAdapter.getRecordset());
|
823 |
ies.getSelection().clear(); |
824 |
refreshControls(); |
825 |
} |
826 |
} |
827 |
|
828 |
/*
|
829 |
GdbmsWriter gdbmswriter = new GdbmsWriter();
|
830 |
gdbmswriter.setDataWare(getModel().getModelo()
|
831 |
.getRecordset()
|
832 |
.getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER));
|
833 |
gdbmswriter.preProcess();
|
834 |
|
835 |
for (int i = 0; i < getModel().getModelo().getRowCount();
|
836 |
i++) {
|
837 |
gdbmswriter.process(getModel().getModelo().getRow(i));
|
838 |
}
|
839 |
|
840 |
gdbmswriter.postProcess();
|
841 |
*/
|
842 |
|
843 |
} |
844 |
|
845 |
} catch (Exception e) { |
846 |
NotificationManager.addError("No se pudo guardar la edici?n", e);
|
847 |
} |
848 |
} |
849 |
|
850 |
/**
|
851 |
* DOCUMENT ME!
|
852 |
*
|
853 |
* @param index DOCUMENT ME!
|
854 |
*/
|
855 |
public void hideColumns(int[] index) { |
856 |
// TODO Auto-generated method stub
|
857 |
} |
858 |
|
859 |
/**
|
860 |
* DOCUMENT ME!
|
861 |
*
|
862 |
* @param index DOCUMENT ME!
|
863 |
*/
|
864 |
public void setUneditableColumns(int[] index) { |
865 |
// TODO Auto-generated method stub
|
866 |
} |
867 |
|
868 |
/**
|
869 |
* DOCUMENT ME!
|
870 |
*
|
871 |
* @param numColumns DOCUMENT ME!
|
872 |
* @param values DOCUMENT ME!
|
873 |
*/
|
874 |
public void setDefaultValues(int[] numColumns, Value[] values) { |
875 |
// TODO Auto-generated method stub
|
876 |
} |
877 |
|
878 |
/**
|
879 |
* DOCUMENT ME!
|
880 |
*
|
881 |
* @return DOCUMENT ME!
|
882 |
*/
|
883 |
public Value getDefaultValue() {
|
884 |
// TODO Auto-generated method stub
|
885 |
return null; |
886 |
} |
887 |
|
888 |
/**
|
889 |
* DOCUMENT ME!
|
890 |
*
|
891 |
* @throws IOException DOCUMENT ME!
|
892 |
*/
|
893 |
public void cancelEditing() throws IOException { |
894 |
this.cancelEditingCell();
|
895 |
getModel().getModelo().cancelEdition(EditionEvent.ALPHANUMERIC); |
896 |
if (antAliases != null) |
897 |
{ |
898 |
getModel().setAliases(antAliases); |
899 |
getModel().setMapping(antMapping); |
900 |
getModel().recalculateColumnsFromAliases(); |
901 |
} |
902 |
else
|
903 |
{ |
904 |
System.err.println("Algo ha ido mal con antAliases"); |
905 |
} |
906 |
//refresh();
|
907 |
refreshControls(); |
908 |
} |
909 |
|
910 |
/**
|
911 |
* DOCUMENT ME!
|
912 |
*
|
913 |
* @return DOCUMENT ME!
|
914 |
*/
|
915 |
public boolean isEditing() { |
916 |
return getModel().getModelo().isEditing();
|
917 |
} |
918 |
|
919 |
/**
|
920 |
* DOCUMENT ME!
|
921 |
*/
|
922 |
public void refresh() { |
923 |
int row=table.getSelectedRow();
|
924 |
int column=table.getSelectedColumn();
|
925 |
if (row!=-1 && column!=-1 && table.getEditorComponent()!=null){ |
926 |
Value[] values=getValueRow(row);
|
927 |
JTextField jtf=(JTextField)table.getEditorComponent(); |
928 |
jtf.setText(values[column].toString()); |
929 |
} |
930 |
updating = true;
|
931 |
((DataSourceDataModel) getTable().getModel()).fireTableDataChanged(); |
932 |
|
933 |
updating = false;
|
934 |
updateSelection(); |
935 |
PluginServices.getMainFrame().enableControls(); |
936 |
|
937 |
} |
938 |
|
939 |
/**
|
940 |
* Add the rows that are passed like parameter and if parameter is null a
|
941 |
* row is added empties.
|
942 |
*
|
943 |
* @param rows Rows to add or null.
|
944 |
*
|
945 |
* @throws DriverIOException
|
946 |
* @throws IOException
|
947 |
*/
|
948 |
public void addRow(IRow[] rows) throws DriverIOException, IOException { |
949 |
IEditableSource ies=getModel().getModelo(); |
950 |
try {
|
951 |
if (rows == null) { |
952 |
|
953 |
if (getModel().getAssociatedTable()!=null){ |
954 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"No se puede a?adir una fila a una tabla asociada a una capa."); |
955 |
return;
|
956 |
} |
957 |
IRow row; |
958 |
int numAttr=getModel().getModelo()
|
959 |
.getRecordset() |
960 |
.getFieldCount(); |
961 |
Value[] values=new Value[numAttr]; |
962 |
for (int i=0;i<numAttr;i++){ |
963 |
values[i]=ValueFactory.createNullValue(); |
964 |
} |
965 |
row = new DefaultRow(values);
|
966 |
ies.addRow(row,"Fila en blanco",EditionEvent.ALPHANUMERIC);
|
967 |
} else {
|
968 |
ies.startComplexRow(); |
969 |
for (int i = 0; i < rows.length; i++) { |
970 |
ies.addRow(((IRowEdited) rows[i]).getLinkedRow(),"Pegar filas",EditionEvent.ALPHANUMERIC);
|
971 |
} |
972 |
String description=PluginServices.getText(this,"add_rows"); |
973 |
ies.endComplexRow(description); |
974 |
} |
975 |
} catch (DriverException e) {
|
976 |
// TODO Auto-generated catch block
|
977 |
e.printStackTrace(); |
978 |
} catch (DriverLoadException e) {
|
979 |
// TODO Auto-generated catch block
|
980 |
e.printStackTrace(); |
981 |
} |
982 |
|
983 |
refresh(); |
984 |
|
985 |
} |
986 |
|
987 |
/**
|
988 |
* Copy in the arraylist the rows that be selected just then.
|
989 |
*
|
990 |
* @throws DriverIOException
|
991 |
* @throws IOException
|
992 |
*/
|
993 |
public void copyRow() throws DriverIOException, IOException { |
994 |
int[] index = getSelectedRowIndices(); |
995 |
rowsCopied = new IRow[index.length];
|
996 |
|
997 |
for (int i = 0; i < index.length; i++) { |
998 |
rowsCopied[i] = getModel().getModelo().getRow(index[i]); |
999 |
} |
1000 |
} |
1001 |
|
1002 |
/**
|
1003 |
* Cut the rows that be selected just then.
|
1004 |
*
|
1005 |
* @throws DriverIOException
|
1006 |
* @throws IOException
|
1007 |
*/
|
1008 |
public void cutRow() throws DriverIOException, IOException { |
1009 |
int[] index = getSelectedRowIndices(); |
1010 |
rowsCopied = new IRow[index.length];
|
1011 |
|
1012 |
for (int i = 0; i < index.length; i++) { |
1013 |
rowsCopied[i] = getModel().getModelo().getRow(index[i]); |
1014 |
} |
1015 |
|
1016 |
removeRow(); |
1017 |
} |
1018 |
|
1019 |
/**
|
1020 |
* Remove in the rows that be selected just then.
|
1021 |
*
|
1022 |
* @throws DriverIOException
|
1023 |
* @throws IOException
|
1024 |
*/
|
1025 |
public void removeRow() throws DriverIOException, IOException { |
1026 |
int[] index = getSelectedRowIndices(); |
1027 |
getModel().getModelo().startComplexRow(); |
1028 |
for (int i = index.length-1; i >=0; i--) { |
1029 |
getModel().getModelo().removeRow(index[i],"Eliminar fila", EditionEvent.ALPHANUMERIC);
|
1030 |
} |
1031 |
// int[] sel={0};
|
1032 |
// getTable().setEditingRow(-1);
|
1033 |
// getTable().getCellEditor().
|
1034 |
// initEditField(sel,sel);
|
1035 |
if (getTable().getCellEditor() != null) |
1036 |
getTable().getCellEditor().cancelCellEditing(); |
1037 |
String description=PluginServices.getText(this,"remove_rows"); |
1038 |
getModel().getModelo().endComplexRow(description); |
1039 |
getTable().clearSelection(); |
1040 |
|
1041 |
refresh(); |
1042 |
//repaintAssociatedView();
|
1043 |
} |
1044 |
|
1045 |
// private void repaintAssociatedView(){
|
1046 |
// View[] views = (View[]) PluginServices.getMDIManager().getAllViews();
|
1047 |
//
|
1048 |
// for (int i=0 ; i<views.length ; i++){
|
1049 |
// if (views[i] instanceof com.iver.cit.gvsig.gui.View){
|
1050 |
// com.iver.cit.gvsig.gui.View view=(com.iver.cit.gvsig.gui.View)views[i];
|
1051 |
// FLayers layers =view.getMapControl().getMapContext().getLayers();
|
1052 |
// for (int j=0;j<layers.getLayersCount();j++){
|
1053 |
// if (layers.getLayer(j).equals(this.getModel().getAssociatedTable())){
|
1054 |
// view.getMapControl().getMapContext().invalidate();
|
1055 |
// }
|
1056 |
// }
|
1057 |
// }
|
1058 |
// }
|
1059 |
// }
|
1060 |
/**
|
1061 |
* DOCUMENT ME!
|
1062 |
*/
|
1063 |
public void addColumn(FieldDescription newField) { |
1064 |
EditableAdapter edAdapter = (EditableAdapter) getModel().getModelo(); |
1065 |
try {
|
1066 |
edAdapter.addField(newField); |
1067 |
if (getTable().getCellEditor() != null) |
1068 |
getTable().getCellEditor().cancelCellEditing(); |
1069 |
getModel().setModel(edAdapter); // Para que se recalculen los campos. TODO: Limpiear todo esto
|
1070 |
// refresh();
|
1071 |
refreshControls(); |
1072 |
} catch (EditionException e) {
|
1073 |
e.printStackTrace(); |
1074 |
NotificationManager.addError(e); |
1075 |
} |
1076 |
} |
1077 |
|
1078 |
/**
|
1079 |
* DOCUMENT ME!
|
1080 |
*/
|
1081 |
public void removeColumn() { |
1082 |
EditableAdapter edAdapter = (EditableAdapter) getModel().getModelo(); |
1083 |
try {
|
1084 |
BitSet selectedFields = getSelectedFieldIndices();
|
1085 |
SelectableDataSource sds = edAdapter.getRecordset(); |
1086 |
edAdapter.startComplexRow(); |
1087 |
FieldDescription[] auxFlds = sds.getFieldsDescription();
|
1088 |
for(int i=selectedFields.nextSetBit(0); i>=0; i=selectedFields.nextSetBit(i+1)) { |
1089 |
FieldDescription fld = auxFlds[i]; |
1090 |
edAdapter.removeField(fld.getFieldAlias()); |
1091 |
} |
1092 |
if (getTable().getCellEditor() != null) |
1093 |
getTable().getCellEditor().cancelCellEditing(); |
1094 |
|
1095 |
edAdapter.endComplexRow(PluginServices.getText(this, "remove_fields")); |
1096 |
clearSelectedFields(); |
1097 |
getModel().setModel(edAdapter); // Para que se recalculen los campos. TODO: Limpiear todo esto
|
1098 |
// refresh();
|
1099 |
refreshControls(); |
1100 |
} catch (EditionException e) {
|
1101 |
e.printStackTrace(); |
1102 |
NotificationManager.addError(e); |
1103 |
} catch (DriverException e) {
|
1104 |
e.printStackTrace(); |
1105 |
NotificationManager.addError(e); |
1106 |
} catch (IOException e) { |
1107 |
e.printStackTrace(); |
1108 |
NotificationManager.addError(e); |
1109 |
} catch (DriverIOException e) {
|
1110 |
e.printStackTrace(); |
1111 |
NotificationManager.addError(e); |
1112 |
} |
1113 |
|
1114 |
} |
1115 |
|
1116 |
/**
|
1117 |
* Return if we have rows copied or not.
|
1118 |
*
|
1119 |
* @return True if we have rows copied.
|
1120 |
*/
|
1121 |
public boolean isCopied() { |
1122 |
return (rowsCopied != null); |
1123 |
} |
1124 |
|
1125 |
/**
|
1126 |
* Paste the arraylist rows.
|
1127 |
*
|
1128 |
* @throws DriverIOException
|
1129 |
* @throws IOException
|
1130 |
*/
|
1131 |
public void pasteRow() throws DriverIOException, IOException { |
1132 |
addRow(rowsCopied); |
1133 |
//repaintAssociatedView();
|
1134 |
} |
1135 |
|
1136 |
/**
|
1137 |
* DOCUMENT ME!
|
1138 |
*/
|
1139 |
public void windowActivated() { |
1140 |
//if (isEditing() && getModel().getModelo() instanceof VectorialEditableAdapter)
|
1141 |
updateSelection(); |
1142 |
} |
1143 |
|
1144 |
/**
|
1145 |
* DOCUMENT ME!
|
1146 |
*/
|
1147 |
public void windowClosed() { |
1148 |
// TODO Auto-generated method stub
|
1149 |
} |
1150 |
|
1151 |
/**
|
1152 |
* DOCUMENT ME!
|
1153 |
*
|
1154 |
* @author Fernando Gonz?lez Cort?s
|
1155 |
*/
|
1156 |
public class DataSourceDataModel extends AbstractTableModel { |
1157 |
//private SelectableDataSource dataSource;
|
1158 |
ProjectTable pt; |
1159 |
|
1160 |
/**
|
1161 |
* Crea un nuevo DataSourceDataModel.
|
1162 |
*
|
1163 |
* @param pt DOCUMENT ME!
|
1164 |
*/
|
1165 |
public DataSourceDataModel(ProjectTable pt) {
|
1166 |
this.pt = pt;
|
1167 |
|
1168 |
//try {
|
1169 |
//dataSource = pt.getModelo().getRecordset();
|
1170 |
//} catch (DriverLoadException e) {
|
1171 |
// TODO Auto-generated catch block
|
1172 |
// e.printStackTrace();
|
1173 |
//}
|
1174 |
} |
1175 |
|
1176 |
/**
|
1177 |
* Returns the name of the field.
|
1178 |
*
|
1179 |
* @param col index of field
|
1180 |
*
|
1181 |
* @return Name of field
|
1182 |
*/
|
1183 |
public String getColumnName(int col) { |
1184 |
// if (col==0)
|
1185 |
// return " ";
|
1186 |
// col--;
|
1187 |
int i=pt.getMapping()[col];
|
1188 |
return pt.getAliases()[i];
|
1189 |
} |
1190 |
|
1191 |
/**
|
1192 |
* Returns the number of fields.
|
1193 |
*
|
1194 |
* @return number of fields
|
1195 |
*/
|
1196 |
public int getColumnCount() { |
1197 |
return pt.getColumnCount();
|
1198 |
} |
1199 |
|
1200 |
/**
|
1201 |
* Returns number of rows.
|
1202 |
*
|
1203 |
* @return number of rows.
|
1204 |
*/
|
1205 |
public int getRowCount() { |
1206 |
try {
|
1207 |
IEditableSource des = pt.getModelo(); |
1208 |
return des.getRowCount();
|
1209 |
} catch (DriverIOException e) {
|
1210 |
return 0; |
1211 |
} catch (IOException e) { |
1212 |
return 0; |
1213 |
} |
1214 |
} |
1215 |
|
1216 |
/**
|
1217 |
* DOCUMENT ME!
|
1218 |
*
|
1219 |
* @param row DOCUMENT ME!
|
1220 |
* @param col DOCUMENT ME!
|
1221 |
*
|
1222 |
* @return DOCUMENT ME!
|
1223 |
*/
|
1224 |
public Object getValueAt(int row, int col) { |
1225 |
|
1226 |
// if (col==0){
|
1227 |
// return new Integer(row);
|
1228 |
// }
|
1229 |
// col--;
|
1230 |
int numRow;
|
1231 |
if (orderIndexes != null && row < orderIndexes.length) { |
1232 |
numRow=(int)orderIndexes[row];
|
1233 |
}else {
|
1234 |
numRow=row; |
1235 |
} |
1236 |
try {
|
1237 |
IEditableSource des = pt.getModelo(); |
1238 |
Object obj =null; |
1239 |
IRowEdited rowEdited=des.getRow(numRow); |
1240 |
obj= rowEdited.getAttribute(pt.getMapping()[col]); |
1241 |
return obj;
|
1242 |
} catch (DriverIOException e1) {
|
1243 |
e1.printStackTrace(); |
1244 |
return ValueFactory.createValue("").toString(); |
1245 |
} catch (IOException e1) { |
1246 |
e1.printStackTrace(); |
1247 |
return ValueFactory.createValue("").toString(); |
1248 |
} |
1249 |
} |
1250 |
|
1251 |
/**
|
1252 |
* DOCUMENT ME!
|
1253 |
*
|
1254 |
* @param rowIndex DOCUMENT ME!
|
1255 |
* @param columnIndex DOCUMENT ME!
|
1256 |
*
|
1257 |
* @return DOCUMENT ME!
|
1258 |
*/
|
1259 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
1260 |
// if (columnIndex==0)
|
1261 |
// return false;
|
1262 |
try {
|
1263 |
if (getModel().getModelo().getRecordset().getFieldType(columnIndex)==Types.STRUCT) |
1264 |
return true; |
1265 |
} catch (DriverLoadException e) {
|
1266 |
e.printStackTrace(); |
1267 |
} catch (DriverException e) {
|
1268 |
e.printStackTrace(); |
1269 |
} |
1270 |
return isEditing();
|
1271 |
} |
1272 |
|
1273 |
/**
|
1274 |
* DOCUMENT ME!
|
1275 |
*
|
1276 |
* @param aValue DOCUMENT ME!
|
1277 |
* @param rowIndex DOCUMENT ME!
|
1278 |
* @param columnIndex DOCUMENT ME!
|
1279 |
*
|
1280 |
* @throws RuntimeException DOCUMENT ME!
|
1281 |
*/
|
1282 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
1283 |
// if (columnIndex==0)
|
1284 |
// throw new UnsupportedOperationException("Row Number is a read-only column");
|
1285 |
// columnIndex--;
|
1286 |
Value v; |
1287 |
int numRow;
|
1288 |
if (orderIndexes != null) { |
1289 |
numRow=(int)orderIndexes[rowIndex];
|
1290 |
}else {
|
1291 |
numRow=rowIndex; |
1292 |
} |
1293 |
if (getValueAt(rowIndex,columnIndex)==null || getValueAt(rowIndex,columnIndex).toString().equals(aValue)) |
1294 |
return;
|
1295 |
try {
|
1296 |
IEditableSource des = pt.getModelo(); |
1297 |
v = ValueFactory.createValueByType(aValue.toString(), |
1298 |
des.getRecordset().getFieldType(columnIndex)); |
1299 |
IRowEdited row = des.getRow(numRow); //.getAttribute(columnIndex);
|
1300 |
Value[] values = row.getAttributes();
|
1301 |
values[columnIndex] = v; |
1302 |
|
1303 |
IRow newRow = null;
|
1304 |
|
1305 |
if (row.getLinkedRow() instanceof IFeature) { |
1306 |
IGeometry geometry = ((DefaultFeature) row.getLinkedRow()).getGeometry(); |
1307 |
newRow = new DefaultFeature(geometry, values,row.getID());
|
1308 |
} else {
|
1309 |
newRow = new DefaultRow(values,row.getID());
|
1310 |
} |
1311 |
|
1312 |
des.modifyRow(numRow, newRow,"Editar valor", EditionEvent.ALPHANUMERIC);
|
1313 |
} catch (DriverException e1) {
|
1314 |
throw new RuntimeException(e1); |
1315 |
} catch (ParseException e) { |
1316 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"formato_del_campo_incorrecto"); |
1317 |
return;
|
1318 |
} catch (DriverLoadException e) {
|
1319 |
throw new RuntimeException(e); |
1320 |
} catch (DriverIOException e) {
|
1321 |
throw new RuntimeException(e); |
1322 |
} catch (IOException e) { |
1323 |
throw new RuntimeException(e); |
1324 |
} catch (NumberFormatException e) { |
1325 |
/* NotificationManager.addError(PluginServices.-getText(this,"numero_incorrecto")+
|
1326 |
"\n"+PluginServices.-getText(this,"fila")+" = "+rowIndex+
|
1327 |
"\n"+PluginServices.-getText(this,"columna")+ " = "+columnIndex,e);
|
1328 |
*/
|
1329 |
} |
1330 |
} |
1331 |
} |
1332 |
public class ColumnModel extends DefaultTableColumnModel{ |
1333 |
private ProjectTable pt;
|
1334 |
public ColumnModel(ProjectTable pt) {
|
1335 |
this.pt = pt;
|
1336 |
} |
1337 |
|
1338 |
|
1339 |
public int getTotalColumnWidth() { |
1340 |
// int w=0;
|
1341 |
// for (int i=0;i<getColumnCount();i++){
|
1342 |
// w+=pt.getColumn(i).getWidth();
|
1343 |
// }
|
1344 |
return super.getTotalColumnWidth(); |
1345 |
} |
1346 |
|
1347 |
public void moveColumn(int arg0, int arg1) { |
1348 |
//super.moveColumn(arg0, arg1);
|
1349 |
if (arg0==arg1){
|
1350 |
super.moveColumn(arg0,arg1);
|
1351 |
} |
1352 |
} |
1353 |
|
1354 |
|
1355 |
public void propertyChange(PropertyChangeEvent arg0) { |
1356 |
try{
|
1357 |
super.propertyChange(arg0);
|
1358 |
int w=((Integer)arg0.getNewValue()).intValue(); |
1359 |
if (arg0.getSource() instanceof TableColumn && (w!=75)){ |
1360 |
TableColumn tc=(TableColumn)arg0.getSource(); |
1361 |
Column column=pt.getColumn(tc.getModelIndex()); |
1362 |
column.setWidth(w); |
1363 |
System.out.println("Index guardar = "+tc.getModelIndex()+" , "+"Anchura = "+w); |
1364 |
} |
1365 |
}catch (Exception e) { |
1366 |
System.out.println("PETA"); |
1367 |
} |
1368 |
|
1369 |
} |
1370 |
} |
1371 |
/**
|
1372 |
* DOCUMENT ME!
|
1373 |
*
|
1374 |
* @author Vicente Caballero Navarro
|
1375 |
*/
|
1376 |
public class TableSelectionListener implements SelectionListener { |
1377 |
/**
|
1378 |
* @see com.iver.cit.gvsig.fmap.layers.LegendListener#selectionChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
1379 |
*/
|
1380 |
public void selectionChanged(SelectionEvent e) { |
1381 |
updateSelection(); |
1382 |
Table.this.repaint(); |
1383 |
//((ValueComplexRenderer)Table.this.getTable().getColumnModel().getColumn(getSelectedFieldIndices().nextSetBit(0)).getCellRenderer()).getValue();
|
1384 |
} |
1385 |
} |
1386 |
|
1387 |
/**
|
1388 |
* DOCUMENT ME!
|
1389 |
*
|
1390 |
* @author Vicente Caballero Navarro
|
1391 |
*/
|
1392 |
private class MouseHandler extends MouseAdapter { |
1393 |
/**
|
1394 |
* DOCUMENT ME!
|
1395 |
*
|
1396 |
* @param e DOCUMENT ME!
|
1397 |
*/
|
1398 |
public void mouseClicked(MouseEvent e) { |
1399 |
|
1400 |
/* JTableHeader h = (JTableHeader) e.getSource();
|
1401 |
TableColumnModel columnModel = h.getColumnModel();
|
1402 |
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
|
1403 |
int column = columnModel.getColumn(viewColumn).getModelIndex();
|
1404 |
if (column != -1) {
|
1405 |
}*/
|
1406 |
} |
1407 |
} |
1408 |
/**
|
1409 |
* DOCUMENT ME!
|
1410 |
*
|
1411 |
* @author Vicente Caballero Navarro
|
1412 |
*/
|
1413 |
private class TableKeyListener implements KeyListener { |
1414 |
|
1415 |
public void keyPressed(KeyEvent arg0) { |
1416 |
//JTextField tf=(JTextField)table.getEditorComponent();
|
1417 |
//table.setCellSelectionEnabled(true);
|
1418 |
//FocusManager fm = FocusManager.getCurrentManager();
|
1419 |
//fm.focusPreviousComponent(table);
|
1420 |
} |
1421 |
|
1422 |
public void keyReleased(KeyEvent ke) { |
1423 |
int[] row=table.getSelectedRows(); |
1424 |
int[] column=table.getSelectedColumns(); |
1425 |
initEditField(column,row); |
1426 |
} |
1427 |
|
1428 |
public void keyTyped(KeyEvent arg0) { |
1429 |
// TODO Auto-generated method stub
|
1430 |
|
1431 |
} |
1432 |
|
1433 |
} |
1434 |
|
1435 |
/**
|
1436 |
* DOCUMENT ME!
|
1437 |
*
|
1438 |
* @author Vicente Caballero Navarro
|
1439 |
*/
|
1440 |
private class MouseRow extends MouseAdapter { |
1441 |
public void mouseReleased(MouseEvent arg0) { |
1442 |
super.mouseReleased(arg0);
|
1443 |
int[] row=table.getSelectedRows(); |
1444 |
int[] column=table.getSelectedColumns(); |
1445 |
initEditField(column,row); |
1446 |
} |
1447 |
|
1448 |
/**
|
1449 |
* DOCUMENT ME!
|
1450 |
*
|
1451 |
* @param e DOCUMENT ME!
|
1452 |
*/
|
1453 |
/* public void mouseClicked(MouseEvent e) {
|
1454 |
super.mouseClicked(e);
|
1455 |
|
1456 |
|
1457 |
PluginServices.getMainFrame().enableControls();
|
1458 |
|
1459 |
if (e.getButton() == MouseEvent.BUTTON3) {
|
1460 |
new PopupMenu(e.getPoint());
|
1461 |
}
|
1462 |
}
|
1463 |
*/
|
1464 |
} |
1465 |
|
1466 |
public void commandRepaint() { |
1467 |
refresh(); |
1468 |
} |
1469 |
|
1470 |
public void commandRefresh() { |
1471 |
commandRepaint(); |
1472 |
} |
1473 |
|
1474 |
public void toPalette() { |
1475 |
isPalette=true;
|
1476 |
m_viewInfo.toPalette(true);
|
1477 |
m_viewInfo.setClosed(false);
|
1478 |
PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
|
1479 |
} |
1480 |
|
1481 |
public void restore() { |
1482 |
isPalette=false;
|
1483 |
m_viewInfo.toPalette(false);
|
1484 |
m_viewInfo.setClosed(false);
|
1485 |
PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
|
1486 |
} |
1487 |
|
1488 |
public boolean isPalette() { |
1489 |
return isPalette;
|
1490 |
} |
1491 |
|
1492 |
public static void main(String[] args) { |
1493 |
JTextField tf=new JTextField("hola"); |
1494 |
tf.selectAll(); |
1495 |
JFrame frame=new JFrame(); |
1496 |
frame.getContentPane().add(tf); |
1497 |
frame.setVisible(true);
|
1498 |
} |
1499 |
|
1500 |
public void stopEditingCell() { |
1501 |
if (table.isEditing()) {
|
1502 |
// TODO: finalizar la edicion de la columna
|
1503 |
this.table.getCellEditor().stopCellEditing();
|
1504 |
this.refresh();
|
1505 |
} |
1506 |
|
1507 |
} |
1508 |
|
1509 |
public void cancelEditingCell() { |
1510 |
if (table.isEditing()) {
|
1511 |
// TODO: finalizar la edicion de la columna
|
1512 |
this.table.getCellEditor().cancelCellEditing();
|
1513 |
this.refresh();
|
1514 |
} |
1515 |
|
1516 |
} |
1517 |
|
1518 |
public void processEvent(EditionEvent e) { |
1519 |
if (e.getChangeType() == EditionEvent.STOP_EDITION)
|
1520 |
{ |
1521 |
refreshControls(); |
1522 |
} |
1523 |
|
1524 |
} |
1525 |
|
1526 |
public void beforeRowEditEvent(IRow feat, BeforeRowEditEvent e) { |
1527 |
// TODO Auto-generated method stub
|
1528 |
|
1529 |
} |
1530 |
|
1531 |
public void afterRowEditEvent(IRow feat, AfterRowEditEvent e) { |
1532 |
// TODO Auto-generated method stub
|
1533 |
|
1534 |
} |
1535 |
|
1536 |
public void beforeFieldEditEvent(BeforeFieldEditEvent e) { |
1537 |
// TODO Auto-generated method stub
|
1538 |
|
1539 |
} |
1540 |
|
1541 |
public void afterFieldEditEvent(AfterFieldEditEvent e) { |
1542 |
try {
|
1543 |
// getModel().createAlias();
|
1544 |
clearSelectedFields(); |
1545 |
// refresh();
|
1546 |
refreshControls(); |
1547 |
// ((DataSourceDataModel) getTable().getModel()).fireTableDataChanged();
|
1548 |
} catch (DriverLoadException e1) {
|
1549 |
// TODO Auto-generated catch block
|
1550 |
e1.printStackTrace(); |
1551 |
/* } catch (DriverException e1) {
|
1552 |
// TODO Auto-generated catch block
|
1553 |
e1.printStackTrace(); */
|
1554 |
} |
1555 |
|
1556 |
} |
1557 |
} |