Statistics
| Revision:

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

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

    
24

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

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

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

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

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

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

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

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

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

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

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

    
97
//                                        if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){
98
//                                                VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv);
99
//                                                vle.setLegend(legendOriginal);
100
//                                        }
101
                                        lv.getFeatureStore().addObserver(mapControl);
102
//                                        vea.getCommandRecord().addCommandListener(mapControl);
103
                                        // Si existe una tabla asociada a esta capa se cambia su
104
                                        // modelo por el VectorialEditableAdapter.
105
                                        ProjectExtension pe = (ProjectExtension) PluginServices
106
                                        .getExtension(ProjectExtension.class);
107

    
108
                                        startCommandsApplicable(vista,lv);
109
                                        vista.repaintMap();
110

    
111
                                } catch (StartEditionLayerException e) {
112
                                        NotificationManager.addError(e.getMessage(),e);
113
//                                } catch (ReadException e) {
114
//                                        NotificationManager.addError(e.getMessage(),e);
115
//                                } catch (DataException e) {
116
//                                        NotificationManager.addError(e.getMessage(),e);
117
                                }
118

    
119
//                                return;
120
                        }
121
                }
122

    
123
                /*
124
                 * PluginServices.getMDIManager().setWaitCursor(); try { if
125
                 * (((FLyrVect) capa).getSource().getDriver().getClass() ==
126
                 * DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
127
                 * (Component) PluginServices.getMainFrame(), "Todas las geometr?as
128
                 * del formato DXF no se pueden editar, de momento podemos editar:
129
                 * Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
130
                 * geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
131
                 * JOptionPane.YES_OPTION) { capa.startEdition();
132
                 * vista.getMapControl().setCadTool("selection"); } else { } } else {
133
                 * capa.startEdition();
134
                 * vista.getMapControl().setCadTool("selection"); } } catch
135
                 * (EditionException e) { // TODO Auto-generated catch block
136
                 * e.printStackTrace(); }
137
                 * PluginServices.getMDIManager().restoreCursor();
138
                 */
139
                // vista.getMapControl().drawMap(false);
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
                CADTool[] cadtools = CADExtension.getCADTools();
163
                KeywordMap keywordMap = new KeywordMap(true);
164
                for (int i = 0; i < cadtools.length; i++) {
165
                        try {
166
                                if (cadtools[i].isApplicable(lv.getShapeType())){
167
                                        keywordMap.add(cadtools[i].getName(), Token.KEYWORD2);
168
                                        keywordMap.add(cadtools[i].toString(), Token.KEYWORD3);
169
                                }
170
                        } catch (ReadException e) {
171
                                NotificationManager.addError(e.getMessage(),e);
172
                        }
173

    
174
                }
175
                ConsoleToken consoletoken = new ConsoleToken(keywordMap);
176
                vista.getConsolePanel().setTokenMarker(consoletoken);
177

    
178
        }
179

    
180
//        private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
181
//            com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
182
//
183
//                for (int i=0 ; i<views.length ; i++){
184
//                        if (views[i] instanceof Table){
185
//                                Table table=(Table)views[i];
186
//                                ProjectTable model =table.getModel();
187
//                                if (model.equals(pt)){
188
//                                                table.setModel(pt);
189
//                                                vea.getCommandRecord().addCommandListener(table);
190
//                                }
191
//                        }
192
//                }
193
//   }
194
        /**
195
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
196
         */
197
        public boolean isEnabled() {
198
                return true;
199
        }
200

    
201
        /**
202
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
203
         */
204
        public boolean isVisible() {
205
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
206
                                .getActiveWindow();
207

    
208
                if (f == null) {
209
                        return false;
210
                }
211
                if (f instanceof DefaultViewPanel){
212
                        DefaultViewPanel view=(DefaultViewPanel)f;
213
                        FLayer[] selected = view.getModel().getMapContext().getLayers()
214
                        .getActives();
215
                        if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) {
216
                                if (selected[0].isEditing())
217
                                        return false;
218
                                return true;
219
                        }
220
                }
221
                return false;
222
        }
223
}