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