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