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