Statistics
| Revision:

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

History | View | Annotate | Download (7.18 KB)

1 29616 jpiera
package org.gvsig.editing;
2 3698 caballero
3 6856 fjp
import java.awt.Component;
4
5
import javax.swing.JOptionPane;
6
7 29616 jpiera
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 31496 jjdelcerro
import org.gvsig.app.project.documents.view.ViewDocument;
12
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
13 29616 jpiera
import org.gvsig.editing.gui.cad.CADTool;
14
import org.gvsig.editing.gui.tokenmarker.ConsoleToken;
15 24500 jmvivo
import org.gvsig.fmap.dal.exception.ReadException;
16 21666 vcaballero
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 29616 jpiera
import org.gvsig.utils.console.jedit.KeywordMap;
22
import org.gvsig.utils.console.jedit.Token;
23 21666 vcaballero
24 3698 caballero
25
/**
26
 * DOCUMENT ME!
27 4892 caballero
 *
28 3698 caballero
 * @author Vicente Caballero Navarro
29
 */
30 5005 jorpiell
public class StartEditing extends Extension {
31 6312 caballero
32 6604 caballero
//        private class MyAction extends AbstractAction
33
//        {
34
//
35
//                public void actionPerformed(ActionEvent e) {
36
//                        System.err.println("F3");
37
//                }
38
//
39
//        }
40 5845 fjp
41 9371 jmvivo
        //View vista;
42 4727 fjp
        /**
43 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#initialize()
44 4727 fjp
         */
45 5005 jorpiell
        public void initialize() {
46 4727 fjp
        }
47 3698 caballero
48 4727 fjp
        /**
49 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
50 4727 fjp
         */
51
        public void execute(String actionCommand) {
52 5087 caballero
                CADExtension.initFocus();
53 29616 jpiera
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
54 9371 jmvivo
                .getActiveWindow();
55 10626 caballero
56 31496 jjdelcerro
                if (f instanceof DefaultViewPanel) {
57
                        DefaultViewPanel vista = (DefaultViewPanel) f;
58 10626 caballero
59 6604 caballero
                        MapControl mapControl = vista.getMapControl();
60 31496 jjdelcerro
                        ViewDocument model = vista.getModel();
61 9371 jmvivo
                        FLayer[] actives = model.getMapContext().getLayers().getActives();
62 10626 caballero
63 6856 fjp
                        boolean bEditingStarted = false;
64 9371 jmvivo
                        if (actives.length == 1 &&        actives[0] instanceof FLyrVect) {
65 3698 caballero
66 9371 jmvivo
                                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 10626 caballero
74 9371 jmvivo
                                FLyrVect lv = (FLyrVect) actives[0];
75
                                // lv.setVisible(true);
76
                                lv.addLayerListener(editionManager);
77
                                try {
78 11558 jaume
                                        ILegend legendOriginal=lv.getLegend().cloneLegend();
79 10626 caballero
80 9371 jmvivo
                                        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 5152 fjp
                                        }
88 10626 caballero
89 9371 jmvivo
                                        lv.setEditing(true);
90 25563 vcaballero
//                                        FeatureType featureType=lv.getFeatureStore().getDefaultFeatureType();
91
//                                        featureType.getRules().clear();
92 23086 vcaballero
//                                        if (lv.getShapeType()==Geometry.TYPES.SURFACE){
93
//                                                FeatureRule rulePol = new FeatureRulePolygon("PolygonRule", "Sentido correcto de un pol?gono");
94
//                                                featureType.addRule(rulePol);
95
//                                        }
96 10626 caballero
97 22986 vcaballero
//                                        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 9371 jmvivo
                                        // 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 10626 caballero
108 9371 jmvivo
                                        startCommandsApplicable(vista,lv);
109 15602 vcaballero
                                        vista.repaintMap();
110 10626 caballero
111
                                } catch (StartEditionLayerException e) {
112 12739 caballero
                                        NotificationManager.addError(e.getMessage(),e);
113 30050 cordinyana
//                                } catch (ReadException e) {
114
//                                        NotificationManager.addError(e.getMessage(),e);
115
//                                } catch (DataException e) {
116
//                                        NotificationManager.addError(e.getMessage(),e);
117 4727 fjp
                                }
118 10626 caballero
119 9371 jmvivo
//                                return;
120 4727 fjp
                        }
121
                }
122 10626 caballero
123 9371 jmvivo
                /*
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 4727 fjp
        }
141 9371 jmvivo
142 5845 fjp
//         private void registerKeyStrokes() {
143
//                 JComponent theComponent = vista.getConsolePanel().getTxt();
144 6312 caballero
//
145 5845 fjp
//                 // 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 6312 caballero
//                 // actionMap.put("REFENT", new MyAction());
157 5845 fjp
//                 actionMap.put(F3Action.getValue(Action.NAME), F3Action);
158 6312 caballero
//
159 5845 fjp
//        }
160
161 31496 jjdelcerro
        public static void startCommandsApplicable(DefaultViewPanel vista,FLyrVect lv) {
162 5207 caballero
                if (vista==null)
163 31496 jjdelcerro
                        vista=(DefaultViewPanel)PluginServices.getMDIManager().getActiveWindow();
164 5177 caballero
                CADTool[] cadtools = CADExtension.getCADTools();
165
                KeywordMap keywordMap = new KeywordMap(true);
166
                for (int i = 0; i < cadtools.length; i++) {
167
                        try {
168
                                if (cadtools[i].isApplicable(lv.getShapeType())){
169
                                        keywordMap.add(cadtools[i].getName(), Token.KEYWORD2);
170
                                        keywordMap.add(cadtools[i].toString(), Token.KEYWORD3);
171
                                }
172 21666 vcaballero
                        } catch (ReadException e) {
173 12739 caballero
                                NotificationManager.addError(e.getMessage(),e);
174 5177 caballero
                        }
175
176
                }
177
                ConsoleToken consoletoken = new ConsoleToken(keywordMap);
178
                vista.getConsolePanel().setTokenMarker(consoletoken);
179
180
        }
181
182 22986 vcaballero
//        private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
183
//            com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
184
//
185
//                for (int i=0 ; i<views.length ; i++){
186
//                        if (views[i] instanceof Table){
187
//                                Table table=(Table)views[i];
188
//                                ProjectTable model =table.getModel();
189
//                                if (model.equals(pt)){
190
//                                                table.setModel(pt);
191
//                                                vea.getCommandRecord().addCommandListener(table);
192
//                                }
193
//                        }
194
//                }
195
//   }
196 4727 fjp
        /**
197 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
198 4727 fjp
         */
199
        public boolean isEnabled() {
200 31404 vcaballero
                return true;
201 4727 fjp
        }
202 3698 caballero
203 4727 fjp
        /**
204 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
205 4727 fjp
         */
206
        public boolean isVisible() {
207 29616 jpiera
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
208 6880 cesar
                                .getActiveWindow();
209 3698 caballero
210 4727 fjp
                if (f == null) {
211
                        return false;
212
                }
213 31496 jjdelcerro
                if (f instanceof DefaultViewPanel){
214
                        DefaultViewPanel view=(DefaultViewPanel)f;
215 31404 vcaballero
                        FLayer[] selected = view.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
                }
223 6604 caballero
                return false;
224 4727 fjp
        }
225 3698 caballero
}