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