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