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