Revision 40053
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/ClearSelectionExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.PluginServices; |
|
26 |
import org.gvsig.andami.messages.NotificationManager; |
|
27 |
import org.gvsig.andami.plugins.Extension; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
29 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
32 |
|
|
33 |
/** |
|
34 |
* Extensi?n encargada de limpiar la selecci?n. |
|
35 |
* |
|
36 |
* @author Vicente Caballero Navarro |
|
37 |
*/ |
|
38 |
public class ClearSelectionExtension extends Extension { |
|
39 |
|
|
40 |
public void execute(String s) { |
|
41 |
if (s.compareTo("selection-clear-table") == 0) { |
|
42 |
IWindow activeWindow = |
|
43 |
PluginServices.getMDIManager().getActiveWindow(); |
|
44 |
|
|
45 |
if (isFeatureTableDocumentPanel(activeWindow)) { |
|
46 |
try { |
|
47 |
FeatureSelection selection = getSelection(activeWindow); |
|
48 |
selection.deselectAll(); |
|
49 |
} catch (DataException e) { |
|
50 |
NotificationManager.addError(e); |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public boolean isVisible() { |
|
57 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
58 |
return isFeatureTableDocumentPanel(activeWindow); |
|
59 |
} |
|
60 |
|
|
61 |
private boolean isFeatureTableDocumentPanel(IWindow activeWindow) { |
|
62 |
return activeWindow instanceof FeatureTableDocumentPanel; |
|
63 |
} |
|
64 |
|
|
65 |
public boolean isEnabled() { |
|
66 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
67 |
|
|
68 |
if (isFeatureTableDocumentPanel(activeWindow)) { |
|
69 |
try { |
|
70 |
return !getSelection(activeWindow).isEmpty(); |
|
71 |
} catch (DataException e) { |
|
72 |
throw new RuntimeException( |
|
73 |
"Error getting the selection to check if it is empty", e); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
return false; |
|
78 |
} |
|
79 |
|
|
80 |
private FeatureSelection getSelection(IWindow activeWindow) |
|
81 |
throws DataException { |
|
82 |
return (FeatureSelection) ((FeatureTableDocumentPanel) activeWindow) |
|
83 |
.getModel().getStore().getSelection(); |
|
84 |
} |
|
85 |
|
|
86 |
public void initialize() { |
|
87 |
IconThemeHelper.registerIcon("action", "selection-clear", this); |
|
88 |
} |
|
89 |
|
|
90 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableOperations.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import javax.swing.JOptionPane; |
|
29 |
|
|
30 |
import org.gvsig.andami.IconThemeHelper; |
|
31 |
import org.gvsig.andami.PluginServices; |
|
32 |
import org.gvsig.andami.messages.NotificationManager; |
|
33 |
import org.gvsig.andami.plugins.Extension; |
|
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
35 |
import org.gvsig.app.gui.filter.ExpressionListener; |
|
36 |
import org.gvsig.app.project.Project; |
|
37 |
import org.gvsig.app.project.ProjectManager; |
|
38 |
import org.gvsig.app.project.documents.Document; |
|
39 |
import org.gvsig.app.project.documents.gui.AndamiWizard; |
|
40 |
import org.gvsig.app.project.documents.gui.ObjectSelectionStep; |
|
41 |
import org.gvsig.app.project.documents.table.FieldSelectionModel; |
|
42 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
43 |
import org.gvsig.app.project.documents.table.TableManager; |
|
44 |
import org.gvsig.app.project.documents.table.TableSelectionModel; |
|
45 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
46 |
import org.gvsig.fmap.dal.DALLocator; |
|
47 |
import org.gvsig.fmap.dal.exception.DataException; |
|
48 |
import org.gvsig.fmap.dal.feature.Feature; |
|
49 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
53 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
54 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
55 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
56 |
import org.gvsig.utils.swing.objectSelection.SelectionException; |
|
57 |
import org.gvsig.utils.swing.wizard.WizardControl; |
|
58 |
import org.gvsig.utils.swing.wizard.WizardEvent; |
|
59 |
import org.gvsig.utils.swing.wizard.WizardListener; |
|
60 |
|
|
61 |
/** |
|
62 |
* Extensi?n que controla las operaciones realizadas sobre las tablas. |
|
63 |
* |
|
64 |
* @author Fernando Gonz?lez Cort?s |
|
65 |
*/ |
|
66 |
public class TableOperations extends Extension implements ExpressionListener { |
|
67 |
|
|
68 |
private FeatureStore featureStore = null; |
|
69 |
|
|
70 |
public void execute(String actionCommand) { |
|
71 |
final Project project = |
|
72 |
ProjectManager.getInstance().getCurrentProject(); |
|
73 |
List<Document> tableDcouments = |
|
74 |
project.getDocuments(TableManager.TYPENAME); |
|
75 |
TableDocument[] pts = |
|
76 |
tableDcouments |
|
77 |
.toArray(new TableDocument[tableDcouments.size()]); |
|
78 |
|
|
79 |
if ("table-create-link".equals(actionCommand)) { |
|
80 |
try { |
|
81 |
final ObjectSelectionStep sourceTable = |
|
82 |
new ObjectSelectionStep(); |
|
83 |
sourceTable.setModel(new TableSelectionModel(pts, |
|
84 |
PluginServices.getText(this, "seleccione_tabla_origen"))); |
|
85 |
|
|
86 |
final ObjectSelectionStep targetTable = |
|
87 |
new ObjectSelectionStep(); |
|
88 |
targetTable |
|
89 |
.setModel(new TableSelectionModel(pts, PluginServices |
|
90 |
.getText(this, "seleccione_tabla_a_enlazar"))); |
|
91 |
|
|
92 |
final ObjectSelectionStep firstTableField = |
|
93 |
new ObjectSelectionStep(); |
|
94 |
final ObjectSelectionStep secondTableField = |
|
95 |
new ObjectSelectionStep(); |
|
96 |
final AndamiWizard wiz = |
|
97 |
new AndamiWizard(PluginServices.getText(this, "back"), |
|
98 |
PluginServices.getText(this, "next"), |
|
99 |
PluginServices.getText(this, "finish"), |
|
100 |
PluginServices.getText(this, "cancel")); |
|
101 |
wiz.setSize(new Dimension(450, 200)); |
|
102 |
wiz.addStep(sourceTable); |
|
103 |
wiz.addStep(firstTableField); |
|
104 |
wiz.addStep(targetTable); |
|
105 |
wiz.addStep(secondTableField); |
|
106 |
|
|
107 |
wiz.addWizardListener(new WizardListener() { |
|
108 |
|
|
109 |
public void cancel(WizardEvent w) { |
|
110 |
PluginServices.getMDIManager().closeWindow(wiz); |
|
111 |
} |
|
112 |
|
|
113 |
public void finished(WizardEvent w) { |
|
114 |
PluginServices.getMDIManager().closeWindow(wiz); |
|
115 |
|
|
116 |
TableDocument sourceProjectTable = |
|
117 |
(TableDocument) sourceTable.getSelected(); |
|
118 |
|
|
119 |
TableDocument targetProjectTable = |
|
120 |
(TableDocument) targetTable.getSelected(); |
|
121 |
FeatureStore sds2 = targetProjectTable.getStore(); |
|
122 |
|
|
123 |
String field1 = (String) firstTableField.getSelected(); |
|
124 |
String field2 = (String) secondTableField.getSelected(); |
|
125 |
sourceProjectTable.addLinkTable( |
|
126 |
targetProjectTable.getName(), field1, |
|
127 |
field2); |
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
public void next(WizardEvent w) { |
|
132 |
WizardControl wiz = w.wizard; |
|
133 |
wiz.enableBack(true); |
|
134 |
wiz.enableNext(((ObjectSelectionStep) wiz |
|
135 |
.getCurrentStep()).getSelectedItem() != null); |
|
136 |
|
|
137 |
if (w.currentStep == 1) { |
|
138 |
TableDocument pt = |
|
139 |
(TableDocument) sourceTable.getSelected(); |
|
140 |
|
|
141 |
try { |
|
142 |
firstTableField |
|
143 |
.setModel(new FieldSelectionModel(pt |
|
144 |
.getStore(), PluginServices.getText( |
|
145 |
this, "seleccione_campo_enlace"))); |
|
146 |
} catch (SelectionException e) { |
|
147 |
NotificationManager.addError( |
|
148 |
"Error obteniendo los campos de la tabla", |
|
149 |
e); |
|
150 |
} |
|
151 |
} else |
|
152 |
if (w.currentStep == 3) { |
|
153 |
try { |
|
154 |
// tabla |
|
155 |
TableDocument pt = |
|
156 |
(TableDocument) sourceTable |
|
157 |
.getSelected(); |
|
158 |
|
|
159 |
// ?ndice del campo |
|
160 |
FeatureStore fs = pt.getStore(); |
|
161 |
String fieldName = |
|
162 |
(String) firstTableField.getSelected(); |
|
163 |
int type = |
|
164 |
((FeatureAttributeDescriptor) fs |
|
165 |
.getDefaultFeatureType().get( |
|
166 |
fieldName)).getType(); |
|
167 |
|
|
168 |
secondTableField |
|
169 |
.setModel(new FieldSelectionModel( |
|
170 |
((TableDocument) targetTable |
|
171 |
.getSelected()).getStore(), |
|
172 |
PluginServices.getText(this, |
|
173 |
"seleccione_campo_enlace"), |
|
174 |
type)); |
|
175 |
} catch (SelectionException e) { |
|
176 |
NotificationManager |
|
177 |
.addError( |
|
178 |
"Error obteniendo los campos de la tabla", |
|
179 |
e); |
|
180 |
} catch (DataException e) { |
|
181 |
NotificationManager |
|
182 |
.addError( |
|
183 |
"Error obteniendo los campos de la tabla", |
|
184 |
e); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
public void back(WizardEvent w) { |
|
190 |
WizardControl wiz = w.wizard; |
|
191 |
wiz.enableBack(true); |
|
192 |
wiz.enableNext(((ObjectSelectionStep) wiz |
|
193 |
.getCurrentStep()).getSelectedItem() != null); |
|
194 |
} |
|
195 |
}); |
|
196 |
project.setModified(true); |
|
197 |
PluginServices.getMDIManager().addWindow(wiz); |
|
198 |
} catch (SelectionException e) { |
|
199 |
NotificationManager.addError("Error abriendo el asistente", e); |
|
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* @see org.gvsig.app.gui.filter.ExpressionListener#newSet(java.lang.String) |
|
206 |
*/ |
|
207 |
public void newSet(String expression) throws DataException { |
|
208 |
// By Pablo: if no filter expression -> no element selected |
|
209 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
|
210 |
FeatureSet set = null; |
|
211 |
try { |
|
212 |
set = doSet(expression); |
|
213 |
|
|
214 |
if (set == null) { |
|
215 |
throw new RuntimeException("Not a 'where' clause?"); |
|
216 |
} |
|
217 |
FeatureSelection newSel = featureStore.createFeatureSelection(); |
|
218 |
newSel.select(set); |
|
219 |
featureStore.setSelection(newSel); |
|
220 |
} catch (Exception e) { |
|
221 |
JOptionPane.showMessageDialog( |
|
222 |
(Component) PluginServices.getMainFrame(), |
|
223 |
"Asegurate de que la consulta es correcta."); |
|
224 |
} finally { |
|
225 |
if (set != null) { |
|
226 |
set.dispose(); |
|
227 |
} |
|
228 |
} |
|
229 |
} else { |
|
230 |
// By Pablo: if no expression -> no element selected |
|
231 |
featureStore.getFeatureSelection().deselectAll(); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* @see org.gvsig.app.gui.filter.ExpressionListener#newSet(java.lang.String) |
|
237 |
*/ |
|
238 |
private FeatureSet doSet(String expression) throws DataException { |
|
239 |
FeatureQuery query = featureStore.createFeatureQuery(); |
|
240 |
query |
|
241 |
.setFilter(DALLocator.getDataManager().createExpresion(expression)); |
|
242 |
return featureStore.getFeatureSet(query); |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* @see org.gvsig.app.gui.filter.ExpressionListener#addToSet(java.lang.String) |
|
247 |
*/ |
|
248 |
public void addToSet(String expression) throws DataException { |
|
249 |
// By Pablo: if no filter expression -> don't add more elements to set |
|
250 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
|
251 |
FeatureSet set = null; |
|
252 |
try { |
|
253 |
set = doSet(expression); |
|
254 |
|
|
255 |
featureStore.getFeatureSelection().select(set); |
|
256 |
} finally { |
|
257 |
if (set != null) { |
|
258 |
set.dispose(); |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* @see org.gvsig.app.gui.filter.ExpressionListener#fromSet(java.lang.String) |
|
266 |
*/ |
|
267 |
public void fromSet(String expression) throws DataException { |
|
268 |
// By Pablo: if no filter expression -> no element selected |
|
269 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
|
270 |
|
|
271 |
FeatureSet set = null; |
|
272 |
DisposableIterator iterator = null; |
|
273 |
try { |
|
274 |
set = doSet(expression); |
|
275 |
|
|
276 |
if (set == null) { |
|
277 |
throw new RuntimeException("Not a 'where' clause?"); |
|
278 |
} |
|
279 |
FeatureSelection oldSelection = |
|
280 |
featureStore.getFeatureSelection(); |
|
281 |
|
|
282 |
FeatureSelection newSelection = |
|
283 |
featureStore.createFeatureSelection(); |
|
284 |
iterator = set.fastIterator(); |
|
285 |
while (iterator.hasNext()) { |
|
286 |
Feature feature = (Feature) iterator.next(); |
|
287 |
if (oldSelection.isSelected(feature)) { |
|
288 |
newSelection.select(feature); |
|
289 |
} |
|
290 |
} |
|
291 |
featureStore.setSelection(newSelection); |
|
292 |
} finally { |
|
293 |
DisposeUtils.dispose(iterator); |
|
294 |
DisposeUtils.dispose(set); |
|
295 |
} |
|
296 |
} else { |
|
297 |
// By Pablo: if no expression -> no element selected |
|
298 |
// featureStore.setSelection(featureStore.createSelection()); |
|
299 |
featureStore.getFeatureSelection().deselectAll(); |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Returns true if the WHERE subconsultation of the filterExpression is |
|
305 |
* empty ("") |
|
306 |
* |
|
307 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
|
308 |
* @param expression |
|
309 |
* An string |
|
310 |
* @return A boolean value |
|
311 |
*/ |
|
312 |
private boolean filterExpressionFromWhereIsEmpty(String expression) { |
|
313 |
String subExpression = expression.trim(); |
|
314 |
int pos; |
|
315 |
|
|
316 |
// Remove last ';' if exists |
|
317 |
if (subExpression.charAt(subExpression.length() - 1) == ';') { |
|
318 |
subExpression = |
|
319 |
subExpression.substring(0, subExpression.length() - 1).trim(); |
|
320 |
} |
|
321 |
|
|
322 |
// If there is no 'where' clause |
|
323 |
if ((pos = subExpression.indexOf("where")) == -1) { |
|
324 |
return false; |
|
325 |
} |
|
326 |
|
|
327 |
// If there is no subexpression in the WHERE clause -> true |
|
328 |
subExpression = |
|
329 |
subExpression.substring(pos + 5, subExpression.length()).trim(); // + |
|
330 |
// 5 |
|
331 |
// is |
|
332 |
// the |
|
333 |
// length |
|
334 |
// of |
|
335 |
// 'where' |
|
336 |
if (subExpression.length() == 0) { |
|
337 |
return true; |
|
338 |
} else { |
|
339 |
return false; |
|
340 |
} |
|
341 |
} |
|
342 |
|
|
343 |
/** |
|
344 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible() |
|
345 |
*/ |
|
346 |
public boolean isVisible() { |
|
347 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
348 |
|
|
349 |
if (v == null) { |
|
350 |
return false; |
|
351 |
} |
|
352 |
|
|
353 |
if (v instanceof FeatureTableDocumentPanel) { |
|
354 |
return true; |
|
355 |
} /* |
|
356 |
* else { |
|
357 |
* if (v instanceof com.iver.cit.gvsig.gui.View) { |
|
358 |
* com.iver.cit.gvsig.gui.View view = (com.iver.cit.gvsig.gui.View) v; |
|
359 |
* ProjectView pv = view.getModel(); |
|
360 |
* FLayer[] seleccionadas = pv.getMapContext().getLayers() |
|
361 |
* .getActives(); |
|
362 |
* |
|
363 |
* if (seleccionadas.length == 1) { |
|
364 |
* if (seleccionadas[0] instanceof AlphanumericData) { |
|
365 |
* return true; |
|
366 |
* } |
|
367 |
* } |
|
368 |
* } |
|
369 |
*/ |
|
370 |
return false; |
|
371 |
// } |
|
372 |
} |
|
373 |
|
|
374 |
/** |
|
375 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
376 |
*/ |
|
377 |
public void initialize() { |
|
378 |
IconThemeHelper.registerIcon("action", "table-create-link", this); |
|
379 |
|
|
380 |
} |
|
381 |
|
|
382 |
/** |
|
383 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
384 |
*/ |
|
385 |
public boolean isEnabled() { |
|
386 |
return true; |
|
387 |
} |
|
388 |
|
|
389 |
/** |
|
390 |
* Ensure that field name only has 'safe' characters |
|
391 |
* (no spaces, special characters, etc). |
|
392 |
*/ |
|
393 |
public String sanitizeFieldName(String fieldName) { |
|
394 |
return fieldName.replaceAll("\\W", "_"); // replace any non-word |
|
395 |
// character by an underscore |
|
396 |
} |
|
397 |
|
|
398 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/FiltroExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
|
|
26 |
import javax.swing.JOptionPane; |
|
27 |
|
|
28 |
import org.gvsig.andami.IconThemeHelper; |
|
29 |
import org.gvsig.andami.PluginServices; |
|
30 |
import org.gvsig.andami.messages.NotificationManager; |
|
31 |
import org.gvsig.andami.plugins.Extension; |
|
32 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
33 |
import org.gvsig.app.gui.filter.ExpressionListener; |
|
34 |
import org.gvsig.app.gui.filter.FilterDialog; |
|
35 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
36 |
import org.gvsig.fmap.dal.DALLocator; |
|
37 |
import org.gvsig.fmap.dal.DataManager; |
|
38 |
import org.gvsig.fmap.dal.exception.DataException; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
42 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
|
43 |
|
|
44 |
/** |
|
45 |
* Extensi?n que abre un di?logo para poder hacer un filtro de una capa o tabla. |
|
46 |
* |
|
47 |
* @author Vicente Caballero Navarro |
|
48 |
*/ |
|
49 |
public class FiltroExtension extends Extension implements ExpressionListener { |
|
50 |
|
|
51 |
protected FeatureStore featureStore = null; |
|
52 |
protected FeatureTableDocumentPanel table; |
|
53 |
private String filterTitle; |
|
54 |
|
|
55 |
public void initialize() { |
|
56 |
registerIcons(); |
|
57 |
} |
|
58 |
|
|
59 |
private void registerIcons() { |
|
60 |
IconThemeHelper.registerIcon("action", "table-filter", this); |
|
61 |
} |
|
62 |
|
|
63 |
public void execute(String actionCommand) { |
|
64 |
if ("table-filter".equals(actionCommand)) { |
|
65 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
66 |
|
|
67 |
if (v instanceof FeatureTableDocumentPanel) { |
|
68 |
table = (FeatureTableDocumentPanel) v; |
|
69 |
|
|
70 |
featureStore = table.getModel().getStore(); |
|
71 |
filterTitle = table.getModel().getName(); |
|
72 |
table.getModel().setModified(true); |
|
73 |
} |
|
74 |
|
|
75 |
doExecute(); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
protected void doExecute() { |
|
80 |
FilterDialog dlg = new FilterDialog(filterTitle); |
|
81 |
dlg.addExpressionListener(this); |
|
82 |
dlg.addExceptionListener(new ExceptionListener() { |
|
83 |
|
|
84 |
public void exceptionThrown(Throwable t) { |
|
85 |
NotificationManager.addError(t.getMessage(), t); |
|
86 |
} |
|
87 |
}); |
|
88 |
dlg.setModel(featureStore); |
|
89 |
PluginServices.getMDIManager().addWindow(dlg); |
|
90 |
} |
|
91 |
|
|
92 |
public boolean isEnabled() { |
|
93 |
return isVisible(); |
|
94 |
} |
|
95 |
|
|
96 |
public boolean isVisible() { |
|
97 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
98 |
return (v instanceof FeatureTableDocumentPanel); |
|
99 |
} |
|
100 |
|
|
101 |
// By Pablo: if no filter expression -> no element selected |
|
102 |
public void newSet(String expression) throws DataException { |
|
103 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
|
104 |
FeatureSet set = null; |
|
105 |
try { |
|
106 |
set = doSet(expression); |
|
107 |
|
|
108 |
if (set == null) { |
|
109 |
return; |
|
110 |
} |
|
111 |
featureStore.setSelection(set); |
|
112 |
|
|
113 |
} catch (Exception e) { |
|
114 |
JOptionPane.showMessageDialog( |
|
115 |
(Component) PluginServices.getMainFrame(), |
|
116 |
"Asegurate de que la consulta es correcta."); |
|
117 |
} finally { |
|
118 |
if (set != null) { |
|
119 |
set.dispose(); |
|
120 |
} |
|
121 |
} |
|
122 |
} else { |
|
123 |
// By Pablo: if no expression -> no element selected |
|
124 |
featureStore.getFeatureSelection().deselectAll(); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
private FeatureSet doSet(String expression) throws DataException { |
|
129 |
FeatureQuery query = featureStore.createFeatureQuery(); |
|
130 |
DataManager manager = DALLocator.getDataManager(); |
|
131 |
query.setFilter(manager.createExpresion(expression)); |
|
132 |
return featureStore.getFeatureSet(query); |
|
133 |
} |
|
134 |
|
|
135 |
public void addToSet(String expression) throws DataException { |
|
136 |
// By Pablo: if no filter expression -> don't add more elements to set |
|
137 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
|
138 |
FeatureSet set = null; |
|
139 |
try { |
|
140 |
set = doSet(expression); |
|
141 |
|
|
142 |
if (set == null) { |
|
143 |
return; |
|
144 |
} |
|
145 |
featureStore.getFeatureSelection().select(set); |
|
146 |
} finally { |
|
147 |
if (set != null) { |
|
148 |
set.dispose(); |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
public void fromSet(String expression) throws DataException { |
|
155 |
// By Pablo: if no filter expression -> no element selected |
|
156 |
try { |
|
157 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
|
158 |
NotificationManager.showMessageInfo("Falta por implementar", |
|
159 |
null); |
|
160 |
} else { |
|
161 |
// By Pablo: if no expression -> no element selected |
|
162 |
featureStore.getFeatureSelection().deselectAll(); |
|
163 |
} |
|
164 |
} catch (DataException e) { |
|
165 |
NotificationManager.addError(e); |
|
166 |
} |
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Returns true if the WHERE subconsultation of the filterExpression is |
|
172 |
* empty ("") |
|
173 |
* |
|
174 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
|
175 |
* @param expression |
|
176 |
* An string |
|
177 |
* @return A boolean value |
|
178 |
*/ |
|
179 |
private boolean filterExpressionFromWhereIsEmpty(String expression) { |
|
180 |
|
|
181 |
if (expression == null) { |
|
182 |
return true; |
|
183 |
} |
|
184 |
|
|
185 |
String subExpression = expression.trim(); |
|
186 |
|
|
187 |
if (subExpression.length() == 0) { |
|
188 |
return true; |
|
189 |
} |
|
190 |
|
|
191 |
int pos; |
|
192 |
|
|
193 |
// Remove last ';' if exists |
|
194 |
if (subExpression.charAt(subExpression.length() - 1) == ';') { |
|
195 |
subExpression = |
|
196 |
subExpression.substring(0, subExpression.length() - 1).trim(); |
|
197 |
} |
|
198 |
|
|
199 |
// If there is no 'where' clause |
|
200 |
if ((pos = subExpression.indexOf("where")) == -1) { |
|
201 |
return false; |
|
202 |
} |
|
203 |
|
|
204 |
// If there is no subexpression in the WHERE clause -> true |
|
205 |
subExpression = |
|
206 |
subExpression.substring(pos + 5, subExpression.length()).trim(); // + |
|
207 |
// 5 |
|
208 |
// is |
|
209 |
// the |
|
210 |
// length |
|
211 |
// of |
|
212 |
// 'where' |
|
213 |
if (subExpression.length() == 0) { |
|
214 |
return true; |
|
215 |
} else { |
|
216 |
return false; |
|
217 |
} |
|
218 |
} |
|
219 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/RedoTableExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import org.gvsig.andami.PluginServices; |
|
25 |
import org.gvsig.andami.messages.NotificationManager; |
|
26 |
import org.gvsig.andami.plugins.Extension; |
|
27 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
28 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
29 |
import org.gvsig.tools.undo.RedoException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Extensi?n encargada de gestionar el rehacer un comando anteriormente |
|
33 |
* deshecho. |
|
34 |
* |
|
35 |
* @author Vicente Caballero Navarro |
|
36 |
*/ |
|
37 |
public class RedoTableExtension extends Extension { |
|
38 |
|
|
39 |
/** |
|
40 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
41 |
*/ |
|
42 |
public void initialize() { |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
49 |
*/ |
|
50 |
public void execute(String s) { |
|
51 |
FeatureTableDocumentPanel tabla = |
|
52 |
(FeatureTableDocumentPanel) PluginServices.getMDIManager() |
|
53 |
.getActiveWindow(); |
|
54 |
|
|
55 |
if ( "edit-redo-table".equalsIgnoreCase(s)) { |
|
56 |
if (tabla.getModel().getStore().isEditing()) { |
|
57 |
FeatureStore fs = tabla.getModel().getStore(); |
|
58 |
try { |
|
59 |
fs.redo(); |
|
60 |
} catch (RedoException e) { |
|
61 |
NotificationManager.addError(e); |
|
62 |
} |
|
63 |
} |
|
64 |
tabla.getModel().setModified(true); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
70 |
*/ |
|
71 |
public boolean isEnabled() { |
|
72 |
FeatureTableDocumentPanel tabla = |
|
73 |
(FeatureTableDocumentPanel) PluginServices.getMDIManager() |
|
74 |
.getActiveWindow(); |
|
75 |
FeatureStore fs = tabla.getModel().getStore(); |
|
76 |
if (fs != null && fs.isEditing()) { |
|
77 |
return fs.canRedo(); |
|
78 |
} |
|
79 |
return false; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
84 |
*/ |
|
85 |
public boolean isVisible() { |
|
86 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
|
87 |
PluginServices.getMDIManager().getActiveWindow(); |
|
88 |
|
|
89 |
if (f == null) { |
|
90 |
return false; |
|
91 |
} |
|
92 |
|
|
93 |
if (f instanceof FeatureTableDocumentPanel) { |
|
94 |
return true; |
|
95 |
} else { |
|
96 |
return false; |
|
97 |
} |
|
98 |
} |
|
99 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableFieldOperations.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.PluginServices; |
|
26 |
import org.gvsig.andami.plugins.Extension; |
|
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
28 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel; |
|
31 |
import org.gvsig.tools.exception.BaseException; |
|
32 |
|
|
33 |
/** |
|
34 |
* Ascending or descending order operations. |
|
35 |
* |
|
36 |
* @author Vicente Caballero Navarro |
|
37 |
*/ |
|
38 |
public class TableFieldOperations extends Extension { |
|
39 |
|
|
40 |
private FeatureTableDocumentPanel table = null; |
|
41 |
|
|
42 |
/** |
|
43 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
44 |
*/ |
|
45 |
public void initialize() { |
|
46 |
IconThemeHelper.registerIcon("action", "table-order-desc", this); |
|
47 |
IconThemeHelper.registerIcon("action", "table-order-asc", this); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
52 |
*/ |
|
53 |
public void execute(String actionCommand) { |
|
54 |
doExecute(actionCommand, table); |
|
55 |
table.getModel().setModified(true); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* "execute" method acction |
|
60 |
* |
|
61 |
* @param actionCommand |
|
62 |
* The acction command that executes this method |
|
63 |
* @param table |
|
64 |
* Table to operate |
|
65 |
*/ |
|
66 |
protected void doExecute(String actionCommand, |
|
67 |
FeatureTableDocumentPanel table) { |
|
68 |
// FIXME |
|
69 |
ConfigurableFeatureTableModel cftm = |
|
70 |
table.getTablePanel().getTableModel(); |
|
71 |
try { |
|
72 |
if ("table-order-asc".equals(actionCommand)) { |
|
73 |
cftm.orderByColumn(table.getTablePanel().getTable() |
|
74 |
.getSelectedColumnsAttributeDescriptor()[0].getName(), true); |
|
75 |
} else |
|
76 |
if ("table-order-desc".equals(actionCommand)) { |
|
77 |
cftm.orderByColumn(table.getTablePanel().getTable() |
|
78 |
.getSelectedColumnsAttributeDescriptor()[0].getName(), |
|
79 |
false); |
|
80 |
} |
|
81 |
} catch (BaseException e) { |
|
82 |
e.printStackTrace(); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
88 |
*/ |
|
89 |
public boolean isEnabled() { |
|
90 |
try { |
|
91 |
return (table.getTablePanel().getTable().getSelectedColumnCount() == 1); |
|
92 |
} catch (DataException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} |
|
95 |
return false; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
100 |
*/ |
|
101 |
public boolean isVisible() { |
|
102 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
103 |
if (v != null && v instanceof FeatureTableDocumentPanel) { |
|
104 |
table = (FeatureTableDocumentPanel) v; |
|
105 |
return true; |
|
106 |
} |
|
107 |
return false; |
|
108 |
} |
|
109 |
|
|
110 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditRemoveRowExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.fmap.dal.exception.DataException; |
|
26 |
|
|
27 |
/** |
|
28 |
* DOCUMENT ME! |
|
29 |
* |
|
30 |
* @author Vicente Caballero Navarro |
|
31 |
*/ |
|
32 |
public class TableEditRemoveRowExtension extends AbstractTableEditExtension { |
|
33 |
|
|
34 |
public void initialize() { |
|
35 |
super.initialize(); |
|
36 |
IconThemeHelper.registerIcon("action", "table-remove-row", this); |
|
37 |
} |
|
38 |
/** |
|
39 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
40 |
*/ |
|
41 |
public void execute(String actionCommand) { |
|
42 |
if ("table-remove-row".equals(actionCommand)) { |
|
43 |
try { |
|
44 |
featureTableOperations.setTablePanel(table); |
|
45 |
featureTableOperations.deleteFeatures(); |
|
46 |
} catch (DataException e) { |
|
47 |
e.printStackTrace(); |
|
48 |
} |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
54 |
*/ |
|
55 |
public boolean isEnabled() { |
|
56 |
try { |
|
57 |
if (table.getTablePanel().getTable().getSelectedRowCount() > 0) |
|
58 |
return true; |
|
59 |
} catch (DataException e) { |
|
60 |
e.printStackTrace(); |
|
61 |
} |
|
62 |
return false; |
|
63 |
} |
|
64 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditStopExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.Component; |
|
26 |
import java.awt.Font; |
|
27 |
import java.awt.GridBagConstraints; |
|
28 |
import java.awt.GridBagLayout; |
|
29 |
import java.awt.Insets; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import javax.swing.JLabel; |
|
34 |
import javax.swing.JOptionPane; |
|
35 |
import javax.swing.JPanel; |
|
36 |
|
|
37 |
import org.slf4j.Logger; |
|
38 |
import org.slf4j.LoggerFactory; |
|
39 |
|
|
40 |
import org.gvsig.andami.IconThemeHelper; |
|
41 |
import org.gvsig.andami.PluginServices; |
|
42 |
import org.gvsig.andami.messages.NotificationManager; |
|
43 |
import org.gvsig.andami.plugins.IExtension; |
|
44 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
|
45 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
|
46 |
import org.gvsig.andami.plugins.status.UnsavedData; |
|
47 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
48 |
import org.gvsig.app.ApplicationLocator; |
|
49 |
import org.gvsig.app.project.Project; |
|
50 |
import org.gvsig.app.project.ProjectManager; |
|
51 |
import org.gvsig.app.project.documents.Document; |
|
52 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
53 |
import org.gvsig.app.project.documents.table.TableManager; |
|
54 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
55 |
import org.gvsig.fmap.dal.exception.DataException; |
|
56 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
57 |
import org.gvsig.fmap.dal.exception.WriteException; |
|
58 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
59 |
import org.gvsig.gui.beans.Messages; |
|
60 |
import org.gvsig.utils.swing.threads.IMonitorableTask; |
|
61 |
|
|
62 |
public class TableEditStopExtension extends AbstractTableEditExtension { |
|
63 |
|
|
64 |
private static Logger logger = |
|
65 |
LoggerFactory.getLogger(TableEditStopExtension.class); |
|
66 |
|
|
67 |
public void initialize() { |
|
68 |
super.initialize(); |
|
69 |
IconThemeHelper.registerIcon("action", "table-stop-editing", this); |
|
70 |
} |
|
71 |
|
|
72 |
public void execute(String actionCommand) { |
|
73 |
if ("table-stop-editing".equals(actionCommand)) { |
|
74 |
stopEditing(table); |
|
75 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
private void stopEditing(FeatureTableDocumentPanel table) { |
|
80 |
|
|
81 |
Object[] options = { |
|
82 |
PluginServices.getText(this, "_Guardar"), |
|
83 |
" " + PluginServices.getText(this, "_Descartar") + " ", |
|
84 |
PluginServices.getText(this, "_Continuar") }; |
|
85 |
|
|
86 |
JPanel explanation_panel = getExplanationPanel(table.getModel().getName()); |
|
87 |
|
|
88 |
int resp = JOptionPane |
|
89 |
.showOptionDialog( |
|
90 |
(Component) PluginServices.getMainFrame(), |
|
91 |
explanation_panel, |
|
92 |
PluginServices.getText(this, "stop_edition"), |
|
93 |
JOptionPane.YES_NO_CANCEL_OPTION, |
|
94 |
JOptionPane.QUESTION_MESSAGE, null, options, |
|
95 |
options[2]); |
|
96 |
|
|
97 |
try { |
|
98 |
if (resp == JOptionPane.NO_OPTION) { |
|
99 |
// CANCEL EDITING |
|
100 |
table.getModel().getStore().cancelEditing(); |
|
101 |
} else { |
|
102 |
|
|
103 |
if (resp == JOptionPane.YES_OPTION) { |
|
104 |
// Save table |
|
105 |
table.getModel().getStore().finishEditing(); |
|
106 |
} else { |
|
107 |
// This happens when user clicks on [x] |
|
108 |
// to abruptly close previous JOptionPane dialog |
|
109 |
// We do nothing (equivalent to 'Continue editing') |
|
110 |
} |
|
111 |
} |
|
112 |
} catch (DataException e) { |
|
113 |
logger.error("While finishing or canceling table editing: " |
|
114 |
+ e.getMessage(), e); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
120 |
*/ |
|
121 |
public boolean isEnabled() { |
|
122 |
return true; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
127 |
*/ |
|
128 |
public boolean isVisible() { |
|
129 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
130 |
|
|
131 |
if (v == null) { |
|
132 |
return false; |
|
133 |
} else |
|
134 |
if (v instanceof FeatureTableDocumentPanel |
|
135 |
&& ((FeatureTableDocumentPanel) v).getModel().getStore() |
|
136 |
.isEditing() |
|
137 |
&& ((FeatureTableDocumentPanel) v).getModel() |
|
138 |
.getAssociatedLayer() == null) { |
|
139 |
table = (FeatureTableDocumentPanel) v; |
|
140 |
return true; |
|
141 |
} else { |
|
142 |
return false; |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* <p> |
|
148 |
* This class provides the status of extensions. If this extension has some |
|
149 |
* unsaved editing table (and save them), and methods to check if the |
|
150 |
* extension has some associated background tasks. |
|
151 |
* |
|
152 |
* @author Vicente Caballero Navarro |
|
153 |
* |
|
154 |
*/ |
|
155 |
private class StopEditingStatus implements IExtensionStatus { |
|
156 |
|
|
157 |
/** |
|
158 |
* This method is used to check if this extension has some unsaved |
|
159 |
* editing tables. |
|
160 |
* |
|
161 |
* @return true if the extension has some unsaved editing tables, false |
|
162 |
* otherwise. |
|
163 |
*/ |
|
164 |
public boolean hasUnsavedData() { |
|
165 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
166 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
|
167 |
for (int i = 0; i < tables.size(); i++) { |
|
168 |
FeatureStore store = ((TableDocument) tables.get(i)).getStore(); |
|
169 |
if (store == null) { |
|
170 |
continue; |
|
171 |
} |
|
172 |
if (store.isEditing()) { |
|
173 |
return true; |
|
174 |
} |
|
175 |
} |
|
176 |
return false; |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* This method is used to check if the extension has some associated |
|
181 |
* background process which is currently running. |
|
182 |
* |
|
183 |
* @return true if the extension has some associated background process, |
|
184 |
* false otherwise. |
|
185 |
*/ |
|
186 |
public boolean hasRunningProcesses() { |
|
187 |
return false; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* <p> |
|
192 |
* Gets an array of the traceable background tasks associated with this |
|
193 |
* extension. These tasks may be tracked, canceled, etc. |
|
194 |
* </p> |
|
195 |
* |
|
196 |
* @return An array of the associated background tasks, or null in case |
|
197 |
* there is |
|
198 |
* no associated background tasks. |
|
199 |
*/ |
|
200 |
public IMonitorableTask[] getRunningProcesses() { |
|
201 |
return null; |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* <p> |
|
206 |
* Gets an array of the UnsavedData objects, which contain information |
|
207 |
* about the unsaved editing tables and allows to save it. |
|
208 |
* </p> |
|
209 |
* |
|
210 |
* @return An array of the associated unsaved editing layers, or null in |
|
211 |
* case the extension |
|
212 |
* has not unsaved editing tables. |
|
213 |
*/ |
|
214 |
public IUnsavedData[] getUnsavedData() { |
|
215 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
216 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
|
217 |
List<UnsavedTable> unsavedTables = new ArrayList<UnsavedTable>(); |
|
218 |
for (int i = 0; i < tables.size(); i++) { |
|
219 |
TableDocument table = (TableDocument) tables.get(i); |
|
220 |
FeatureStore store = table.getStore(); |
|
221 |
if (store == null) { |
|
222 |
continue; |
|
223 |
} |
|
224 |
if (store.isEditing()) { |
|
225 |
UnsavedTable ul = |
|
226 |
new UnsavedTable(TableEditStopExtension.this); |
|
227 |
ul.setTable(table); |
|
228 |
unsavedTables.add(ul); |
|
229 |
} |
|
230 |
} |
|
231 |
return unsavedTables |
|
232 |
.toArray(new IUnsavedData[unsavedTables.size()]); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
private class UnsavedTable extends UnsavedData { |
|
237 |
|
|
238 |
private TableDocument table; |
|
239 |
|
|
240 |
public UnsavedTable(IExtension extension) { |
|
241 |
super(extension); |
|
242 |
} |
|
243 |
|
|
244 |
public String getDescription() { |
|
245 |
return PluginServices.getText(this, "editing_table_unsaved"); |
|
246 |
} |
|
247 |
|
|
248 |
public String getResourceName() { |
|
249 |
return table.getName(); |
|
250 |
} |
|
251 |
|
|
252 |
public boolean saveData() { |
|
253 |
return executeSaveTable(table); |
|
254 |
} |
|
255 |
|
|
256 |
public void setTable(TableDocument table) { |
|
257 |
this.table = table; |
|
258 |
} |
|
259 |
|
|
260 |
public String getIcon() { |
|
261 |
return "document-table-icon-small"; |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
// TODO Este c?digo est? duplicado, tambi?n est? en la clase Table en el |
|
266 |
// m?todo "public void stopEditing()" |
|
267 |
private boolean executeSaveTable(TableDocument table2) { |
|
268 |
FeatureStore fs = table2.getStore(); |
|
269 |
try { |
|
270 |
fs.finishEditing(); |
|
271 |
} catch (WriteException e) { |
|
272 |
NotificationManager.addError( |
|
273 |
PluginServices.getText(this, "error_saving_table"), e); |
|
274 |
return false; |
|
275 |
} catch (ReadException e) { |
|
276 |
NotificationManager.addError( |
|
277 |
PluginServices.getText(this, "error_saving_table"), e); |
|
278 |
return false; |
|
279 |
} catch (DataException e) { |
|
280 |
NotificationManager.addError( |
|
281 |
PluginServices.getText(this, "error_saving_table"), e); |
|
282 |
return false; |
|
283 |
} |
|
284 |
// if (ies instanceof IWriteable) { |
|
285 |
// IWriteable w = (IWriteable) ies; |
|
286 |
// IWriter writer = w.getWriter(); |
|
287 |
// if (writer == null) { |
|
288 |
// return false; |
|
289 |
// } |
|
290 |
// try { |
|
291 |
// ITableDefinition tableDef = ies.getTableDefinition(); |
|
292 |
// writer.initialize(tableDef); |
|
293 |
// ies.stopEdition(writer, EditionEvent.ALPHANUMERIC); |
|
294 |
// ies.getSelection().clear(); |
|
295 |
// } catch (InitializeWriterException e) { |
|
296 |
// NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e); |
|
297 |
// return false; |
|
298 |
// } catch (StopWriterVisitorException e) { |
|
299 |
// NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e); |
|
300 |
// return false; |
|
301 |
// } catch (ReadDriverException e) { |
|
302 |
// NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e); |
|
303 |
// return false; |
|
304 |
// } |
|
305 |
// } |
|
306 |
return true; |
|
307 |
} |
|
308 |
|
|
309 |
public IExtensionStatus getStatus() { |
|
310 |
return new StopEditingStatus(); |
|
311 |
} |
|
312 |
|
|
313 |
|
|
314 |
private JPanel getExplanationPanel(String name) { |
|
315 |
|
|
316 |
BorderLayout bl = new BorderLayout(10, 10); |
|
317 |
JPanel resp = new JPanel(bl); |
|
318 |
|
|
319 |
String msg = Messages.getText("realmente_desea_guardar"); |
|
320 |
JLabel topLabel = new JLabel(msg); |
|
321 |
|
|
322 |
JPanel mainPanel = new JPanel(new GridBagLayout()); |
|
323 |
GridBagConstraints cc = new GridBagConstraints(); |
|
324 |
|
|
325 |
cc.gridx = 0; |
|
326 |
cc.gridy = 0; |
|
327 |
cc.anchor = GridBagConstraints.WEST; |
|
328 |
|
|
329 |
cc.insets = new Insets(3, 6, 3, 6); |
|
330 |
|
|
331 |
Font boldf = mainPanel.getFont().deriveFont(Font.BOLD); |
|
332 |
|
|
333 |
JLabel lbl = new JLabel(Messages.getText("_Guardar")); |
|
334 |
lbl.setFont(boldf); |
|
335 |
mainPanel.add(lbl, cc); |
|
336 |
cc.gridx = 1; |
|
337 |
mainPanel.add(new JLabel(Messages.getText("_Save_changes_performed")), cc); |
|
338 |
|
|
339 |
cc.gridx = 0; |
|
340 |
cc.gridy = 1; |
|
341 |
lbl = new JLabel(Messages.getText("_Descartar")); |
|
342 |
lbl.setFont(boldf); |
|
343 |
mainPanel.add(lbl, cc); |
|
344 |
cc.gridx = 1; |
|
345 |
mainPanel.add(new JLabel(Messages.getText("_Discard_and_lose_changes")), cc); |
|
346 |
|
|
347 |
cc.gridx = 0; |
|
348 |
cc.gridy = 2; |
|
349 |
lbl = new JLabel(Messages.getText("_Continuar")); |
|
350 |
lbl.setFont(boldf); |
|
351 |
mainPanel.add(lbl, cc); |
|
352 |
cc.gridx = 1; |
|
353 |
mainPanel.add(new JLabel(Messages.getText("_Do_not_save_yet_Stay_in_editing_mode")), cc); |
|
354 |
|
|
355 |
resp.add(mainPanel, BorderLayout.CENTER); |
|
356 |
resp.add(topLabel, BorderLayout.NORTH); |
|
357 |
return resp; |
|
358 |
} |
|
359 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditChangeColumnsExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.PluginServices; |
|
26 |
import org.gvsig.andami.messages.NotificationManager; |
|
27 |
import org.gvsig.fmap.dal.exception.DataException; |
|
28 |
|
|
29 |
/** |
|
30 |
* DOCUMENT ME! |
|
31 |
* |
|
32 |
* @author Vicente Caballero Navarro |
|
33 |
*/ |
|
34 |
public class TableEditChangeColumnsExtension extends AbstractTableEditExtension { |
|
35 |
|
|
36 |
public void initialize() { |
|
37 |
super.initialize(); |
|
38 |
IconThemeHelper.registerIcon("action", "table-add-column", this); |
|
39 |
IconThemeHelper.registerIcon("action", "table-rename-column", this); |
|
40 |
IconThemeHelper.registerIcon("action", "table-remove-column", this); |
|
41 |
} |
|
42 |
/** |
|
43 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
44 |
*/ |
|
45 |
public void execute(String actionCommand) { |
|
46 |
try { |
|
47 |
featureTableOperations.setTablePanel(table); |
|
48 |
if ("table-remove-column".equals(actionCommand)) { |
|
49 |
featureTableOperations.deleteAttributes(table.getTablePanel() |
|
50 |
.getTable()); |
|
51 |
} else |
|
52 |
if ("table-add-column".equals(actionCommand)) { |
|
53 |
featureTableOperations.insertAttributes(table |
|
54 |
.getTablePanel().getTable()); |
|
55 |
} else |
|
56 |
if ("table-rename-column".equals(actionCommand)) { |
|
57 |
featureTableOperations.renameAttributes(table |
|
58 |
.getTablePanel().getTable()); |
|
59 |
} |
|
60 |
} catch (DataException e) { |
|
61 |
NotificationManager.showMessageError( |
|
62 |
PluginServices.getText(this, "update_featuretype_error"), null); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
69 |
*/ |
|
70 |
public boolean isEnabled() { |
|
71 |
try { |
|
72 |
if (table.getTablePanel().getTable().getSelectedColumnCount() > 0) { |
|
73 |
return true; |
|
74 |
} |
|
75 |
} catch (DataException e) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
return false; |
|
79 |
} |
|
80 |
} |
tags/extensions/org.gvsig.app.document.table.app/2.0.0/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/PrintTable.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.extension; |
|
23 |
|
|
24 |
import java.awt.Color; |
|
25 |
import java.awt.Graphics; |
|
26 |
import java.awt.Graphics2D; |
|
27 |
import java.awt.print.PageFormat; |
|
28 |
import java.awt.print.Printable; |
|
29 |
import java.awt.print.PrinterException; |
|
30 |
import java.awt.print.PrinterJob; |
|
31 |
|
|
32 |
import javax.swing.JTable; |
|
33 |
|
|
34 |
import org.gvsig.andami.IconThemeHelper; |
|
35 |
import org.gvsig.andami.PluginServices; |
|
36 |
import org.gvsig.andami.messages.NotificationManager; |
|
37 |
import org.gvsig.andami.plugins.Extension; |
Also available in: Unified diff