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