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