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