svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / StartEditing.java @ 40557
History | View | Annotate | Download (7.4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing; |
25 |
|
26 |
import java.awt.Component; |
27 |
|
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import org.slf4j.Logger; |
31 |
import org.slf4j.LoggerFactory; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.messages.Messages; |
35 |
import org.gvsig.andami.messages.NotificationManager; |
36 |
import org.gvsig.andami.plugins.Extension; |
37 |
import org.gvsig.app.ApplicationLocator; |
38 |
import org.gvsig.app.project.documents.view.ViewDocument; |
39 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
40 |
import org.gvsig.editing.gui.cad.CADTool; |
41 |
import org.gvsig.editing.gui.tokenmarker.ConsoleToken; |
42 |
import org.gvsig.fmap.dal.exception.DataException; |
43 |
import org.gvsig.fmap.dal.exception.ReadException; |
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
46 |
import org.gvsig.fmap.mapcontrol.MapControl; |
47 |
import org.gvsig.utils.console.jedit.KeywordMap; |
48 |
import org.gvsig.utils.console.jedit.Token; |
49 |
|
50 |
|
51 |
/**
|
52 |
* DOCUMENT ME!
|
53 |
*
|
54 |
* @author Vicente Caballero Navarro
|
55 |
*/
|
56 |
public class StartEditing extends Extension { |
57 |
|
58 |
private static Logger logger = LoggerFactory.getLogger(StartEditing.class); |
59 |
|
60 |
// private class MyAction extends AbstractAction
|
61 |
// {
|
62 |
//
|
63 |
// public void actionPerformed(ActionEvent e) {
|
64 |
// System.err.println("F3");
|
65 |
// }
|
66 |
//
|
67 |
// }
|
68 |
|
69 |
//View vista;
|
70 |
/**
|
71 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
72 |
*/
|
73 |
public void initialize() { |
74 |
} |
75 |
|
76 |
/**
|
77 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
78 |
*/
|
79 |
public void execute(String actionCommand) { |
80 |
|
81 |
if (actionCommand.compareTo("layer-start-editing") == 0) { |
82 |
|
83 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
84 |
PluginServices.getMDIManager().getActiveWindow(); |
85 |
|
86 |
if (f instanceof DefaultViewPanel) { |
87 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
88 |
|
89 |
MapControl mapControl = vista.getMapControl(); |
90 |
ViewDocument model = vista.getModel(); |
91 |
FLayer[] actives =
|
92 |
model.getMapContext().getLayers().getActives(); |
93 |
|
94 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
95 |
|
96 |
FLyrVect lv = (FLyrVect) actives[0];
|
97 |
|
98 |
if (!lv.getFeatureStore().getTransforms().isEmpty()) {
|
99 |
|
100 |
// cannot edit transformed
|
101 |
JOptionPane
|
102 |
.showMessageDialog( |
103 |
(Component) f,
|
104 |
Messages |
105 |
.get("_Cannot_start_edition_in_transformed_layer")
|
106 |
+ ": '" + lv.getName() + "'", |
107 |
PluginServices.getText(this, "warning_title"), |
108 |
JOptionPane.INFORMATION_MESSAGE);
|
109 |
return;
|
110 |
} |
111 |
|
112 |
if (!lv.isWritable()) {
|
113 |
JOptionPane.showMessageDialog((Component) f, |
114 |
PluginServices.getText(this,
|
115 |
"this_layer_is_not_self_editable"),
|
116 |
PluginServices.getText(this, "warning_title"), |
117 |
JOptionPane.WARNING_MESSAGE);
|
118 |
} |
119 |
|
120 |
IEditionManager editionManager = |
121 |
EditionLocator.getEditionManager(); |
122 |
|
123 |
try {
|
124 |
editionManager.editLayer(lv, vista); |
125 |
} catch (DataException e) {
|
126 |
|
127 |
logger.info( |
128 |
"Error while starting edition: " + e.getMessage(),
|
129 |
e); |
130 |
|
131 |
ApplicationLocator.getManager().message( |
132 |
Messages.get("_Unable_to_start_edition_in_layer")
|
133 |
+ ": " + lv.getName(),
|
134 |
JOptionPane.ERROR_MESSAGE);
|
135 |
} |
136 |
} |
137 |
} |
138 |
} |
139 |
} |
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 |
|
165 |
CADTool[] cadtools = CADExtension.getCADTools();
|
166 |
KeywordMap keywordMap = new KeywordMap(true); |
167 |
for (int i = 0; i < cadtools.length; i++) { |
168 |
try {
|
169 |
if (cadtools[i].isApplicable(lv.getShapeType())){
|
170 |
keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
171 |
keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
172 |
} |
173 |
} catch (ReadException e) {
|
174 |
NotificationManager.addError(e.getMessage(),e); |
175 |
} |
176 |
|
177 |
} |
178 |
ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
179 |
vista.getConsolePanel().setTokenMarker(consoletoken); |
180 |
|
181 |
} |
182 |
|
183 |
// private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
|
184 |
// com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
185 |
//
|
186 |
// for (int i=0 ; i<views.length ; i++){
|
187 |
// if (views[i] instanceof Table){
|
188 |
// Table table=(Table)views[i];
|
189 |
// ProjectTable model =table.getModel();
|
190 |
// if (model.equals(pt)){
|
191 |
// table.setModel(pt);
|
192 |
// vea.getCommandRecord().addCommandListener(table);
|
193 |
// }
|
194 |
// }
|
195 |
// }
|
196 |
// }
|
197 |
/**
|
198 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
199 |
*/
|
200 |
public boolean isEnabled() { |
201 |
return true; |
202 |
} |
203 |
|
204 |
/**
|
205 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
206 |
*/
|
207 |
public boolean isVisible() { |
208 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
209 |
.getActiveWindow(); |
210 |
|
211 |
if (f == null) { |
212 |
return false; |
213 |
} |
214 |
if (f instanceof DefaultViewPanel){ |
215 |
DefaultViewPanel view=(DefaultViewPanel)f; |
216 |
FLayer[] selected = view.getModel().getMapContext().getLayers()
|
217 |
.getActives(); |
218 |
if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
219 |
if (selected[0].isEditing()) |
220 |
return false; |
221 |
return true; |
222 |
} |
223 |
} |
224 |
return false; |
225 |
} |
226 |
} |