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