Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / StartEditing.java @ 30335

History | View | Annotate | Download (7.51 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.FeatureTableDocument;
12
import org.gvsig.app.project.documents.view.IProjectView;
13
import org.gvsig.app.project.documents.view.gui.View;
14
import org.gvsig.editing.gui.cad.CADTool;
15
import org.gvsig.editing.gui.tokenmarker.ConsoleToken;
16
import org.gvsig.fmap.dal.exception.DataException;
17
import org.gvsig.fmap.dal.exception.ReadException;
18
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
19
import org.gvsig.fmap.mapcontext.layers.FLayer;
20
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
21
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
22
import org.gvsig.fmap.mapcontrol.MapControl;
23
import org.gvsig.utils.XMLException;
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 class MyAction extends AbstractAction
36
//        {
37
//
38
//                public void actionPerformed(ActionEvent e) {
39
//                        System.err.println("F3");
40
//                }
41
//
42
//        }
43

    
44
        //View vista;
45
        /**
46
         * @see org.gvsig.andami.plugins.IExtension#initialize()
47
         */
48
        public void initialize() {
49
        }
50

    
51
        /**
52
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
53
         */
54
        public void execute(String actionCommand) {
55
                CADExtension.initFocus();
56
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
57
                .getActiveWindow();
58

    
59
                if (f instanceof View) {
60
                        View vista = (View) f;
61

    
62
                        MapControl mapControl = vista.getMapControl();
63
                        mapControl.enableSnapping();
64
                        IProjectView model = vista.getModel();
65
                        FLayer[] actives = model.getMapContext().getLayers().getActives();
66

    
67
                        boolean bEditingStarted = false;
68
                        if (actives.length == 1 &&        actives[0] instanceof FLyrVect) {
69

    
70
                                vista.showConsole();
71
                                EditionManager editionManager=CADExtension.getEditionManager();
72
                                editionManager.setMapControl(mapControl);
73
                                /*
74
                                 * for (int j = 0; j < i; j++) {
75
                                 * layers.getLayer(j).setVisible(false); }
76
                                 */
77

    
78
                                FLyrVect lv = (FLyrVect) actives[0];
79
                                // lv.setVisible(true);
80
                                lv.addLayerListener(editionManager);
81
                                try {
82
                                        ILegend legendOriginal=lv.getLegend().cloneLegend();
83

    
84
                                        if (!lv.isWritable())
85
                                        {
86
                                                JOptionPane.showMessageDialog(
87
                                                                (Component) PluginServices.getMDIManager().getActiveWindow(),
88
                                                                PluginServices.getText(this, "this_layer_is_not_self_editable"),
89
                                                                PluginServices.getText(this, "warning_title"),
90
                                                                JOptionPane.WARNING_MESSAGE);
91
                                        }
92

    
93
                                        lv.setEditing(true);
94
//                                        FeatureType featureType=lv.getFeatureStore().getDefaultFeatureType();
95
//                                        featureType.getRules().clear();
96
//                                        if (lv.getShapeType()==Geometry.TYPES.SURFACE){
97
//                                                FeatureRule rulePol = new FeatureRulePolygon("PolygonRule", "Sentido correcto de un pol?gono");
98
//                                                featureType.addRule(rulePol);
99
//                                        }
100

    
101
//                                        if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){
102
//                                                VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv);
103
//                                                vle.setLegend(legendOriginal);
104
//                                        }
105
                                        lv.getFeatureStore().addObserver(mapControl);
106
//                                        vea.getCommandRecord().addCommandListener(mapControl);
107
                                        // Si existe una tabla asociada a esta capa se cambia su
108
                                        // modelo por el VectorialEditableAdapter.
109
                                        ProjectExtension pe = (ProjectExtension) PluginServices
110
                                        .getExtension(ProjectExtension.class);
111
                                        FeatureTableDocument pt = pe.getProject().getTable(lv);
112
                                        if (pt != null){
113
                                                pt.setStore(lv.getFeatureStore());
114
//                                                changeModelTable(pt,vea);
115
                                        }
116

    
117
                                        startCommandsApplicable(vista,lv);
118
                                        vista.repaintMap();
119

    
120
                                } catch (StartEditionLayerException e) {
121
                                        NotificationManager.addError(e.getMessage(),e);
122
//                                } catch (ReadException e) {
123
//                                        NotificationManager.addError(e.getMessage(),e);
124
//                                } catch (DataException e) {
125
//                                        NotificationManager.addError(e.getMessage(),e);
126
                                }
127

    
128
//                                return;
129
                        }
130
                }
131

    
132
                /*
133
                 * PluginServices.getMDIManager().setWaitCursor(); try { if
134
                 * (((FLyrVect) capa).getSource().getDriver().getClass() ==
135
                 * DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
136
                 * (Component) PluginServices.getMainFrame(), "Todas las geometr?as
137
                 * del formato DXF no se pueden editar, de momento podemos editar:
138
                 * Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
139
                 * geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
140
                 * JOptionPane.YES_OPTION) { capa.startEdition();
141
                 * vista.getMapControl().setCadTool("selection"); } else { } } else {
142
                 * capa.startEdition();
143
                 * vista.getMapControl().setCadTool("selection"); } } catch
144
                 * (EditionException e) { // TODO Auto-generated catch block
145
                 * e.printStackTrace(); }
146
                 * PluginServices.getMDIManager().restoreCursor();
147
                 */
148
                // vista.getMapControl().drawMap(false);
149
        }
150

    
151
//         private void registerKeyStrokes() {
152
//                 JComponent theComponent = vista.getConsolePanel().getTxt();
153
//
154
//                 // The actions
155
//                 Action F3Action = new AbstractAction("REFENT") {
156
//                        public void actionPerformed(ActionEvent evt) {
157
//                                System.err.println("SOY F3");
158
//                        }
159
//                };
160
//
161
//                 InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
162
//                 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
163
//
164
//                 ActionMap actionMap = theComponent.getActionMap();
165
//                 // actionMap.put("REFENT", new MyAction());
166
//                 actionMap.put(F3Action.getValue(Action.NAME), F3Action);
167
//
168
//        }
169

    
170
        public static void startCommandsApplicable(View vista,FLyrVect lv) {
171
                if (vista==null)
172
                        vista=(View)PluginServices.getMDIManager().getActiveWindow();
173
                CADTool[] cadtools = CADExtension.getCADTools();
174
                KeywordMap keywordMap = new KeywordMap(true);
175
                for (int i = 0; i < cadtools.length; i++) {
176
                        try {
177
                                if (cadtools[i].isApplicable(lv.getShapeType())){
178
                                        keywordMap.add(cadtools[i].getName(), Token.KEYWORD2);
179
                                        keywordMap.add(cadtools[i].toString(), Token.KEYWORD3);
180
                                }
181
                        } catch (ReadException e) {
182
                                NotificationManager.addError(e.getMessage(),e);
183
                        }
184

    
185
                }
186
                ConsoleToken consoletoken = new ConsoleToken(keywordMap);
187
                vista.getConsolePanel().setTokenMarker(consoletoken);
188

    
189
        }
190

    
191
//        private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
192
//            com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
193
//
194
//                for (int i=0 ; i<views.length ; i++){
195
//                        if (views[i] instanceof Table){
196
//                                Table table=(Table)views[i];
197
//                                ProjectTable model =table.getModel();
198
//                                if (model.equals(pt)){
199
//                                                table.setModel(pt);
200
//                                                vea.getCommandRecord().addCommandListener(table);
201
//                                }
202
//                        }
203
//                }
204
//   }
205
        /**
206
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
207
         */
208
        public boolean isEnabled() {
209
                View f = (View) PluginServices.getMDIManager().getActiveWindow();
210

    
211
                if (f == null) {
212
                        return false;
213
                }
214

    
215
                FLayer[] selected = f.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
                return false;
223
        }
224

    
225
        /**
226
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
227
         */
228
        public boolean isVisible() {
229
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
230
                                .getActiveWindow();
231

    
232
                if (f == null) {
233
                        return false;
234
                }
235

    
236
                if (f instanceof View)
237
                        return true;
238
                return false;
239
        }
240
}