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