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