root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / StartEditing.java @ 38705
History | View | Annotate | Download (6.96 KB)
1 |
package org.gvsig.editing; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
|
5 |
import javax.swing.JOptionPane; |
6 |
|
7 |
import org.slf4j.Logger; |
8 |
import org.slf4j.LoggerFactory; |
9 |
|
10 |
import org.gvsig.andami.PluginServices; |
11 |
import org.gvsig.andami.messages.Messages; |
12 |
import org.gvsig.andami.messages.NotificationManager; |
13 |
import org.gvsig.andami.plugins.Extension; |
14 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
15 |
import org.gvsig.app.ApplicationLocator; |
16 |
import org.gvsig.app.extension.ProjectExtension; |
17 |
import org.gvsig.app.project.documents.view.ViewDocument; |
18 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
19 |
import org.gvsig.editing.gui.cad.CADTool; |
20 |
import org.gvsig.editing.gui.tokenmarker.ConsoleToken; |
21 |
import org.gvsig.fmap.dal.exception.ReadException; |
22 |
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 |
import org.gvsig.utils.console.jedit.KeywordMap; |
28 |
import org.gvsig.utils.console.jedit.Token; |
29 |
|
30 |
|
31 |
/**
|
32 |
* DOCUMENT ME!
|
33 |
*
|
34 |
* @author Vicente Caballero Navarro
|
35 |
*/
|
36 |
public class StartEditing extends Extension { |
37 |
|
38 |
private static Logger logger = LoggerFactory.getLogger(StartEditing.class); |
39 |
|
40 |
// private class MyAction extends AbstractAction
|
41 |
// {
|
42 |
//
|
43 |
// public void actionPerformed(ActionEvent e) {
|
44 |
// System.err.println("F3");
|
45 |
// }
|
46 |
//
|
47 |
// }
|
48 |
|
49 |
//View vista;
|
50 |
/**
|
51 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
52 |
*/
|
53 |
public void initialize() { |
54 |
} |
55 |
|
56 |
/**
|
57 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
58 |
*/
|
59 |
public void execute(String actionCommand) { |
60 |
|
61 |
if (actionCommand.compareTo("layer-start-editing") == 0) { |
62 |
|
63 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
64 |
PluginServices.getMDIManager().getActiveWindow(); |
65 |
|
66 |
if (f instanceof DefaultViewPanel) { |
67 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
68 |
|
69 |
MapControl mapControl = vista.getMapControl(); |
70 |
ViewDocument model = vista.getModel(); |
71 |
FLayer[] actives =
|
72 |
model.getMapContext().getLayers().getActives(); |
73 |
|
74 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
75 |
|
76 |
FLyrVect lv = (FLyrVect) actives[0];
|
77 |
|
78 |
if (!lv.getFeatureStore().getTransforms().isEmpty()) {
|
79 |
|
80 |
// cannot edit transformed
|
81 |
JOptionPane
|
82 |
.showMessageDialog( |
83 |
(Component) f,
|
84 |
Messages |
85 |
.get("_Cannot_start_edition_in_transformed_layer")
|
86 |
+ ": '" + lv.getName() + "'", |
87 |
PluginServices.getText(this, "warning_title"), |
88 |
JOptionPane.INFORMATION_MESSAGE);
|
89 |
return;
|
90 |
} |
91 |
|
92 |
CADExtension.initFocus(); |
93 |
vista.showConsole(); |
94 |
EditionManager editionManager = |
95 |
CADExtension.getEditionManager(); |
96 |
editionManager.setMapControl(mapControl); |
97 |
|
98 |
lv.addLayerListener(editionManager); |
99 |
try {
|
100 |
if (!lv.isWritable()) {
|
101 |
JOptionPane.showMessageDialog((Component) f, |
102 |
PluginServices.getText(this,
|
103 |
"this_layer_is_not_self_editable"),
|
104 |
PluginServices.getText(this, "warning_title"), |
105 |
JOptionPane.WARNING_MESSAGE);
|
106 |
} |
107 |
lv.setEditing(true);
|
108 |
lv.getFeatureStore().addObserver(mapControl); |
109 |
startCommandsApplicable(vista, lv); |
110 |
vista.repaintMap(); |
111 |
|
112 |
} catch (StartEditionLayerException e) {
|
113 |
|
114 |
logger.info( |
115 |
"Error while starting edition: " + e.getMessage(),
|
116 |
e); |
117 |
|
118 |
ApplicationLocator.getManager().message( |
119 |
Messages.get("_Unable_to_start_edition_in_layer")
|
120 |
+ ": " + lv.getName(),
|
121 |
JOptionPane.ERROR_MESSAGE);
|
122 |
} |
123 |
} |
124 |
} |
125 |
} |
126 |
} |
127 |
|
128 |
// private void registerKeyStrokes() {
|
129 |
// JComponent theComponent = vista.getConsolePanel().getTxt();
|
130 |
//
|
131 |
// // The actions
|
132 |
// Action F3Action = new AbstractAction("REFENT") {
|
133 |
// public void actionPerformed(ActionEvent evt) {
|
134 |
// System.err.println("SOY F3");
|
135 |
// }
|
136 |
// };
|
137 |
//
|
138 |
// InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
139 |
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
|
140 |
//
|
141 |
// ActionMap actionMap = theComponent.getActionMap();
|
142 |
// // actionMap.put("REFENT", new MyAction());
|
143 |
// actionMap.put(F3Action.getValue(Action.NAME), F3Action);
|
144 |
//
|
145 |
// }
|
146 |
|
147 |
public static void startCommandsApplicable(DefaultViewPanel vista,FLyrVect lv) { |
148 |
if (vista==null) |
149 |
vista=(DefaultViewPanel)PluginServices.getMDIManager().getActiveWindow(); |
150 |
|
151 |
CADTool[] cadtools = CADExtension.getCADTools();
|
152 |
KeywordMap keywordMap = new KeywordMap(true); |
153 |
for (int i = 0; i < cadtools.length; i++) { |
154 |
try {
|
155 |
if (cadtools[i].isApplicable(lv.getShapeType())){
|
156 |
keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
157 |
keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
158 |
} |
159 |
} catch (ReadException e) {
|
160 |
NotificationManager.addError(e.getMessage(),e); |
161 |
} |
162 |
|
163 |
} |
164 |
ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
165 |
vista.getConsolePanel().setTokenMarker(consoletoken); |
166 |
|
167 |
} |
168 |
|
169 |
// private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
|
170 |
// com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
171 |
//
|
172 |
// for (int i=0 ; i<views.length ; i++){
|
173 |
// if (views[i] instanceof Table){
|
174 |
// Table table=(Table)views[i];
|
175 |
// ProjectTable model =table.getModel();
|
176 |
// if (model.equals(pt)){
|
177 |
// table.setModel(pt);
|
178 |
// vea.getCommandRecord().addCommandListener(table);
|
179 |
// }
|
180 |
// }
|
181 |
// }
|
182 |
// }
|
183 |
/**
|
184 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
185 |
*/
|
186 |
public boolean isEnabled() { |
187 |
return true; |
188 |
} |
189 |
|
190 |
/**
|
191 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
192 |
*/
|
193 |
public boolean isVisible() { |
194 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
195 |
.getActiveWindow(); |
196 |
|
197 |
if (f == null) { |
198 |
return false; |
199 |
} |
200 |
if (f instanceof DefaultViewPanel){ |
201 |
DefaultViewPanel view=(DefaultViewPanel)f; |
202 |
FLayer[] selected = view.getModel().getMapContext().getLayers()
|
203 |
.getActives(); |
204 |
if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
205 |
if (selected[0].isEditing()) |
206 |
return false; |
207 |
return true; |
208 |
} |
209 |
} |
210 |
return false; |
211 |
} |
212 |
} |