root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableEditStartExtension.java @ 9212
History | View | Annotate | Download (4.97 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; |
42 |
|
43 |
import java.awt.Component; |
44 |
|
45 |
import javax.swing.JOptionPane; |
46 |
|
47 |
import com.hardcode.driverManager.Driver; |
48 |
import com.iver.andami.PluginServices; |
49 |
import com.iver.andami.plugins.Extension; |
50 |
import com.iver.andami.ui.mdiManager.IWindow; |
51 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
52 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
53 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
54 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
55 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
56 |
|
57 |
|
58 |
/**
|
59 |
* DOCUMENT ME!
|
60 |
*
|
61 |
* @author Vicente Caballero Navarro
|
62 |
*/
|
63 |
public class TableEditStartExtension extends Extension { |
64 |
/**
|
65 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
66 |
*/
|
67 |
public void initialize() { |
68 |
} |
69 |
|
70 |
/**
|
71 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
72 |
*/
|
73 |
public void execute(String actionCommand) { |
74 |
if ("STARTEDIT".equals(actionCommand)) { |
75 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
76 |
|
77 |
try {
|
78 |
Table table = (Table) v; |
79 |
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 |
(Component) PluginServices.getMDIManager().getActiveWindow(),
|
87 |
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 |
(Component) PluginServices.getMDIManager().getActiveWindow(),
|
97 |
PluginServices.getText(this, "this_table_is_not_self_editable"), |
98 |
PluginServices.getText(this, "warning"), |
99 |
JOptionPane.WARNING_MESSAGE);
|
100 |
return;
|
101 |
} |
102 |
|
103 |
table.startEditing(); |
104 |
/* IEditableSource edTable = (IEditableSource) table.getModel().getAssociatedTable();
|
105 |
edTable.getCommandRecord().addCommandListener(table); */
|
106 |
|
107 |
} catch (EditionException e) {
|
108 |
// TODO Auto-generated catch block
|
109 |
e.printStackTrace(); |
110 |
} |
111 |
|
112 |
} |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
117 |
*/
|
118 |
public boolean isEnabled() { |
119 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
120 |
|
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 |
// 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 |
if (ies.getOriginalDriver() instanceof IWriteable) |
139 |
{ |
140 |
return true; |
141 |
} |
142 |
} |
143 |
return false; |
144 |
} |
145 |
|
146 |
/**
|
147 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
148 |
*/
|
149 |
public boolean isVisible() { |
150 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
151 |
|
152 |
if (v == null) { |
153 |
return false; |
154 |
} |
155 |
|
156 |
if (v instanceof Table && !((Table) v).isEditing() && ((Table)v).getModel().getAssociatedTable()==null) { |
157 |
return true; |
158 |
} |
159 |
|
160 |
return false; |
161 |
} |
162 |
} |