root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / StartEditing.java @ 31407
History | View | Annotate | Download (8.82 KB)
1 | 3698 | caballero | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | 6856 | fjp | import java.awt.Component; |
4 | |||
5 | import javax.swing.JOptionPane; |
||
6 | |||
7 | 30185 | vcaballero | import com.hardcode.driverManager.DriverLoadException; |
8 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
9 | 3698 | caballero | import com.iver.andami.PluginServices; |
10 | 5152 | fjp | import com.iver.andami.messages.NotificationManager; |
11 | 3698 | caballero | import com.iver.andami.plugins.Extension; |
12 | 31403 | vcaballero | import com.iver.andami.ui.mdiManager.IWindow; |
13 | 10626 | caballero | import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
14 | 4118 | caballero | import com.iver.cit.gvsig.fmap.MapControl; |
15 | 5893 | fjp | import com.iver.cit.gvsig.fmap.core.FShape; |
16 | 6312 | caballero | import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
17 | 3698 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
18 | 5893 | fjp | import com.iver.cit.gvsig.fmap.edition.rules.IRule; |
19 | import com.iver.cit.gvsig.fmap.edition.rules.RulePolygon; |
||
20 | 3808 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
21 | 3698 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
22 | 6312 | caballero | import com.iver.cit.gvsig.fmap.layers.XMLException; |
23 | 11558 | jaume | import com.iver.cit.gvsig.fmap.rendering.ILegend; |
24 | 4892 | caballero | import com.iver.cit.gvsig.gui.cad.CADTool; |
25 | import com.iver.cit.gvsig.gui.tokenmarker.ConsoleToken; |
||
26 | 6312 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
27 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
28 | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
||
29 | 7410 | caballero | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
30 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
31 | 4892 | caballero | import com.iver.utiles.console.jedit.KeywordMap; |
32 | import com.iver.utiles.console.jedit.Token; |
||
33 | 3698 | caballero | |
34 | /**
|
||
35 | * DOCUMENT ME!
|
||
36 | 4892 | caballero | *
|
37 | 3698 | caballero | * @author Vicente Caballero Navarro
|
38 | */
|
||
39 | 5005 | jorpiell | public class StartEditing extends Extension { |
40 | 6312 | caballero | |
41 | 6604 | caballero | // private class MyAction extends AbstractAction
|
42 | // {
|
||
43 | //
|
||
44 | // public void actionPerformed(ActionEvent e) {
|
||
45 | // System.err.println("F3");
|
||
46 | // }
|
||
47 | //
|
||
48 | // }
|
||
49 | 5845 | fjp | |
50 | 9371 | jmvivo | //View vista;
|
51 | 4727 | fjp | /**
|
52 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
53 | 4727 | fjp | */
|
54 | 5005 | jorpiell | public void initialize() { |
55 | 4727 | fjp | } |
56 | 3698 | caballero | |
57 | 4727 | fjp | /**
|
58 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
59 | 4727 | fjp | */
|
60 | public void execute(String actionCommand) { |
||
61 | 25391 | vcaballero | |
62 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
63 | 9371 | jmvivo | .getActiveWindow(); |
64 | 10626 | caballero | |
65 | 4727 | fjp | if (f instanceof View) { |
66 | 9371 | jmvivo | View vista = (View) f; |
67 | 10626 | caballero | |
68 | 6604 | caballero | MapControl mapControl = vista.getMapControl(); |
69 | 10626 | caballero | |
70 | IProjectView model = vista.getModel(); |
||
71 | 9371 | jmvivo | FLayer[] actives = model.getMapContext().getLayers().getActives();
|
72 | 10626 | caballero | |
73 | 6856 | fjp | boolean bEditingStarted = false; |
74 | 9371 | jmvivo | if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
75 | 29775 | vcaballero | FLyrVect lv = (FLyrVect) actives[0];
|
76 | if (!mapControl.getProjection().getAbrev().equals(lv.getProjection().getAbrev())){
|
||
77 | 25391 | vcaballero | NotificationManager.showMessageInfo(PluginServices.getText(this,"no_es_posible_editar_capa_reproyectada"),null); |
78 | return;
|
||
79 | } |
||
80 | 29775 | vcaballero | if (lv.isJoined()) {
|
81 | int resp = JOptionPane.showConfirmDialog((Component) PluginServices |
||
82 | .getMainFrame(), PluginServices.getText(this,"se_perdera_la_union")+ |
||
83 | "\n" + PluginServices.getText(this,"desea_continuar"), |
||
84 | PluginServices.getText(this,"start_edition"), |
||
85 | JOptionPane.YES_NO_OPTION);
|
||
86 | if (resp != JOptionPane.YES_OPTION) { // CANCEL EDITING |
||
87 | return; // Salimos sin iniciar edici?n |
||
88 | } |
||
89 | } |
||
90 | 25391 | vcaballero | CADExtension.initFocus(); |
91 | 9371 | jmvivo | vista.showConsole(); |
92 | EditionManager editionManager=CADExtension.getEditionManager(); |
||
93 | editionManager.setMapControl(mapControl); |
||
94 | 24160 | jmvivo | // mapControl.getMapContext().clearAllCachingImageDrawnLayers();
|
95 | 9371 | jmvivo | /*
|
96 | * for (int j = 0; j < i; j++) {
|
||
97 | * layers.getLayer(j).setVisible(false); }
|
||
98 | */
|
||
99 | 10626 | caballero | |
100 | 29775 | vcaballero | |
101 | 9371 | jmvivo | // lv.setVisible(true);
|
102 | lv.addLayerListener(editionManager); |
||
103 | try {
|
||
104 | 11558 | jaume | ILegend legendOriginal=lv.getLegend().cloneLegend(); |
105 | 10626 | caballero | |
106 | 9371 | jmvivo | if (!lv.isWritable())
|
107 | { |
||
108 | JOptionPane.showMessageDialog(
|
||
109 | (Component) PluginServices.getMDIManager().getActiveWindow(),
|
||
110 | PluginServices.getText(this, "this_layer_is_not_self_editable"), |
||
111 | PluginServices.getText(this, "warning_title"), |
||
112 | JOptionPane.WARNING_MESSAGE);
|
||
113 | 5152 | fjp | } |
114 | 9371 | jmvivo | lv.setEditing(true);
|
115 | VectorialEditableAdapter vea = (VectorialEditableAdapter) lv |
||
116 | .getSource(); |
||
117 | 10626 | caballero | |
118 | 9371 | jmvivo | vea.getRules().clear(); |
119 | if (vea.getShapeType() == FShape.POLYGON)
|
||
120 | { |
||
121 | IRule rulePol = new RulePolygon();
|
||
122 | vea.getRules().add(rulePol); |
||
123 | } |
||
124 | 10626 | caballero | |
125 | 9371 | jmvivo | if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){ |
126 | VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv); |
||
127 | vle.setLegend(legendOriginal); |
||
128 | } |
||
129 | vea.getCommandRecord().addCommandListener(mapControl); |
||
130 | // Si existe una tabla asociada a esta capa se cambia su
|
||
131 | // modelo por el VectorialEditableAdapter.
|
||
132 | ProjectExtension pe = (ProjectExtension) PluginServices |
||
133 | .getExtension(ProjectExtension.class); |
||
134 | ProjectTable pt = pe.getProject().getTable(lv); |
||
135 | if (pt != null){ |
||
136 | pt.setModel(vea); |
||
137 | 11355 | caballero | changeModelTable(pt,vea); |
138 | 30185 | vcaballero | if(lv.isJoined()){
|
139 | pt.restoreDataSource(); |
||
140 | } |
||
141 | 9371 | jmvivo | } |
142 | 10626 | caballero | |
143 | 9371 | jmvivo | startCommandsApplicable(vista,lv); |
144 | 15602 | vcaballero | vista.repaintMap(); |
145 | 10626 | caballero | |
146 | } catch (XMLException e) {
|
||
147 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
148 | 10626 | caballero | } catch (StartEditionLayerException e) {
|
149 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
150 | 10626 | caballero | } catch (ReadDriverException e) {
|
151 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
152 | 30185 | vcaballero | } catch (DriverLoadException e) {
|
153 | NotificationManager.addError(e.getMessage(),e); |
||
154 | 4727 | fjp | } |
155 | 10626 | caballero | |
156 | 9371 | jmvivo | // return;
|
157 | 4727 | fjp | } |
158 | } |
||
159 | 10626 | caballero | |
160 | 9371 | jmvivo | /*
|
161 | * PluginServices.getMDIManager().setWaitCursor(); try { if
|
||
162 | * (((FLyrVect) capa).getSource().getDriver().getClass() ==
|
||
163 | * DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
|
||
164 | * (Component) PluginServices.getMainFrame(), "Todas las geometr?as
|
||
165 | * del formato DXF no se pueden editar, de momento podemos editar:
|
||
166 | * Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
|
||
167 | * geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
|
||
168 | * JOptionPane.YES_OPTION) { capa.startEdition();
|
||
169 | * vista.getMapControl().setCadTool("selection"); } else { } } else {
|
||
170 | * capa.startEdition();
|
||
171 | * vista.getMapControl().setCadTool("selection"); } } catch
|
||
172 | * (EditionException e) { // TODO Auto-generated catch block
|
||
173 | * e.printStackTrace(); }
|
||
174 | * PluginServices.getMDIManager().restoreCursor();
|
||
175 | */
|
||
176 | // vista.getMapControl().drawMap(false);
|
||
177 | 4727 | fjp | } |
178 | 9371 | jmvivo | |
179 | 5845 | fjp | // private void registerKeyStrokes() {
|
180 | // JComponent theComponent = vista.getConsolePanel().getTxt();
|
||
181 | 6312 | caballero | //
|
182 | 5845 | fjp | // // The actions
|
183 | // Action F3Action = new AbstractAction("REFENT") {
|
||
184 | // public void actionPerformed(ActionEvent evt) {
|
||
185 | // System.err.println("SOY F3");
|
||
186 | // }
|
||
187 | // };
|
||
188 | //
|
||
189 | // InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||
190 | // inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
|
||
191 | //
|
||
192 | // ActionMap actionMap = theComponent.getActionMap();
|
||
193 | 6312 | caballero | // // actionMap.put("REFENT", new MyAction());
|
194 | 5845 | fjp | // actionMap.put(F3Action.getValue(Action.NAME), F3Action);
|
195 | 6312 | caballero | //
|
196 | 5845 | fjp | // }
|
197 | |||
198 | public static void startCommandsApplicable(View vista,FLyrVect lv) { |
||
199 | 5207 | caballero | if (vista==null) |
200 | 6880 | cesar | vista=(View)PluginServices.getMDIManager().getActiveWindow();
|
201 | 5177 | caballero | CADTool[] cadtools = CADExtension.getCADTools();
|
202 | KeywordMap keywordMap = new KeywordMap(true); |
||
203 | for (int i = 0; i < cadtools.length; i++) { |
||
204 | try {
|
||
205 | if (cadtools[i].isApplicable(lv.getShapeType())){
|
||
206 | keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
||
207 | keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
||
208 | } |
||
209 | 10626 | caballero | } catch (ReadDriverException e) {
|
210 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
211 | 5177 | caballero | } |
212 | |||
213 | } |
||
214 | ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
||
215 | vista.getConsolePanel().setTokenMarker(consoletoken); |
||
216 | |||
217 | } |
||
218 | |||
219 | 23993 | vcaballero | protected void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){ |
220 | 11355 | caballero | com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
221 | 3698 | caballero | |
222 | 11355 | caballero | for (int i=0 ; i<views.length ; i++){ |
223 | if (views[i] instanceof Table){ |
||
224 | Table table=(Table)views[i]; |
||
225 | ProjectTable model =table.getModel(); |
||
226 | if (model.equals(pt)){
|
||
227 | table.setModel(pt); |
||
228 | vea.getCommandRecord().addCommandListener(table); |
||
229 | } |
||
230 | } |
||
231 | } |
||
232 | } |
||
233 | 4727 | fjp | /**
|
234 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
235 | 4727 | fjp | */
|
236 | public boolean isEnabled() { |
||
237 | 6880 | cesar | View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
238 | 3698 | caballero | |
239 | 3808 | fjp | if (f == null) { |
240 | return false; |
||
241 | } |
||
242 | 3698 | caballero | |
243 | 4727 | fjp | FLayer[] selected = f.getModel().getMapContext().getLayers()
|
244 | .getActives(); |
||
245 | 6779 | jmvivo | if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
246 | 31304 | vcaballero | if (((FLyrVect)selected[0]).isJoined()){ |
247 | return false; |
||
248 | } |
||
249 | 6604 | caballero | return true; |
250 | 3808 | fjp | } |
251 | return false; |
||
252 | 4727 | fjp | } |
253 | 3698 | caballero | |
254 | 4727 | fjp | /**
|
255 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
256 | 4727 | fjp | */
|
257 | public boolean isVisible() { |
||
258 | 31407 | vcaballero | IWindow f = (IWindow) PluginServices.getMDIManager().getActiveWindow(); |
259 | 3698 | caballero | |
260 | 4727 | fjp | if (f == null) { |
261 | return false; |
||
262 | } |
||
263 | 31403 | vcaballero | if (f instanceof View){ |
264 | View view=(View)f; |
||
265 | FLayer[] selected = view.getModel().getMapContext().getLayers()
|
||
266 | .getActives(); |
||
267 | if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
||
268 | if (selected[0].isEditing()) |
||
269 | return false; |
||
270 | return true; |
||
271 | } |
||
272 | } |
||
273 | 6604 | caballero | return false; |
274 | 4727 | fjp | } |
275 | 3698 | caballero | } |