gvsig-vectorediting / 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 @ 42
History | View | Annotate | Download (3.74 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.swing.impl
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.swing.impl; |
8 |
|
9 |
import org.gvsig.app.ApplicationLocator; |
10 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
11 |
import org.gvsig.editing.EditingNotification; |
12 |
import org.gvsig.editing.EditingNotificationManager; |
13 |
import org.gvsig.fmap.dal.exception.DataException; |
14 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
15 |
import org.gvsig.fmap.mapcontrol.MapControl; |
16 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
17 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
18 |
import org.gvsig.tools.dynobject.DynObject; |
19 |
import org.gvsig.tools.service.AbstractManager; |
20 |
import org.gvsig.tools.service.Service; |
21 |
import org.gvsig.tools.service.ServiceException; |
22 |
import org.gvsig.tools.service.spi.ProviderManager; |
23 |
import org.gvsig.utils.console.jedit.JEditTextArea; |
24 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
25 |
import org.gvsig.vectorediting.lib.impl.DefaultEditingProviderManager; |
26 |
import org.gvsig.vectorediting.swing.api.EditingBehavior; |
27 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
28 |
import org.slf4j.Logger; |
29 |
import org.slf4j.LoggerFactory; |
30 |
|
31 |
public class DefaultEditingSwingManager extends AbstractManager implements |
32 |
EditingSwingManager { |
33 |
|
34 |
private static final Logger logger = LoggerFactory |
35 |
.getLogger(EditingManager.class); |
36 |
|
37 |
public DefaultEditingSwingManager() {
|
38 |
super(new DefaultEditingProviderManager()); |
39 |
// TODO Auto-generated constructor stub
|
40 |
} |
41 |
|
42 |
public Service getService(DynObject parameters) throws ServiceException { |
43 |
// TODO Auto-generated method stub
|
44 |
return null; |
45 |
} |
46 |
|
47 |
public void activateTool(String name, MapControl mapControl) { |
48 |
// TODO Auto-generated method stub
|
49 |
if (mapControl != null && mapControl.hasTool("VectorEditing")) { |
50 |
EditingBehavior behavior = (EditingBehavior) mapControl |
51 |
.getMapTool("VectorEditing");
|
52 |
behavior.activateTool(name); |
53 |
} |
54 |
} |
55 |
|
56 |
public void beginEdition(FLyrVect layer, DefaultViewPanel view) |
57 |
throws DataException {
|
58 |
|
59 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
60 |
.getEditingNotificationManager(); |
61 |
|
62 |
EditingNotification notification = editingNotificationManager |
63 |
.notifyObservers(this, EditingNotification.BEFORE_ENTER_EDITING_STORE,
|
64 |
view.getDocument(), layer); |
65 |
|
66 |
if (notification.isCanceled()) {
|
67 |
logger.info("Edit layer '" + layer.getName()
|
68 |
+ "' canceled by somme observer.");
|
69 |
throw new RuntimeException("Edit layer '" + layer.getName() |
70 |
+ "' canceled.");
|
71 |
} |
72 |
|
73 |
initFocus(view); |
74 |
view.showConsole(); |
75 |
setCaretPosition(view); |
76 |
|
77 |
layer.getFeatureStore().edit(); |
78 |
layer.getFeatureStore().addObserver(view); |
79 |
layer.getFeatureStore().addObserver(view.getMapControl()); |
80 |
|
81 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
82 |
|
83 |
editingNotificationManager.notifyObservers(this,
|
84 |
EditingNotification.AFTER_ENTER_EDITING_STORE, view.getDocument(), |
85 |
layer); |
86 |
} |
87 |
|
88 |
private void initFocus(DefaultViewPanel view) { |
89 |
|
90 |
MapControl mapControl = view.getMapControl(); |
91 |
|
92 |
if (!mapControl.hasTool("VectorEditing")) { |
93 |
Behavior vectorEditing = new DefaultEditingBehavior(mapControl);
|
94 |
mapControl.addBehavior("VectorEditing", vectorEditing);
|
95 |
} |
96 |
else {
|
97 |
EditingBehavior editingBehavior = (EditingBehavior) mapControl |
98 |
.getMapTool("VectorEditing");
|
99 |
editingBehavior.cleanBehavior(); |
100 |
} |
101 |
|
102 |
mapControl.setTool("VectorEditing");
|
103 |
|
104 |
} |
105 |
|
106 |
private void setCaretPosition(DefaultViewPanel view) { |
107 |
|
108 |
JEditTextArea jeta = view.getConsolePanel().getTxt(); |
109 |
jeta.requestFocusInWindow(); |
110 |
jeta.setCaretPosition(jeta.getText().length()); |
111 |
|
112 |
} |
113 |
|
114 |
} |