root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / StartEditing.java @ 30349
History | View | Annotate | Download (7.48 KB)
1 |
package org.gvsig.editing; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
|
5 |
import javax.swing.JOptionPane; |
6 |
|
7 |
import org.gvsig.andami.PluginServices; |
8 |
import org.gvsig.andami.messages.NotificationManager; |
9 |
import org.gvsig.andami.plugins.Extension; |
10 |
import org.gvsig.app.extension.ProjectExtension; |
11 |
import org.gvsig.app.project.documents.table.FeatureTableDocument; |
12 |
import org.gvsig.app.project.documents.view.IProjectView; |
13 |
import org.gvsig.app.project.documents.view.gui.View; |
14 |
import org.gvsig.editing.gui.cad.CADTool; |
15 |
import org.gvsig.editing.gui.tokenmarker.ConsoleToken; |
16 |
import org.gvsig.fmap.dal.exception.DataException; |
17 |
import org.gvsig.fmap.dal.exception.ReadException; |
18 |
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
19 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
20 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
21 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
22 |
import org.gvsig.fmap.mapcontrol.MapControl; |
23 |
import org.gvsig.utils.XMLException; |
24 |
import org.gvsig.utils.console.jedit.KeywordMap; |
25 |
import org.gvsig.utils.console.jedit.Token; |
26 |
|
27 |
|
28 |
/**
|
29 |
* DOCUMENT ME!
|
30 |
*
|
31 |
* @author Vicente Caballero Navarro
|
32 |
*/
|
33 |
public class StartEditing extends Extension { |
34 |
|
35 |
// private class MyAction extends AbstractAction
|
36 |
// {
|
37 |
//
|
38 |
// public void actionPerformed(ActionEvent e) {
|
39 |
// System.err.println("F3");
|
40 |
// }
|
41 |
//
|
42 |
// }
|
43 |
|
44 |
//View vista;
|
45 |
/**
|
46 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
47 |
*/
|
48 |
public void initialize() { |
49 |
} |
50 |
|
51 |
/**
|
52 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
53 |
*/
|
54 |
public void execute(String actionCommand) { |
55 |
CADExtension.initFocus(); |
56 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
57 |
.getActiveWindow(); |
58 |
|
59 |
if (f instanceof View) { |
60 |
View vista = (View) f; |
61 |
|
62 |
MapControl mapControl = vista.getMapControl(); |
63 |
IProjectView model = vista.getModel(); |
64 |
FLayer[] actives = model.getMapContext().getLayers().getActives();
|
65 |
|
66 |
boolean bEditingStarted = false; |
67 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
68 |
|
69 |
vista.showConsole(); |
70 |
EditionManager editionManager=CADExtension.getEditionManager(); |
71 |
editionManager.setMapControl(mapControl); |
72 |
/*
|
73 |
* for (int j = 0; j < i; j++) {
|
74 |
* layers.getLayer(j).setVisible(false); }
|
75 |
*/
|
76 |
|
77 |
FLyrVect lv = (FLyrVect) actives[0];
|
78 |
// lv.setVisible(true);
|
79 |
lv.addLayerListener(editionManager); |
80 |
try {
|
81 |
ILegend legendOriginal=lv.getLegend().cloneLegend(); |
82 |
|
83 |
if (!lv.isWritable())
|
84 |
{ |
85 |
JOptionPane.showMessageDialog(
|
86 |
(Component) PluginServices.getMDIManager().getActiveWindow(),
|
87 |
PluginServices.getText(this, "this_layer_is_not_self_editable"), |
88 |
PluginServices.getText(this, "warning_title"), |
89 |
JOptionPane.WARNING_MESSAGE);
|
90 |
} |
91 |
|
92 |
lv.setEditing(true);
|
93 |
// FeatureType featureType=lv.getFeatureStore().getDefaultFeatureType();
|
94 |
// featureType.getRules().clear();
|
95 |
// if (lv.getShapeType()==Geometry.TYPES.SURFACE){
|
96 |
// FeatureRule rulePol = new FeatureRulePolygon("PolygonRule", "Sentido correcto de un pol?gono");
|
97 |
// featureType.addRule(rulePol);
|
98 |
// }
|
99 |
|
100 |
// if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){
|
101 |
// VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv);
|
102 |
// vle.setLegend(legendOriginal);
|
103 |
// }
|
104 |
lv.getFeatureStore().addObserver(mapControl); |
105 |
// vea.getCommandRecord().addCommandListener(mapControl);
|
106 |
// Si existe una tabla asociada a esta capa se cambia su
|
107 |
// modelo por el VectorialEditableAdapter.
|
108 |
ProjectExtension pe = (ProjectExtension) PluginServices |
109 |
.getExtension(ProjectExtension.class); |
110 |
FeatureTableDocument pt = pe.getProject().getTable(lv); |
111 |
if (pt != null){ |
112 |
pt.setStore(lv.getFeatureStore()); |
113 |
// changeModelTable(pt,vea);
|
114 |
} |
115 |
|
116 |
startCommandsApplicable(vista,lv); |
117 |
vista.repaintMap(); |
118 |
|
119 |
} catch (StartEditionLayerException e) {
|
120 |
NotificationManager.addError(e.getMessage(),e); |
121 |
// } catch (ReadException e) {
|
122 |
// NotificationManager.addError(e.getMessage(),e);
|
123 |
// } catch (DataException e) {
|
124 |
// NotificationManager.addError(e.getMessage(),e);
|
125 |
} |
126 |
|
127 |
// return;
|
128 |
} |
129 |
} |
130 |
|
131 |
/*
|
132 |
* PluginServices.getMDIManager().setWaitCursor(); try { if
|
133 |
* (((FLyrVect) capa).getSource().getDriver().getClass() ==
|
134 |
* DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
|
135 |
* (Component) PluginServices.getMainFrame(), "Todas las geometr?as
|
136 |
* del formato DXF no se pueden editar, de momento podemos editar:
|
137 |
* Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
|
138 |
* geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
|
139 |
* JOptionPane.YES_OPTION) { capa.startEdition();
|
140 |
* vista.getMapControl().setCadTool("selection"); } else { } } else {
|
141 |
* capa.startEdition();
|
142 |
* vista.getMapControl().setCadTool("selection"); } } catch
|
143 |
* (EditionException e) { // TODO Auto-generated catch block
|
144 |
* e.printStackTrace(); }
|
145 |
* PluginServices.getMDIManager().restoreCursor();
|
146 |
*/
|
147 |
// vista.getMapControl().drawMap(false);
|
148 |
} |
149 |
|
150 |
// private void registerKeyStrokes() {
|
151 |
// JComponent theComponent = vista.getConsolePanel().getTxt();
|
152 |
//
|
153 |
// // The actions
|
154 |
// Action F3Action = new AbstractAction("REFENT") {
|
155 |
// public void actionPerformed(ActionEvent evt) {
|
156 |
// System.err.println("SOY F3");
|
157 |
// }
|
158 |
// };
|
159 |
//
|
160 |
// InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
161 |
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
|
162 |
//
|
163 |
// ActionMap actionMap = theComponent.getActionMap();
|
164 |
// // actionMap.put("REFENT", new MyAction());
|
165 |
// actionMap.put(F3Action.getValue(Action.NAME), F3Action);
|
166 |
//
|
167 |
// }
|
168 |
|
169 |
public static void startCommandsApplicable(View vista,FLyrVect lv) { |
170 |
if (vista==null) |
171 |
vista=(View)PluginServices.getMDIManager().getActiveWindow();
|
172 |
CADTool[] cadtools = CADExtension.getCADTools();
|
173 |
KeywordMap keywordMap = new KeywordMap(true); |
174 |
for (int i = 0; i < cadtools.length; i++) { |
175 |
try {
|
176 |
if (cadtools[i].isApplicable(lv.getShapeType())){
|
177 |
keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
178 |
keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
179 |
} |
180 |
} catch (ReadException e) {
|
181 |
NotificationManager.addError(e.getMessage(),e); |
182 |
} |
183 |
|
184 |
} |
185 |
ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
186 |
vista.getConsolePanel().setTokenMarker(consoletoken); |
187 |
|
188 |
} |
189 |
|
190 |
// private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
|
191 |
// com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
192 |
//
|
193 |
// for (int i=0 ; i<views.length ; i++){
|
194 |
// if (views[i] instanceof Table){
|
195 |
// Table table=(Table)views[i];
|
196 |
// ProjectTable model =table.getModel();
|
197 |
// if (model.equals(pt)){
|
198 |
// table.setModel(pt);
|
199 |
// vea.getCommandRecord().addCommandListener(table);
|
200 |
// }
|
201 |
// }
|
202 |
// }
|
203 |
// }
|
204 |
/**
|
205 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
206 |
*/
|
207 |
public boolean isEnabled() { |
208 |
View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
209 |
|
210 |
if (f == null) { |
211 |
return false; |
212 |
} |
213 |
|
214 |
FLayer[] selected = f.getModel().getMapContext().getLayers()
|
215 |
.getActives(); |
216 |
if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
217 |
if (selected[0].isEditing()) |
218 |
return false; |
219 |
return true; |
220 |
} |
221 |
return false; |
222 |
} |
223 |
|
224 |
/**
|
225 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
226 |
*/
|
227 |
public boolean isVisible() { |
228 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
229 |
.getActiveWindow(); |
230 |
|
231 |
if (f == null) { |
232 |
return false; |
233 |
} |
234 |
|
235 |
if (f instanceof View) |
236 |
return true; |
237 |
return false; |
238 |
} |
239 |
} |