root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableEditStopExtension.java @ 22932
History | View | Annotate | Download (7.14 KB)
1 | 2936 | caballero | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | 13519 | caballero | import java.util.ArrayList; |
4 | |||
5 | 5318 | caballero | import javax.swing.JOptionPane; |
6 | |||
7 | 21911 | jmvivo | import org.gvsig.fmap.data.ReadException; |
8 | import org.gvsig.fmap.data.WriteException; |
||
9 | 22360 | jmvivo | import org.gvsig.fmap.data.feature.FeatureStore; |
10 | 20994 | jmvivo | |
11 | 2936 | caballero | import com.iver.andami.PluginServices; |
12 | 13519 | caballero | import com.iver.andami.messages.NotificationManager; |
13 | 2936 | caballero | import com.iver.andami.plugins.Extension; |
14 | 13519 | caballero | import com.iver.andami.plugins.IExtension; |
15 | import com.iver.andami.plugins.status.IExtensionStatus; |
||
16 | import com.iver.andami.plugins.status.IUnsavedData; |
||
17 | import com.iver.andami.plugins.status.UnsavedData; |
||
18 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
19 | 13519 | caballero | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
20 | import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
||
21 | 20994 | jmvivo | import com.iver.cit.gvsig.project.documents.table.exceptions.CancelEditingTableException; |
22 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
23 | 13519 | caballero | import com.iver.utiles.swing.threads.IMonitorableTask; |
24 | 2936 | caballero | |
25 | |||
26 | /**
|
||
27 | * DOCUMENT ME!
|
||
28 | *
|
||
29 | * @author Vicente Caballero Navarro
|
||
30 | */
|
||
31 | 5005 | jorpiell | public class TableEditStopExtension extends Extension { |
32 | 2936 | caballero | /**
|
33 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
34 | 2936 | caballero | */
|
35 | 5005 | jorpiell | public void initialize() { |
36 | 2936 | caballero | } |
37 | |||
38 | /**
|
||
39 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
40 | 2936 | caballero | */
|
41 | public void execute(String actionCommand) { |
||
42 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
43 | 4475 | fjp | Table table = (Table) v; |
44 | 5318 | caballero | if ("STOPEDITING".equals(actionCommand)) { |
45 | stopEditing(table); |
||
46 | 2936 | caballero | } |
47 | 4535 | fjp | /* IEditableSource edTable = (IEditableSource) table.getModel().getAssociatedTable();
|
48 | edTable.getCommandRecord().removeCommandListener(table); */
|
||
49 | 4475 | fjp | |
50 | 2936 | caballero | } |
51 | |||
52 | /**
|
||
53 | 5318 | caballero | * DOCUMENT ME!
|
54 | */
|
||
55 | public void stopEditing(Table table) { |
||
56 | int resp = JOptionPane |
||
57 | .showConfirmDialog(null, PluginServices.getText(this, |
||
58 | "realmente_desea_guardar") +" : "+ table.getModel().getName(), "Guardar", |
||
59 | JOptionPane.YES_NO_OPTION);
|
||
60 | if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING |
||
61 | try {
|
||
62 | table.cancelEditing(); |
||
63 | 10626 | caballero | } catch (CancelEditingTableException e) {
|
64 | 5318 | caballero | e.printStackTrace(); |
65 | } |
||
66 | } else { // GUARDAMOS LA TABLA |
||
67 | table.stopEditing(); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | |||
72 | /**
|
||
73 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
74 | 2936 | caballero | */
|
75 | public boolean isEnabled() { |
||
76 | 5081 | caballero | return true; |
77 | 2936 | caballero | } |
78 | |||
79 | /**
|
||
80 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
81 | 2936 | caballero | */
|
82 | public boolean isVisible() { |
||
83 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
84 | 2936 | caballero | |
85 | if (v == null) { |
||
86 | return false; |
||
87 | 5900 | jorpiell | } else if (v instanceof Table && ((Table) v).isEditing() && ((Table)v).getModel().getAssociatedTable()==null) { |
88 | 2936 | caballero | return true; |
89 | } else {
|
||
90 | return false; |
||
91 | } |
||
92 | } |
||
93 | 13519 | caballero | /**
|
94 | * <p>This class provides the status of extensions.
|
||
95 | * If this extension has some unsaved editing table (and save them), and methods
|
||
96 | * to check if the extension has some associated background tasks.
|
||
97 | *
|
||
98 | * @author Vicente Caballero Navarro
|
||
99 | *
|
||
100 | */
|
||
101 | private class StopEditingStatus implements IExtensionStatus { |
||
102 | /**
|
||
103 | * This method is used to check if this extension has some unsaved editing tables.
|
||
104 | *
|
||
105 | * @return true if the extension has some unsaved editing tables, false otherwise.
|
||
106 | */
|
||
107 | public boolean hasUnsavedData() { |
||
108 | ProjectExtension pe=(ProjectExtension)PluginServices.getExtension(ProjectExtension.class); |
||
109 | ProjectTable[] tables=(ProjectTable[])pe.getProject().getDocumentsByType(ProjectTableFactory.registerName).toArray(new ProjectTable[0]); |
||
110 | for (int i=0;i<tables.length;i++) { |
||
111 | 22932 | jmvivo | if (tables[i].getModel() == null){ |
112 | 14845 | jmvivo | continue;
|
113 | } |
||
114 | 22932 | jmvivo | if (tables[i].getModel().isEditing())
|
115 | 13519 | caballero | return true; |
116 | } |
||
117 | return false; |
||
118 | } |
||
119 | /**
|
||
120 | * This method is used to check if the extension has some associated
|
||
121 | * background process which is currently running.
|
||
122 | *
|
||
123 | * @return true if the extension has some associated background process,
|
||
124 | * false otherwise.
|
||
125 | */
|
||
126 | public boolean hasRunningProcesses() { |
||
127 | return false; |
||
128 | } |
||
129 | /**
|
||
130 | * <p>Gets an array of the traceable background tasks associated with this
|
||
131 | * extension. These tasks may be tracked, canceled, etc.</p>
|
||
132 | *
|
||
133 | * @return An array of the associated background tasks, or null in case there is
|
||
134 | * no associated background tasks.
|
||
135 | */
|
||
136 | public IMonitorableTask[] getRunningProcesses() { |
||
137 | return null; |
||
138 | } |
||
139 | /**
|
||
140 | * <p>Gets an array of the UnsavedData objects, which contain information about
|
||
141 | * the unsaved editing tables and allows to save it.</p>
|
||
142 | *
|
||
143 | * @return An array of the associated unsaved editing layers, or null in case the extension
|
||
144 | * has not unsaved editing tables.
|
||
145 | */
|
||
146 | public IUnsavedData[] getUnsavedData() { |
||
147 | ProjectExtension pe=(ProjectExtension)PluginServices.getExtension(ProjectExtension.class); |
||
148 | ProjectTable[] tables =(ProjectTable[])pe.getProject().getDocumentsByType(ProjectTableFactory.registerName).toArray(new ProjectTable[0]); |
||
149 | ArrayList unsavedTables = new ArrayList(); |
||
150 | for (int i=0;i<tables.length;i++) { |
||
151 | 22932 | jmvivo | if (tables[i].getModel() == null){ |
152 | 14845 | jmvivo | continue;
|
153 | } |
||
154 | 22932 | jmvivo | if (tables[i].getModel().isEditing()) {
|
155 | 13519 | caballero | UnsavedTable ul=new UnsavedTable(TableEditStopExtension.this);
|
156 | ul.setTable(tables[i]); |
||
157 | unsavedTables.add(ul); |
||
158 | } |
||
159 | } |
||
160 | return (IUnsavedData[])unsavedTables.toArray(new IUnsavedData[0]); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | private class UnsavedTable extends UnsavedData{ |
||
165 | |||
166 | private ProjectTable table;
|
||
167 | |||
168 | public UnsavedTable(IExtension extension) {
|
||
169 | super(extension);
|
||
170 | } |
||
171 | |||
172 | public String getDescription() { |
||
173 | return PluginServices.getText(this,"editing_table_unsaved"); |
||
174 | } |
||
175 | |||
176 | public String getResourceName() { |
||
177 | return table.getName();
|
||
178 | } |
||
179 | |||
180 | |||
181 | |||
182 | public boolean saveData() { |
||
183 | return executeSaveTable(table);
|
||
184 | } |
||
185 | |||
186 | |||
187 | |||
188 | public void setTable(ProjectTable table) { |
||
189 | this.table=table;
|
||
190 | |||
191 | } |
||
192 | } |
||
193 | |||
194 | |||
195 | //TODO Este c?digo est? duplicado, tambi?n est? en la clase Table en el m?todo "public void stopEditing()"
|
||
196 | private boolean executeSaveTable(ProjectTable table2) { |
||
197 | 22932 | jmvivo | FeatureStore fs = table2.getModel(); |
198 | 21354 | vcaballero | try {
|
199 | fs.finishEditing(); |
||
200 | } catch (WriteException e) {
|
||
201 | NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e); |
||
202 | return false; |
||
203 | } catch (ReadException e) {
|
||
204 | NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e); |
||
205 | return false; |
||
206 | 13519 | caballero | } |
207 | 21354 | vcaballero | // if (ies instanceof IWriteable) {
|
208 | // IWriteable w = (IWriteable) ies;
|
||
209 | // IWriter writer = w.getWriter();
|
||
210 | // if (writer == null) {
|
||
211 | // return false;
|
||
212 | // }
|
||
213 | // try {
|
||
214 | // ITableDefinition tableDef = ies.getTableDefinition();
|
||
215 | // writer.initialize(tableDef);
|
||
216 | // ies.stopEdition(writer, EditionEvent.ALPHANUMERIC);
|
||
217 | // ies.getSelection().clear();
|
||
218 | // } catch (InitializeWriterException e) {
|
||
219 | // NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e);
|
||
220 | // return false;
|
||
221 | // } catch (StopWriterVisitorException e) {
|
||
222 | // NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e);
|
||
223 | // return false;
|
||
224 | // } catch (ReadDriverException e) {
|
||
225 | // NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e);
|
||
226 | // return false;
|
||
227 | // }
|
||
228 | // }
|
||
229 | 13519 | caballero | return true; |
230 | } |
||
231 | public IExtensionStatus getStatus() {
|
||
232 | return new StopEditingStatus(); |
||
233 | } |
||
234 | 2936 | caballero | } |