svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSFilterPanel.java @ 9391
History | View | Annotate | Download (41.1 KB)
1 |
package com.iver.cit.gvsig.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.event.KeyAdapter; |
5 |
import java.awt.event.KeyEvent; |
6 |
import java.awt.event.KeyListener; |
7 |
import java.awt.event.MouseAdapter; |
8 |
import java.awt.event.MouseEvent; |
9 |
import java.beans.PropertyChangeEvent; |
10 |
import java.beans.PropertyChangeListener; |
11 |
import java.io.UnsupportedEncodingException; |
12 |
import java.net.URLEncoder; |
13 |
import java.text.NumberFormat; |
14 |
import java.text.ParseException; |
15 |
import java.util.ArrayList; |
16 |
import java.util.Comparator; |
17 |
import java.util.HashMap; |
18 |
import java.util.Iterator; |
19 |
import java.util.Map; |
20 |
import java.util.Set; |
21 |
import java.util.StringTokenizer; |
22 |
import java.util.TreeSet; |
23 |
import java.util.Vector; |
24 |
import java.util.regex.Matcher; |
25 |
import java.util.regex.Pattern; |
26 |
|
27 |
import javax.swing.DefaultListModel; |
28 |
import javax.swing.JLabel; |
29 |
import javax.swing.JOptionPane; |
30 |
import javax.swing.JTextArea; |
31 |
import javax.swing.event.DocumentEvent; |
32 |
import javax.swing.event.DocumentListener; |
33 |
import javax.swing.event.TreeSelectionEvent; |
34 |
import javax.swing.event.TreeSelectionListener; |
35 |
import javax.swing.text.NumberFormatter; |
36 |
import javax.swing.tree.DefaultMutableTreeNode; |
37 |
import javax.swing.tree.DefaultTreeModel; |
38 |
import javax.swing.tree.TreePath; |
39 |
|
40 |
import org.apache.log4j.Logger; |
41 |
import org.gvsig.gui.beans.Messages; |
42 |
import org.gvsig.gui.beans.filterPanel.filterButtons.FilterButtonsJPanel; |
43 |
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.FilterQueryJPanel; |
44 |
import org.gvsig.remoteClient.gml.schemas.IXMLType; |
45 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
46 |
|
47 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
48 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
49 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
50 |
import com.hardcode.gdbms.engine.values.ComplexValue; |
51 |
import com.hardcode.gdbms.engine.values.NullValue; |
52 |
import com.hardcode.gdbms.engine.values.Value; |
53 |
import com.iver.andami.PluginServices; |
54 |
import com.iver.andami.messages.NotificationManager; |
55 |
import com.iver.andami.ui.mdiManager.IWindow; |
56 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
57 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
58 |
import com.iver.cit.gvsig.ProjectExtension; |
59 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
60 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
63 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
64 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
65 |
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode; |
66 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
67 |
import com.iver.cit.gvsig.gui.filter.ExpressionDataSource; |
68 |
import com.iver.cit.gvsig.gui.filter.ExpressionListener; |
69 |
import com.iver.cit.gvsig.gui.filter.FilterException; |
70 |
import com.iver.cit.gvsig.gui.panels.attributesTree.AttributesTreeTableModel; |
71 |
import com.iver.cit.gvsig.gui.panels.sqlQueryValidation.SQLQueryValidation; |
72 |
import com.iver.cit.gvsig.project.ProjectFactory; |
73 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
74 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
75 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
76 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
77 |
import com.iver.utiles.DefaultCharSet; |
78 |
import com.iver.utiles.StringUtilities; |
79 |
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport; |
80 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
81 |
|
82 |
|
83 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
84 |
*
|
85 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
86 |
*
|
87 |
* This program is free software; you can redistribute it and/or
|
88 |
* modify it under the terms of the GNU General Public License
|
89 |
* as published by the Free Software Foundation; either version 2
|
90 |
* of the License, or (at your option) any later version.
|
91 |
*
|
92 |
* This program is distributed in the hope that it will be useful,
|
93 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
94 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
95 |
* GNU General Public License for more details.
|
96 |
*
|
97 |
* You should have received a copy of the GNU General Public License
|
98 |
* along with this program; if not, write to the Free Software
|
99 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
100 |
*
|
101 |
* For more information, contact:
|
102 |
*
|
103 |
* Generalitat Valenciana
|
104 |
* Conselleria d'Infraestructures i Transport
|
105 |
* Av. Blasco Ib??ez, 50
|
106 |
* 46010 VALENCIA
|
107 |
* SPAIN
|
108 |
*
|
109 |
* +34 963862235
|
110 |
* gvsig@gva.es
|
111 |
* www.gvsig.gva.es
|
112 |
*
|
113 |
* or
|
114 |
*
|
115 |
* IVER T.I. S.A
|
116 |
* Salamanca 50
|
117 |
* 46005 Valencia
|
118 |
* Spain
|
119 |
*
|
120 |
* +34 963163400
|
121 |
* dac@iver.es
|
122 |
*/
|
123 |
|
124 |
/**
|
125 |
* This will be the tab for add a filter to a WFS query.
|
126 |
* This class gets the graphical interface from FilterQueryJPanel and add logic.
|
127 |
*
|
128 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
129 |
*/
|
130 |
public class WFSFilterPanel extends FilterQueryJPanel implements IWindow, IWindowListener { |
131 |
private static Logger logger = Logger.getLogger(Table.class.getName()); |
132 |
private WFSParamsPanel parent = null; |
133 |
private ArrayList expressionListeners = new ArrayList(); |
134 |
private ExpressionDataSource model = null; |
135 |
private NumberFormat nf = NumberFormat.getNumberInstance(); |
136 |
private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport(); |
137 |
private AttributesTreeTableModel attributesTreeTableModel;
|
138 |
private boolean panelAsATabForWFSLayersLoad; |
139 |
private TreePath currentPath; |
140 |
private String featureName; |
141 |
private Map allFieldsAndValuesKnownOfCurrentLayer; // This will have all values (not repeated) known of all fields (not repeated) |
142 |
|
143 |
///// GUI METHODS ////
|
144 |
|
145 |
/**
|
146 |
* This method initializes
|
147 |
*
|
148 |
* @param parent A reference to the parent container component of this component
|
149 |
*/
|
150 |
public WFSFilterPanel(WFSParamsPanel parent) {
|
151 |
super();
|
152 |
this.parent = parent;
|
153 |
currentPath = null;
|
154 |
featureName = null;
|
155 |
allFieldsAndValuesKnownOfCurrentLayer = new HashMap(); // Initial capacity = 0 |
156 |
|
157 |
// At beginning, the JList is disabled (and its set a particular color for user could knew it)
|
158 |
super.getValuesJList().setEnabled(false); |
159 |
getValuesJList().setBackground(new Color(220, 220, 220)); |
160 |
} |
161 |
|
162 |
/*
|
163 |
* (non-Javadoc)
|
164 |
* @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
|
165 |
*/
|
166 |
protected void initialize() { |
167 |
super.initialize();
|
168 |
this.resizeHeight(380); |
169 |
|
170 |
defaultTreeModel = (DefaultTreeModel)fieldsJTree.getModel();
|
171 |
|
172 |
this.addNewListeners();
|
173 |
panelAsATabForWFSLayersLoad = true;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Adds some more listener to the components of the panel
|
178 |
*/
|
179 |
private void addNewListeners() { |
180 |
|
181 |
// Enable "Apply" button when user changes the filter query
|
182 |
txtExpression.getDocument().addDocumentListener(new DocumentListener() { |
183 |
/*
|
184 |
* (non-Javadoc)
|
185 |
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
186 |
*/
|
187 |
public void changedUpdate(DocumentEvent e) { |
188 |
} |
189 |
|
190 |
/*
|
191 |
* (non-Javadoc)
|
192 |
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
193 |
*/
|
194 |
public void insertUpdate(DocumentEvent e) { |
195 |
if (!panelAsATabForWFSLayersLoad)
|
196 |
parent.isApplicable(true);
|
197 |
} |
198 |
|
199 |
/*
|
200 |
* (non-Javadoc)
|
201 |
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
202 |
*/
|
203 |
public void removeUpdate(DocumentEvent e) { |
204 |
if (!panelAsATabForWFSLayersLoad)
|
205 |
parent.isApplicable(true);
|
206 |
} |
207 |
}); |
208 |
|
209 |
// Listener for "fieldsJTree"
|
210 |
getFieldsJTree().addMouseListener(new MouseAdapter() { |
211 |
/*
|
212 |
* (non-Javadoc)
|
213 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
214 |
*/
|
215 |
public void mouseClicked(MouseEvent e) { |
216 |
int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
|
217 |
TreePath treePath = fieldsJTree.getPathForLocation(e.getX(), e.getY());
|
218 |
|
219 |
if (row > -1) { |
220 |
switch (e.getClickCount()) {
|
221 |
case 2: |
222 |
putSymbolOfSelectedByMouseBranch(treePath); |
223 |
break;
|
224 |
} |
225 |
} |
226 |
} |
227 |
}); |
228 |
|
229 |
// Listener for "valuesJList"
|
230 |
getValuesJList().addMouseListener(new MouseAdapter() { |
231 |
/*
|
232 |
* (non-Javadoc)
|
233 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
234 |
*/
|
235 |
public void mouseClicked(MouseEvent e) { |
236 |
int index = getValuesJList().getSelectedIndex();
|
237 |
|
238 |
if (index == -1) |
239 |
return;
|
240 |
|
241 |
if (e.getClickCount() == 2){ |
242 |
String valor = ((JLabel) valuesListModel.getElementAt(index)).getText(); |
243 |
|
244 |
// If value is an string -> set it between apostrophes
|
245 |
if (getNodeOfCurrentPath().getEntityType().getName().compareTo("xs:string") == 0) { |
246 |
putSymbol("'" + valor + "'"); |
247 |
} |
248 |
else {
|
249 |
putSymbol(valor); |
250 |
} |
251 |
} |
252 |
} |
253 |
}); |
254 |
|
255 |
// Listener for a branch of the tree selection
|
256 |
getFieldsJTree().addTreeSelectionListener(new TreeSelectionListener() { |
257 |
/*
|
258 |
* (non-Javadoc)
|
259 |
* @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
|
260 |
*/
|
261 |
public void valueChanged(TreeSelectionEvent e) { |
262 |
if (!panelAsATabForWFSLayersLoad) {
|
263 |
DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource(); |
264 |
|
265 |
if ((data != null) && (data.getData() != null)) { |
266 |
// setModel(data.getData());
|
267 |
currentPath = e.getPath(); |
268 |
fillValuesByPath(currentPath); |
269 |
} |
270 |
} |
271 |
} |
272 |
}); |
273 |
|
274 |
// Listener: when a user writes something on the textarea -> set it's foreground color to black
|
275 |
getTxtExpression().getDocument().addDocumentListener(new DocumentListener() { |
276 |
/*
|
277 |
* (non-Javadoc)
|
278 |
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
279 |
*/
|
280 |
public void changedUpdate(DocumentEvent e) { |
281 |
} |
282 |
|
283 |
/*
|
284 |
* (non-Javadoc)
|
285 |
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
286 |
*/
|
287 |
public void insertUpdate(DocumentEvent e) { |
288 |
getTxtExpression().setForeground(Color.BLACK);
|
289 |
} |
290 |
|
291 |
/*
|
292 |
* (non-Javadoc)
|
293 |
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
294 |
*/
|
295 |
public void removeUpdate(DocumentEvent e) { |
296 |
getTxtExpression().setForeground(Color.BLACK);
|
297 |
} |
298 |
}); |
299 |
|
300 |
// .addKeyListener(new KeyAdapter() {
|
301 |
// /*
|
302 |
// * (non-Javadoc)
|
303 |
// * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
304 |
// */
|
305 |
// public void keyTyped(KeyEvent e) {
|
306 |
// ((JTextArea)e.getSource()).setForeground(Color.black);
|
307 |
// }
|
308 |
// });
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Gets the element that the 'currentPath' attribute aims
|
313 |
*
|
314 |
* @return An XMLElement
|
315 |
*/
|
316 |
private XMLElement getNodeOfCurrentPath() {
|
317 |
|
318 |
if (currentPath != null) { |
319 |
Object node = currentPath.getLastPathComponent();
|
320 |
|
321 |
if ((node != null) && (node instanceof XMLElement)) { |
322 |
// XMLElement element = (XMLElement) node;
|
323 |
return (XMLElement) node;
|
324 |
} |
325 |
} |
326 |
|
327 |
return null; |
328 |
} |
329 |
|
330 |
/**
|
331 |
* Puts the symbol of selected brach
|
332 |
*
|
333 |
* @param mouseEvent A MouseEvent with information of the selected branch
|
334 |
*/
|
335 |
public void putSymbolOfSelectedByMouseBranch(TreePath treePath) { |
336 |
// Sets the node selected
|
337 |
if (treePath != null) { |
338 |
Object node = treePath.getLastPathComponent();
|
339 |
if ((node != null) && (node instanceof XMLElement)) { |
340 |
XMLElement element = (XMLElement) node; |
341 |
XMLElement parent = element.getParentElement(); |
342 |
String path = element.getName();
|
343 |
while (parent.getParentElement() != null){ |
344 |
path = parent.getName() + "/" + path;
|
345 |
parent = parent.getParentElement(); |
346 |
} |
347 |
putSymbol("\"" + path + "\""); |
348 |
} |
349 |
} |
350 |
} |
351 |
|
352 |
/**
|
353 |
* Gets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
|
354 |
*
|
355 |
* @return A boolean value
|
356 |
*/
|
357 |
public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() { |
358 |
return this.panelAsATabForWFSLayersLoad; |
359 |
} |
360 |
|
361 |
/**
|
362 |
* Sets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
|
363 |
*
|
364 |
* @param b A boolean value
|
365 |
*/
|
366 |
public void setWFSFilterPanelIsAsTabForWFSLayersLoad (boolean b) { |
367 |
this.panelAsATabForWFSLayersLoad = b;
|
368 |
|
369 |
if (this.panelAsATabForWFSLayersLoad == true) { |
370 |
// At beginning, the JList is disabled (and its set a particular color for user could knew it)
|
371 |
super.getValuesJList().setEnabled(false); |
372 |
super.getValuesJList().setBackground(new Color(220, 220, 220)); // a grey color |
373 |
|
374 |
this.allFieldsAndValuesKnownOfCurrentLayer.clear();
|
375 |
} |
376 |
else {
|
377 |
// Unselect the selected path in the tree (if there was any selected)
|
378 |
if (this.currentPath != null) { |
379 |
this.currentPath = null; |
380 |
this.getFieldsJTree().removeSelectionPath(this.getFieldsJTree().getSelectionPath()); |
381 |
} |
382 |
|
383 |
// Resets data loaded
|
384 |
super.getValuesJList().setEnabled(true); |
385 |
super.getValuesJList().setBackground(Color.WHITE); |
386 |
|
387 |
this.getFieldsJTree().removeAll();
|
388 |
this.getValuesJList().removeAll();
|
389 |
|
390 |
// Updates data associated to view with the new layer data
|
391 |
this.setNewDataToTable();
|
392 |
|
393 |
// If theres is any table associated to the current view -> update that table/s
|
394 |
// this.updateTablesThatHasNewData();
|
395 |
|
396 |
// Reads that new data
|
397 |
DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource(); |
398 |
|
399 |
if ((data != null) && (data.getData() != null)) { |
400 |
setModel(data.getData()); |
401 |
// currentPath = e.getPath();
|
402 |
// fillValuesByPath(currentPath);
|
403 |
} |
404 |
|
405 |
// Loads values known of fields
|
406 |
this.setValuesKnownOfFields();
|
407 |
} |
408 |
} |
409 |
|
410 |
/**
|
411 |
* Refresh all information about fields
|
412 |
*
|
413 |
* @param feature
|
414 |
*/
|
415 |
public void refresh(WFSLayerNode feature) { |
416 |
featureName = feature.getTitle(); |
417 |
setFields(feature); |
418 |
} |
419 |
|
420 |
///// END GUI METHODS /////
|
421 |
|
422 |
///// METHODS FOR THE FILTER QUERY /////
|
423 |
|
424 |
/**
|
425 |
* Gets the query that will be send to the server
|
426 |
* @return SQL query (just the where part)
|
427 |
*/
|
428 |
public String getQuery(){ |
429 |
String writtenQuery = txtExpression.getText().trim();
|
430 |
|
431 |
// Validate expression
|
432 |
if (!this.validateExpression(writtenQuery)) { |
433 |
getTxtExpression().setForeground(Color.red);
|
434 |
return null; |
435 |
} |
436 |
else
|
437 |
// Codify expression (only if the validation has been successful)
|
438 |
return this.codifyExpression(writtenQuery); // Ignores the spaces at beginning and end of the chain of characters |
439 |
} |
440 |
|
441 |
/**
|
442 |
* Gets the filter expression from the user interface
|
443 |
*/
|
444 |
public String getFilterExpressionFromInterface() { |
445 |
return getTxtExpression().getText();
|
446 |
} |
447 |
|
448 |
/**
|
449 |
* Writes the filter expression into the user interface
|
450 |
* @param filterExpression An string
|
451 |
*/
|
452 |
public void setFilterExpressionIntoInterface(String filterExpression){ |
453 |
getTxtExpression().setText(filterExpression); |
454 |
} |
455 |
|
456 |
/**
|
457 |
* Codifies the expression to ISO ISO-8859_1 and a format that the SQL parser could validate
|
458 |
*
|
459 |
* @param expression The expression to be codified
|
460 |
*
|
461 |
* @return The expression codified
|
462 |
*/
|
463 |
private String codifyExpression(String expression) { |
464 |
String result = new String(""); |
465 |
|
466 |
try
|
467 |
{ |
468 |
// Encode each string of the query
|
469 |
int index = 0; |
470 |
int lastIndex = 0; |
471 |
boolean endInnerLoop;
|
472 |
// Encodes all inner strings to the equivalent codification in ISO-8859_1 with each ' symbol converted to ''
|
473 |
while (index != -1) { |
474 |
index = expression.indexOf("'", index);
|
475 |
|
476 |
// Add the parts of the chain of characters that not are string
|
477 |
if (index == -1) { |
478 |
result += expression.substring(lastIndex, expression.length()); |
479 |
} |
480 |
else {
|
481 |
result += expression.substring(lastIndex, index).replaceAll(" [ ]+", " "); |
482 |
} |
483 |
|
484 |
lastIndex = index; |
485 |
endInnerLoop = false;
|
486 |
|
487 |
// Tries to find each first apostrophe of each string of the query
|
488 |
if ((index > 0) && (expression.charAt(index - 1) == ' ')) { |
489 |
index++; |
490 |
|
491 |
// Ignore all inner apostrophes and try to find the last of the string
|
492 |
while (!endInnerLoop) {
|
493 |
index = expression.indexOf("'", index);
|
494 |
index++; |
495 |
|
496 |
// If we haven't arrived to the finish of the string
|
497 |
if (index != expression.length()) {
|
498 |
if ((index == -1) || (expression.charAt(index) == ' ')) { |
499 |
result += translateString(expression.substring(lastIndex, index)); |
500 |
endInnerLoop = true;
|
501 |
} |
502 |
} |
503 |
else {
|
504 |
result += translateString(expression.substring(lastIndex, index)); |
505 |
endInnerLoop = true;
|
506 |
index = -1; // Force to finish the external loop |
507 |
} |
508 |
} |
509 |
lastIndex = index; |
510 |
} |
511 |
} |
512 |
|
513 |
// Field names are transformated in xix variables that will be analyzed
|
514 |
// Date(date) is substituted by the correct date format
|
515 |
result = translateDates(result); |
516 |
result = translateNumber(result); |
517 |
result = translateWord(result, "true", "1"); |
518 |
result = translateWord(result, "false", "0"); |
519 |
|
520 |
logger.debug(result); |
521 |
} |
522 |
catch(Exception e) { |
523 |
JOptionPane.showMessageDialog(this, Messages.getText("error_coding_filter_query"), Messages.getText("error"), JOptionPane.ERROR_MESSAGE); |
524 |
return null; |
525 |
} |
526 |
|
527 |
return result;
|
528 |
} |
529 |
|
530 |
/**
|
531 |
* Checks the filter expression if it's correct
|
532 |
*
|
533 |
* @param query The query expression to analyze
|
534 |
* @return True if it's valid or false if not
|
535 |
*/
|
536 |
private boolean validateExpression(String query) { |
537 |
SQLQueryValidation sQLQueryValidation = new SQLQueryValidation(query, true); |
538 |
|
539 |
// StringTokenizer tokens = new StringTokenizer(query, " ");
|
540 |
// String token;
|
541 |
// Set operatorNamesAndSymbols = getOperatorNamesAndSymbols();
|
542 |
//
|
543 |
// while (tokens.hasMoreTokens()) {
|
544 |
// token = tokens.nextToken();
|
545 |
//
|
546 |
// // If it's an string or date (between ' ') -> ignore
|
547 |
// if (! ((token.charAt(0) == token.charAt(token.length() - 1)) && (token.charAt(0) == '\''))) {
|
548 |
//
|
549 |
// // If it's a number
|
550 |
// if ((! StringNumberUtilities.isNumber(token)) && (this.isAField(token)) && (this.isAnOperatorNameOrSymbol(token, operatorNamesAndSymbols))) {
|
551 |
// return false;
|
552 |
// }
|
553 |
// }
|
554 |
// }
|
555 |
|
556 |
// Tries to validate the query, and if fails shows a message
|
557 |
if (!sQLQueryValidation.validateQuery()) {
|
558 |
JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_validating_sql_filter_query") + ":\n" + sQLQueryValidation.getErrorMessage(), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE); |
559 |
return false; |
560 |
} |
561 |
else
|
562 |
return true; |
563 |
} |
564 |
|
565 |
/**
|
566 |
* Returns true if there is a field with the same name as 'text'
|
567 |
*
|
568 |
* @param text An string
|
569 |
* @return A boolean value
|
570 |
*/
|
571 |
private boolean isAField(String text) { |
572 |
return this.allFieldsAndValuesKnownOfCurrentLayer.containsKey(text); |
573 |
} |
574 |
|
575 |
/**
|
576 |
* Returns true if there is the 'text' is a symbol or a operator name
|
577 |
*
|
578 |
* @param text An string
|
579 |
* @return A boolean value
|
580 |
*/
|
581 |
private boolean isAnOperatorNameOrSymbol(String text, Set operatorNamesAndSymbols) { |
582 |
return operatorNamesAndSymbols.contains(text);
|
583 |
} |
584 |
|
585 |
/**
|
586 |
* DOCUMENT ME!
|
587 |
*
|
588 |
* @return DOCUMENT ME!
|
589 |
*
|
590 |
* @throws ParseException DOCUMENT ME!
|
591 |
* @deprecated In this moments its a reference of the old Validate Expression method
|
592 |
*/
|
593 |
private String oldValidateExpressionMethod() throws ParseException { |
594 |
String expression = txtExpression.getText();
|
595 |
// HashSet variablesIndexes = new HashSet();
|
596 |
//
|
597 |
// StringBuffer traducida = new StringBuffer();
|
598 |
|
599 |
//Se transforman los nombres de los campos en las variables xix que analizar?n
|
600 |
//Se quitan los Date(fecha) y se mete la fecha correspondiente
|
601 |
expression = translateDates(expression); |
602 |
expression = translateNumber(expression); |
603 |
expression = translateWord(expression, "true", "1"); |
604 |
expression = translateWord(expression, "false", "0"); |
605 |
|
606 |
String replacement;
|
607 |
Pattern patron = Pattern.compile("[^<>!]="); |
608 |
Matcher m = patron.matcher(expression);
|
609 |
int index = 0; |
610 |
|
611 |
while (m.find(index)) {
|
612 |
index = m.start(); |
613 |
replacement = expression.charAt(index) + "==";
|
614 |
m.replaceFirst(replacement); |
615 |
index++; |
616 |
} |
617 |
|
618 |
expression = expression.replaceAll("[^<>!]=", "=="); |
619 |
|
620 |
logger.debug(expression); |
621 |
|
622 |
return expression;
|
623 |
} |
624 |
|
625 |
///// END METHODS FOR THE FILTER QUERY /////
|
626 |
|
627 |
///// METHODS FOR TRANSLATE DATA IN FILTER SENTENCES /////
|
628 |
|
629 |
/**
|
630 |
* DOCUMENT ME!
|
631 |
*
|
632 |
* @param expresion DOCUMENT ME!
|
633 |
* @param word DOCUMENT ME!
|
634 |
* @param translation DOCUMENT ME!
|
635 |
*
|
636 |
* @return DOCUMENT ME!
|
637 |
*
|
638 |
* @throws ParseException DOCUMENT ME!
|
639 |
*/
|
640 |
private String translateWord(String expresion, String word, String translation) throws ParseException { |
641 |
int booleanIndex = 0; |
642 |
int endIndex = 0; |
643 |
StringBuffer res = new StringBuffer(); |
644 |
|
645 |
while ((booleanIndex = getIndex(expresion, word, booleanIndex)) != -1) { |
646 |
res.append(expresion.substring(endIndex, booleanIndex)); |
647 |
endIndex = booleanIndex + word.length(); |
648 |
booleanIndex++; |
649 |
res.append(translation); |
650 |
} |
651 |
|
652 |
if (endIndex < expresion.length()) {
|
653 |
res.append(expresion.substring(endIndex)); |
654 |
} |
655 |
|
656 |
return res.toString();
|
657 |
} |
658 |
|
659 |
/**
|
660 |
* DOCUMENT ME!
|
661 |
*
|
662 |
* @param expresion DOCUMENT ME!
|
663 |
*
|
664 |
* @return DOCUMENT ME!
|
665 |
*
|
666 |
* @throws ParseException DOCUMENT ME!
|
667 |
*/
|
668 |
private String translateDates(String expresion) throws ParseException { |
669 |
//Se obtiene el valor de la fecha
|
670 |
String date = StringUtilities.substringDelimited(expresion, "Date(", ")", 0); |
671 |
|
672 |
if (date == null) { |
673 |
return expresion;
|
674 |
} |
675 |
|
676 |
//Se comprueba que no est? entre comillas
|
677 |
int startIndex = expresion.indexOf(date);
|
678 |
|
679 |
while (startIndex != -1) { |
680 |
if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) { |
681 |
|
682 |
//Se sustituye por el valor ordinal de la fecha
|
683 |
expresion = expresion.substring(0, startIndex - 5) + |
684 |
expresion.substring(startIndex).replaceFirst(date + "\\)",
|
685 |
new Long((filterButtonsJPanel.getDateFormat().parse(date)).getTime()).toString()); |
686 |
|
687 |
} else {
|
688 |
startIndex += date.length(); |
689 |
} |
690 |
|
691 |
if (date == null) { |
692 |
return expresion;
|
693 |
} |
694 |
|
695 |
startIndex = expresion.indexOf(date, startIndex); |
696 |
} |
697 |
|
698 |
return expresion;
|
699 |
} |
700 |
|
701 |
/**
|
702 |
* DOCUMENT ME!
|
703 |
*
|
704 |
* @param expresion DOCUMENT ME!
|
705 |
*
|
706 |
* @return DOCUMENT ME!
|
707 |
*
|
708 |
* @throws ParseException DOCUMENT ME!
|
709 |
*/
|
710 |
private String translateNumber(String expresion) throws ParseException { |
711 |
DefaultCharSet ss = new DefaultCharSet();
|
712 |
ss.addInterval('0', '9'); |
713 |
ss.addCharacter(',');
|
714 |
ss.addCharacter('.');
|
715 |
|
716 |
String number = StringUtilities.substringWithSymbols(expresion, ss, 0); |
717 |
|
718 |
if (number == null) { |
719 |
return expresion;
|
720 |
} |
721 |
|
722 |
int startIndex = expresion.indexOf(number);
|
723 |
|
724 |
while (startIndex != -1) { |
725 |
Number n = nf.parse(number);
|
726 |
|
727 |
if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) { |
728 |
|
729 |
//Se sustituye por el valor ordinal de la fecha
|
730 |
expresion = expresion.substring(0, startIndex) +
|
731 |
expresion.substring(startIndex).replaceFirst(number, |
732 |
n.toString()); |
733 |
} else {
|
734 |
startIndex += n.toString().length(); |
735 |
} |
736 |
|
737 |
number = StringUtilities.substringWithSymbols(expresion, ss, |
738 |
startIndex); |
739 |
|
740 |
if (number == null) { |
741 |
return expresion;
|
742 |
} |
743 |
|
744 |
startIndex = expresion.indexOf(number, startIndex); |
745 |
} |
746 |
|
747 |
return expresion;
|
748 |
} |
749 |
|
750 |
/**
|
751 |
* Encodes an string to ISO 8859_1 with each ' symbol converted to ''
|
752 |
*
|
753 |
* @param text An string started and finished with simple apostrophes
|
754 |
*
|
755 |
* @return An string started and finished with simple apostrophes
|
756 |
*/
|
757 |
private String translateString(String text) { |
758 |
// Encode to the string to ISO 8859_1 (the URL codification)
|
759 |
try {
|
760 |
|
761 |
// Ignore the first and last apostrophes
|
762 |
if (text.length() > 2) { |
763 |
text = text.substring(1, text.length() -1); |
764 |
|
765 |
// Convert the string to ISO 8859_1 codification
|
766 |
text = URLEncoder.encode(text, "8859_1"); |
767 |
|
768 |
// Change ' (%27 code) to '' for the SQL parser (bebore sent the query)
|
769 |
text = text.replaceAll("\\%27", "\\'\\'"); |
770 |
} |
771 |
|
772 |
} catch (UnsupportedEncodingException e1) { |
773 |
e1.printStackTrace(); |
774 |
} |
775 |
|
776 |
return "'" + text + "'"; |
777 |
} |
778 |
|
779 |
///// END METHODS FOR TRANSLATE DATA IN FILTER SENTENCES /////
|
780 |
|
781 |
///// METHODS FOR MANIPULATE 'fields' and 'values' /////
|
782 |
|
783 |
/**
|
784 |
* DOCUMENT ME!
|
785 |
*
|
786 |
* @param t DOCUMENT ME!
|
787 |
*/
|
788 |
public void setModel(ExpressionDataSource t) { |
789 |
try {
|
790 |
model = t; |
791 |
model.start(); |
792 |
} catch (DriverException e1) {
|
793 |
NotificationManager.addError(e1.getMessage(), e1); |
794 |
} |
795 |
|
796 |
try {
|
797 |
int numberOfFields = model.getFieldCount();
|
798 |
|
799 |
if (numberOfFields > 0) { |
800 |
Vector fields = new Vector(0, 1); |
801 |
int j = 0; |
802 |
|
803 |
for (int i = 0; i < numberOfFields; i++) { |
804 |
Object field = model.getFieldName(i);
|
805 |
|
806 |
if (field != null) { |
807 |
fields.add(field); |
808 |
j++; |
809 |
} |
810 |
} |
811 |
|
812 |
attributesTreeTableModel = new AttributesTreeTableModel(fields.toArray());
|
813 |
} |
814 |
} catch (FilterException e) {
|
815 |
throwException(e); |
816 |
} |
817 |
} |
818 |
|
819 |
/**
|
820 |
* If there is a field selected, show its new values
|
821 |
*/
|
822 |
public void updateFieldValues() { |
823 |
if (currentPath != null) { |
824 |
|
825 |
DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource(); |
826 |
|
827 |
if ((data != null) && (data.getData() != null)) { |
828 |
setModel(data.getData()); |
829 |
fillValuesByPath(currentPath); |
830 |
|
831 |
// valuesListModel.clear();
|
832 |
|
833 |
// Updates all tables that their data is about the changed view
|
834 |
this.updateTablesThatHasNewData();
|
835 |
} |
836 |
} |
837 |
} |
838 |
|
839 |
/**
|
840 |
* Sets Fields
|
841 |
*
|
842 |
* @param feature A Layer node with fields information
|
843 |
*/
|
844 |
private void setFields(WFSLayerNode feature) { |
845 |
Vector fields = feature.getFields();
|
846 |
|
847 |
this.resetFieldsAndValuesData();
|
848 |
|
849 |
int numberOfFields = fields.size();
|
850 |
|
851 |
if (numberOfFields > 0) { |
852 |
Vector fieldBranches = new Vector(0, 1); |
853 |
|
854 |
for (int i=0; i<fields.size(); i++) { |
855 |
XMLElement field = (XMLElement)fields.get(i); |
856 |
|
857 |
IXMLType type = field.getEntityType(); |
858 |
|
859 |
if (type != null) { |
860 |
|
861 |
switch (type.getType()) {
|
862 |
case IXMLType.GML_GEOMETRY: // Don't add branch / field |
863 |
break;
|
864 |
case IXMLType.COMPLEX: case IXMLType.SIMPLE: // Add branch / field |
865 |
fieldBranches.add(field); |
866 |
|
867 |
break;
|
868 |
} |
869 |
} |
870 |
} |
871 |
|
872 |
attributesTreeTableModel = new AttributesTreeTableModel(fieldBranches.get(0)); |
873 |
fieldsJTree.setModel(new AttributesTreeTableModel(fieldBranches.get(0), false)); |
874 |
|
875 |
// Stores the name of all leafs (fields) of treeTableModel
|
876 |
Object root = attributesTreeTableModel.getRoot();
|
877 |
|
878 |
if (root != null) { |
879 |
Vector fieldsNames = attributesTreeTableModel.getLeafsFromNodeBranch(root);
|
880 |
|
881 |
for (int j = 0; j < fieldsNames.size(); j++) { |
882 |
Object field = fieldsNames.get(j);
|
883 |
|
884 |
// Avoid errors
|
885 |
if ( (! (field instanceof XMLElement)) || (field == null) ) |
886 |
continue;
|
887 |
|
888 |
// Don't load a geometry field
|
889 |
if ( ((XMLElement)field).getEntityType().getType() == IXMLType.GML_GEOMETRY )
|
890 |
continue;
|
891 |
|
892 |
if (! allFieldsAndValuesKnownOfCurrentLayer.containsKey( ((XMLElement)field).getName()) ) {
|
893 |
allFieldsAndValuesKnownOfCurrentLayer.put(((XMLElement)field).getName(), new HashMap()); |
894 |
} |
895 |
} |
896 |
} |
897 |
} |
898 |
} |
899 |
|
900 |
/**
|
901 |
* This method load all values known of all fields known
|
902 |
* (It's used when a new layer is load)
|
903 |
*/
|
904 |
private void setValuesKnownOfFields() { |
905 |
// Desde el modelo se deber?a acceder a los campos y sus valores cargados
|
906 |
try {
|
907 |
for (int i = 0; i < model.getFieldCount(); i++) { |
908 |
String fieldName = model.getFieldName(i);
|
909 |
HashMap fieldValues = (HashMap) allFieldsAndValuesKnownOfCurrentLayer.get(fieldName); |
910 |
|
911 |
if (fieldValues != null) { |
912 |
for (int j = 0; j < model.getRowCount(); j++) { |
913 |
Value value = model.getFieldValue(j, i); |
914 |
|
915 |
if (value instanceof NullValue) |
916 |
continue;
|
917 |
|
918 |
Object obj = (Object)value; |
919 |
|
920 |
if (obj == null) |
921 |
continue;
|
922 |
|
923 |
fieldValues.put(obj.toString(), obj.toString()); |
924 |
|
925 |
} |
926 |
} |
927 |
} |
928 |
} |
929 |
catch (Exception e) { |
930 |
e.printStackTrace(); |
931 |
} |
932 |
} |
933 |
|
934 |
/**
|
935 |
* Resets the data of fields and their values of the current layer feature, and removes the branches of JTree
|
936 |
*/
|
937 |
private void resetFieldsAndValuesData() { |
938 |
fieldsJTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); |
939 |
txtExpression.setText("");
|
940 |
((DefaultListModel)valuesJList.getModel()).removeAllElements();
|
941 |
} |
942 |
|
943 |
/**
|
944 |
* FIlls list with the values of selected field
|
945 |
*
|
946 |
* @param treePath A path in the tree
|
947 |
*/
|
948 |
private void fillValuesByPath(TreePath treePath) { |
949 |
// Duplicates are removed
|
950 |
TreeSet conjunto = new TreeSet(new Comparator() { |
951 |
public int compare(Object o1, Object o2) { |
952 |
if ((o1 != null) && (o2 != null)) { |
953 |
Value v2 = (Value) o2; |
954 |
Value v1 = (Value) o1; |
955 |
BooleanValue boolVal; |
956 |
|
957 |
try {
|
958 |
boolVal = (BooleanValue) (v1.greater(v2)); |
959 |
|
960 |
if (boolVal.getValue()) {
|
961 |
return 1; |
962 |
} |
963 |
|
964 |
boolVal = (BooleanValue) (v1.less(v2)); |
965 |
|
966 |
if (boolVal.getValue()) {
|
967 |
return -1; |
968 |
} |
969 |
} catch (IncompatibleTypesException e) {
|
970 |
throw new RuntimeException(e); |
971 |
} |
972 |
} |
973 |
|
974 |
return 0; |
975 |
} |
976 |
}); // For ordernation
|
977 |
|
978 |
// Remove the previous items
|
979 |
valuesListModel.clear(); |
980 |
|
981 |
try {
|
982 |
//Object root = treePath.getPath()[0];
|
983 |
XMLElement element = ((XMLElement)treePath.getLastPathComponent()); |
984 |
|
985 |
// Gets the values associated to the selected branch
|
986 |
switch (element.getEntityType().getType()) {
|
987 |
case IXMLType.SIMPLE:
|
988 |
|
989 |
if(element.getParentElement().getParentElement() == null) { |
990 |
// Find the selected field and try to obtein values related
|
991 |
for (int i = 0; i < model.getFieldCount(); i++) { |
992 |
String name = model.getFieldName(i);
|
993 |
|
994 |
// If we find the field (this means that are loaded its values and we can obtein them)
|
995 |
if (name.equals(element.getName())) {
|
996 |
for (int j = 0; j < model.getRowCount(); j++) { |
997 |
Value value = model.getFieldValue(j, i); |
998 |
|
999 |
if (value instanceof NullValue) |
1000 |
continue;
|
1001 |
|
1002 |
if (!conjunto.contains(value)) {
|
1003 |
conjunto.add(value); |
1004 |
} |
1005 |
} |
1006 |
|
1007 |
break;
|
1008 |
} |
1009 |
} |
1010 |
}else{
|
1011 |
//create a vector with the parent names from the leaf until the root
|
1012 |
XMLElement parent = element.getParentElement(); |
1013 |
Vector parentNames = new Vector(); |
1014 |
parentNames.add(element.getName()); |
1015 |
while (parent != null){ |
1016 |
parentNames.add(parent.getName()); |
1017 |
parent = parent.getParentElement(); |
1018 |
} |
1019 |
|
1020 |
//The field name (in the gvSIG table) is the second field name
|
1021 |
String fieldName = (String)parentNames.get(parentNames.size()-2); |
1022 |
|
1023 |
for (int i = 0; i < model.getFieldCount(); i++) { |
1024 |
String name = model.getFieldName(i);
|
1025 |
|
1026 |
// If we find the field (this means that are loaded its values and we can obtein them)
|
1027 |
if (name.equals(fieldName)) {
|
1028 |
for (int j = 0; j < model.getRowCount(); j++) { |
1029 |
Value value = model.getFieldValue(j, i); |
1030 |
|
1031 |
if (value instanceof NullValue) |
1032 |
continue;
|
1033 |
|
1034 |
if (value instanceof ComplexValue){ |
1035 |
for (int k=parentNames.size()-3 ; k>=0 ; k--){ |
1036 |
ComplexValue complex = (ComplexValue)value; |
1037 |
Value childValue = (Value)complex.get(parentNames.get(k)); |
1038 |
if (k==0){ |
1039 |
if (!conjunto.contains(childValue)) {
|
1040 |
conjunto.add(childValue); |
1041 |
} |
1042 |
}else{
|
1043 |
value = childValue; |
1044 |
} |
1045 |
} |
1046 |
} |
1047 |
} |
1048 |
|
1049 |
break;
|
1050 |
} |
1051 |
} |
1052 |
} |
1053 |
break;
|
1054 |
case IXMLType.COMPLEX:
|
1055 |
break;
|
1056 |
default:
|
1057 |
// Do Nothing
|
1058 |
} |
1059 |
|
1060 |
// Add the values to the model of the graphic list
|
1061 |
Iterator it = conjunto.iterator();
|
1062 |
Object[] objects = currentPath.getPath(); |
1063 |
|
1064 |
if (objects.length == 0) |
1065 |
return;
|
1066 |
|
1067 |
String selectedField = ((XMLElement)objects[objects.length-1]).getName(); // Gets the selected field |
1068 |
|
1069 |
if (selectedField != null) { // If there is a selected field |
1070 |
Map fieldValues = (HashMap)allFieldsAndValuesKnownOfCurrentLayer.get(selectedField); // Gets valus stored associated to this field |
1071 |
JLabel currentValueLabel = null; |
1072 |
|
1073 |
// If the field doesn't exits -> create a new Map with its values
|
1074 |
if (fieldValues == null) { |
1075 |
fieldValues = new HashMap(); |
1076 |
allFieldsAndValuesKnownOfCurrentLayer.put(selectedField, fieldValues); |
1077 |
|
1078 |
while (it.hasNext()) {
|
1079 |
// A label with text with yelow background color for values that are loaded in the layer
|
1080 |
currentValueLabel = new JLabelValueLoaded();
|
1081 |
|
1082 |
currentValueLabel.setText(it.next().toString()); |
1083 |
|
1084 |
if (currentValueLabel.getText().compareTo("") != 0) { |
1085 |
fieldValues.put(currentValueLabel.getText(), currentValueLabel.getText()); |
1086 |
|
1087 |
// All values loaded in this loop must be at beginning of the list (and in a differenciated color)
|
1088 |
if ( ! valuesListModel.contains(currentValueLabel) )
|
1089 |
valuesListModel.addElement(currentValueLabel); |
1090 |
} |
1091 |
} |
1092 |
} |
1093 |
else { // Else -> Adds the new ones, and changes element labels that have changed (before were loaded and now not, or before weren't loaded but now yes) |
1094 |
|
1095 |
// Changes element labels that have changed (before were loaded and now not, or before weren't loaded but now yes)
|
1096 |
((DefaultListModelForJLabelAsCell)valuesListModel).setAllElementsToNotLoaded(); |
1097 |
|
1098 |
// For each current value associated to de current selected field -> if its loaded -> put it at beginning of the list and change to 'JLabelLoadedValue'
|
1099 |
while (it.hasNext()) {
|
1100 |
String text = it.next().toString();
|
1101 |
int elementPosition = ((DefaultListModelForJLabelAsCell)valuesListModel).getIndexOfJLabelText(text);
|
1102 |
|
1103 |
// if (! ((DefaultListModelForJLabelAsCell)valuesListModel).containsJLabelText(text) )
|
1104 |
if (elementPosition == -1) // If it must be added |
1105 |
valuesListModel.addElement(new JLabelValueLoaded(text));
|
1106 |
else
|
1107 |
((DefaultListModelForJLabelAsCell)valuesListModel).changeElementThatHasTextToJLabelLoadedValue(text); // Change to 'JLabelLoadedValue'
|
1108 |
|
1109 |
|
1110 |
// // A label with text with yellow background color for values that are loaded in the layer
|
1111 |
// currentValueLabel = new JLabelValueLoaded();
|
1112 |
//
|
1113 |
// currentValueLabel.setText(it.next().toString());
|
1114 |
//
|
1115 |
//
|
1116 |
// if ( ! fieldValues.containsKey(currentValueLabel.getText()) ) {
|
1117 |
// fieldValues.put(currentValueLabel.getText(), currentValueLabel.getText());
|
1118 |
// }
|
1119 |
//
|
1120 |
// // All values loaded in this loop must be at beginning of the list (and in a differenciated color)
|
1121 |
// if ( ! (valuesListModel).contains(currentValueLabel) )
|
1122 |
// valuesListModel.addElement(currentValueLabel);
|
1123 |
//
|
1124 |
// else
|
1125 |
} |
1126 |
} |
1127 |
|
1128 |
// Load the rest of the values associated to the current selected field
|
1129 |
if (fieldValues != null) { |
1130 |
// A label with text with yelow background color for values that are loaded in the layer
|
1131 |
currentValueLabel = new JLabelValueNotLoaded();
|
1132 |
|
1133 |
Set values = fieldValues.keySet();
|
1134 |
|
1135 |
it = values.iterator(); |
1136 |
|
1137 |
while (it.hasNext()) {
|
1138 |
String name = it.next().toString();
|
1139 |
|
1140 |
if ( ! ((DefaultListModelForJLabelAsCell)valuesListModel).containsJLabelText(name) )
|
1141 |
valuesListModel.addElement(new JLabelValueNotLoaded(name));
|
1142 |
} |
1143 |
} |
1144 |
} |
1145 |
|
1146 |
} catch (Exception e) { |
1147 |
throwException(e); |
1148 |
} |
1149 |
} |
1150 |
|
1151 |
///// END METHODS FOR MANIPULATE 'fields' and 'values' /////
|
1152 |
|
1153 |
///// METHODS FOR PARENT NOTIFICATIONS /////
|
1154 |
|
1155 |
/**
|
1156 |
* @see WFSParamsPanel#isApplicable(boolean)
|
1157 |
*
|
1158 |
* This also loads values of fields
|
1159 |
*
|
1160 |
* @param b A boolean value
|
1161 |
*/
|
1162 |
private void setApplicate(boolean b) { |
1163 |
parent.isApplicable(b); |
1164 |
} |
1165 |
|
1166 |
///// END METHODS FOR PARENT NOTIFICATIONS /////
|
1167 |
|
1168 |
///// METHOS FOR 'allFieldsAndValuesKnownOfCurrentLayer' /////
|
1169 |
|
1170 |
/**
|
1171 |
* Sets all fields and values known about the current layer
|
1172 |
*
|
1173 |
* @param _allFieldsAndValuesKnownOfCurrentLayer A Map object
|
1174 |
*/
|
1175 |
public void setAllFieldsAndValuesKnownOfCurrentLayer(Map _allFieldsAndValuesKnownOfCurrentLayer) { |
1176 |
if (_allFieldsAndValuesKnownOfCurrentLayer == null) |
1177 |
this.allFieldsAndValuesKnownOfCurrentLayer = new HashMap(); |
1178 |
else
|
1179 |
this.allFieldsAndValuesKnownOfCurrentLayer = _allFieldsAndValuesKnownOfCurrentLayer;
|
1180 |
} |
1181 |
|
1182 |
/**
|
1183 |
* Gets all fields and values known about the current layer
|
1184 |
*
|
1185 |
* @return _allFieldsAndValuesKnownOfCurrentLayer A Map object
|
1186 |
*/
|
1187 |
public Map getAllFieldsAndValuesKnownOfCurrentLayer() { |
1188 |
return allFieldsAndValuesKnownOfCurrentLayer;
|
1189 |
} |
1190 |
|
1191 |
///// METHOS FOR 'allFieldsAndValuesKnownOfCurrentLayer' /////
|
1192 |
|
1193 |
///// IMPLEMENTATION OF METHODS OF 'IWindowListener' /////
|
1194 |
|
1195 |
/* (non-Javadoc)
|
1196 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
1197 |
*/
|
1198 |
public void windowActivated() { |
1199 |
} |
1200 |
|
1201 |
/* (non-Javadoc)
|
1202 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
1203 |
*/
|
1204 |
public void windowClosed() { |
1205 |
try {
|
1206 |
model.stop(); |
1207 |
} catch (DriverException e) {
|
1208 |
NotificationManager.addError(e.getMessage(), e); |
1209 |
} |
1210 |
} |
1211 |
|
1212 |
///// END IMPLEMENTATION OF METHODS OF 'IWindowListener' /////
|
1213 |
|
1214 |
///// IMPLEMENTATION OF METHODS OF 'IWindow' /////
|
1215 |
|
1216 |
/*
|
1217 |
* (non-Javadoc)
|
1218 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
1219 |
*/
|
1220 |
public WindowInfo getWindowInfo() {
|
1221 |
return null; |
1222 |
} |
1223 |
|
1224 |
///// END IMPLEMENTATION OF METHODS OF 'IWindow' /////
|
1225 |
|
1226 |
///// UPDATE TABLES DATA /////
|
1227 |
|
1228 |
/**
|
1229 |
* Updates all tables that their data is about the changed view
|
1230 |
*/
|
1231 |
private void updateTablesThatHasNewData() { |
1232 |
boolean oneTimeNewDataToTableAdded = false; |
1233 |
|
1234 |
IWindow[] activeNoModalWindows = PluginServices.getMDIManager().getAllWindows();
|
1235 |
|
1236 |
for (int i = 0; i < activeNoModalWindows.length; i++) { |
1237 |
IWindow window = activeNoModalWindows[i]; |
1238 |
if (window instanceof Table) { |
1239 |
Table table = (Table) window; |
1240 |
|
1241 |
int pos1 = featureName.indexOf(':'); |
1242 |
|
1243 |
if ((pos1 >= 0) && (pos1 < featureName.length())) |
1244 |
featureName = featureName.substring(pos1 +1, featureName.length());
|
1245 |
|
1246 |
// String featureOfTable = ((XMLElement)currentPath.getParentPath().getLastPathComponent()).getName();
|
1247 |
String featureOfTable = table.getModel().getName();
|
1248 |
int pos2 = featureOfTable.indexOf(':'); |
1249 |
|
1250 |
if ((pos2 >= 0) && (pos2 < featureName.length())) |
1251 |
featureOfTable = featureOfTable.substring(pos2 +1, featureOfTable.length());
|
1252 |
|
1253 |
if (featureName.trim().compareTo(featureOfTable.trim()) == 0) { |
1254 |
// Only add the new data associated to the table one time
|
1255 |
if (oneTimeNewDataToTableAdded == false) { |
1256 |
setNewDataToTable(); |
1257 |
oneTimeNewDataToTableAdded = true;
|
1258 |
} |
1259 |
|
1260 |
// Refresh the table with the new data
|
1261 |
table.refresh(); |
1262 |
} |
1263 |
} |
1264 |
} |
1265 |
} |
1266 |
|
1267 |
/**
|
1268 |
* This method is a modification of the "execute" method from the "ShowTable" class
|
1269 |
*
|
1270 |
* @see com.iver.cit.gvsig.ShowTable#execute(String)
|
1271 |
*/
|
1272 |
private void setNewDataToTable() { |
1273 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
1274 |
FLayer[] actives = vista.getModel().getMapContext().getLayers().getActives();
|
1275 |
|
1276 |
try {
|
1277 |
for (int i = 0; i < actives.length; i++) { |
1278 |
if (actives[i] instanceof AlphanumericData) { |
1279 |
AlphanumericData co = (AlphanumericData) actives[i]; |
1280 |
|
1281 |
//SelectableDataSource dataSource;
|
1282 |
//dataSource = co.getRecordset();
|
1283 |
|
1284 |
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
1285 |
|
1286 |
ProjectTable projectTable = ext.getProject().getTable(co); |
1287 |
EditableAdapter ea=null;
|
1288 |
ReadableVectorial rv=((FLyrVect)actives[i]).getSource(); |
1289 |
if (rv instanceof VectorialEditableAdapter){ |
1290 |
ea=(EditableAdapter)((FLyrVect)actives[i]).getSource(); |
1291 |
}else{
|
1292 |
ea=new EditableAdapter();
|
1293 |
SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset(); |
1294 |
ea.setOriginalDataSource(sds); |
1295 |
} |
1296 |
|
1297 |
if (projectTable == null) { |
1298 |
projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(), |
1299 |
ea); |
1300 |
projectTable.setProjectDocumentFactory(new ProjectTableFactory());
|
1301 |
projectTable.setAssociatedTable(co); |
1302 |
ext.getProject().addDocument(projectTable); |
1303 |
} |
1304 |
projectTable.setModel(ea); |
1305 |
|
1306 |
// Removed part of code that created another (visual) table
|
1307 |
// Table t = new Table();
|
1308 |
// t.setModel(projectTable);
|
1309 |
// PluginServices.getMDIManager().addWindow(t);
|
1310 |
} |
1311 |
} |
1312 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
1313 |
NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e); |
1314 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
1315 |
e.printStackTrace(); |
1316 |
NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e); |
1317 |
} |
1318 |
} |
1319 |
|
1320 |
///// END UPDATE TABLES DATA /////
|
1321 |
|
1322 |
///// OTHER METHODS /////
|
1323 |
|
1324 |
/**
|
1325 |
* DOCUMENT ME!
|
1326 |
*
|
1327 |
* @param expresion DOCUMENT ME!
|
1328 |
* @param substring DOCUMENT ME!
|
1329 |
* @param startingPos DOCUMENT ME!
|
1330 |
*
|
1331 |
* @return DOCUMENT ME!
|
1332 |
*/
|
1333 |
private int getIndex(String expresion, String substring, int startingPos) { |
1334 |
int index = startingPos;
|
1335 |
|
1336 |
do {
|
1337 |
index = expresion.indexOf(substring, index); |
1338 |
} while ((StringUtilities.isBetweenSymbols(expresion, index, "\"")) && |
1339 |
(index != -1));
|
1340 |
|
1341 |
return index;
|
1342 |
} |
1343 |
|
1344 |
/**
|
1345 |
* DOCUMENT ME!
|
1346 |
*
|
1347 |
* @param arg0
|
1348 |
*
|
1349 |
* @return
|
1350 |
*/
|
1351 |
public boolean addExpressionListener(ExpressionListener arg0) { |
1352 |
return expressionListeners.add(arg0);
|
1353 |
} |
1354 |
|
1355 |
/**
|
1356 |
* DOCUMENT ME!
|
1357 |
*
|
1358 |
* @param arg0
|
1359 |
*
|
1360 |
* @return
|
1361 |
*/
|
1362 |
public boolean removeExpressionListener(ExpressionListener arg0) { |
1363 |
return expressionListeners.remove(arg0);
|
1364 |
} |
1365 |
/**
|
1366 |
* DOCUMENT ME!
|
1367 |
*
|
1368 |
* @param o DOCUMENT ME!
|
1369 |
*
|
1370 |
* @return DOCUMENT ME!
|
1371 |
*/
|
1372 |
public boolean removeExceptionListener(ExceptionListener o) { |
1373 |
return exceptionHandlingSupport.removeExceptionListener(o);
|
1374 |
} |
1375 |
|
1376 |
/**
|
1377 |
* DOCUMENT ME!
|
1378 |
*
|
1379 |
* @param t DOCUMENT ME!
|
1380 |
*/
|
1381 |
private void throwException(Throwable t) { |
1382 |
exceptionHandlingSupport.throwException(t); |
1383 |
} |
1384 |
|
1385 |
///// END OTHER METHODS /////
|
1386 |
} |