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