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