Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / StartEditing.java @ 34145

History | View | Annotate | Download (7.47 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.TableDocument;
12
import org.gvsig.app.project.documents.view.ViewDocument;
13
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
14
import org.gvsig.editing.gui.cad.CADTool;
15
import org.gvsig.editing.gui.tokenmarker.ConsoleToken;
16
import org.gvsig.fmap.dal.exception.ReadException;
17
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
18
import org.gvsig.fmap.mapcontext.layers.FLayer;
19
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
20
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
21
import org.gvsig.fmap.mapcontrol.MapControl;
22
import org.gvsig.utils.console.jedit.KeywordMap;
23
import org.gvsig.utils.console.jedit.Token;
24

    
25

    
26
/**
27
 * DOCUMENT ME!
28
 *
29
 * @author Vicente Caballero Navarro
30
 */
31
public class StartEditing extends Extension {
32

    
33
//        private class MyAction extends AbstractAction
34
//        {
35
//
36
//                public void actionPerformed(ActionEvent e) {
37
//                        System.err.println("F3");
38
//                }
39
//
40
//        }
41

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

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

    
57
                if (f instanceof DefaultViewPanel) {
58
                        DefaultViewPanel vista = (DefaultViewPanel) f;
59

    
60
                        MapControl mapControl = vista.getMapControl();
61
                        ViewDocument model = vista.getModel();
62
                        FLayer[] actives = model.getMapContext().getLayers().getActives();
63

    
64
                        boolean bEditingStarted = false;
65
                        if (actives.length == 1 &&        actives[0] instanceof FLyrVect) {
66

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

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

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

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

    
98
//                                        if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){
99
//                                                VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv);
100
//                                                vle.setLegend(legendOriginal);
101
//                                        }
102
                                        lv.getFeatureStore().addObserver(mapControl);
103
//                                        vea.getCommandRecord().addCommandListener(mapControl);
104
                                        // Si existe una tabla asociada a esta capa se cambia su
105
                                        // modelo por el VectorialEditableAdapter.
106
                                        ProjectExtension pe = (ProjectExtension) PluginServices
107
                                        .getExtension(ProjectExtension.class);
108
                                        TableDocument pt = pe.getProject().getTable(lv);
109
                                        if (pt != null){
110
                                            if(pt.getStore() == null){
111
                                                    pt.setStore(lv.getFeatureStore());
112
//                                                    changeModelTable(pt,vea);
113
                                                    
114
                                            }                                                
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(DefaultViewPanel vista,FLyrVect lv) {
171
                if (vista==null)
172
                        vista=(DefaultViewPanel)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
                return true;
210
        }
211

    
212
        /**
213
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
214
         */
215
        public boolean isVisible() {
216
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
217
                                .getActiveWindow();
218

    
219
                if (f == null) {
220
                        return false;
221
                }
222
                if (f instanceof DefaultViewPanel){
223
                        DefaultViewPanel view=(DefaultViewPanel)f;
224
                        FLayer[] selected = view.getModel().getMapContext().getLayers()
225
                        .getActives();
226
                        if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) {
227
                                if (selected[0].isEditing())
228
                                        return false;
229
                                return true;
230
                        }
231
                }
232
                return false;
233
        }
234
}