Revision 84 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingSwingManager.java

View differences:

DefaultEditingSwingManager.java
12 12
import java.awt.GridBagConstraints;
13 13
import java.awt.GridBagLayout;
14 14
import java.awt.Insets;
15
import java.util.List;
15 16

  
16 17
import javax.swing.JLabel;
17 18
import javax.swing.JOptionPane;
18 19
import javax.swing.JPanel;
19 20

  
20
import org.gvsig.andami.PluginServices;
21
import org.gvsig.andami.messages.NotificationManager;
22 21
import org.gvsig.editing.EditingNotification;
23 22
import org.gvsig.editing.EditingNotificationManager;
24 23
import org.gvsig.fmap.dal.feature.FeatureStore;
......
62 61

  
63 62
  public DefaultEditingSwingManager() {
64 63
    super(new DefaultEditingProviderManager());
65
    // TODO Auto-generated constructor stub
66 64
  }
67 65

  
68 66
  public void activateService(String name, MapControl mapControl) {
69 67
    if (mapControl != null && mapControl.hasTool("VectorEditing")) {
70
      CompoundBehavior behavior = (CompoundBehavior) mapControl.getMapTool("VectorEditing");
68
      CompoundBehavior editingCompoundBehavior = getEditingCompoundBehavior(mapControl);
71 69
      mapControl.setTool("VectorEditing");
72
      EditingBehavior editingBehavior = (EditingBehavior) behavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
73
      behavior.setDrawnBehavior(EditingCompoundBehavior.EDITING_INDEX, true);
70
      EditingBehavior editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
71
      editingCompoundBehavior.setDrawnBehavior(EditingCompoundBehavior.EDITING_INDEX, true);
74 72
      editingBehavior.activateService(name);
75 73
    }
76 74
  }
77 75

  
78
  public void beginEdition(FLyrVect layer, MapControl mapControl) {
76
  public void beginEdition(FLyrVect layer, MapControl mapControl, Behavior[] additionalBehaviors) {
79 77

  
80 78
    EditingNotificationManager editingNotificationManager = MapControlLocator
81 79
        .getEditingNotificationManager();
......
92 90
    }
93 91

  
94 92
    try {
95
		initFocus(mapControl);
93
		addBehaviors(mapControl, additionalBehaviors);
96 94
	} catch (CreateEditingBehaviorException e1) {
97
		NotificationManager.addError(e1.getMessage(), e1);
95
		logger.error(e1.getMessage(), e1);
98 96
	}
99 97

  
100 98
    try {
......
121 119
    FeatureStore featureStore = layer.getFeatureStore();
122 120
    try {
123 121
      featureStore.cancelEditing();
124
      EditingCompoundBehavior editingCompoundBehavior = (EditingCompoundBehavior) mapControl.getMapTool("VectorEditing");
122
      EditingCompoundBehavior editingCompoundBehavior = getEditingCompoundBehavior(mapControl);
125 123
      EditingBehavior editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
126
      //FIXME: ?habr?a que poner el editingCompoundBehavior en modo editing? No, ya lo hace el cleanBehavior
127
//      editingCompoundBehavior.setDrawnBehavior(EditingCompoundBehavior.EDITING_INDEX, true);
128 124
      editingBehavior.cleanBehavior();
129 125
      editingBehavior.hideConsole();
130 126
    }
......
191 187
      mapControl.getCanceldraw().setCanceled(true);
192 188
      int option;
193 189
      if (layer.isWritable()) {
194
        option = showPanelSaveOrDiscard(layer.getName());
190
        option = showPanelSaveOrDiscard(mapControl, layer.getName());
195 191
      }
196 192
      else {
197
        option = showPanelExportOrDiscard(layer.getName());
193
        option = showPanelExportOrDiscard(mapControl, layer.getName());
198 194
      }
199 195

  
200 196
      doAction(layer, mapControl, option);
......
276 272
   * @param mapControl
277 273
 * @throws CreateEditingBehaviorException
278 274
   */
279
  private void initFocus(MapControl mapControl) throws CreateEditingBehaviorException {
275
  private void addBehaviors(MapControl mapControl, Behavior[] additionalBehavior) throws CreateEditingBehaviorException {
280 276

  
281 277
    EditingBehavior editingBehavior;
282 278
    EditingCompoundBehavior editingCompoundBehavior;
......
284 280
      editingBehavior = new DefaultEditingBehavior(mapControl);
285 281
      editingCompoundBehavior = new EditingCompoundBehavior(editingBehavior);
286 282
      ((DefaultEditingBehavior)editingBehavior).setCompoundBehavior(editingCompoundBehavior);
287
      mapControl.addBehavior("VectorEditing",editingCompoundBehavior);
288

  
289

  
283
      if(additionalBehavior != null){
284
	      Behavior[] behaviors = new Behavior[additionalBehavior.length+1];
285
	      behaviors[0] = editingCompoundBehavior;
286
	      for (int i = 0; i < additionalBehavior.length; i++) {
287
	    	  behaviors[i+1]= additionalBehavior[i];
288
	      }
289
	      mapControl.addBehavior("VectorEditing",behaviors);
290
      } else {
291
	      mapControl.addBehavior("VectorEditing",editingCompoundBehavior);
292
      }
290 293
    }
291 294
    else {
292
		editingCompoundBehavior = (EditingCompoundBehavior) mapControl.getMapTool("VectorEditing");
295
    	editingCompoundBehavior = getEditingCompoundBehavior(mapControl);
293 296
	    editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
294 297
	    ((DefaultEditingBehavior)editingBehavior).setCompoundBehavior(editingCompoundBehavior);
295 298
	    editingBehavior.cleanBehavior();
296 299
    }
297 300

  
301

  
298 302
    mapControl.setTool("VectorEditing");
299 303
    editingBehavior.showConsole();
300 304
  }
......
310 314
    try {
311 315
      featureStore.finishEditing();
312 316
      EditingBehavior editingBehavior;
313
      EditingCompoundBehavior editingCompoundBehavior;
314
      editingCompoundBehavior = (EditingCompoundBehavior) mapControl.getMapTool("VectorEditing");
315
      editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
316 317

  
317
      editingBehavior.cleanBehavior();
318
      editingBehavior.hideConsole();
318
    EditingCompoundBehavior editingCompoundBehavior = getEditingCompoundBehavior(mapControl);
319

  
320
  	editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
321

  
322
    editingBehavior.cleanBehavior();
323
    editingBehavior.hideConsole();
319 324
    }
320 325
    catch (Exception e) {
321 326
      throw new EndEditingException(e);
......
324 329
    featureStore.deleteObserver(mapControl);
325 330
  }
326 331

  
332
private EditingCompoundBehavior getEditingCompoundBehavior(MapControl mapControl) {
333
	EditingCompoundBehavior editingCompoundBehavior;
334

  
335
  	CompoundBehavior compoundBehavior = (CompoundBehavior) mapControl.getMapTool("VectorEditing");
336
  	if(compoundBehavior instanceof EditingCompoundBehavior){
337
  		editingCompoundBehavior = (EditingCompoundBehavior) compoundBehavior;
338
  	} else {
339
  		editingCompoundBehavior = (EditingCompoundBehavior) compoundBehavior.getBehavior(0);
340
  	}
341
	return editingCompoundBehavior;
342
}
343

  
327 344
  /**
328 345
   * @param name
329 346
   * @return
330 347
   */
331
  private int showPanelExportOrDiscard(String name) {
332
    Object[] options = { PluginServices.getText(this, "export"),
348
  private int showPanelExportOrDiscard(Component root, String name) {
349
    Object[] options = { i18nManager.getTranslation("export"),
333 350
        "       " + i18nManager.getTranslation("discard") + "       ",
334 351
        i18nManager.getTranslation("continue") };
335 352

  
......
342 359
        firstDesc);
343 360

  
344 361
    int resp = JOptionPane.showOptionDialog(
345
        (Component) PluginServices.getMainFrame(), explanation_panel,
362
        root, explanation_panel,
346 363
        i18nManager.getTranslation("stop_edition"),
347 364
        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
348 365
        options, options[2]);
......
360 377
   * @param layerName
361 378
   * @return
362 379
   */
363
  private int showPanelSaveOrDiscard(String layerName) {
364
    Object[] options = { PluginServices.getText(this, "_Guardar"),
365
        "       " + PluginServices.getText(this, "_Descartar") + "       ",
366
        PluginServices.getText(this, "_Continuar") };
380
  private int showPanelSaveOrDiscard(Component root, String layerName) {
381
    Object[] options = { i18nManager.getTranslation("_Guardar"),
382
        "       " + i18nManager.getTranslation("_Descartar") + "       ",
383
        i18nManager.getTranslation("_Continuar") };
367 384

  
368 385
    String question = i18nManager
369 386
        .getTranslation("realmente_desea_guardar_la_capa");
......
374 391
        firstDesc);
375 392

  
376 393
    int resp = JOptionPane.showOptionDialog(
377
        (Component) PluginServices.getMainFrame(), explanation_panel,
378
        PluginServices.getText(this, "stop_edition"),
394
        root, explanation_panel,
395
        i18nManager.getTranslation("stop_edition"),
379 396
        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
380 397
        options, options[2]);
381 398

  

Also available in: Unified diff