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