root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / StartEditing.java @ 38790
History | View | Annotate | Download (7.83 KB)
1 |
package org.gvsig.editing; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
|
5 |
import javax.swing.JOptionPane; |
6 |
|
7 |
import org.slf4j.Logger; |
8 |
import org.slf4j.LoggerFactory; |
9 |
|
10 |
import org.gvsig.andami.PluginServices; |
11 |
import org.gvsig.andami.messages.Messages; |
12 |
import org.gvsig.andami.messages.NotificationManager; |
13 |
import org.gvsig.andami.plugins.Extension; |
14 |
import org.gvsig.app.ApplicationLocator; |
15 |
import org.gvsig.app.project.documents.view.ViewDocument; |
16 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
17 |
import org.gvsig.editing.gui.cad.CADTool; |
18 |
import org.gvsig.editing.gui.tokenmarker.ConsoleToken; |
19 |
import org.gvsig.fmap.dal.exception.ReadException; |
20 |
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
21 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
22 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
23 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
24 |
import org.gvsig.fmap.mapcontrol.MapControl; |
25 |
import org.gvsig.utils.console.jedit.KeywordMap; |
26 |
import org.gvsig.utils.console.jedit.Token; |
27 |
|
28 |
|
29 |
/**
|
30 |
* DOCUMENT ME!
|
31 |
*
|
32 |
* @author Vicente Caballero Navarro
|
33 |
*/
|
34 |
public class StartEditing extends Extension { |
35 |
|
36 |
private static Logger logger = LoggerFactory.getLogger(StartEditing.class); |
37 |
|
38 |
// private class MyAction extends AbstractAction
|
39 |
// {
|
40 |
//
|
41 |
// public void actionPerformed(ActionEvent e) {
|
42 |
// System.err.println("F3");
|
43 |
// }
|
44 |
//
|
45 |
// }
|
46 |
|
47 |
//View vista;
|
48 |
/**
|
49 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
50 |
*/
|
51 |
public void initialize() { |
52 |
} |
53 |
|
54 |
/**
|
55 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
56 |
*/
|
57 |
public void execute(String actionCommand) { |
58 |
|
59 |
if (actionCommand.compareTo("layer-start-editing") == 0) { |
60 |
|
61 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
62 |
PluginServices.getMDIManager().getActiveWindow(); |
63 |
|
64 |
if (f instanceof DefaultViewPanel) { |
65 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
66 |
|
67 |
MapControl mapControl = vista.getMapControl(); |
68 |
ViewDocument model = vista.getModel(); |
69 |
FLayer[] actives =
|
70 |
model.getMapContext().getLayers().getActives(); |
71 |
|
72 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
73 |
|
74 |
FLyrVect lv = (FLyrVect) actives[0];
|
75 |
|
76 |
if (!lv.getFeatureStore().getTransforms().isEmpty()) {
|
77 |
|
78 |
// cannot edit transformed
|
79 |
JOptionPane
|
80 |
.showMessageDialog( |
81 |
(Component) f,
|
82 |
Messages |
83 |
.get("_Cannot_start_edition_in_transformed_layer")
|
84 |
+ ": '" + lv.getName() + "'", |
85 |
PluginServices.getText(this, "warning_title"), |
86 |
JOptionPane.INFORMATION_MESSAGE);
|
87 |
return;
|
88 |
} |
89 |
|
90 |
CADExtension.initFocus(); |
91 |
vista.showConsole(); |
92 |
EditionManager editionManager = |
93 |
CADExtension.getEditionManager(); |
94 |
editionManager.setMapControl(mapControl); |
95 |
|
96 |
lv.addLayerListener(editionManager); |
97 |
try {
|
98 |
if (!lv.isWritable()) {
|
99 |
JOptionPane.showMessageDialog((Component) f, |
100 |
PluginServices.getText(this,
|
101 |
"this_layer_is_not_self_editable"),
|
102 |
PluginServices.getText(this, "warning_title"), |
103 |
JOptionPane.WARNING_MESSAGE);
|
104 |
} |
105 |
|
106 |
// This line also enables the spatial cache for snapping:
|
107 |
lv.setEditing(true);
|
108 |
|
109 |
lv.getFeatureStore().addObserver(mapControl); |
110 |
startCommandsApplicable(vista, lv); |
111 |
|
112 |
// vista.repaintMap();
|
113 |
// ----------------------------
|
114 |
// this forces a true repaint:
|
115 |
forceMapRepaint(mapControl, lv); |
116 |
|
117 |
} catch (StartEditionLayerException e) {
|
118 |
|
119 |
logger.info( |
120 |
"Error while starting edition: " + e.getMessage(),
|
121 |
e); |
122 |
|
123 |
ApplicationLocator.getManager().message( |
124 |
Messages.get("_Unable_to_start_edition_in_layer")
|
125 |
+ ": " + lv.getName(),
|
126 |
JOptionPane.ERROR_MESSAGE);
|
127 |
} |
128 |
} |
129 |
} |
130 |
} |
131 |
} |
132 |
|
133 |
|
134 |
/**
|
135 |
* @param mapControl
|
136 |
* @param lv
|
137 |
*/
|
138 |
private void forceMapRepaint(MapControl mc, FLyrVect lv) { |
139 |
|
140 |
lv.drawValueChanged( |
141 |
LayerEvent.createDrawValuesChangedEvent(lv, ""));
|
142 |
|
143 |
/*
|
144 |
*
|
145 |
*
|
146 |
* Alternative: force small change of extent:
|
147 |
*
|
148 |
Envelope env = mc.getViewPort().getAdjustedEnvelope();
|
149 |
Point uc = env.getUpperCorner();
|
150 |
double len = env.getLength(0);
|
151 |
uc.setX(uc.getX() + len * 0.0001);
|
152 |
env.setUpperCorner(uc);
|
153 |
mc.getViewPort().setEnvelope(env);
|
154 |
|
155 |
*
|
156 |
* Alternative (?)
|
157 |
*
|
158 |
* mc.invalidate();
|
159 |
*
|
160 |
*/
|
161 |
|
162 |
} |
163 |
|
164 |
// private void registerKeyStrokes() {
|
165 |
// JComponent theComponent = vista.getConsolePanel().getTxt();
|
166 |
//
|
167 |
// // The actions
|
168 |
// Action F3Action = new AbstractAction("REFENT") {
|
169 |
// public void actionPerformed(ActionEvent evt) {
|
170 |
// System.err.println("SOY F3");
|
171 |
// }
|
172 |
// };
|
173 |
//
|
174 |
// InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
175 |
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
|
176 |
//
|
177 |
// ActionMap actionMap = theComponent.getActionMap();
|
178 |
// // actionMap.put("REFENT", new MyAction());
|
179 |
// actionMap.put(F3Action.getValue(Action.NAME), F3Action);
|
180 |
//
|
181 |
// }
|
182 |
|
183 |
public static void startCommandsApplicable(DefaultViewPanel vista,FLyrVect lv) { |
184 |
if (vista==null) |
185 |
vista=(DefaultViewPanel)PluginServices.getMDIManager().getActiveWindow(); |
186 |
|
187 |
CADTool[] cadtools = CADExtension.getCADTools();
|
188 |
KeywordMap keywordMap = new KeywordMap(true); |
189 |
for (int i = 0; i < cadtools.length; i++) { |
190 |
try {
|
191 |
if (cadtools[i].isApplicable(lv.getShapeType())){
|
192 |
keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
193 |
keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
194 |
} |
195 |
} catch (ReadException e) {
|
196 |
NotificationManager.addError(e.getMessage(),e); |
197 |
} |
198 |
|
199 |
} |
200 |
ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
201 |
vista.getConsolePanel().setTokenMarker(consoletoken); |
202 |
|
203 |
} |
204 |
|
205 |
// private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
|
206 |
// com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
207 |
//
|
208 |
// for (int i=0 ; i<views.length ; i++){
|
209 |
// if (views[i] instanceof Table){
|
210 |
// Table table=(Table)views[i];
|
211 |
// ProjectTable model =table.getModel();
|
212 |
// if (model.equals(pt)){
|
213 |
// table.setModel(pt);
|
214 |
// vea.getCommandRecord().addCommandListener(table);
|
215 |
// }
|
216 |
// }
|
217 |
// }
|
218 |
// }
|
219 |
/**
|
220 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
221 |
*/
|
222 |
public boolean isEnabled() { |
223 |
return true; |
224 |
} |
225 |
|
226 |
/**
|
227 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
228 |
*/
|
229 |
public boolean isVisible() { |
230 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
231 |
.getActiveWindow(); |
232 |
|
233 |
if (f == null) { |
234 |
return false; |
235 |
} |
236 |
if (f instanceof DefaultViewPanel){ |
237 |
DefaultViewPanel view=(DefaultViewPanel)f; |
238 |
FLayer[] selected = view.getModel().getMapContext().getLayers()
|
239 |
.getActives(); |
240 |
if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
241 |
if (selected[0].isEditing()) |
242 |
return false; |
243 |
return true; |
244 |
} |
245 |
} |
246 |
return false; |
247 |
} |
248 |
} |