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