Revision 130 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingBehavior.java

View differences:

DefaultEditingBehavior.java
36 36
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
37 37
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE;
38 38
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException;
39
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
40 39
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException;
41 40
import org.gvsig.vectorediting.lib.api.exceptions.ParsePointException;
42 41
import org.gvsig.vectorediting.lib.api.exceptions.ParseValueException;
......
103 102
                try {
104 103
                    service.start();
105 104
                } catch (StartServiceException e) {
106
                    logger.error(
107
                        String.format("Can't start the service %(s)",
105
                    logger.info(
106
                        String.format("Can't start the service %1$s",
108 107
                            service.getName()), e);
108
                    cleanBehavior();
109
                    return;
109 110
                }
110 111

  
111 112
                if (!serviceStack.isEmpty()
......
190 191
    private void finishService() {
191 192
        EditingService lastService = serviceStack.pop();
192 193
        try {
193
            if (serviceStack.isEmpty()
194
                || !getActiveService().next().getTypes()
195
                    .contains(EditingServiceParameter.TYPE.GEOMETRY)) {
196 194

  
197
                lastService.finishAndStore();
198
                editingContext.getMapControl().rePaintDirtyLayers();
199
                setActiveService(lastService);
200

  
201
            } else if (!serviceStack.isEmpty()
195
            if (!serviceStack.isEmpty()
202 196
                && getActiveService().next().getTypes()
203 197
                    .contains(EditingServiceParameter.TYPE.GEOMETRY)) {
204 198

  
......
208 202

  
209 203
                    getActiveService().setValue(geometry);
210 204

  
211
                } else {
205
                }
212 206

  
213
                    lastService.finishAndStore();
214
                    editingContext.getMapControl().rePaintDirtyLayers();
215
                    setActiveService(lastService);
207
            } else {
216 208

  
217
                }
209
                lastService.finishAndStore();
210
                editingContext.getMapControl().rePaintDirtyLayers();
211
                setActiveService(lastService);
218 212

  
219 213
            }
220 214

  
......
224 218
        } catch (InvalidEntryException ex) {
225 219
            I18nManager i18nManager = ToolsLocator.getI18nManager();
226 220
            showConsoleMessage(i18nManager.getTranslation("invalid_option"));
227
        } catch (FinishServiceException ex) {
228
            logger.error("Can't finish " + lastService.getName(), ex);
229
        } catch (StopServiceException ex) {
230
            logger.error("Can't stop " + lastService.getName(), ex);
231
        } catch (StartServiceException ex) {
232
            logger.error("Can't start " + lastService.getName(), ex);
221
        } catch (VectorEditingException ex) {
222
            logger.info("Can't finish " + lastService.getName(), ex);
223
            cleanBehavior();
224
            return;
233 225
        }
234 226

  
235 227
        getNextParameter();
......
239 231
        ViewPort vp = editingContext.getMapControl().getViewPort();
240 232
        if (getActiveService() != null) {
241 233
            if (currentParam != null) {
234

  
242 235
                List<TYPE> typesOfParam = currentParam.getTypes();
236

  
243 237
                if (typesOfParam.contains(TYPE.LIST_POSITIONS)
244 238
                    || typesOfParam.contains(TYPE.POSITION)) {
239

  
245 240
                    if (typesOfParam.contains(TYPE.LIST_POSITIONS)) {
246 241
                        if (e.getClickCount() == 2) {
247 242
                            finishService();
248 243
                            return;
249 244
                        }
250 245
                    }
246

  
251 247
                    Point point;
252 248
                    point = vp.convertToMapPoint(e.getX(), e.getY());
249

  
253 250
                    try {
254 251
                        getActiveService().setValue(point);
255 252
                    } catch (VectorEditingException ex) {
256
                        logger
257
                            .error("Invalid value %s", new Object[] { point });
253
                        I18nManager i18nManager = ToolsLocator.getI18nManager();
254
                        showConsoleMessage(i18nManager
255
                            .getTranslation("invalid_option"));
258 256
                    }
257

  
259 258
                }
260
                if (typesOfParam.contains(TYPE.SELECTION)) {
261
                    // Do nothing
262
                }
259

  
263 260
                getNextParameter();
264 261
            }
265 262
        }
......
271 268
    public void mouseMoved(MouseEvent e) throws BehaviorException {
272 269
        ViewPort vp = editingContext.getMapControl().getViewPort();
273 270
        adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY());
274
        getMapControl().repaint();
275 271
    }
276 272

  
277 273
    public void mousePressed(MouseEvent e) throws BehaviorException {
......
282 278

  
283 279
    public void paintComponent(MapControlDrawer mapControlDrawer) {
284 280
        super.paintComponent(mapControlDrawer);
281
        
285 282
        if (getActiveService() == null || adjustedPoint == null) {
286 283
            return;
287 284
        }
288 285

  
289 286
        DrawingStatus helperGeo = null;
287
        
290 288
        try {
291 289
            helperGeo = getActiveService().getDrawingStatus(adjustedPoint);
292 290
        } catch (VectorEditingException e) {
293
            logger.error("An error ocurred when draw service geometries", e);
291
            logger.info("An error ocurred when draw service geometries", e);
294 292
        }
293
        
295 294
        if (helperGeo != null) {
296
            for (@SuppressWarnings("rawtypes")
297
            Iterator iterator = helperGeo.getGeometries().iterator(); iterator
295
            for (Iterator iterator = helperGeo.getGeometries().iterator(); iterator
298 296
                .hasNext();) {
299 297
                Geometry geometry = (Geometry) iterator.next();
300 298
                editingContext
......
342 340
    public void textEntered(String response) {
343 341
        if (response == null) {
344 342
            if (getActiveService() != null) {
343
                
345 344
                try {
345
                    
346 346
                    getActiveService().stop();
347
                    
347 348
                } catch (StopServiceException e) {
348
                    logger.error("Can't stop " + getActiveService().getName(),
349
                    logger.info("Can't stop " + getActiveService().getName(),
349 350
                        e);
351
                    return;
352
                } finally {
353
                    cleanBehavior();
350 354
                }
351
                cleanBehavior();
352 355
            }
353 356
        } else {
354 357
            List<TYPE> types = currentParam.getTypes();
......
358 361
            boolean insertedValue = false;
359 362
            if (!insertedValue && types.contains(TYPE.POSITION)
360 363
                || types.contains(TYPE.LIST_POSITIONS)) {
364
                
361 365
                try {
366
                    
362 367
                    point = parsePoint(response);
363 368
                    if (point != null) {
364 369
                        getActiveService().setValue(point);
365 370
                        insertedValue = true;
366 371
                    }
372
                    
367 373
                } catch (VectorEditingException e) {
368 374
                    // Do nothing to try other types
369 375
                }
370 376
            }
371 377
            if (!insertedValue && types.contains(TYPE.VALUE)) {
378
                
372 379
                try {
380
                    
373 381
                    value = parseValue(response);
374 382
                    if (value != null) {
375 383
                        getActiveService().setValue(value);
376 384
                        insertedValue = true;
377 385
                    }
386
                    
378 387
                } catch (VectorEditingException e) {
379 388
                    // Do nothing to try other types
380 389
                }
381 390

  
382 391
            }
383 392
            if (!insertedValue && types.contains(TYPE.OPTION)) {
393
                
384 394
                try {
395
                    
385 396
                    response = response.replace("\n", "");
386 397
                    if (response != null) {
387 398
                        getActiveService().setValue(response);
388 399
                        insertedValue = true;
389 400
                    }
401
                    
390 402
                } catch (VectorEditingException e) {
391 403
                    // Do nothing to try other types
392 404
                }
......
395 407
                if (response.equalsIgnoreCase("\n")) {
396 408
                    enableSelection(false);
397 409
                    insertedValue = true;
410
                    
398 411
                    try {
412
                        
399 413
                        getActiveService().setValue(
400 414
                            currentLayer.getFeatureStore()
401 415
                                .getFeatureSelection().clone());
416
                        
402 417
                    } catch (InvalidEntryException e) {
403 418
                        I18nManager i18nManager = ToolsLocator.getI18nManager();
404 419
                        showConsoleMessage(i18nManager
405 420
                            .getTranslation("invalid_option"));
406 421
                    } catch (Exception e) {
422
                        logger.info("Can't access to selecction.", e);
407 423
                        cleanBehavior();
408
                        logger.error("Can't access to selecction.", e);
424
                        return;
409 425
                    }
410 426
                }
411 427
            }

Also available in: Unified diff