svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / TableEditStartExtension.java @ 7365
History | View | Annotate | Download (4.94 KB)
1 | 2936 | 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; |
||
42 | |||
43 | 6856 | fjp | import java.awt.Component; |
44 | |||
45 | import javax.swing.JOptionPane; |
||
46 | |||
47 | import com.hardcode.driverManager.Driver; |
||
48 | 2936 | caballero | import com.iver.andami.PluginServices; |
49 | import com.iver.andami.plugins.Extension; |
||
50 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
51 | 3996 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionException; |
52 | 6609 | fjp | import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
53 | import com.iver.cit.gvsig.fmap.edition.IWriteable; |
||
54 | 6856 | fjp | import com.iver.cit.gvsig.fmap.edition.IWriter; |
55 | 2936 | caballero | import com.iver.cit.gvsig.gui.Table; |
56 | |||
57 | |||
58 | /**
|
||
59 | * DOCUMENT ME!
|
||
60 | *
|
||
61 | * @author Vicente Caballero Navarro
|
||
62 | */
|
||
63 | 5005 | jorpiell | public class TableEditStartExtension extends Extension { |
64 | 2936 | caballero | /**
|
65 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
66 | 2936 | caballero | */
|
67 | 5005 | jorpiell | public void initialize() { |
68 | 2936 | caballero | } |
69 | |||
70 | /**
|
||
71 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
72 | 2936 | caballero | */
|
73 | public void execute(String actionCommand) { |
||
74 | if ("STARTEDIT".equals(actionCommand)) { |
||
75 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
76 | 2936 | caballero | |
77 | 3996 | caballero | try {
|
78 | 4475 | fjp | Table table = (Table) v; |
79 | 6856 | fjp | Driver drv = table.getModel().getModelo().getOriginalDriver();
|
80 | if (drv instanceof IWriteable) |
||
81 | { |
||
82 | IWriter writer = ((IWriteable) drv).getWriter(); |
||
83 | if (!writer.canSaveEdits())
|
||
84 | { |
||
85 | JOptionPane.showMessageDialog(
|
||
86 | 6880 | cesar | (Component) PluginServices.getMDIManager().getActiveWindow(),
|
87 | 6856 | fjp | PluginServices.getText(this, "this_table_is_not_self_editable"), |
88 | PluginServices.getText(this, "warning"), |
||
89 | JOptionPane.WARNING_MESSAGE);
|
||
90 | return;
|
||
91 | } |
||
92 | } |
||
93 | else
|
||
94 | { |
||
95 | JOptionPane.showMessageDialog(
|
||
96 | 6880 | cesar | (Component) PluginServices.getMDIManager().getActiveWindow(),
|
97 | 6856 | fjp | PluginServices.getText(this, "this_table_is_not_self_editable"), |
98 | PluginServices.getText(this, "warning"), |
||
99 | JOptionPane.WARNING_MESSAGE);
|
||
100 | return;
|
||
101 | } |
||
102 | |||
103 | 4475 | fjp | table.startEditing(); |
104 | 4535 | fjp | /* IEditableSource edTable = (IEditableSource) table.getModel().getAssociatedTable();
|
105 | edTable.getCommandRecord().addCommandListener(table); */
|
||
106 | 5081 | caballero | |
107 | 3996 | caballero | } catch (EditionException e) {
|
108 | // TODO Auto-generated catch block
|
||
109 | e.printStackTrace(); |
||
110 | } |
||
111 | |||
112 | 2936 | caballero | } |
113 | } |
||
114 | |||
115 | /**
|
||
116 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
117 | 2936 | caballero | */
|
118 | public boolean isEnabled() { |
||
119 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
120 | 6609 | fjp | |
121 | if (v == null) { |
||
122 | return false; |
||
123 | } |
||
124 | if (v instanceof Table) |
||
125 | { |
||
126 | Table t = (Table) v; |
||
127 | IEditableSource ies = t.getModel().getModelo(); |
||
128 | 6840 | fjp | // FJP:
|
129 | // Si est? linkada, por ahora no dejamos editar
|
||
130 | // TODO: Esto evita la edici?n en un sentido, pero no en el otro
|
||
131 | // Hay que permitir la edici?n, pero evitar que toquen el/los
|
||
132 | // campos de uni?n. Para eso tendremos que a?adir alguna funci?n
|
||
133 | // que indique si un campo est? involucrado en alguna uni?n, o
|
||
134 | // quiz?s algo m?s gen?rico, algo que permita bloquear campos
|
||
135 | // para que no se puedan editar.
|
||
136 | if (t.getModel().getLinkTable() != null) |
||
137 | return false; |
||
138 | 6609 | fjp | if (ies.getOriginalDriver() instanceof IWriteable) |
139 | { |
||
140 | return true; |
||
141 | } |
||
142 | } |
||
143 | return false; |
||
144 | 2936 | caballero | } |
145 | |||
146 | /**
|
||
147 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
148 | 2936 | caballero | */
|
149 | public boolean isVisible() { |
||
150 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
151 | 2936 | caballero | |
152 | if (v == null) { |
||
153 | return false; |
||
154 | } |
||
155 | |||
156 | 5900 | jorpiell | if (v instanceof Table && !((Table) v).isEditing() && ((Table)v).getModel().getAssociatedTable()==null) { |
157 | 6609 | fjp | return true; |
158 | 2936 | caballero | } |
159 | |||
160 | return false; |
||
161 | } |
||
162 | } |