Revision 107

View differences:

org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/fmap/rendering/VectorFilterExpressionLegend.java
72 72
 * depending on the value of an expression. That is, if the expression is
73 73
 * evaluated to true, then the symbol associated to the expression is painted.
74 74
 * In other case it is not showed.
75
 * 
75
 *
76 76
 * If the expression result is a string, it is considered false if
77 77
 * it is the empty string "", true otherwise.
78
 * 
78
 *
79 79
 * If the expression result is numeric, it is considered false
80 80
 * if it is zero, and true otherwise.
81
 * 
81
 *
82 82
 * In other cases, it is considered false if the result is null and true
83 83
 * otherwise.
84 84
 *
......
90 90

  
91 91
    private static final Logger logger = LoggerFactory.getLogger(
92 92
        VectorFilterExpressionLegend.class);
93
    
93

  
94 94
    public static final String
95 95
    FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME =
96 96
    "FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME";
97
    
97

  
98 98
    public static final String
99 99
    FILTER_EXPRESSION_LEGEND_NAME = "FILTER_EXPRESSION_LEGEND_NAME";
100 100

  
101 101
    public static final String I18N_DEFAULT = Messages.getText("default_value");
102 102
    public static final String NON_I18N_DEFAULT = Messages.getText("Default");
103
    
103

  
104 104
	private int shapeType;
105 105
	private ISymbol defaultSymbol;
106
	/*
107
	private String labelFieldName;
108
	private String labelFieldHeight;
109
	private String labelFieldRotation;
110
	*/
106

  
111 107
	private boolean useDefaultSymbol = false;
112 108

  
113 109
	private long error_msg_count = 0;
114
	/*
115
	private Hashtable<String, Object> parser_symbol_table =
116
	    new Hashtable<String, Object>();
117
	*/
118
	
119
	
110

  
120 111
	private ArrayList<Item> newSymbols = new ArrayList<Item>() {
121 112
		private static final long serialVersionUID = 1L;
122 113

  
......
127 118

  
128 119

  
129 120
	private class Item implements Cloneable {
130
	    
121

  
131 122
		private ISymbol sym;
132 123
		// get it with getSql()
133 124
		// private String expression;
......
153 144
		public Evaluator getEvaluator() {
154 145
			return evaluator;
155 146
		}
156
		
147

  
157 148
		public Object clone() {
158
		    
149

  
159 150
		    ISymbol clonesym = null;
160 151
		    try {
161 152
                clonesym = (ISymbol) this.sym.clone();
......
172 163
        this.setClassifyingFieldTypes(new int[0]);
173 164
    }
174 165

  
175

  
176
	/*
177
	public VectorFilterExpressionLegend(int type,String[] fieldNames) {
178
		setShapeType(type);
179
		this.setClassifyingFieldNames(fieldNames);
180
		// this.fNames = fieldNames;
181
	}
182
	*/
183

  
184

  
185

  
186 166
	public ISymbol getSymbolByFeature(Feature featu) {
187
	    
167

  
188 168
	    EvaluatorData evda = featu.getEvaluatorData();
189
	    
169

  
190 170
		ISymbol returnSymbol = null;
191 171
		Object result = null;
192 172
		String expr = null;
193
		
194
		String[] fNames =  getClassifyingFieldNames();
173

  
195 174
		try {
196
			// updateSymbolsTable(featu, fNames);
197 175

  
198 176
			for (int i = 0; i < newSymbols.size(); i++) {
199
			    
177

  
200 178
				Evaluator eval = newSymbols.get(i).getEvaluator();
201 179
				expr = eval.getSQL();
202
				
180

  
203 181
                if (expr.equalsIgnoreCase(VectorFilterExpressionLegend.I18N_DEFAULT)){
204 182
                    /*
205 183
                     * Skip default item
206 184
                     */
207 185
                    continue;
208 186
                }
209
                
187

  
210 188
				result = eval.evaluate(evda);
211 189
				if (isConsideredTrue(result)) {
212 190
                    returnSymbol = newSymbols.get(i).sym;
......
216 194
				}
217 195
			}
218 196
		} catch (Exception e) {
219
		    
197

  
220 198
		    if (error_msg_count % 1000 == 0) {
221 199
		        logger.info("Error (msg every 1000 occurrences) while getting symbol in VectorFilterExpressionLegend", e);
222 200
		        error_msg_count = 0;
......
229 207

  
230 208
		return null;
231 209
	}
232
	
210

  
233 211
	/**
234 212
	 * Tells whether the input object is considered true.
235 213
	 * Basically, it is false if it has an empty value
236 214
	 * (FALSE, null, 0, "")
237
	 * 
215
	 *
238 216
     * @param result
239 217
     * @return
240 218
     */
241 219
    private boolean isConsideredTrue(Object res) {
242
        
220

  
243 221
        if (res == null) {
244 222
            return false;
245 223
        }
246
        
224

  
247 225
        if (res instanceof Boolean) {
248 226
            return ((Boolean) res).booleanValue();
249 227
        }
250
        
228

  
251 229
        if (res instanceof Number) {
252 230
            return ((Number) res).doubleValue() != 0d;
253 231
        }
254
        
232

  
255 233
        if (res instanceof String) {
256 234
            return ((String) res).length() > 0;
257 235
        }
258
        
236

  
259 237
        // Because it is not null
260 238
        return true;
261 239
    }
262 240

  
263

  
264
    /**
265
	 * Returns a HashTable containing the name of the field of an specific feature
266
	 * and its values
267
	 *
268
	 * @param feat specific feature
269
	 * @param fNames field names
270
	 * @return HashTable
271
	 * @throws LegendDriverException
272
	 */
273
	/*
274
	private void updateSymbolsTable(Feature feat, String[] fNames)
275
	throws EvaluatorException {
276

  
277
	    Object val = null;
278
	    
279
		if (fNames != null)
280
			for (int j = 0; j < fNames.length; j++) {
281
			    
282
			    val = feat.get(fNames[j]);
283
				if (val != null) {
284
				    parser_symbol_table.put(fNames[j], val);
285
				} else {
286
				    throw new EvaluatorException(
287
				        new Exception("Field not found: '" + fNames[j] + "'"));
288
				}
289
			}
290
	}
291
	*/
292

  
293

  
294 241
	public void addSymbol(Object key, ISymbol symbol) {
295 242
		newSymbols.add(new Item((String)key.toString(),
296 243
				symbol));
......
299 246
	public void clear() {
300 247
		newSymbols.clear();
301 248
	}
302
	
249

  
303 250
	public void resetItems() {
304 251
	    newSymbols = new ArrayList<Item>() {
305 252
            private static final long serialVersionUID = 1L;
......
388 335

  
389 336
	public void setShapeType(int shapeType) {
390 337
		if (this.shapeType != shapeType) {
391
		    
338

  
392 339
		    ISymbol sym = MapContextLocator.getSymbolManager(
393 340
		        ).createSymbol(shapeType);
394 341
			setDefaultSymbol(sym);
......
410 357
		}
411 358
		return null;
412 359
	}
413
	
360

  
414 361
    public static boolean isPolygonal(int ty) {
415 362
        if (ty == Geometry.TYPES.MULTISURFACE
416 363
            || ty == Geometry.TYPES.SURFACE
......
436 383
            return false;
437 384
        }
438 385
    }
439
    
386

  
440 387
    public static boolean isPoint(int ty) {
441 388
        if (ty == Geometry.TYPES.POINT
442 389
            || ty == Geometry.TYPES.MULTIPOINT
......
446 393
            return false;
447 394
        }
448 395
    }
449
    
396

  
450 397
    public void removeDefaultSymbol() {
451
        
398

  
452 399
    }
453
    
400

  
454 401
    // =============================
455
    
402

  
456 403
    public static class RegisterPersistence implements Callable {
457 404

  
458 405
        public Object call() throws Exception {
459
            
406

  
460 407
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
461 408
            if (manager.getDefinition(
462 409
                FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
......
465 412
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME,
466 413
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME
467 414
                        + " Persistence definition", null, null);
468
                
415

  
469 416
                definition.extend(manager.getDefinition(
470 417
                    AbstractClassifiedVectorLegend
471 418
                    .CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME));
472
                
419

  
473 420
                definition.addDynFieldBoolean("useDefaultSymbol")
474 421
                .setMandatory(true);
475 422
                definition.addDynFieldObject("defaultSymbol")
476 423
                .setClassOfValue(ISymbol.class).setMandatory(true);
477 424
                definition.addDynFieldInt("shapeType")
478 425
                .setMandatory(true);
479
                
426

  
480 427
                definition.addDynFieldArray("itemSymbolArray")
481 428
                .setClassOfItems(ISymbol.class);
482 429
                definition.addDynFieldArray("itemStringArray")
......
502 449
        }
503 450

  
504 451
    }
505
    
452

  
506 453
    public void saveToState(PersistentState state) throws PersistenceException {
507 454

  
508 455
        super.saveToState(state);
509 456
        state.set("useDefaultSymbol", this.isUseDefaultSymbol());
510 457
        state.set("defaultSymbol", this.getDefaultSymbol());
511 458
        state.set("shapeType", this.getShapeType());
512
        
459

  
513 460
        ISymbol[] syms = this.getSymbols();
514 461
        if (syms == null) {
515 462
            syms = new ISymbol[0];
......
527 474
                vals_str[i] = aux;
528 475
            }
529 476
        }
530
        
477

  
531 478
        state.set("itemSymbolArray", syms);
532 479
        state.set("itemStringArray", vals_str);
533
        
480

  
534 481
    }
535 482

  
536 483
    public void loadFromState(PersistentState state)
537 484
        throws PersistenceException {
538
        
485

  
539 486
        super.loadFromState(state);
540
        
487

  
541 488
        this.setShapeType(state.getInt("shapeType"));
542 489
        Boolean b = state.getBoolean("useDefaultSymbol");
543 490
        this.useDefaultSymbol(b);
544 491
        ISymbol defsym = (ISymbol) state.get("defaultSymbol");
545 492
        this.setDefaultSymbol(defsym);
546
        
493

  
547 494
        String[] strs = state.getStringArray("itemStringArray");
548 495
        ISymbol[] syms = (ISymbol[]) state.getArray("itemSymbolArray",
549 496
            ISymbol.class);
550
        
497

  
551 498
        if (strs.length != syms.length) {
552 499
            logger.info("VectorFilterExpressionLegend - load state - Different size in arrays: " + strs.length + ", " + syms.length);
553 500
        }
......
558 505
            this.addSymbol(aux, syms[i]);
559 506
        }
560 507
    }
561
    
508

  
562 509
    /**
563 510
     * Utility method to (un)translate the word 'Default'
564 511
     * @param aux
......
568 515
     * @return
569 516
     */
570 517
    private String translateDefault(String aux, boolean forward) {
571
        
518

  
572 519
        if (aux == null) {
573 520
            return null;
574 521
        }
......
583 530

  
584 531

  
585 532
    public Object clone() throws CloneNotSupportedException {
586
        
533

  
587 534
        VectorFilterExpressionLegend resp =
588 535
            (VectorFilterExpressionLegend) super.clone();
589
        
536

  
590 537
        Object[] vals = this.getValues();
591 538
        ISymbol[] syms = this.getSymbols();
592 539
        if (vals != null && syms != null) {
593
            
540

  
594 541
            resp.resetItems();
595
                
542

  
596 543
            int n = Math.min(vals.length, syms.length);
597 544
            for (int i=0; i<n; i++) {
598 545
                resp.addSymbol(
......
605 552
        resp.setDefaultSymbol(sym);
606 553
        return resp;
607 554
    }
608
    
609 555

  
610 556

  
557

  
611 558
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionSymbolPanel.java
60 60
 * library) and shows a symbol preview panel with a description
61 61
 * so the user can associate a symbol to the expression (symbol
62 62
 * will be used if expression evaluates to TRUE)
63
 * 
63
 *
64 64
 * @see EvaluatorPanel
65
 * 
66
 * 
65
 *
66
 *
67 67
 * @author jldominguez
68 68
 *
69 69
 */
70 70
public class ExpressionSymbolPanel extends JPanel
71 71
implements ActionListener, IWindow {
72
    
72

  
73
    /**
74
     *
75
     */
76
    private static final long serialVersionUID = 6299256060002740452L;
73 77
    private Feature dummyFeature = null;
74 78
    private EvaluatorWithDescriptions evald = null;
75 79
    private int shptype = Geometry.TYPES.GEOMETRY;
76
    
80

  
77 81
    private JPanel symPanel = null;
78 82
    private JSymbolPreviewButton templateButton = null;
79 83
    private JTextArea descArea = null;
80 84
    private AcceptCancelPanel acPanel;
81 85
    private boolean okPressed = false;
82 86
    private WindowInfo winfo = null;
83
    
87

  
84 88
    private EvaluatorPanel evapa = null;
85
    
89

  
86 90
    public ExpressionSymbolPanel(
87 91
        Feature dummy_feat, EvaluatorWithDescriptions ed, int st, ISymbol sym) {
88
        
92

  
89 93
        dummyFeature = dummy_feat;
90 94
        evald = ed;
91 95
        shptype = st;
92
        
96

  
93 97
        initialize(sym);
94 98
    }
95
    
99

  
96 100
    private EvaluatorPanel getEvaluatorPanel() {
97 101
        if (evapa == null) {
98 102
            ComponentSwingManager esm =
......
103 107
        }
104 108
        return evapa;
105 109
    }
106
    
110

  
107 111
    public String getExpression() {
108 112
        return getEvaluatorPanel().getExpression();
109 113
    }
110
    
114

  
111 115
    public ISymbol getSymbol() {
112 116
        ISymbol resp = getTemplateButton(null).getSymbol();
113 117
        resp.setDescription(this.getDescArea(null).getText());
......
115 119
    }
116 120

  
117 121
    /**
118
     * 
122
     *
119 123
     */
120 124
    private void initialize(ISymbol sym) {
121
        
125

  
122 126
        this.setLayout(new GridBagLayout());
123 127
        GridBagConstraints gbc = new GridBagConstraints();
124
        
128

  
125 129
        gbc.gridx = 0;
126 130
        gbc.gridy = 0;
127 131
        gbc.anchor = GridBagConstraints.CENTER;
......
140 144
     * @return
141 145
     */
142 146
    private JPanel getAcceptCancel() {
143
        
147

  
144 148
        if (acPanel == null) {
145 149
            acPanel = new AcceptCancelPanel(this, this);
146 150
        }
......
151 155
     * @return
152 156
     */
153 157
    private JPanel getSymbolPanel(ISymbol sym) {
154
        
158

  
155 159
        if (symPanel == null) {
156
            
160

  
157 161
            symPanel = new JPanel();
158 162
            symPanel.setLayout(new GridBagLayout());
159 163
            symPanel.setBorder(BorderFactory.createTitledBorder(
160 164
                Messages.getText("_Symbol_and_description")));
161 165

  
162 166
            GridBagConstraints gbc = new GridBagConstraints();
163
            
167

  
164 168
            gbc.fill = GridBagConstraints.BOTH;
165 169
            gbc.anchor = GridBagConstraints.NORTHWEST;
166 170
            gbc.gridx = 0;
......
169 173
            gbc.weighty = 0;
170 174
            gbc.insets = new Insets(7, 7, 7, 7);
171 175
            symPanel.add(getTemplateButton(sym), gbc);
172
            
176

  
173 177
            gbc.gridx = 1;
174 178
            gbc.weightx = 0.8;
175
            
179

  
176 180
            JScrollPane scroll = new JScrollPane(getDescArea(sym));
177 181
            scroll.setHorizontalScrollBarPolicy(
178 182
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
......
188 192
     */
189 193
    private JTextArea getDescArea(ISymbol sym) {
190 194
        if (descArea == null) {
191
            
195

  
192 196
            descArea = new JTextArea();
193 197
            descArea.setWrapStyleWord(true);
194 198
            descArea.setLineWrap(true);
......
220 224
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
221 225
     */
222 226
    public void actionPerformed(ActionEvent e) {
223
        
227

  
224 228
        if (e.getActionCommand().compareToIgnoreCase("ok") == 0) {
225
            
226
            Class return_class = null;
229

  
230
            Class<?> return_class = null;
227 231
            try {
228 232
                return_class = validateExpression();
229 233
            } catch (EvaluatorException epe) {
230
                
234

  
231 235
                if (epe.getCause() instanceof ArithmeticException) {
232
                    
236

  
233 237
                    if (!userTolerates(epe)) {
234 238
                        okPressed = false;
235 239
                        return;
......
239 243
                        closeThis();
240 244
                        return;
241 245
                    }
242
                    
246

  
243 247
                } else {
244 248
                    String detail = epe.getMessageStack();
245 249
                    ApplicationLocator.getManager().messageDialog(
......
251 255
                    return;
252 256
                }
253 257
            }
254
            
258

  
255 259
            if (return_class != Boolean.class) {
256 260
                int usr_opt = JOptionPane.showConfirmDialog(
257 261
                    this,
......
265 269
            }
266 270
            okPressed = true;
267 271
            closeThis();
268
            
272

  
269 273
        } else {
270 274
            if (e.getActionCommand().compareToIgnoreCase("cancel") == 0) {
271 275
                okPressed = false;
......
273 277
            }
274 278
        }
275 279
    }
276
    
277
 
280

  
281

  
278 282
    /**
279 283
     * @param epe
280 284
     * @return
281 285
     */
282 286
    private boolean userTolerates(EvaluatorException epe) {
283
        
287

  
284 288
        String detail = Messages.getText(
285 289
            "_Expression_can_cause_arithmetic_issues_Continue_question");
286 290
        detail = detail + "\n\nMessage: ";
......
291 295
            detail,
292 296
            Messages.getText("confirmation_dialog"),
293 297
            JOptionPane.YES_NO_OPTION);
294
        
298

  
295 299
        return usr_opt == JOptionPane.YES_OPTION;
296 300
    }
297 301

  
298 302
    /**
299 303
     * @return class of the return value
300 304
     */
301
    private Class validateExpression() throws EvaluatorException {
302
        
305
    private Class<? extends Object> validateExpression() throws EvaluatorException {
306

  
303 307
        String expr = this.getExpression();
304 308
        EvaluatorWithDescriptions evde = EvaluatorCreator.getEvaluator(expr);
305 309
        Object resp_class = null;
306
        
310

  
307 311
        try {
308 312
            /*
309 313
             * Try evaluate feature with default values
......
323 327
             * We assume a strange
324 328
             * exception (NPE, etc) and decide it's not a valid
325 329
             * expression
326
             *  
330
             *
327 331
             */
328 332
            throw new EvaluatorException(e);
329 333
        }
330
        
334

  
331 335
        if (resp_class == null) {
332 336
            return null;
333 337
        } else {
......
339 343
        MDIManager mm = ApplicationLocator.getManager().getUIManager();
340 344
        mm.closeWindow(this);
341 345
    }
342
    
346

  
343 347
    public boolean isOkPressed() {
344 348
        return okPressed;
345 349
    }
org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java
51 51

  
52 52
import javax.swing.BoxLayout;
53 53
import javax.swing.ImageIcon;
54
import javax.swing.JButton;
54 55
import javax.swing.JCheckBox;
55 56
import javax.swing.JOptionPane;
56 57
import javax.swing.JPanel;
......
77 78
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
78 79
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
79 80
import org.gvsig.gui.beans.swing.JBlank;
80
import org.gvsig.gui.beans.swing.JButton;
81 81
import org.gvsig.i18n.Messages;
82 82
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
83 83
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
84 84
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
85 85
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator;
86 86
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
87
import org.gvsig.tools.swing.api.ToolsSwingLocator;
88
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
87 89

  
88 90
/**
89 91
 * Implements the JPanel that shows the properties of a
......
95 97
 */
96 98
public class VectorFilterExpressionPanel extends JPanel
97 99
implements ILegendPanel, ActionListener {
98
    
100

  
99 101
    private static final Logger logger = LoggerFactory.getLogger(
100 102
        VectorFilterExpressionPanel.class);
101
    
103

  
102 104
	private static final long serialVersionUID = -7187473609965942511L;
103 105
	private VectorFilterExpressionLegend theLegend;
104 106
	private VectorFilterExpressionLegend auxLegend;
......
116 118
	protected JCheckBox chkdefaultvalues = null;
117 119
	protected JSymbolPreviewButton defaultSymbolPrev;
118 120
	private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
121
	private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager();
119 122

  
120 123
	/**
121 124
	 * This is the default constructor
......
135 138
		pnlCenter.setLayout(new BorderLayout());
136 139

  
137 140
		JPanel pnlButtons = new JPanel();
138
		btnAddExpression = new JButton(
141
		btnAddExpression = usabilitySwingManager.createJButton(
139 142
		    Messages.getText("new_filter_expression"));
140 143
		btnAddExpression.setActionCommand("NEW_EXPRESSION");
141 144
		btnAddExpression.addActionListener(this);
142 145
		pnlButtons.add(btnAddExpression);
143 146

  
144
		btnModExpression = new JButton(
147
		btnModExpression = usabilitySwingManager.createJButton(
145 148
		    Messages.getText("modify_filter_expression"));
146 149
		btnModExpression.setActionCommand("MODIFY_EXPRESSION");
147 150
		btnModExpression.addActionListener(this);
148 151
		pnlButtons.add(btnModExpression);
149 152

  
150
		btnRemoveExpression = new JButton(
153
		btnRemoveExpression = usabilitySwingManager.createJButton(
151 154
		    Messages.getText("delete_filter_expression"));
152 155
		btnRemoveExpression.setActionCommand("REMOVE");
153 156
		btnRemoveExpression.addActionListener(this);
......
212 215
	private void fillSymbolListFromTable() {
213 216
		Object clave;
214 217
		ISymbol theSymbol;
215
		boolean bRestoValores = false;
216
		int hasta;
217 218

  
218 219
		FLyrVect m = (FLyrVect) layer;
219 220
		try {
......
224 225

  
225 226
				FeatureStore fsto = (FeatureStore) m.getDataStore();
226 227
				FeatureType fty = fsto.getDefaultFeatureType();
227
				FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
228
				
228

  
229 229
				for (int i = 0; i < fNames.length; i++) {
230 230
					fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType();
231 231
				}
......
233 233
				auxLegend.setClassifyingFieldTypes(fieldTypes);
234 234
			}
235 235
		} catch (Exception e) {
236
		    
236

  
237 237
		}
238 238

  
239 239
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
240
		if (bRestoValores) {
241
			hasta = symbolTable.getRowCount() - 1;
242
		} else {
243
			hasta = symbolTable.getRowCount();
244
		}
245 240

  
246 241
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
247 242
			clave =  symbolTable.getFieldValue(row, 1);
......
260 255

  
261 256
	}
262 257

  
263
	public Class getLegendClass() {
258
	public Class<VectorFilterExpressionLegend> getLegendClass() {
264 259
		return VectorFilterExpressionLegend.class;
265 260
	}
266 261

  
......
268 263
		return this;
269 264
	}
270 265

  
271
	public Class getParentClass() {
266
	public Class<Categories> getParentClass() {
272 267
		return Categories.class;
273 268
	}
274 269

  
......
317 312

  
318 313

  
319 314
		if (legend instanceof VectorFilterExpressionLegend) {
320
		    
315

  
321 316
            auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
322 317
            if (auxLegend.isUseDefaultSymbol()) {
323 318
                // Default must not be in table
324
                fillTableSkipDefault(auxLegend);                
319
                fillTableSkipDefault(auxLegend);
325 320
            } else {
326 321
                symbolTable.fillTableFromSymbolList(
327 322
                    auxLegend.getSymbols(),
328 323
                    auxLegend.getValues(),
329 324
                    auxLegend.getDescriptions());
330 325
            }
331
            
332
			
326

  
327

  
333 328
		} else {
334 329
			auxLegend = new VectorFilterExpressionLegend();
335 330
			auxLegend.setShapeType(shapeType);
......
345 340
			pnlMovBut.add(new JBlank(1, 70));
346 341
			ImageIcon ico = IconThemeHelper.getImageIcon(
347 342
			    "symbol-layer-move-up");
348
			moveUp = new JButton(ico);
343
			moveUp = usabilitySwingManager.createJButton(ico);
349 344
			pnlMovBut.add(moveUp);
350 345
			moveUp.setSize(new Dimension(15,15));
351 346
			pnlMovBut.add(new JBlank(1,10));
352 347
			ico = IconThemeHelper.getImageIcon(
353 348
                "symbol-layer-move-down");
354
			moveDown = new JButton(ico);
349
			moveDown = usabilitySwingManager.createJButton(ico);
355 350
			pnlMovBut.add(moveDown);
356 351
			pnlMovBut.add(new JBlank(1, 70));
357 352
			moveDown.setActionCommand("MOVE-DOWN");
......
363 358
	}
364 359

  
365 360
	public void actionPerformed(ActionEvent e) {
366
	    
361

  
367 362
		int[] indices = null;
368 363
		Feature dummyFeat = null;
369 364

  
......
388 383
		}
389 384

  
390 385
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
391
			ArrayList orders = new ArrayList();
386
			ArrayList<String> orders = new ArrayList<String>();
392 387

  
393 388
			for (int i = 0; i < symbolTable.getRowCount(); i++) {
394 389
				orders.add(symbolTable.getFieldValue(i,1).toString());
395 390
			}
396 391
		}
397 392
		if (e.getActionCommand() == "NEW_EXPRESSION") {
398
		    
393

  
399 394
		    FLyrVect vect = (FLyrVect) layer;
400 395
		    FeatureStore fsto = (FeatureStore) vect.getDataStore();
401 396
		    FeatureType fty = null;
402 397
		    int shptype = 0;
403
		    
398

  
404 399
		    try {
405 400
		        fty = fsto.getDefaultFeatureType();
406 401
		        shptype = vect.getGeometryType().getType();
......
411 406
		        return;
412 407
		    }
413 408

  
414
		    EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator(""); 
409
		    EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator("");
415 410
		    MDIManager mm = ApplicationLocator.getManager().getUIManager();
416
		    
411

  
417 412
		    ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
418 413
		        dummyFeat, evalu, shptype, null);
419 414
		    mm.addCentredWindow(esp);
420
		    
415

  
421 416
		    /*
422 417
		     * esp is modal
423 418
		     */
424 419
		    if (!esp.isOkPressed()) {
425 420
		        return;
426 421
		    }
427
		    
422

  
428 423
		    String expr = esp.getExpression();
429 424
		    if (expr == null || expr.length() == 0) {
430 425
		        ApplicationLocator.getManager().messageDialog(
......
433 428
		            JOptionPane.ERROR_MESSAGE);
434 429
		        return;
435 430
		    }
436
		    
431

  
437 432
		    ISymbol sym = esp.getSymbol();
438 433
		    evalu = EvaluatorCreator.getEvaluator(expr);
439 434
		    // Add all fields in the feature type
......
442 437
            auxLegend.addSymbol(expr, sym);
443 438
            symbolTable.removeAllItems();
444 439
            fillTableSkipDefault(auxLegend);
445
            
440

  
446 441
			repaint();
447 442
		}
448 443
		else if (e.getActionCommand() == "MODIFY_EXPRESSION") {
449
		    
444

  
450 445
			if(symbolTable.getSelectedRowElements() == null) {
451 446
				JOptionPane.showMessageDialog(this,
452 447
				    Messages.getText("select_one_row")+".\n");
453 448
			} else {
454
			    
449

  
455 450
		         FLyrVect vect = (FLyrVect) layer;
456 451
		         FeatureStore fsto = (FeatureStore) vect.getDataStore();
457 452
		         FeatureType fty = null;
......
471 466

  
472 467
                EvaluatorWithDescriptions evalu =
473 468
                    EvaluatorCreator.getEvaluator(expression);
474
                
469

  
475 470
                MDIManager mm = ApplicationLocator.getManager().getUIManager();
476 471
                ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
477 472
                    dummyFeat, evalu, shptype, mySymbol);
......
482 477
	            if (!esp.isOkPressed()) {
483 478
	                return;
484 479
	            }
485
	            
480

  
486 481
	            String expr = esp.getExpression();
487 482
	            if (expr == null || expr.length() == 0) {
488 483
	                ApplicationLocator.getManager().messageDialog(
......
491 486
	                    JOptionPane.ERROR_MESSAGE);
492 487
	                return;
493 488
	            }
494
	            
489

  
495 490
	            ISymbol sym = esp.getSymbol();
496 491
	            evalu = EvaluatorCreator.getEvaluator(expr);
497 492
	            // Add all fields in the feature type
......
508 503
		}
509 504

  
510 505
		else if (e.getActionCommand() == "REMOVE") {
511
		    
506

  
512 507
			if(symbolTable.getSelectedRowElements() == null) {
513 508
				JOptionPane.showMessageDialog(this,
514 509
				    Messages.getText("select_one_row"));
......
522 517
			}
523 518
		}
524 519
	}
525
	
526
	
520

  
521

  
527 522
	private void addClassFieldNames(FeatureType ft) {
528
	    
523

  
529 524
	    FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
530 525
	    String[] nn = new String[atts.length];
531 526
	    for (int i=0; i<atts.length; i++) {
......
577 572
	        "legend-overview-vector-filter-expression");
578 573
	    return ii;
579 574
	}
580
	
575

  
581 576
	/**
582 577
	 * This method initializes chkdefaultvalues
583 578
	 *
......
602 597

  
603 598
		return chkdefaultvalues;
604 599
	}
605
	
600

  
606 601
	private void fillTableSkipDefault(VectorFilterExpressionLegend leg) {
607
	    
602

  
608 603
	    Object[] src_expr = leg.getValues();
609
	    List rem_ind = new ArrayList();
604
	    List<Integer> rem_ind = new ArrayList<Integer>();
610 605
	    for (int i=0; i<src_expr.length; i++) {
611 606
	        if (VectorFilterExpressionLegend.I18N_DEFAULT.
612 607
	            compareToIgnoreCase((String) src_expr[i]) == 0) {
......
616 611
        ISymbol[] src_syms = leg.getSymbols();
617 612
        String[] src_descs = leg.getDescriptions();
618 613
        // Object[] src_expr
619
	    
620
        List syms = new ArrayList();
621
        List vals = new ArrayList();
622
        List descs = new ArrayList();
614

  
615
        List<ISymbol> syms = new ArrayList<ISymbol>();
616
        List<Object> vals = new ArrayList<Object>();
617
        List<String> descs = new ArrayList<String>();
623 618
        for (int i=0; i<src_expr.length; i++) {
624 619
            if (!isIn(i, rem_ind)) {
625 620
                syms.add(src_syms[i]);
......
639 634
     * @param rem_ind
640 635
     * @return
641 636
     */
642
    private boolean isIn(int n, List int_list) {
643
        
637
    private boolean isIn(int n, List<Integer> int_list) {
638

  
644 639
        if (int_list == null || int_list.size() == 0) {
645 640
            return false;
646 641
        }
647
        
642

  
648 643
        for (int i=0; i<int_list.size(); i++) {
649 644
            if (int_list.get(i) instanceof Integer) {
650 645
                Integer item = (Integer) int_list.get(i);
org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionFieldCellEditor.java
68 68
	}
69 69

  
70 70
	public void addCellEditorListener(CellEditorListener l) {
71
		// TODO Auto-generated method stub
72 71
		throw new RuntimeException("Not yet implemented");
73 72
	}
74 73

  
75 74
	public void cancelCellEditing() {
76
		// TODO Auto-generated method stub
77 75
		throw new RuntimeException("Not yet implemented");
78 76

  
79 77
	}
......
87 85
	}
88 86

  
89 87
	public void removeCellEditorListener(CellEditorListener l) {
90
		// TODO Auto-generated method stub
91 88
		throw new RuntimeException("Not yet implemented");
92 89

  
93 90
	}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/library/VectorFilterExpressionLibrary.java
23 23
package org.gvsig.symbology.library;
24 24

  
25 25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.app.project.documents.view.legend.gui.LegendManager;
27 26
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable;
28 27
import org.gvsig.symbology.SymbologyLibrary;
29 28
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
30 29
import org.gvsig.symbology.gui.layerproperties.ExpressionFieldCellEditor;
31 30
import org.gvsig.symbology.gui.layerproperties.VectorFilterExpressionPanel;
31
import org.gvsig.symbology.swing.SymbologySwingLocator;
32 32
import org.gvsig.tools.library.AbstractLibrary;
33 33
import org.gvsig.tools.library.LibraryException;
34 34
import org.gvsig.tools.persistence.xml.XMLPersistenceLibrary;
......
38 38

  
39 39
/**
40 40
 * Simple library to register vector filter expression legend
41
 * 
41
 *
42 42
 * @author jldominguez
43 43
 *
44 44
 */
......
63 63

  
64 64

  
65 65
    protected void doPostInitialize() throws LibraryException {
66
        
66

  
67 67
        IconThemeHelper.registerIcon("legend",
68 68
            "legend-overview-vector-filter-expression", this);
69 69
        IconThemeHelper.registerIcon("legend",
......
74 74
            "symbol-layer-move-up", this);
75 75

  
76 76
        Caller caller = new DefaultCaller();
77
        
77

  
78 78
        caller.add(new VectorFilterExpressionLegend.RegisterLegend());
79 79
        caller.add(new VectorFilterExpressionLegend.RegisterPersistence());
80
        
80

  
81 81
        /*
82 82
         * Do register of all
83 83
         */
......
86 86
                VectorFilterExpressionLibrary.class,
87 87
                caller.getExceptions());
88 88
        }
89
        LegendManager.addLegendPage(VectorFilterExpressionPanel.class);
90
        
89
        SymbologySwingLocator.getSwingManager().registerLegendEditor(VectorFilterExpressionPanel.class);
90

  
91 91
        SymbolTable.addNewCellEditor("expressions",
92 92
            new ExpressionFieldCellEditor());
93 93

  
94 94
    }
95
    
96 95

  
97 96

  
97

  
98 98
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/pom.xml
10 10
  <parent>
11 11
      <groupId>org.gvsig</groupId>
12 12
      <artifactId>org.gvsig.desktop</artifactId>
13
      <version>2.0.21</version>
13
      <version>2.0.89</version>
14 14
  </parent>
15 15
	
16 16
	<url>https://devel.gvsig.org/redmine/projects/gvsig-base-legends</url>
......
57 57
		<dependency>
58 58
			<groupId>org.gvsig</groupId>
59 59
			<artifactId>org.gvsig.app.mainplugin</artifactId>
60
            <scope>compile</scope>
61 60
		</dependency>
62 61
        <dependency>
63 62
            <groupId>org.gvsig</groupId>
64 63
            <artifactId>org.gvsig.andami</artifactId>
65
            <scope>compile</scope>
66 64
        </dependency>
67 65
        <dependency>
68 66
            <groupId>org.gvsig</groupId>
69 67
            <artifactId>org.gvsig.symbology.lib.api</artifactId>
70
            <scope>compile</scope>
71 68
        </dependency>
72 69
        <dependency>
73 70
            <groupId>org.gvsig</groupId>
74 71
            <artifactId>org.gvsig.symbology.lib.impl</artifactId>
75
            <scope>compile</scope>
76 72
        </dependency>
77 73
        <dependency>
78 74
            <groupId>org.gvsig</groupId>
79 75
            <artifactId>org.gvsig.symbology.swing.api</artifactId>
80
            <scope>compile</scope>
81 76
        </dependency>
82 77
        <dependency>
83 78
            <groupId>org.gvsig</groupId>
84 79
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
85
            <scope>compile</scope>
86 80
        </dependency>
87 81
        <dependency>
88 82
            <groupId>org.gvsig</groupId>
89 83
            <artifactId>org.gvsig.utils</artifactId>
90
            <scope>compile</scope>
91 84
        </dependency>
92 85
        <dependency>
93 86
            <groupId>org.gvsig</groupId>
94 87
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
95
            <scope>compile</scope>
96 88
        </dependency>
97 89

  
98 90
        <dependency>
99 91
            <groupId>org.gvsig</groupId>
100 92
            <artifactId>org.gvsig.i18n</artifactId>
101
            <scope>compile</scope>
102 93
        </dependency>
103 94
        
104 95
		<dependency>
105 96
            <groupId>org.gvsig</groupId>
106 97
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
107
            <scope>compile</scope>
108 98
        </dependency>
109 99
        
110 100
        <dependency>
111 101
            <groupId>org.gvsig</groupId>
112 102
            <artifactId>org.gvsig.tools.lib</artifactId>
113
            <scope>compile</scope>
114 103
        </dependency>
115 104
        <dependency>
116 105
            <groupId>org.gvsig</groupId>
117 106
            <artifactId>org.gvsig.ui</artifactId>
118
            <scope>compile</scope>
119 107
        </dependency>        
120 108
        <dependency>
121 109
            <groupId>org.gvsig</groupId>
122 110
            <artifactId>org.gvsig.projection.api</artifactId>
123
            <scope>compile</scope>
124 111
        </dependency>        
125 112
        <dependency>
126 113
            <groupId>org.gvsig</groupId>
127 114
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
128
            <scope>compile</scope>
129 115
        </dependency>        
130 116
        
131 117
        <dependency>
132 118
            <groupId>org.gvsig</groupId>
133 119
            <artifactId>org.gvsig.compat.api</artifactId>
134
            <scope>compile</scope>
135 120
        </dependency>
136 121
        
137 122
		<dependency>
138 123
            <groupId>org.gvsig</groupId>
139 124
			<artifactId>org.gvsig.tools.evaluator.sqljep</artifactId>
140
            <scope>compile</scope>
141 125
		</dependency>
142 126
		
143 127
        <dependency>
......
149 133
        <dependency>
150 134
            <groupId>org.gvsig</groupId>
151 135
            <artifactId>org.gvsig.tools.swing.api</artifactId>
152
            <scope>compile</scope>
153 136
        </dependency>
154 137

  
155 138
        <!--

Also available in: Unified diff