Statistics
| Revision:

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

History | View | Annotate | Download (7.59 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.initializeSnapping();
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 (XMLException e) {
121
                                        NotificationManager.addError(e.getMessage(),e);
122
                                } catch (StartEditionLayerException e) {
123
                                        NotificationManager.addError(e.getMessage(),e);
124
                                } catch (ReadException e) {
125
                                        NotificationManager.addError(e.getMessage(),e);
126
                                } catch (DataException e) {
127
                                        NotificationManager.addError(e.getMessage(),e);
128
                                }
129

    
130
//                                return;
131
                        }
132
                }
133

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

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

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

    
187
                }
188
                ConsoleToken consoletoken = new ConsoleToken(keywordMap);
189
                vista.getConsolePanel().setTokenMarker(consoletoken);
190

    
191
        }
192

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

    
213
                if (f == null) {
214
                        return false;
215
                }
216

    
217
                FLayer[] selected = f.getModel().getMapContext().getLayers()
218
                                .getActives();
219
                if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) {
220
                        if (selected[0].isEditing())
221
                                return false;
222
                        return true;
223
                }
224
                return false;
225
        }
226

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

    
234
                if (f == null) {
235
                        return false;
236
                }
237

    
238
                if (f instanceof View)
239
                        return true;
240
                return false;
241
        }
242
}