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