Revision 23383 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/gui/panels/TextFieldEdit.java
TextFieldEdit.java | ||
---|---|---|
12 | 12 |
import javax.swing.JPopupMenu; |
13 | 13 |
import javax.swing.JTextField; |
14 | 14 |
|
15 |
import org.gvsig.fmap.core.features.DefaultFeature; |
|
16 |
import org.gvsig.fmap.core.features.DefaultRow; |
|
17 |
import org.gvsig.fmap.core.features.IFeature; |
|
18 |
import org.gvsig.fmap.core.features.IRow; |
|
19 |
import org.gvsig.fmap.core.features.IRowEdited; |
|
20 |
import org.gvsig.fmap.core.geometries.IGeometry; |
|
21 |
import org.gvsig.fmap.drivers.exceptions.ValidateRowException; |
|
22 |
import org.gvsig.fmap.drivers.writing.EditionEvent; |
|
23 |
import org.gvsig.fmap.drivers.writing.adapters.VectorialEditableAdapter; |
|
24 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrAnnotation; |
|
25 |
|
|
26 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
27 |
import com.hardcode.gdbms.engine.values.Value; |
|
28 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
15 |
//import org.gvsig.fmap.core.features.DefaultFeature;
|
|
16 |
//import org.gvsig.fmap.core.features.DefaultRow;
|
|
17 |
//import org.gvsig.fmap.core.features.IFeature;
|
|
18 |
//import org.gvsig.fmap.core.features.IRow;
|
|
19 |
//import org.gvsig.fmap.core.features.IRowEdited;
|
|
20 |
//import org.gvsig.fmap.core.geometries.IGeometry;
|
|
21 |
//import org.gvsig.fmap.drivers.exceptions.ValidateRowException;
|
|
22 |
//import org.gvsig.fmap.drivers.writing.EditionEvent;
|
|
23 |
//import org.gvsig.fmap.drivers.writing.adapters.VectorialEditableAdapter;
|
|
24 |
//import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrAnnotation;
|
|
25 |
// |
|
26 |
//import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
|
|
27 |
//import com.hardcode.gdbms.engine.values.Value;
|
|
28 |
//import com.hardcode.gdbms.engine.values.ValueFactory;
|
|
29 | 29 |
import com.iver.andami.PluginServices; |
30 | 30 |
import com.iver.andami.messages.NotificationManager; |
31 | 31 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
... | ... | |
36 | 36 |
* |
37 | 37 |
* @author Vicente Caballero Navarro |
38 | 38 |
*/ |
39 |
//TODO comentado para que compile |
|
39 | 40 |
public class TextFieldEdit extends JPopupMenu implements KeyListener { |
40 | 41 |
private JTextField txt = new JTextField(); |
41 |
private FLyrAnnotation lyr; |
|
42 |
// private FLyrAnnotation lyr;
|
|
42 | 43 |
/** |
43 | 44 |
* This is the default constructor |
44 | 45 |
*/ |
45 |
public TextFieldEdit(FLyrAnnotation lyr) { |
|
46 |
super(); |
|
47 |
this.lyr=lyr; |
|
48 |
initialize(); |
|
49 |
} |
|
46 |
// public TextFieldEdit(FLyrAnnotation lyr) {
|
|
47 |
// super();
|
|
48 |
// this.lyr=lyr;
|
|
49 |
// initialize();
|
|
50 |
// }
|
|
50 | 51 |
|
51 | 52 |
/** |
52 | 53 |
* This method initializes this |
... | ... | |
54 | 55 |
private void initialize() { |
55 | 56 |
this.setSize(100, 20); |
56 | 57 |
txt.setPreferredSize(new Dimension(100, 20)); |
57 |
txt.addActionListener(new java.awt.event.ActionListener() { |
|
58 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
59 |
try { |
|
60 |
VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource(); |
|
61 |
int index=lyr.getInEdition(); |
|
62 |
IRowEdited row = vea.getRow(index); //.getAttribute(columnIndex); |
|
63 |
Value[] values = row.getAttributes(); |
|
64 |
int columnText=lyr.getMapping().getColumnText(); |
|
65 |
int type=vea.getRecordset().getFieldType(columnText); |
|
66 |
values[columnText] = ValueFactory.createValueByType(txt.getText(),type); |
|
67 |
|
|
68 |
IRow newRow = null; |
|
69 |
|
|
70 |
if (row.getLinkedRow() instanceof IFeature) { |
|
71 |
IGeometry geometry = ((DefaultFeature) row.getLinkedRow()).getGeometry(); |
|
72 |
newRow = new DefaultFeature(geometry, values); |
|
73 |
} else { |
|
74 |
newRow = new DefaultRow(values); |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
vea.modifyRow(index, newRow,"Editar valor de texto", EditionEvent.GRAPHIC); |
|
79 |
} catch (ReadDriverException e1) { |
|
80 |
e1.printStackTrace(); |
|
81 |
} catch (ParseException e1) { |
|
82 |
e1.printStackTrace(); |
|
83 |
} catch (NumberFormatException e1) { |
|
84 |
NotificationManager.addError("no_es_de_tipo_numerico",e1); |
|
85 |
} catch (ValidateRowException e1) { |
|
86 |
e1.printStackTrace(); |
|
87 |
} |
|
88 |
View view=(View)PluginServices.getMDIManager().getActiveWindow(); |
|
89 |
TextFieldEdit.this.show(false); |
|
90 |
// view.getMapControl().drawMap(true); |
|
91 |
lyr.setDirty(true); |
|
92 |
view.getMapControl().rePaintDirtyLayers(); |
|
93 |
|
|
94 |
PluginServices.getMainFrame().enableControls(); |
|
95 |
} |
|
96 |
}); |
|
58 |
// txt.addActionListener(new java.awt.event.ActionListener() {
|
|
59 |
// public void actionPerformed(java.awt.event.ActionEvent e) {
|
|
60 |
// try {
|
|
61 |
// VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource();
|
|
62 |
// int index=lyr.getInEdition();
|
|
63 |
// IRowEdited row = vea.getRow(index); //.getAttribute(columnIndex);
|
|
64 |
// Value[] values = row.getAttributes();
|
|
65 |
// int columnText=lyr.getMapping().getColumnText();
|
|
66 |
// int type=vea.getRecordset().getFieldType(columnText);
|
|
67 |
// values[columnText] = ValueFactory.createValueByType(txt.getText(),type);
|
|
68 |
// |
|
69 |
// IRow newRow = null;
|
|
70 |
// |
|
71 |
// if (row.getLinkedRow() instanceof IFeature) {
|
|
72 |
// IGeometry geometry = ((DefaultFeature) row.getLinkedRow()).getGeometry();
|
|
73 |
// newRow = new DefaultFeature(geometry, values);
|
|
74 |
// } else {
|
|
75 |
// newRow = new DefaultRow(values);
|
|
76 |
// }
|
|
77 |
// |
|
78 |
// |
|
79 |
// vea.modifyRow(index, newRow,"Editar valor de texto", EditionEvent.GRAPHIC);
|
|
80 |
// } catch (ReadDriverException e1) {
|
|
81 |
// e1.printStackTrace();
|
|
82 |
// } catch (ParseException e1) {
|
|
83 |
// e1.printStackTrace();
|
|
84 |
// } catch (NumberFormatException e1) {
|
|
85 |
// NotificationManager.addError("no_es_de_tipo_numerico",e1);
|
|
86 |
// } catch (ValidateRowException e1) {
|
|
87 |
// e1.printStackTrace();
|
|
88 |
// }
|
|
89 |
// View view=(View)PluginServices.getMDIManager().getActiveWindow();
|
|
90 |
// TextFieldEdit.this.show(false);
|
|
91 |
// // view.getMapControl().drawMap(true);
|
|
92 |
// lyr.setDirty(true);
|
|
93 |
// view.getMapControl().rePaintDirtyLayers();
|
|
94 |
// |
|
95 |
// PluginServices.getMainFrame().enableControls();
|
|
96 |
// }
|
|
97 |
// });
|
|
97 | 98 |
this.add(txt); |
98 | 99 |
this.setBorderPainted(false); |
99 | 100 |
this.setBorder(BorderFactory.createEmptyBorder()); |
... | ... | |
107 | 108 |
*/ |
108 | 109 |
public void show(Point2D p, JComponent component) { |
109 | 110 |
|
110 |
VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource(); |
|
111 |
int index=lyr.getInEdition(); |
|
112 |
Value value=null; |
|
113 |
try { |
|
114 |
int columnText=lyr.getMapping().getColumnText(); |
|
115 |
value = vea.getRecordset().getFieldValue(index,columnText); |
|
116 |
txt.setText(value.toString()); |
|
117 |
} catch (ReadDriverException e) { |
|
118 |
e.printStackTrace(); |
|
119 |
} |
|
111 |
// VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource();
|
|
112 |
// int index=lyr.getInEdition();
|
|
113 |
// Value value=null;
|
|
114 |
// try {
|
|
115 |
// int columnText=lyr.getMapping().getColumnText();
|
|
116 |
// value = vea.getRecordset().getFieldValue(index,columnText);
|
|
117 |
// txt.setText(value.toString());
|
|
118 |
// } catch (ReadDriverException e) {
|
|
119 |
// e.printStackTrace();
|
|
120 |
// }
|
|
120 | 121 |
|
121 | 122 |
this.show(component, (int)p.getX(), (int)p.getY()-20); |
122 | 123 |
FocusManager fm = FocusManager.getCurrentManager(); |
Also available in: Unified diff