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