root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Table.java @ 2970
History | View | Annotate | Download (17.9 KB)
1 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig.gui; |
42 | |||
43 | 2913 | caballero | import java.awt.event.MouseAdapter; |
44 | import java.awt.event.MouseEvent; |
||
45 | 1047 | fernando | import java.beans.PropertyChangeEvent; |
46 | import java.beans.PropertyChangeListener; |
||
47 | 2266 | fernando | import java.io.IOException; |
48 | 2913 | caballero | import java.sql.Date; |
49 | import java.sql.Time; |
||
50 | import java.sql.Timestamp; |
||
51 | 312 | fernando | import java.text.DateFormat; |
52 | import java.text.NumberFormat; |
||
53 | 2481 | fernando | import java.text.ParseException; |
54 | 2913 | caballero | import java.util.ArrayList; |
55 | 457 | fernando | import java.util.BitSet; |
56 | |||
57 | import javax.swing.DefaultListSelectionModel; |
||
58 | 312 | fernando | import javax.swing.JLabel; |
59 | import javax.swing.JPanel; |
||
60 | 457 | fernando | import javax.swing.event.ListSelectionEvent; |
61 | import javax.swing.event.ListSelectionListener; |
||
62 | 312 | fernando | import javax.swing.table.AbstractTableModel; |
63 | 2913 | caballero | import javax.swing.table.DefaultTableModel; |
64 | import javax.swing.table.JTableHeader; |
||
65 | import javax.swing.table.TableColumnModel; |
||
66 | 312 | fernando | |
67 | 464 | fernando | import org.apache.log4j.Logger; |
68 | 312 | fernando | |
69 | 2913 | caballero | import com.hardcode.gdbms.engine.data.DataSource; |
70 | 2481 | fernando | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
71 | 1830 | fernando | import com.hardcode.gdbms.engine.data.driver.DriverException; |
72 | 2481 | fernando | import com.hardcode.gdbms.engine.data.edition.DataWare; |
73 | 2913 | caballero | import com.hardcode.gdbms.engine.values.LongValue; |
74 | 2481 | fernando | import com.hardcode.gdbms.engine.values.Value; |
75 | 2913 | caballero | import com.hardcode.gdbms.engine.values.ValueCollection; |
76 | 464 | fernando | import com.hardcode.gdbms.engine.values.ValueFactory; |
77 | 596 | fernando | import com.iver.andami.PluginServices; |
78 | 732 | fernando | import com.iver.andami.messages.NotificationManager; |
79 | 2710 | fjp | import com.iver.andami.ui.mdiFrame.MainFrame; |
80 | 596 | fernando | import com.iver.andami.ui.mdiManager.SingletonView; |
81 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
82 | 464 | fernando | import com.iver.cit.gvsig.fmap.FMap; |
83 | 694 | fernando | import com.iver.cit.gvsig.fmap.layers.FLayer; |
84 | 464 | fernando | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
85 | import com.iver.cit.gvsig.fmap.layers.SelectionEvent; |
||
86 | import com.iver.cit.gvsig.fmap.layers.SelectionListener; |
||
87 | 2936 | caballero | import com.iver.cit.gvsig.gui.layout.Popupmenu; |
88 | import com.iver.cit.gvsig.gui.tables.PopupMenu; |
||
89 | 1221 | fernando | import com.iver.cit.gvsig.project.ProjectTable; |
90 | 2241 | fernando | import com.iver.utiles.swing.jtable.FieldSelectionEvent; |
91 | import com.iver.utiles.swing.jtable.FieldSelectionListener; |
||
92 | 2481 | fernando | import com.iver.utiles.swing.jtable.JTable; |
93 | 2241 | fernando | import com.iver.utiles.swing.jtable.SelectionHeaderSupport; |
94 | 2481 | fernando | import com.iver.utiles.swing.jtable.TextFieldCellEditor; |
95 | 464 | fernando | |
96 | |||
97 | 428 | fernando | /**
|
98 | * DOCUMENT ME!
|
||
99 | *
|
||
100 | * @author Fernando Gonz?lez Cort?s
|
||
101 | */
|
||
102 | 1830 | fernando | public class Table extends JPanel implements SingletonView { |
103 | 428 | fernando | private static Logger logger = Logger.getLogger(Table.class.getName()); |
104 | private javax.swing.JScrollPane jScrollPane = null; |
||
105 | 2481 | fernando | private JTable table = null; |
106 | 457 | fernando | private ProjectTable model = null; |
107 | 428 | fernando | private DateFormat df = DateFormat.getDateInstance(); |
108 | private NumberFormat nf = NumberFormat.getInstance(); |
||
109 | private JLabel jLabelStatus = null; |
||
110 | private ViewInfo m_viewInfo = null; |
||
111 | 457 | fernando | private FMap fmap;
|
112 | |||
113 | private boolean updating = false; |
||
114 | |||
115 | private TableSelectionListener selectionListener = new TableSelectionListener(); |
||
116 | 2202 | vcaballero | private long numReg=0; |
117 | 2266 | fernando | private SelectionHeaderSupport headerSelectionSupport = new SelectionHeaderSupport(); |
118 | 2241 | fernando | |
119 | 2266 | fernando | private long[] orderIndexes = null; |
120 | private long[] orderIndexesInverted = null; |
||
121 | |||
122 | 2481 | fernando | private DataWare dw;
|
123 | 2913 | caballero | private ArrayList rowsCopied=new ArrayList(); |
124 | 2481 | fernando | |
125 | 428 | fernando | /**
|
126 | * This is the default constructor
|
||
127 | */
|
||
128 | public Table() {
|
||
129 | super();
|
||
130 | initialize(); |
||
131 | } |
||
132 | 312 | fernando | |
133 | 428 | fernando | /**
|
134 | * DOCUMENT ME!
|
||
135 | *
|
||
136 | * @return DOCUMENT ME!
|
||
137 | */
|
||
138 | 457 | fernando | public ProjectTable getModel() {
|
139 | return model;
|
||
140 | 428 | fernando | } |
141 | 2241 | fernando | |
142 | public BitSet getSelectedFieldIndices(){ |
||
143 | 2266 | fernando | return headerSelectionSupport.getSelectedColumns();
|
144 | 2241 | fernando | } |
145 | 2913 | caballero | public int[] getSelectedRowIndices(){ |
146 | return getTable().getSelectedRows();
|
||
147 | } |
||
148 | 1830 | fernando | private void refreshControls(){ |
149 | try{
|
||
150 | 2710 | fjp | MainFrame mF = PluginServices.getMainFrame(); |
151 | if (mF != null) |
||
152 | PluginServices.getMDIManager().getViewInfo(Table.this).setTitle(PluginServices.getText(this, "Tabla")+": " + model.getName()); |
||
153 | |||
154 | 1830 | fernando | if (model.getAssociatedTable() != null){ |
155 | this.fmap = ((FLayer)model.getAssociatedTable()).getFMap();
|
||
156 | }else{
|
||
157 | this.fmap = null; |
||
158 | } |
||
159 | |||
160 | SelectableDataSource dataSource = model.getModelo(); |
||
161 | logger.debug("dataSource.start()");
|
||
162 | dataSource.start(); |
||
163 | |||
164 | 2565 | fernando | AbstractTableModel dataModel = new DataSourceDataModel(model); |
165 | 1830 | fernando | |
166 | 2241 | fernando | getTable().setModel(dataModel); |
167 | |||
168 | 2266 | fernando | headerSelectionSupport.setTableHeader(getTable().getTableHeader()); |
169 | headerSelectionSupport.addFieldSelectionListener(new FieldSelectionListener() {
|
||
170 | 2241 | fernando | public void fieldSelected(FieldSelectionEvent e) { |
171 | 2710 | fjp | if (PluginServices.getMainFrame() != null) |
172 | PluginServices.getMainFrame().enableControls(); |
||
173 | 2241 | fernando | } |
174 | }); |
||
175 | 1830 | fernando | |
176 | model.getModelo().addSelectionListener(selectionListener); |
||
177 | |||
178 | updateSelection(); |
||
179 | }catch (DriverException e){
|
||
180 | NotificationManager.addError("No se pudo leer la informaci?n", e);
|
||
181 | } |
||
182 | |||
183 | } |
||
184 | |||
185 | 428 | fernando | /**
|
186 | * DOCUMENT ME!
|
||
187 | *
|
||
188 | 457 | fernando | * @param table DOCUMENT ME!
|
189 | 428 | fernando | */
|
190 | 694 | fernando | public void setModel(ProjectTable table) { |
191 | 1830 | fernando | SelectableDataSource dataSource; |
192 | model = table; |
||
193 | 457 | fernando | |
194 | 1830 | fernando | //Gesti?n del nombre de la ventana
|
195 | model.addPropertyChangeListener(new PropertyChangeListener() { |
||
196 | public void propertyChange(PropertyChangeEvent evt) { |
||
197 | if (evt.getPropertyName().equals("name")){ |
||
198 | PluginServices.getMDIManager().getViewInfo(Table.this).setTitle(PluginServices.getText(this, "Tabla")+": " + (String)evt.getNewValue()); |
||
199 | }else if (evt.getPropertyName().equals("model")){ |
||
200 | refreshControls(); |
||
201 | } |
||
202 | } |
||
203 | }); |
||
204 | |||
205 | refreshControls(); |
||
206 | 428 | fernando | } |
207 | |||
208 | /**
|
||
209 | 457 | fernando | *
|
210 | */
|
||
211 | private void updateSelection() { |
||
212 | updating = true;
|
||
213 | |||
214 | DefaultListSelectionModel sm = (DefaultListSelectionModel) getTable() |
||
215 | 2266 | fernando | .getSelectionModel(); |
216 | 457 | fernando | sm.clearSelection(); |
217 | 464 | fernando | BitSet bs = model.getModelo().getSelection();
|
218 | 457 | fernando | sm.setValueIsAdjusting(true);
|
219 | |||
220 | 2481 | fernando | if (orderIndexes != null){ |
221 | for (int i = 0; i < orderIndexes.length; i++) { |
||
222 | if (bs.get(i)){
|
||
223 | sm.addSelectionInterval((int) orderIndexesInverted[i], (int) orderIndexesInverted[i]); |
||
224 | } |
||
225 | } |
||
226 | }else{
|
||
227 | for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { |
||
228 | 2266 | fernando | sm.addSelectionInterval(i, i); |
229 | } |
||
230 | 457 | fernando | } |
231 | |||
232 | sm.setValueIsAdjusting(false);
|
||
233 | |||
234 | 2530 | ldiaz | try {
|
235 | numReg=model.getModelo().getRowCount(); |
||
236 | } catch (DriverException e) {
|
||
237 | NotificationManager.addError("", e);
|
||
238 | } |
||
239 | jLabelStatus.setText(" " + model.getModelo().getSelection().cardinality() + " / " + numReg +" "+ |
||
240 | PluginServices.getText(this, "registros_seleccionados_total") + "."); |
||
241 | |||
242 | 457 | fernando | updating = false;
|
243 | } |
||
244 | |||
245 | /**
|
||
246 | 428 | fernando | * This method initializes this
|
247 | */
|
||
248 | private void initialize() { |
||
249 | jLabelStatus = new JLabel(); |
||
250 | setLayout(new java.awt.BorderLayout());
|
||
251 | jLabelStatus.setText("");
|
||
252 | jLabelStatus.setName("");
|
||
253 | jLabelStatus.setPreferredSize(new java.awt.Dimension(100, 18)); |
||
254 | add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
||
255 | this.add(jLabelStatus, java.awt.BorderLayout.SOUTH);
|
||
256 | } |
||
257 | |||
258 | /**
|
||
259 | * This method initializes table
|
||
260 | *
|
||
261 | * @return javax.swing.JTable
|
||
262 | */
|
||
263 | private javax.swing.JTable getTable() {
|
||
264 | if (table == null) { |
||
265 | 2481 | fernando | table = new JTable(); |
266 | 428 | fernando | table.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); |
267 | 457 | fernando | table.setSelectionModel(new DefaultListSelectionModel()); |
268 | 2913 | caballero | table.getTableHeader().addMouseListener(new MouseHandler());
|
269 | 2936 | caballero | table.addMouseListener(new MouseRow());
|
270 | 457 | fernando | table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
271 | public void valueChanged(ListSelectionEvent e) { |
||
272 | if (updating) return; |
||
273 | 2266 | fernando | |
274 | 464 | fernando | SelectableDataSource dataModel = Table.this.model.getModelo(); |
275 | |||
276 | DefaultListSelectionModel model = (DefaultListSelectionModel) table.getSelectionModel(); |
||
277 | BitSet selection = dataModel.getSelection();
|
||
278 | 428 | fernando | |
279 | 464 | fernando | for (int i = e.getFirstIndex(); |
280 | i <= e.getLastIndex(); i++) { |
||
281 | 2266 | fernando | if (orderIndexes != null){ |
282 | selection.set((int) orderIndexes[i], model.isSelectedIndex(i));
|
||
283 | }else{
|
||
284 | selection.set(i, model.isSelectedIndex(i)); |
||
285 | } |
||
286 | 457 | fernando | } |
287 | |||
288 | if (e.getValueIsAdjusting() == false) { |
||
289 | if (fmap != null){ |
||
290 | 681 | fernando | fmap.endAtomicEvent(); |
291 | 457 | fernando | } |
292 | 464 | fernando | dataModel.fireSelectionEvents(); |
293 | 681 | fernando | }else{
|
294 | 694 | fernando | if (fmap != null) |
295 | 681 | fernando | fmap.beginAtomicEvent(); |
296 | 457 | fernando | } |
297 | 2202 | vcaballero | jLabelStatus.setText(" " + selection.cardinality() + " / " + numReg + " " + |
298 | PluginServices.getText(this, "registros_seleccionados_total") + "."); |
||
299 | 428 | fernando | } |
300 | }); |
||
301 | 2481 | fernando | TextFieldCellEditor ce = new TextFieldCellEditor();
|
302 | for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { |
||
303 | table.getColumnModel().getColumn(i).setCellEditor(ce); |
||
304 | } |
||
305 | 428 | fernando | } |
306 | |||
307 | return table;
|
||
308 | } |
||
309 | |||
310 | /**
|
||
311 | * This method initializes jScrollPane
|
||
312 | *
|
||
313 | * @return javax.swing.JScrollPane
|
||
314 | */
|
||
315 | private javax.swing.JScrollPane getJScrollPane() {
|
||
316 | if (jScrollPane == null) { |
||
317 | jScrollPane = new javax.swing.JScrollPane();
|
||
318 | jScrollPane.setViewportView(getTable()); |
||
319 | } |
||
320 | |||
321 | return jScrollPane;
|
||
322 | } |
||
323 | |||
324 | /**
|
||
325 | * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
|
||
326 | */
|
||
327 | public Object getViewModel() { |
||
328 | 457 | fernando | return model;
|
329 | 428 | fernando | } |
330 | |||
331 | /**
|
||
332 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
333 | */
|
||
334 | public ViewInfo getViewInfo() {
|
||
335 | 596 | fernando | ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.MAXIMIZABLE |
|
336 | 428 | fernando | ViewInfo.RESIZABLE); |
337 | 596 | fernando | m_viewInfo.setTitle(PluginServices.getText(this, "Tabla")); |
338 | 428 | fernando | m_viewInfo.setWidth(300);
|
339 | m_viewInfo.setHeight(200);
|
||
340 | |||
341 | return m_viewInfo;
|
||
342 | } |
||
343 | |||
344 | /**
|
||
345 | 457 | fernando | * DOCUMENT ME!
|
346 | *
|
||
347 | * @author Fernando Gonz?lez Cort?s
|
||
348 | */
|
||
349 | public class DataSourceDataModel extends AbstractTableModel { |
||
350 | 464 | fernando | private SelectableDataSource dataSource;
|
351 | 2565 | fernando | private ProjectTable pt;
|
352 | private String[] aliases; |
||
353 | private int[] mapping; |
||
354 | 457 | fernando | |
355 | /**
|
||
356 | * Crea un nuevo DataSourceDataModel.
|
||
357 | *
|
||
358 | * @param ds DOCUMENT ME!
|
||
359 | */
|
||
360 | 2565 | fernando | public DataSourceDataModel(ProjectTable pt) {
|
361 | this.pt = pt;
|
||
362 | dataSource = pt.getModelo(); |
||
363 | aliases = pt.getAliases(); |
||
364 | mapping = pt.getMapping(); |
||
365 | 457 | fernando | } |
366 | |||
367 | /**
|
||
368 | 2936 | caballero | * Returns the name of the field.
|
369 | 457 | fernando | *
|
370 | 2936 | caballero | * @param col index of field
|
371 | 457 | fernando | *
|
372 | 2936 | caballero | * @return Name of field
|
373 | 457 | fernando | */
|
374 | public String getColumnName(int col) { |
||
375 | 2565 | fernando | return aliases[mapping[col]];
|
376 | 457 | fernando | } |
377 | |||
378 | /**
|
||
379 | 2936 | caballero | * Returns the number of fields.
|
380 | 457 | fernando | *
|
381 | 2936 | caballero | * @return number of fields
|
382 | 457 | fernando | */
|
383 | public int getColumnCount() { |
||
384 | 2565 | fernando | return mapping.length;
|
385 | 457 | fernando | } |
386 | |||
387 | /**
|
||
388 | 2936 | caballero | * Returns number of rows.
|
389 | 457 | fernando | *
|
390 | 2936 | caballero | * @return number of rows.
|
391 | 457 | fernando | */
|
392 | public int getRowCount() { |
||
393 | try {
|
||
394 | return (int) dataSource.getRowCount(); |
||
395 | } catch (DriverException e) {
|
||
396 | return 0; |
||
397 | } |
||
398 | } |
||
399 | |||
400 | /**
|
||
401 | * DOCUMENT ME!
|
||
402 | *
|
||
403 | * @param row DOCUMENT ME!
|
||
404 | * @param col DOCUMENT ME!
|
||
405 | *
|
||
406 | * @return DOCUMENT ME!
|
||
407 | */
|
||
408 | public Object getValueAt(int row, int col) { |
||
409 | try {
|
||
410 | 2481 | fernando | if (dw != null){ |
411 | 2565 | fernando | return dw.getFieldValue(row, mapping[col]);
|
412 | 2266 | fernando | }else{
|
413 | 2481 | fernando | if (orderIndexes != null){ |
414 | 2565 | fernando | return dataSource.getFieldValue(orderIndexes[row], mapping[col]);
|
415 | 2481 | fernando | }else{
|
416 | 2565 | fernando | return dataSource.getFieldValue(row, mapping[col]);
|
417 | 2481 | fernando | } |
418 | 2266 | fernando | } |
419 | 457 | fernando | } catch (DriverException e) {
|
420 | return ValueFactory.createValue("").toString(); |
||
421 | } |
||
422 | } |
||
423 | 2481 | fernando | public boolean isCellEditable(int rowIndex, int columnIndex) { |
424 | return (dw != null); |
||
425 | } |
||
426 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
||
427 | Value v; |
||
428 | try {
|
||
429 | v = ValueFactory.createValueByType(aValue.toString(), dataSource.getFieldType(columnIndex)); |
||
430 | 2565 | fernando | dw.setFieldValue(rowIndex, mapping[columnIndex], v); |
431 | 2481 | fernando | } catch (DriverException e1) {
|
432 | throw new RuntimeException(e1); |
||
433 | } catch (ParseException e) { |
||
434 | throw new RuntimeException(e); |
||
435 | } |
||
436 | } |
||
437 | 457 | fernando | } |
438 | |||
439 | 464 | fernando | public class TableSelectionListener implements SelectionListener{ |
440 | 457 | fernando | |
441 | /**
|
||
442 | 564 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LegendListener#selectionChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
443 | 457 | fernando | */
|
444 | 464 | fernando | public void selectionChanged(SelectionEvent e) { |
445 | 457 | fernando | updateSelection(); |
446 | Table.this.repaint(); |
||
447 | } |
||
448 | |||
449 | } |
||
450 | 2241 | fernando | |
451 | /**
|
||
452 | * @param ds
|
||
453 | 2266 | fernando | * @throws IOException
|
454 | 2241 | fernando | */
|
455 | 2266 | fernando | public void setOrder(long[] indexes) throws IOException { |
456 | orderIndexes = indexes; |
||
457 | orderIndexesInverted = new long[orderIndexes.length]; |
||
458 | for (int i = 0; i < indexes.length; i++) { |
||
459 | orderIndexesInverted[(int) indexes[i]] = i;
|
||
460 | } |
||
461 | 2481 | fernando | |
462 | updating=true;
|
||
463 | 2266 | fernando | ((DataSourceDataModel)getTable().getModel()).fireTableDataChanged(); |
464 | 2481 | fernando | updating=false;
|
465 | updateSelection(); |
||
466 | |||
467 | 2241 | fernando | } |
468 | 2913 | caballero | |
469 | 2481 | fernando | public void startEditing() throws DriverException{ |
470 | dw = model.getModelo().getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER); |
||
471 | dw.beginTrans(); |
||
472 | } |
||
473 | |||
474 | /**
|
||
475 | * @throws DriverException
|
||
476 | *
|
||
477 | */
|
||
478 | public void cancelEditing() throws DriverException { |
||
479 | dw.rollBackTrans(); |
||
480 | dw = null;
|
||
481 | } |
||
482 | |||
483 | /**
|
||
484 | * @throws DriverException
|
||
485 | *
|
||
486 | */
|
||
487 | public void stopEditing() throws DriverException { |
||
488 | dw.commitTrans(); |
||
489 | dw = null;
|
||
490 | model.getModelo().stop(); |
||
491 | model.getModelo().start(); |
||
492 | } |
||
493 | |||
494 | /**
|
||
495 | * @return
|
||
496 | */
|
||
497 | public boolean isEditing() { |
||
498 | return dw != null; |
||
499 | } |
||
500 | 2701 | fjp | |
501 | /**
|
||
502 | * Quita los campos seleccionados
|
||
503 | */
|
||
504 | public void clearSelectedFields() |
||
505 | { |
||
506 | headerSelectionSupport.clearSelectedColumns(); |
||
507 | } |
||
508 | 2913 | caballero | private class MouseHandler extends MouseAdapter { |
509 | public void mouseClicked(MouseEvent e) { |
||
510 | 2936 | caballero | /* JTableHeader h = (JTableHeader) e.getSource();
|
511 | 2913 | caballero | TableColumnModel columnModel = h.getColumnModel();
|
512 | int viewColumn = columnModel.getColumnIndexAtX(e.getX());
|
||
513 | int column = columnModel.getColumn(viewColumn).getModelIndex();
|
||
514 | if (column != -1) {
|
||
515 | 2936 | caballero | |
516 | }*/
|
||
517 | 2913 | caballero | } |
518 | } |
||
519 | 2936 | caballero | private class MouseRow extends MouseAdapter { |
520 | public void mouseClicked(MouseEvent e) { |
||
521 | PluginServices.getMainFrame().enableControls(); |
||
522 | if (e.getButton()==MouseEvent.BUTTON3){ |
||
523 | new PopupMenu(e.getPoint()); |
||
524 | } |
||
525 | } |
||
526 | |||
527 | } |
||
528 | 2913 | caballero | public Value[] getValueRow(int index){ |
529 | DataSourceDataModel dsdm=(DataSourceDataModel)getTable().getModel(); |
||
530 | Value [] values=new Value[dsdm.getColumnCount()]; |
||
531 | for (int i=0;i<dsdm.getColumnCount();i++){ |
||
532 | values[i]=(Value)dsdm.getValueAt(index,i); |
||
533 | } |
||
534 | return values;
|
||
535 | } |
||
536 | 2936 | caballero | private void refresh() throws DriverException{ |
537 | dw.commitTrans(); |
||
538 | model.getModelo().stop(); |
||
539 | dw.beginTrans(); |
||
540 | DataSourceDataModel dsdm=(DataSourceDataModel)getTable().getModel(); |
||
541 | dsdm.fireTableDataChanged(); |
||
542 | } |
||
543 | 2913 | caballero | public void addEmptyRow() throws DriverException{ |
544 | ValueCollection valuePK=new ValueCollection();
|
||
545 | valuePK.setValues(new Value[]{ValueFactory.createValue(dw.getRowCount())}); |
||
546 | dw.insertEmptyRow(valuePK); |
||
547 | 2936 | caballero | refresh(); |
548 | 2913 | caballero | } |
549 | |||
550 | 2936 | caballero | public void copySelectedRows() throws DriverException{ |
551 | 2913 | caballero | int[] sel=getSelectedRowIndices(); |
552 | for(int i=0;i<sel.length;i++){ |
||
553 | rowsCopied.add(getValueRow(sel[i])); |
||
554 | } |
||
555 | } |
||
556 | |||
557 | 2936 | caballero | public void addSelectionToEnd() throws DriverException { |
558 | 2913 | caballero | for (int i=0;i<rowsCopied.size();i++){ |
559 | dw.insertFilledRow((Value[])rowsCopied.get(i));
|
||
560 | } |
||
561 | 2936 | caballero | refresh(); |
562 | 2913 | caballero | } |
563 | 2936 | caballero | public void delSelectionRow() throws DriverException{ |
564 | int[] sel=getSelectedRowIndices(); |
||
565 | for(int i=sel.length-1;i>=0;i--){ |
||
566 | dw.deleteRow(sel[i]); |
||
567 | } |
||
568 | refresh(); |
||
569 | |||
570 | } |
||
571 | public boolean isCopy(){ |
||
572 | return !rowsCopied.isEmpty();
|
||
573 | } |
||
574 | /*
|
||
575 | public void addSelectionToRow() throws DriverException {
|
||
576 | int[] sel=getSelectedRowIndices();
|
||
577 | dw.insertFilledRow((Value[])rowsCopied.get(i),sel[0]);
|
||
578 | refresh();
|
||
579 | }
|
||
580 | */
|
||
581 | 2913 | caballero | |
582 | 312 | fernando | } |